From e1953909748fa014f6c8ea35fec0d1e6f532bb52 Mon Sep 17 00:00:00 2001 From: Cooper Benson Date: Mon, 3 Jan 2022 10:14:03 -0700 Subject: [PATCH 1/2] Allow manual refresh of file enties Signed-off-by: Cooper Benson --- .changeset/wicked-weeks-knock.md | 5 +++++ .../src/components/AboutCard/AboutCard.test.tsx | 14 ++++++++++---- .../catalog/src/components/AboutCard/AboutCard.tsx | 8 +++++--- 3 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 .changeset/wicked-weeks-knock.md diff --git a/.changeset/wicked-weeks-knock.md b/.changeset/wicked-weeks-knock.md new file mode 100644 index 0000000000..9ae36a021d --- /dev/null +++ b/.changeset/wicked-weeks-knock.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog': patch +--- + +Allow enties from file locations to be manually refreshed through the UI diff --git a/plugins/catalog/src/components/AboutCard/AboutCard.test.tsx b/plugins/catalog/src/components/AboutCard/AboutCard.test.tsx index afbed3bdc7..4ef97b3d46 100644 --- a/plugins/catalog/src/components/AboutCard/AboutCard.test.tsx +++ b/plugins/catalog/src/components/AboutCard/AboutCard.test.tsx @@ -43,6 +43,10 @@ describe('', () => { refreshEntity: jest.fn(), } as any; + beforeEach(() => { + jest.clearAllMocks(); + }); + it('renders info', async () => { const entity = { apiVersion: 'v1', @@ -248,14 +252,16 @@ describe('', () => { expect(getByText('View Source').closest('a')).not.toHaveAttribute('href'); }); - it('triggers a refresh', async () => { + it.each([ + 'url:https://backstage.io/catalog-info.yaml', + 'file:../../catalog-info.yaml', + ])('triggers a refresh for %s', async location => { const entity = { apiVersion: 'v1', kind: 'Component', metadata: { annotations: { - 'backstage.io/managed-by-location': - 'url:https://backstage.io/catalog-info.yaml', + 'backstage.io/managed-by-location': location, }, name: 'software', }, @@ -298,7 +304,7 @@ describe('', () => { ); }); - it('should not render refresh button if the location is not an url', async () => { + it('should not render refresh button if the location is not an url or file', async () => { const entity = { apiVersion: 'v1', kind: 'Component', diff --git a/plugins/catalog/src/components/AboutCard/AboutCard.tsx b/plugins/catalog/src/components/AboutCard/AboutCard.tsx index 7e44ae4efb..a6c9635db2 100644 --- a/plugins/catalog/src/components/AboutCard/AboutCard.tsx +++ b/plugins/catalog/src/components/AboutCard/AboutCard.tsx @@ -127,8 +127,10 @@ export function AboutCard({ variant }: AboutCardProps) { cardContentClass = classes.fullHeightCardContent; } - const isUrl = - entity.metadata.annotations?.[LOCATION_ANNOTATION]?.startsWith('url:'); + const entityLocation = entity.metadata.annotations?.[LOCATION_ANNOTATION]; + // Limiting the ability to manually refresh to the less expensive locations + const allowRefresh = + entityLocation?.startsWith('url:') || entityLocation?.startsWith('file:'); const refreshEntity = useCallback(async () => { await catalogApi.refreshEntity(stringifyEntityRef(entity)); alertApi.post({ message: 'Refresh scheduled', severity: 'info' }); @@ -140,7 +142,7 @@ export function AboutCard({ variant }: AboutCardProps) { title="About" action={ <> - {isUrl && ( + {allowRefresh && ( Date: Tue, 4 Jan 2022 10:29:17 +0100 Subject: [PATCH 2/2] Update changeset text for spelling Signed-off-by: Ben Lambert --- .changeset/wicked-weeks-knock.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/wicked-weeks-knock.md b/.changeset/wicked-weeks-knock.md index 9ae36a021d..26fdcc0508 100644 --- a/.changeset/wicked-weeks-knock.md +++ b/.changeset/wicked-weeks-knock.md @@ -2,4 +2,4 @@ '@backstage/plugin-catalog': patch --- -Allow enties from file locations to be manually refreshed through the UI +Allow entities from `file` locations to be manually refreshed through the UI