Catalog: Update AboutCard to only render refresh for url locations
Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user