deprecate all instances of the relationsType property in favor of relationAggregation

Signed-off-by: Brian Phillips <28457+brianphillips@users.noreply.github.com>
This commit is contained in:
Brian Phillips
2024-06-06 07:05:29 -05:00
parent 0391e693ba
commit 4a99e6463d
7 changed files with 45 additions and 26 deletions
+3 -1
View File
@@ -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.
+6 -2
View File
@@ -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;
@@ -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,
);
@@ -288,7 +288,7 @@ describe('OwnershipCard', () => {
const { getByText } = await renderInTestApp(
<TestApiProvider apis={[[catalogApiRef, catalogApi]]}>
<EntityProvider entity={userEntity}>
<OwnershipCard relationsType="aggregated" />
<OwnershipCard relationAggregation="aggregated" />
</EntityProvider>
</TestApiProvider>,
{
@@ -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 (
<InfoCard
@@ -112,16 +115,18 @@ export const OwnershipCard = (props: {
placement="top"
arrow
title={`${
getRelationsType === 'direct' ? 'Direct' : 'Aggregated'
getRelationAggregation === 'direct' ? 'Direct' : 'Aggregated'
} Relations`}
>
<Switch
color="primary"
checked={getRelationsType !== 'direct'}
checked={getRelationAggregation !== 'direct'}
onChange={() => {
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}
/>
</InfoCard>
@@ -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'),
@@ -125,11 +125,11 @@ const getChildOwnershipEntityRefs = async (
const getOwners = async (
entity: Entity,
relations: EntityRelationAggregation,
relationAggregation: EntityRelationAggregation,
catalogApi: CatalogApi,
): Promise<string[]> => {
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,