feat(techdocs) allow referencing other entities for techdocs
Signed-off-by: jrwpatterson <jrwpatterson@gmail.com>
This commit is contained in:
@@ -14,18 +14,31 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
Entity,
|
||||
getCompoundEntityRef,
|
||||
parseEntityRef,
|
||||
} from '@backstage/catalog-model';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { Entity, getCompoundEntityRef } from '@backstage/catalog-model';
|
||||
|
||||
import { TechDocsReaderPage } from './plugin';
|
||||
import { TechDocsReaderPageSubheader } from './reader/components/TechDocsReaderPageSubheader';
|
||||
import { TechDocsReaderPageContent } from './reader/components/TechDocsReaderPageContent';
|
||||
import { TechDocsReaderPageSubheader } from './reader/components/TechDocsReaderPageSubheader';
|
||||
|
||||
type EntityPageDocsProps = { entity: Entity };
|
||||
|
||||
export const EntityPageDocs = ({ entity }: EntityPageDocsProps) => {
|
||||
const entityRef = getCompoundEntityRef(entity);
|
||||
let entityRef = getCompoundEntityRef(entity);
|
||||
|
||||
if (entity.metadata.annotations?.['backstage.io/techdocs-external-ref']) {
|
||||
try {
|
||||
entityRef = parseEntityRef(
|
||||
entity.metadata.annotations?.['backstage.io/techdocs-external-ref'],
|
||||
);
|
||||
} catch {
|
||||
// not a fan of this but we don't care if the parseEntityRef fails
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<TechDocsReaderPage entityRef={entityRef}>
|
||||
|
||||
@@ -18,22 +18,24 @@ import React, { PropsWithChildren } from 'react';
|
||||
import { Route, Routes, useRoutes } from 'react-router-dom';
|
||||
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { useEntity } from '@backstage/plugin-catalog-react';
|
||||
import { MissingAnnotationEmptyState } from '@backstage/core-components';
|
||||
|
||||
import { EntityPageDocs } from './EntityPageDocs';
|
||||
import { MissingAnnotationEmptyState } from '@backstage/core-components';
|
||||
import { TechDocsIndexPage } from './home/components/TechDocsIndexPage';
|
||||
import { TechDocsReaderPage } from './reader/components/TechDocsReaderPage';
|
||||
import { useEntity } from '@backstage/plugin-catalog-react';
|
||||
|
||||
const TECHDOCS_ANNOTATION = 'backstage.io/techdocs-ref';
|
||||
|
||||
const TECHDOCS_EXTERNAL_ANNOTATION = 'backstage.io/techdocs-external-ref';
|
||||
|
||||
/**
|
||||
* Helper that takes in entity and returns true/false if TechDocs is available for the entity
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export const isTechDocsAvailable = (entity: Entity) =>
|
||||
Boolean(entity?.metadata?.annotations?.[TECHDOCS_ANNOTATION]);
|
||||
Boolean(entity?.metadata?.annotations?.[TECHDOCS_ANNOTATION]) ||
|
||||
Boolean(entity?.metadata?.annotations?.[TECHDOCS_EXTERNAL_ANNOTATION]);
|
||||
|
||||
/**
|
||||
* Responsible for registering routes for TechDocs, TechDocs Homepage and separate TechDocs page
|
||||
@@ -75,10 +77,16 @@ export const EmbeddedDocsRouter = (props: PropsWithChildren<{}>) => {
|
||||
},
|
||||
]);
|
||||
|
||||
const projectId = entity.metadata.annotations?.[TECHDOCS_ANNOTATION];
|
||||
const projectId =
|
||||
entity.metadata.annotations?.[TECHDOCS_ANNOTATION] ||
|
||||
entity.metadata.annotations?.[TECHDOCS_EXTERNAL_ANNOTATION];
|
||||
|
||||
if (!projectId) {
|
||||
return <MissingAnnotationEmptyState annotation={TECHDOCS_ANNOTATION} />;
|
||||
return (
|
||||
<MissingAnnotationEmptyState
|
||||
annotation={[TECHDOCS_ANNOTATION, TECHDOCS_EXTERNAL_ANNOTATION]}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return element;
|
||||
|
||||
Reference in New Issue
Block a user