From cb592bfce7fe67cfc885b11252d2a8747f22faf0 Mon Sep 17 00:00:00 2001 From: Andre Wanlin Date: Sun, 3 Apr 2022 15:27:38 -0500 Subject: [PATCH] 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 + + )}