Merge pull request #7314 from backstage/jhaals/refresh-improvements

Catalog: Update AboutCard to only render refresh for url locations
This commit is contained in:
Johan Haals
2021-09-24 15:42:32 +02:00
committed by GitHub
3 changed files with 50 additions and 7 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog': patch
---
Update AboutCard to only render refresh button if the entity is managed by an url location.
@@ -220,6 +220,10 @@ describe('<AboutCard />', () => {
apiVersion: 'v1',
kind: 'Component',
metadata: {
annotations: {
'backstage.io/managed-by-location':
'url:https://backstage.io/catalog-info.yaml',
},
name: 'software',
},
spec: {
@@ -252,6 +256,35 @@ describe('<AboutCard />', () => {
);
});
it('should not render refresh button if the location is not an url', async () => {
const entity = {
apiVersion: 'v1',
kind: 'Component',
metadata: {
name: 'software',
},
spec: {
owner: 'guest',
type: 'service',
lifecycle: 'production',
},
};
const apis = ApiRegistry.with(
scmIntegrationsApiRef,
ScmIntegrationsApi.fromConfig(new ConfigReader({})),
).with(catalogApiRef, catalogApi);
const { queryByTitle } = await renderInTestApp(
<ApiProvider apis={apis}>
<EntityProvider entity={entity}>
<AboutCard />
</EntityProvider>
</ApiProvider>,
);
expect(queryByTitle('Schedule entity refresh')).not.toBeInTheDocument();
});
it('renders techdocs link', async () => {
const entity = {
apiVersion: 'v1',
@@ -17,6 +17,7 @@
import {
Entity,
ENTITY_DEFAULT_NAMESPACE,
LOCATION_ANNOTATION,
RELATION_CONSUMES_API,
RELATION_PROVIDES_API,
stringifyEntityRef,
@@ -147,6 +148,8 @@ export function AboutCard({ variant }: AboutCardProps) {
cardContentClass = classes.fullHeightCardContent;
}
const isUrl =
entity.metadata.annotations?.[LOCATION_ANNOTATION]?.startsWith('url:');
const refreshEntity = useCallback(async () => {
await catalogApi.refreshEntity(stringifyEntityRef(entity));
alertApi.post({ message: 'Refresh scheduled', severity: 'info' });
@@ -158,13 +161,15 @@ export function AboutCard({ variant }: AboutCardProps) {
title="About"
action={
<>
<IconButton
aria-label="Refresh"
title="Schedule entity refresh"
onClick={refreshEntity}
>
<CachedIcon />
</IconButton>
{isUrl && (
<IconButton
aria-label="Refresh"
title="Schedule entity refresh"
onClick={refreshEntity}
>
<CachedIcon />
</IconButton>
)}
<IconButton
component={Link}
aria-label="Edit"