From 4a99e6463d2c9cb8786bad750b1915b89c2b0c8a Mon Sep 17 00:00:00 2001
From: Brian Phillips <28457+brianphillips@users.noreply.github.com>
Date: Thu, 6 Jun 2024 07:05:29 -0500
Subject: [PATCH] deprecate all instances of the relationsType property in
favor of relationAggregation
Signed-off-by: Brian Phillips <28457+brianphillips@users.noreply.github.com>
---
.changeset/little-games-fail.md | 4 ++-
plugins/org/api-report.md | 8 +++--
.../Cards/OwnershipCard/ComponentsGrid.tsx | 12 +++++--
.../OwnershipCard/OwnershipCard.test.tsx | 2 +-
.../Cards/OwnershipCard/OwnershipCard.tsx | 31 +++++++++++--------
.../OwnershipCard/useGetEntities.test.ts | 4 +--
.../Cards/OwnershipCard/useGetEntities.ts | 10 +++---
7 files changed, 45 insertions(+), 26 deletions(-)
diff --git a/.changeset/little-games-fail.md b/.changeset/little-games-fail.md
index dc5d2f7795..199f983be8 100644
--- a/.changeset/little-games-fail.md
+++ b/.changeset/little-games-fail.md
@@ -2,4 +2,6 @@
'@backstage/plugin-org': patch
---
-Added relationship option to EntityMembersListCard component
+Added `relationType` property to EntityMembersListCard component that allows for display users related to a group via some other relationship aside from `memberOf`.
+
+Also, as a side effect, the `relationsType` property has been deprecated in favor of a more accurately named `relationAggregation` property.
diff --git a/plugins/org/api-report.md b/plugins/org/api-report.md
index fe641e5a8b..884832c111 100644
--- a/plugins/org/api-report.md
+++ b/plugins/org/api-report.md
@@ -23,8 +23,9 @@ export const EntityMembersListCard: (props: {
memberDisplayTitle?: string | undefined;
pageSize?: number | undefined;
showAggregateMembersToggle?: boolean | undefined;
- relationship?: string | undefined;
+ relationType?: string | undefined;
relationsType?: EntityRelationAggregation | undefined;
+ relationAggregation?: EntityRelationAggregation | undefined;
}) => JSX_2.Element;
// @public (undocumented)
@@ -33,6 +34,7 @@ export const EntityOwnershipCard: (props: {
entityFilterKind?: string[] | undefined;
hideRelationsToggle?: boolean | undefined;
relationsType?: EntityRelationAggregation | undefined;
+ relationAggregation?: EntityRelationAggregation | undefined;
entityLimit?: number | undefined;
}) => JSX_2.Element;
@@ -56,8 +58,9 @@ export const MembersListCard: (props: {
memberDisplayTitle?: string;
pageSize?: number;
showAggregateMembersToggle?: boolean;
- relationship?: string;
+ relationType?: string;
relationsType?: EntityRelationAggregation;
+ relationAggregation?: EntityRelationAggregation;
}) => React_2.JSX.Element;
// @public
@@ -84,6 +87,7 @@ export const OwnershipCard: (props: {
entityFilterKind?: string[];
hideRelationsToggle?: boolean;
relationsType?: EntityRelationAggregation;
+ relationAggregation?: EntityRelationAggregation;
entityLimit?: number;
}) => React_2.JSX.Element;
diff --git a/plugins/org/src/components/Cards/OwnershipCard/ComponentsGrid.tsx b/plugins/org/src/components/Cards/OwnershipCard/ComponentsGrid.tsx
index ff16a4ab2d..586e612e94 100644
--- a/plugins/org/src/components/Cards/OwnershipCard/ComponentsGrid.tsx
+++ b/plugins/org/src/components/Cards/OwnershipCard/ComponentsGrid.tsx
@@ -107,19 +107,27 @@ export const ComponentsGrid = ({
className,
entity,
relationsType,
+ relationAggregation,
entityFilterKind,
entityLimit = 6,
}: {
className?: string;
entity: Entity;
- relationsType: EntityRelationAggregation;
+ /** @deprecated Please use relationAggregation instead */
+ relationsType?: EntityRelationAggregation;
+ relationAggregation?: EntityRelationAggregation;
entityFilterKind?: string[];
entityLimit?: number;
}) => {
const catalogLink = useRouteRef(catalogIndexRouteRef);
+ if (!relationsType && !relationAggregation) {
+ throw new Error(
+ 'The relationAggregation property must be set as an EntityRelationAggregation type.',
+ );
+ }
const { componentsWithCounters, loading, error } = useGetEntities(
entity,
- relationsType,
+ (relationAggregation ?? relationsType)!, // we can safely use the non-null assertion here because of the run-time check above
entityFilterKind,
entityLimit,
);
diff --git a/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.test.tsx b/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.test.tsx
index f2b949f768..004fb8b964 100644
--- a/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.test.tsx
+++ b/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.test.tsx
@@ -288,7 +288,7 @@ describe('OwnershipCard', () => {
const { getByText } = await renderInTestApp(
-
+
,
{
diff --git a/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.tsx b/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.tsx
index a5b0b7bb19..fce47845bc 100644
--- a/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.tsx
+++ b/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.tsx
@@ -67,31 +67,34 @@ export const OwnershipCard = (props: {
variant?: InfoCardVariants;
entityFilterKind?: string[];
hideRelationsToggle?: boolean;
+ /** @deprecated Please use relationAggregation instead */
relationsType?: EntityRelationAggregation;
+ relationAggregation?: EntityRelationAggregation;
entityLimit?: number;
}) => {
const {
variant,
entityFilterKind,
hideRelationsToggle,
- relationsType,
entityLimit = 6,
} = props;
+ const relationAggregation = props.relationAggregation ?? props.relationsType;
const relationsToggle =
hideRelationsToggle === undefined ? false : hideRelationsToggle;
const classes = useStyles();
const { entity } = useEntity();
- const defaultRelationsType = entity.kind === 'User' ? 'aggregated' : 'direct';
- const [getRelationsType, setRelationsType] = useState(
- relationsType ?? defaultRelationsType,
+ const defaultRelationAggregation =
+ entity.kind === 'User' ? 'aggregated' : 'direct';
+ const [getRelationAggregation, setRelationAggregation] = useState(
+ relationAggregation ?? defaultRelationAggregation,
);
useEffect(() => {
- if (!relationsType) {
- setRelationsType(defaultRelationsType);
+ if (!relationAggregation) {
+ setRelationAggregation(defaultRelationAggregation);
}
- }, [setRelationsType, defaultRelationsType, relationsType]);
+ }, [setRelationAggregation, defaultRelationAggregation, relationAggregation]);
return (
{
- const updatedRelationsType =
- getRelationsType === 'direct' ? 'aggregated' : 'direct';
- setRelationsType(updatedRelationsType);
+ const updatedRelationAggregation =
+ getRelationAggregation === 'direct'
+ ? 'aggregated'
+ : 'direct';
+ setRelationAggregation(updatedRelationAggregation);
}}
name="pin"
inputProps={{ 'aria-label': 'Ownership Type Switch' }}
@@ -136,7 +141,7 @@ export const OwnershipCard = (props: {
className={classes.grid}
entity={entity}
entityLimit={entityLimit}
- relationsType={getRelationsType}
+ relationAggregation={getRelationAggregation}
entityFilterKind={entityFilterKind}
/>
diff --git a/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.test.ts b/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.test.ts
index eac5a171ba..c6cec557c1 100644
--- a/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.test.ts
+++ b/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.test.ts
@@ -64,7 +64,7 @@ describe('useGetEntities', () => {
]),
});
- describe('given aggregated relationsType', () => {
+ describe('given aggregated relationAggregation', () => {
const whenHookIsCalledWith = async (_entity: Entity) => {
const { result } = renderHook(
({ entity }) => useGetEntities(entity, 'aggregated'),
@@ -205,7 +205,7 @@ describe('useGetEntities', () => {
});
});
- describe('given direct relationsType', () => {
+ describe('given direct relationAggregation', () => {
const whenHookIsCalledWith = async (_entity: Entity) => {
const { result } = renderHook(
({ entity }) => useGetEntities(entity, 'direct'),
diff --git a/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts b/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts
index 5a708bcfee..d806bbfef2 100644
--- a/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts
+++ b/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts
@@ -125,11 +125,11 @@ const getChildOwnershipEntityRefs = async (
const getOwners = async (
entity: Entity,
- relations: EntityRelationAggregation,
+ relationAggregation: EntityRelationAggregation,
catalogApi: CatalogApi,
): Promise => {
const isGroup = entity.kind === 'Group';
- const isAggregated = relations === 'aggregated';
+ const isAggregated = relationAggregation === 'aggregated';
const isUserEntity = entity.kind === 'User';
if (isAggregated && isGroup) {
@@ -166,7 +166,7 @@ const getOwnedEntitiesByOwners = (
export function useGetEntities(
entity: Entity,
- relations: EntityRelationAggregation,
+ relationAggregation: EntityRelationAggregation,
entityFilterKind?: string[],
entityLimit = 6,
): {
@@ -189,7 +189,7 @@ export function useGetEntities(
error,
value: componentsWithCounters,
} = useAsync(async () => {
- const owners = await getOwners(entity, relations, catalogApi);
+ const owners = await getOwners(entity, relationAggregation, catalogApi);
const ownedEntitiesList = await getOwnedEntitiesByOwners(
owners,
@@ -230,7 +230,7 @@ export function useGetEntities(
kind: string;
queryParams: string;
}>;
- }, [catalogApi, entity, relations]);
+ }, [catalogApi, entity, relationAggregation]);
return {
componentsWithCounters,