Merge pull request #8731 from cooperbenson-qz/cooperbenson-qz/issue8525
Allow manual refresh of file enties
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog': patch
|
||||
---
|
||||
|
||||
Allow entities from `file` locations to be manually refreshed through the UI
|
||||
@@ -43,6 +43,10 @@ describe('<AboutCard />', () => {
|
||||
refreshEntity: jest.fn(),
|
||||
} as any;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('renders info', async () => {
|
||||
const entity = {
|
||||
apiVersion: 'v1',
|
||||
@@ -248,14 +252,16 @@ describe('<AboutCard />', () => {
|
||||
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('<AboutCard />', () => {
|
||||
);
|
||||
});
|
||||
|
||||
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',
|
||||
|
||||
@@ -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 && (
|
||||
<IconButton
|
||||
aria-label="Refresh"
|
||||
title="Schedule entity refresh"
|
||||
|
||||
Reference in New Issue
Block a user