Use EntityRefLink in header and use relations to reference the owner of the document

Signed-off-by: Oliver Sand <oliver.sand@sda-se.com>
This commit is contained in:
Oliver Sand
2021-04-22 13:25:55 +02:00
parent d203c9e901
commit 23afdba96f
2 changed files with 31 additions and 26 deletions
@@ -14,14 +14,18 @@
* limitations under the License.
*/
import { EntityName, RELATION_OWNED_BY } from '@backstage/catalog-model';
import { Header, HeaderLabel, useRouteRef } from '@backstage/core';
import {
EntityRefLink,
EntityRefLinks,
getEntityRelations,
} from '@backstage/plugin-catalog-react';
import CodeIcon from '@material-ui/icons/Code';
import React from 'react';
import { AsyncState } from 'react-use/lib/useAsync';
import CodeIcon from '@material-ui/icons/Code';
import { EntityName, parseEntityName } from '@backstage/catalog-model';
import { Header, HeaderLabel, Link, useRouteRef } from '@backstage/core';
import { TechDocsMetadata } from '../../types';
import { EntityRefLink, entityRouteRef } from '@backstage/plugin-catalog-react';
import { rootRouteRef } from '../../plugin';
import { TechDocsMetadata } from '../../types';
type TechDocsPageHeaderProps = {
entityId: EntityName;
@@ -50,15 +54,12 @@ export const TechDocsPageHeader = ({
const {
locationMetadata,
spec: { owner, lifecycle },
spec: { lifecycle },
} = entityMetadataValues || { spec: {} };
const componentLink = useRouteRef(entityRouteRef);
let ownerEntity;
if (owner) {
ownerEntity = parseEntityName(owner, { defaultKind: 'group' });
}
const ownedByRelations = entityMetadataValues
? getEntityRelations(entityMetadataValues, RELATION_OWNED_BY)
: [];
const docsRootLink = useRouteRef(rootRouteRef)();
@@ -67,27 +68,25 @@ export const TechDocsPageHeader = ({
<HeaderLabel
label="Component"
value={
<Link style={{ color: '#fff' }} to={componentLink(entityId)}>
{name}
</Link>
<EntityRefLink
color="inherit"
entityRef={entityId}
defaultKind="Component"
/>
}
/>
{owner ? (
{ownedByRelations.length > 0 && (
<HeaderLabel
label="Owner"
value={
ownerEntity ? (
<EntityRefLink
style={{ color: '#fff' }}
entityRef={ownerEntity}
defaultKind="group"
/>
) : (
owner
)
<EntityRefLinks
color="inherit"
entityRefs={ownedByRelations}
defaultKind="group"
/>
}
/>
) : null}
)}
{lifecycle ? <HeaderLabel label="Lifecycle" value={lifecycle} /> : null}
{locationMetadata &&
locationMetadata.type !== 'dir' &&