From bfb59673619fc275d1d04c348ceccb3a38bc7c05 Mon Sep 17 00:00:00 2001 From: Pascal Lukanek Date: Wed, 2 Nov 2022 19:09:28 +0100 Subject: [PATCH 1/6] [OwnershipCard] Add type as subtitle + adjust query params Signed-off-by: Pascal Lukanek --- .../components/Cards/OwnershipCard/ComponentsGrid.tsx | 4 ++++ .../Cards/OwnershipCard/OwnershipCard.test.tsx | 10 ++++++++-- .../components/Cards/OwnershipCard/useGetEntities.ts | 5 ++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/plugins/org/src/components/Cards/OwnershipCard/ComponentsGrid.tsx b/plugins/org/src/components/Cards/OwnershipCard/ComponentsGrid.tsx index 6f7680849c..c1522c1fd1 100644 --- a/plugins/org/src/components/Cards/OwnershipCard/ComponentsGrid.tsx +++ b/plugins/org/src/components/Cards/OwnershipCard/ComponentsGrid.tsx @@ -56,11 +56,13 @@ const useStyles = makeStyles((theme: BackstageTheme) => const EntityCountTile = ({ counter, type, + kind, name, url, }: { counter: number; type: string; + kind: string; name: string; url: string; }) => { @@ -80,6 +82,7 @@ const EntityCountTile = ({ {pluralize(name, counter)} + {kind != type && {kind}} ); @@ -116,6 +119,7 @@ export const ComponentsGrid = ({ { expect( queryByText(getByText('SYSTEM').parentElement!, '1'), ).toBeInTheDocument(); + expect( + queryByText(getByText('SYSTEM').parentElement!, 'System'), + ).not.toBeInTheDocument(); expect(getByText('OPENAPI')).toBeInTheDocument(); expect( queryByText(getByText('OPENAPI').parentElement!, '1'), ).toBeInTheDocument(); + expect( + queryByText(getByText('OPENAPI').parentElement!, 'API'), + ).toBeInTheDocument(); expect(() => getByText('LIBRARY')).toThrow(); }); @@ -246,7 +252,7 @@ describe('OwnershipCard', () => { expect(getByText('OPENAPI').closest('a')).toHaveAttribute( 'href', - '/create/?filters%5Bkind%5D=API&filters%5Btype%5D=openapi&filters%5Bowners%5D=my-team&filters%5Buser%5D=all', + '/create/?filters%5Bkind%5D=api&filters%5Btype%5D=openapi&filters%5Bowners%5D=my-team&filters%5Buser%5D=all', ); }); @@ -292,7 +298,7 @@ describe('OwnershipCard', () => { expect(getByText('OPENAPI').closest('a')).toHaveAttribute( 'href', - '/create/?filters%5Bkind%5D=API&filters%5Btype%5D=openapi&filters%5Bowners%5D=user%3Athe-user&filters%5Bowners%5D=my-team&filters%5Bowners%5D=custom%2Fsome-team&filters%5Buser%5D=all', + '/create/?filters%5Bkind%5D=api&filters%5Btype%5D=openapi&filters%5Bowners%5D=user%3Athe-user&filters%5Bowners%5D=my-team&filters%5Bowners%5D=custom%2Fsome-team&filters%5Buser%5D=all', ); }); diff --git a/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts b/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts index 7c0bb76e2e..77d5164830 100644 --- a/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts +++ b/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts @@ -49,7 +49,7 @@ const getQueryParams = ( humanizeEntityRef(parseEntityRef(owner), { defaultKind: 'group' }), ); const filters = { - kind, + kind: kind.toLowerCase(), type, owners, user: 'all', @@ -135,6 +135,7 @@ export function useGetEntities( | { counter: number; type: string; + kind: string; name: string; queryParams: string; }[] @@ -197,11 +198,13 @@ export function useGetEntities( return topN.map(topOwnedEntity => ({ counter: topOwnedEntity.count, type: topOwnedEntity.type, + kind: topOwnedEntity.kind, name: topOwnedEntity.type.toLocaleUpperCase('en-US'), queryParams: getQueryParams(owners, topOwnedEntity), })) as Array<{ counter: number; type: string; + kind: string; name: string; queryParams: string; }>; From 38dd29ea95aa1f70710f36b5f1b5ee9d15673bcc Mon Sep 17 00:00:00 2001 From: Pascal Lukanek Date: Wed, 2 Nov 2022 19:17:08 +0100 Subject: [PATCH 2/6] Add changeset Signed-off-by: Pascal Lukanek --- .changeset/stale-tools-yawn.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/stale-tools-yawn.md diff --git a/.changeset/stale-tools-yawn.md b/.changeset/stale-tools-yawn.md new file mode 100644 index 0000000000..b053d83acd --- /dev/null +++ b/.changeset/stale-tools-yawn.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-org': patch +--- + +Add entity type to the Ownership Cards. +Fix the query params for the links of the Ownership Cards so that the catalog page actually selects the right entity kind. From 08152905d2d34061b28c3187a9ae0f2e91ec45f8 Mon Sep 17 00:00:00 2001 From: Pascal Lukanek Date: Wed, 2 Nov 2022 20:42:33 +0100 Subject: [PATCH 3/6] Linting Signed-off-by: Pascal Lukanek --- .changeset/stale-tools-yawn.md | 3 +-- .../org/src/components/Cards/OwnershipCard/ComponentsGrid.tsx | 2 +- .../org/src/components/Cards/OwnershipCard/useGetEntities.ts | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.changeset/stale-tools-yawn.md b/.changeset/stale-tools-yawn.md index b053d83acd..ca933d70f4 100644 --- a/.changeset/stale-tools-yawn.md +++ b/.changeset/stale-tools-yawn.md @@ -2,5 +2,4 @@ '@backstage/plugin-org': patch --- -Add entity type to the Ownership Cards. -Fix the query params for the links of the Ownership Cards so that the catalog page actually selects the right entity kind. +Add entity kind to the Ownership Cards. Fix the query params for the links of the Ownership Cards so that the catalog page actually selects the right entity kind. diff --git a/plugins/org/src/components/Cards/OwnershipCard/ComponentsGrid.tsx b/plugins/org/src/components/Cards/OwnershipCard/ComponentsGrid.tsx index c1522c1fd1..ba037f791c 100644 --- a/plugins/org/src/components/Cards/OwnershipCard/ComponentsGrid.tsx +++ b/plugins/org/src/components/Cards/OwnershipCard/ComponentsGrid.tsx @@ -82,7 +82,7 @@ const EntityCountTile = ({ {pluralize(name, counter)} - {kind != type && {kind}} + {kind !== type && {kind}} ); diff --git a/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts b/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts index 77d5164830..3756e6827e 100644 --- a/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts +++ b/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts @@ -49,7 +49,7 @@ const getQueryParams = ( humanizeEntityRef(parseEntityRef(owner), { defaultKind: 'group' }), ); const filters = { - kind: kind.toLowerCase(), + kind: kind.toLocaleLowerCase('en-US'), type, owners, user: 'all', From 12ee4453faa883b6bf5d3913a4e1811750795b2d Mon Sep 17 00:00:00 2001 From: Pascal Lukanek Date: Wed, 2 Nov 2022 20:54:57 +0100 Subject: [PATCH 4/6] Spelling Signed-off-by: Pascal Lukanek --- .changeset/stale-tools-yawn.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/stale-tools-yawn.md b/.changeset/stale-tools-yawn.md index ca933d70f4..f0173c7dd7 100644 --- a/.changeset/stale-tools-yawn.md +++ b/.changeset/stale-tools-yawn.md @@ -2,4 +2,4 @@ '@backstage/plugin-org': patch --- -Add entity kind to the Ownership Cards. Fix the query params for the links of the Ownership Cards so that the catalog page actually selects the right entity kind. +Add entity kind to the Ownership Cards. Fix the query parameters for the links of the Ownership Cards so that the catalog page actually selects the right entity kind. From 964186628e719fed0c2cd6c7bad72fac39a6f2dd Mon Sep 17 00:00:00 2001 From: Pascal Lukanek Date: Wed, 9 Nov 2022 09:38:16 +0100 Subject: [PATCH 5/6] Move name calculation to the EntityCountTile itself Signed-off-by: Pascal Lukanek --- .../Cards/OwnershipCard/ComponentsGrid.tsx | 15 +++++++-------- .../Cards/OwnershipCard/useGetEntities.ts | 9 ++------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/plugins/org/src/components/Cards/OwnershipCard/ComponentsGrid.tsx b/plugins/org/src/components/Cards/OwnershipCard/ComponentsGrid.tsx index ba037f791c..f996342454 100644 --- a/plugins/org/src/components/Cards/OwnershipCard/ComponentsGrid.tsx +++ b/plugins/org/src/components/Cards/OwnershipCard/ComponentsGrid.tsx @@ -57,16 +57,16 @@ const EntityCountTile = ({ counter, type, kind, - name, url, }: { counter: number; - type: string; + type?: string; kind: string; - name: string; url: string; }) => { - const classes = useStyles({ type }); + const classes = useStyles({ type: type ?? kind }); + + const rawTitle = type ?? kind; return ( @@ -80,9 +80,9 @@ const EntityCountTile = ({ {counter} - {pluralize(name, counter)} + {pluralize(rawTitle.toLocaleUpperCase('en-US'), counter)} - {kind !== type && {kind}} + {type && {kind}} ); @@ -116,12 +116,11 @@ export const ComponentsGrid = ({ return ( {componentsWithCounters?.map(c => ( - + diff --git a/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts b/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts index 3756e6827e..b36c41c459 100644 --- a/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts +++ b/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts @@ -136,7 +136,6 @@ export function useGetEntities( counter: number; type: string; kind: string; - name: string; queryParams: string; }[] | undefined; @@ -174,16 +173,14 @@ export function useGetEntities( const counts = ownedEntitiesList.items.reduce( (acc: EntityTypeProps[], ownedEntity) => { const match = acc.find( - x => - x.kind === ownedEntity.kind && - x.type === (ownedEntity.spec?.type ?? ownedEntity.kind), + x => x.kind === ownedEntity.kind && x.type === ownedEntity.spec?.type, ); if (match) { match.count += 1; } else { acc.push({ kind: ownedEntity.kind, - type: ownedEntity.spec?.type?.toString() ?? ownedEntity.kind, + type: ownedEntity.spec?.type?.toString(), count: 1, }); } @@ -199,13 +196,11 @@ export function useGetEntities( counter: topOwnedEntity.count, type: topOwnedEntity.type, kind: topOwnedEntity.kind, - name: topOwnedEntity.type.toLocaleUpperCase('en-US'), queryParams: getQueryParams(owners, topOwnedEntity), })) as Array<{ counter: number; type: string; kind: string; - name: string; queryParams: string; }>; }, [catalogApi, entity, relationsType]); From 7869fab942c213c061656a41a66010f92f830e8a Mon Sep 17 00:00:00 2001 From: Pascal Lukanek Date: Wed, 9 Nov 2022 10:40:05 +0100 Subject: [PATCH 6/6] Type Signed-off-by: Pascal Lukanek --- .../org/src/components/Cards/OwnershipCard/useGetEntities.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts b/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts index b36c41c459..c928d9b55f 100644 --- a/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts +++ b/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts @@ -36,7 +36,7 @@ const limiter = limiterFactory(10); type EntityTypeProps = { kind: string; - type: string; + type?: string; count: number; };