diff --git a/plugins/org/src/components/Cards/Group/GroupProfile/GroupProfileCard.tsx b/plugins/org/src/components/Cards/Group/GroupProfile/GroupProfileCard.tsx index 8d5a553860..8291dfdc1d 100644 --- a/plugins/org/src/components/Cards/Group/GroupProfile/GroupProfileCard.tsx +++ b/plugins/org/src/components/Cards/Group/GroupProfile/GroupProfileCard.tsx @@ -18,8 +18,11 @@ import { GroupEntity, RELATION_CHILD_OF, RELATION_PARENT_OF, + ANNOTATION_LOCATION, + stringifyEntityRef, } from '@backstage/catalog-model'; import { + catalogApiRef, EntityRefLinks, getEntityRelations, useEntity, @@ -39,14 +42,16 @@ import AccountTreeIcon from '@material-ui/icons/AccountTree'; import EmailIcon from '@material-ui/icons/Email'; import GroupIcon from '@material-ui/icons/Group'; import EditIcon from '@material-ui/icons/Edit'; +import CachedIcon from '@material-ui/icons/Cached'; import Alert from '@material-ui/lab/Alert'; -import React from 'react'; +import React, { useCallback } from 'react'; import { Avatar, InfoCard, InfoCardVariants, Link, } from '@backstage/core-components'; +import { alertApiRef, useApi } from '@backstage/core-plugin-api'; const CardTitle = ({ title }: { title: string }) => ( @@ -60,13 +65,21 @@ export const GroupProfileCard = ({ }: { variant?: InfoCardVariants; }) => { + const catalogApi = useApi(catalogApiRef); + const alertApi = useApi(alertApiRef); const { entity: group } = useEntity(); + + const refreshEntity = useCallback(async () => { + await catalogApi.refreshEntity(stringifyEntityRef(group)); + alertApi.post({ message: 'Refresh scheduled', severity: 'info' }); + }, [catalogApi, alertApi, group]); + if (!group) { return Group not found; } const { - metadata: { name, description }, + metadata: { name, description, annotations }, spec: { profile }, } = group; @@ -77,6 +90,10 @@ export const GroupProfileCard = ({ kind: 'group', }); + const entityLocation = annotations?.[ANNOTATION_LOCATION]; + const allowRefresh = + entityLocation?.startsWith('url:') || entityLocation?.startsWith('file:'); + const entityMetadataEditUrl = getEntityMetadataEditUrl(group); const displayName = profile?.displayName ?? name; @@ -101,7 +118,20 @@ export const GroupProfileCard = ({ title={} subheader={description} variant={variant} - action={infoCardAction} + action={ + <> + {allowRefresh && ( + + + + )} + {infoCardAction} + + } >