From c08ed7c47d6eb0ee2820132adcfef968c1423a25 Mon Sep 17 00:00:00 2001 From: roylisto Date: Wed, 23 Feb 2022 11:45:21 +0700 Subject: [PATCH 1/2] Add sync button to Group page Signed-off-by: roylisto --- .../Group/GroupProfile/GroupProfileCard.tsx | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) 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} + + } > From cd8c6970edf71e4c0b26a39f3201d2dbaea73217 Mon Sep 17 00:00:00 2001 From: roylisto Date: Wed, 23 Feb 2022 11:50:55 +0700 Subject: [PATCH 2/2] Update changeset Signed-off-by: roylisto --- .changeset/rude-tools-vanish.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/rude-tools-vanish.md diff --git a/.changeset/rude-tools-vanish.md b/.changeset/rude-tools-vanish.md new file mode 100644 index 0000000000..72849ff4ab --- /dev/null +++ b/.changeset/rude-tools-vanish.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-org': patch +--- + +Add entity sync button to Group page