diff --git a/.changeset/quick-horses-cry.md b/.changeset/quick-horses-cry.md new file mode 100644 index 0000000000..58708d63b2 --- /dev/null +++ b/.changeset/quick-horses-cry.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-org': patch +--- + +Small change to allow disabling of links in the user and group profile cards diff --git a/plugins/org/src/components/Cards/Group/GroupProfile/GroupProfileCard.tsx b/plugins/org/src/components/Cards/Group/GroupProfile/GroupProfileCard.tsx index 3a6b7c238d..f7dd9d20d4 100644 --- a/plugins/org/src/components/Cards/Group/GroupProfile/GroupProfileCard.tsx +++ b/plugins/org/src/components/Cards/Group/GroupProfile/GroupProfileCard.tsx @@ -15,43 +15,44 @@ */ import { + ANNOTATION_EDIT_URL, + ANNOTATION_LOCATION, GroupEntity, RELATION_CHILD_OF, RELATION_PARENT_OF, - ANNOTATION_LOCATION, stringifyEntityRef, - ANNOTATION_EDIT_URL, } from '@backstage/catalog-model'; -import { - catalogApiRef, - EntityRefLinks, - getEntityRelations, - useEntity, -} from '@backstage/plugin-catalog-react'; -import { - Box, - Grid, - List, - ListItem, - ListItemIcon, - ListItemText, - Tooltip, - IconButton, -} from '@material-ui/core'; -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, { useCallback } from 'react'; import { Avatar, InfoCard, InfoCardVariants, Link, } from '@backstage/core-components'; +import { + Box, + Grid, + IconButton, + List, + ListItem, + ListItemIcon, + ListItemText, + Tooltip, +} from '@material-ui/core'; +import { + EntityRefLinks, + catalogApiRef, + getEntityRelations, + useEntity, +} from '@backstage/plugin-catalog-react'; +import React, { useCallback } from 'react'; import { alertApiRef, useApi } from '@backstage/core-plugin-api'; + +import AccountTreeIcon from '@material-ui/icons/AccountTree'; +import Alert from '@material-ui/lab/Alert'; +import CachedIcon from '@material-ui/icons/Cached'; +import EditIcon from '@material-ui/icons/Edit'; +import EmailIcon from '@material-ui/icons/Email'; +import GroupIcon from '@material-ui/icons/Group'; import { LinksGroup } from '../../Meta'; const CardTitle = (props: { title: string }) => ( @@ -62,7 +63,7 @@ const CardTitle = (props: { title: string }) => ( ); /** @public */ -export const GroupProfileCard = (props: { variant?: InfoCardVariants }) => { +export const GroupProfileCard = (props: { variant?: InfoCardVariants, hideLinks?: boolean }) => { const catalogApi = useApi(catalogApiRef); const alertApi = useApi(alertApiRef); const { entity: group } = useEntity(); @@ -191,7 +192,7 @@ export const GroupProfileCard = (props: { variant?: InfoCardVariants }) => { secondary="Child Groups" /> - + {!props?.hideLinks && } diff --git a/plugins/org/src/components/Cards/User/UserProfileCard/UserProfileCard.test.tsx b/plugins/org/src/components/Cards/User/UserProfileCard/UserProfileCard.test.tsx index fb0df3d25f..449b66b96d 100644 --- a/plugins/org/src/components/Cards/User/UserProfileCard/UserProfileCard.test.tsx +++ b/plugins/org/src/components/Cards/User/UserProfileCard/UserProfileCard.test.tsx @@ -156,7 +156,7 @@ describe('Edit Button', () => { expect(rendered.getByRole('button')).toBeInTheDocument(); }); - it('Should show the extra fields if either links or extra profile are filled', async () => { + it('Should show the extra fields if either links', async () => { const annotations: Record = { 'backstage.io/edit-url': 'https://example.com/user.yaml', }; @@ -209,4 +209,58 @@ describe('Edit Button', () => { expect(rendered.getByText('Slack')).toBeInTheDocument(); expect(rendered.getByText('Google')).toBeInTheDocument(); }); + + it('Should hide the links if hidelinks', async () => { + const annotations: Record = { + 'backstage.io/edit-url': 'https://example.com/user.yaml', + }; + const userEntity: UserEntity = { + apiVersion: 'backstage.io/v1alpha1', + kind: 'User', + metadata: { + name: 'calum.leavy', + description: 'Super awesome human', + annotations, + links: [ + { + url: 'slack://user?team=T00000000&id=U00000000', + title: 'Slack', + icon: 'message', + }, + { + url: 'https://www.google.com', + title: 'Google', + }, + ], + }, + spec: { + profile: { + displayName: 'Calum Leavy', + email: 'calum-leavy@example.com', + }, + memberOf: ['ExampleGroup'], + }, + relations: [ + { + type: 'memberOf', + targetRef: 'group:default/examplegroup', + }, + ], + }; + + const rendered = await renderWithEffects( + wrapInTestApp( + + + , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, + ), + ); + expect(rendered.queryByText('Slack')).toBeNull(); + expect(rendered.queryByText('Google')).toBeNull(); + }); }); diff --git a/plugins/org/src/components/Cards/User/UserProfileCard/UserProfileCard.tsx b/plugins/org/src/components/Cards/User/UserProfileCard/UserProfileCard.tsx index a35c1c057b..7d5bb33a4e 100644 --- a/plugins/org/src/components/Cards/User/UserProfileCard/UserProfileCard.tsx +++ b/plugins/org/src/components/Cards/User/UserProfileCard/UserProfileCard.tsx @@ -15,15 +15,16 @@ */ import { + ANNOTATION_EDIT_URL, RELATION_MEMBER_OF, UserEntity, - ANNOTATION_EDIT_URL, } from '@backstage/catalog-model'; import { - EntityRefLinks, - getEntityRelations, - useEntity, -} from '@backstage/plugin-catalog-react'; + Avatar, + InfoCard, + InfoCardVariants, + Link, +} from '@backstage/core-components'; import { Box, Grid, @@ -34,19 +35,19 @@ import { ListItemText, Tooltip, } from '@material-ui/core'; +import { + EntityRefLinks, + getEntityRelations, + useEntity, +} from '@backstage/plugin-catalog-react'; + +import Alert from '@material-ui/lab/Alert'; import EditIcon from '@material-ui/icons/Edit'; import EmailIcon from '@material-ui/icons/Email'; import GroupIcon from '@material-ui/icons/Group'; -import PersonIcon from '@material-ui/icons/Person'; -import Alert from '@material-ui/lab/Alert'; -import React from 'react'; -import { - Avatar, - InfoCard, - InfoCardVariants, - Link, -} from '@backstage/core-components'; import { LinksGroup } from '../../Meta'; +import PersonIcon from '@material-ui/icons/Person'; +import React from 'react'; const CardTitle = (props: { title?: string }) => props.title ? ( @@ -57,7 +58,7 @@ const CardTitle = (props: { title?: string }) => ) : null; /** @public */ -export const UserProfileCard = (props: { variant?: InfoCardVariants }) => { +export const UserProfileCard = (props: { variant?: InfoCardVariants, hideLinks?: boolean }) => { const { entity: user } = useEntity(); if (!user) { return User not found; @@ -130,7 +131,7 @@ export const UserProfileCard = (props: { variant?: InfoCardVariants }) => { - + {!props?.hideLinks && }