From cb592bfce7fe67cfc885b11252d2a8747f22faf0 Mon Sep 17 00:00:00 2001 From: Andre Wanlin Date: Sun, 3 Apr 2022 15:27:38 -0500 Subject: [PATCH 1/3] Optionally hide OwnershipCard relation toggle Signed-off-by: Andre Wanlin --- .changeset/grumpy-parents-prove.md | 5 ++ plugins/org/api-report.md | 4 ++ .../OwnershipCard/OwnershipCard.test.tsx | 70 +++++++++++++++++++ .../Cards/OwnershipCard/OwnershipCard.tsx | 64 ++++++++++------- 4 files changed, 116 insertions(+), 27 deletions(-) create mode 100644 .changeset/grumpy-parents-prove.md diff --git a/.changeset/grumpy-parents-prove.md b/.changeset/grumpy-parents-prove.md new file mode 100644 index 0000000000..0d304c96f4 --- /dev/null +++ b/.changeset/grumpy-parents-prove.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-org': patch +--- + +Provides the ability to hide the relations toggle as well as setting a default relation type diff --git a/plugins/org/api-report.md b/plugins/org/api-report.md index 60d0b20ffc..5f71be44bc 100644 --- a/plugins/org/api-report.md +++ b/plugins/org/api-report.md @@ -25,6 +25,8 @@ export const EntityMembersListCard: (props: { export const EntityOwnershipCard: (props: { variant?: InfoCardVariants | undefined; entityFilterKind?: string[] | undefined; + hideRelationsToggle?: boolean | undefined; + relationsType?: string | undefined; }) => JSX.Element; // @public (undocumented) @@ -64,6 +66,8 @@ export { orgPlugin as plugin }; export const OwnershipCard: (props: { variant?: InfoCardVariants; entityFilterKind?: string[]; + hideRelationsToggle?: boolean; + relationsType?: string; }) => JSX.Element; // @public (undocumented) diff --git a/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.test.tsx b/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.test.tsx index dcaae2d4bf..298c921069 100644 --- a/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.test.tsx +++ b/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.test.tsx @@ -291,4 +291,74 @@ describe('OwnershipCard', () => { '/create/?filters%5Bkind%5D=API&filters%5Btype%5D=openapi&filters%5Bowners%5D%5B0%5D=the-user&filters%5Bowners%5D%5B1%5D=my-team&filters%5Buser%5D=all', ); }); + + describe('OwnershipCard relations', () => { + it('shows relations toggle', async () => { + const catalogApi: jest.Mocked = { + getEntities: jest.fn(), + } as any; + + catalogApi.getEntities.mockImplementation(getEntitiesMock); + + const { getByTitle } = await renderInTestApp( + + + + + , + { + mountedRoutes: { + '/create': catalogIndexRouteRef, + }, + }, + ); + + expect(getByTitle('Direct Relations')).toBeInTheDocument(); + }); + + it('hides relations toggle', async () => { + const catalogApi: jest.Mocked = { + getEntities: jest.fn(), + } as any; + + catalogApi.getEntities.mockImplementation(getEntitiesMock); + + const rendered = await renderInTestApp( + + + + + , + { + mountedRoutes: { + '/create': catalogIndexRouteRef, + }, + }, + ); + + expect(rendered.queryByText('Direct Relations')).toBeNull(); + }); + it('overrides relation type', async () => { + const catalogApi: jest.Mocked = { + getEntities: jest.fn(), + } as any; + + catalogApi.getEntities.mockImplementation(getEntitiesMock); + + const { getByTitle } = await renderInTestApp( + + + + + , + { + mountedRoutes: { + '/create': catalogIndexRouteRef, + }, + }, + ); + + expect(getByTitle('Aggregated Relations')).toBeInTheDocument(); + }); + }); }); diff --git a/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.tsx b/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.tsx index d29298e1a8..fa953ebd02 100644 --- a/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.tsx +++ b/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.tsx @@ -55,48 +55,58 @@ const useStyles = makeStyles(theme => ({ export const OwnershipCard = (props: { variant?: InfoCardVariants; entityFilterKind?: string[]; + hideRelationsToggle?: boolean; + relationsType?: string; }) => { - const { variant, entityFilterKind } = props; - + const { variant, entityFilterKind, hideRelationsToggle, relationsType } = + props; + const relationsToggle = + hideRelationsToggle === undefined ? false : hideRelationsToggle; const classes = useStyles(); const { entity } = useEntity(); const isGroup = entity.kind === 'Group'; - const [relationsType, setRelationsType] = useState('direct'); + const [getRelationsType, setRelationsType] = useState( + relationsType || 'direct', + ); return ( - - Direct Relations - - - relationsType === 'direct' - ? setRelationsType('aggregated') - : setRelationsType('direct') - } - name="pin" - inputProps={{ 'aria-label': 'Ownership Type Switch' }} - disabled={!isGroup} - /> - - Aggregated Relations - + Direct Relations + + + getRelationsType === 'direct' + ? setRelationsType('aggregated') + : setRelationsType('direct') + } + name="pin" + inputProps={{ 'aria-label': 'Ownership Type Switch' }} + disabled={!isGroup} + /> + + Aggregated Relations + + )} From 8d3f09e88cc56382782ded636a386b7be64c9b8a Mon Sep 17 00:00:00 2001 From: Andre Wanlin Date: Sun, 3 Apr 2022 15:39:56 -0500 Subject: [PATCH 2/3] Improved changeset note Signed-off-by: Andre Wanlin --- .changeset/grumpy-parents-prove.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.changeset/grumpy-parents-prove.md b/.changeset/grumpy-parents-prove.md index 0d304c96f4..ff01fe13f0 100644 --- a/.changeset/grumpy-parents-prove.md +++ b/.changeset/grumpy-parents-prove.md @@ -2,4 +2,24 @@ '@backstage/plugin-org': patch --- -Provides the ability to hide the relations toggle as well as setting a default relation type +Provides the ability to hide the relations toggle on the `OwnershipCard` as well as setting a default relation type. + +To hide the toggle simply include the `hideRelationsToggle` prop like this: + +```tsx + +``` + +To set the default relation type, add the `relationsType` prop with a value of direct or aggregated, the default if not provided is direct. Here is an example: + +```tsx + +``` From 724522c79cd3daa3d31fbd9509c1ced1f0fd6225 Mon Sep 17 00:00:00 2001 From: Andre Wanlin Date: Sun, 3 Apr 2022 15:46:13 -0500 Subject: [PATCH 3/3] Tighten up when hiddent Signed-off-by: Andre Wanlin --- .../Cards/OwnershipCard/OwnershipCard.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.tsx b/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.tsx index fa953ebd02..1cb52a4762 100644 --- a/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.tsx +++ b/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.tsx @@ -71,10 +71,10 @@ export const OwnershipCard = (props: { return ( - - - - {!relationsToggle && ( + {!relationsToggle && ( + + + @@ -101,9 +101,9 @@ export const OwnershipCard = (props: { Aggregated Relations - )} - - + + + )}