diff --git a/.changeset/wicked-weeks-knock.md b/.changeset/wicked-weeks-knock.md new file mode 100644 index 0000000000..26fdcc0508 --- /dev/null +++ b/.changeset/wicked-weeks-knock.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog': patch +--- + +Allow entities 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 && (