fix(techdocs): use object routes on entity docs pages

Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
Camila Belo
2022-05-19 14:23:52 +02:00
parent f1707219b2
commit 443accb4bb
3 changed files with 44 additions and 13 deletions
+4 -2
View File
@@ -111,7 +111,9 @@ export type DocsTableRow = {
};
// @public
export const EmbeddedDocsRouter: (props: PropsWithChildren<{}>) => JSX.Element;
export const EmbeddedDocsRouter: (
props: PropsWithChildren<{}>,
) => JSX.Element | null;
// @public
export const EntityListDocsGrid: () => JSX.Element;
@@ -153,7 +155,7 @@ export type EntityListDocsTableProps = {
// @public
export const EntityTechdocsContent: (props: {
children?: ReactNode;
}) => JSX.Element;
}) => JSX.Element | null;
// @public
export const isTechDocsAvailable: (entity: Entity) => boolean;
+16 -8
View File
@@ -15,7 +15,7 @@
*/
import React, { PropsWithChildren } from 'react';
import { Route, Routes } from 'react-router-dom';
import { Route, Routes, useRoutes } from 'react-router-dom';
import { Entity } from '@backstage/catalog-model';
import { useEntity } from '@backstage/plugin-catalog-react';
@@ -61,17 +61,25 @@ export const EmbeddedDocsRouter = (props: PropsWithChildren<{}>) => {
const { children } = props;
const { entity } = useEntity();
// Using objects instead of <Route> elements, otherwise "outlet" will be null on sub-pages and add-ons won't render
const element = useRoutes([
{
path: '/*',
element: <EntityPageDocs entity={entity} />,
children: [
{
path: '/*',
element: children,
},
],
},
]);
const projectId = entity.metadata.annotations?.[TECHDOCS_ANNOTATION];
if (!projectId) {
return <MissingAnnotationEmptyState annotation={TECHDOCS_ANNOTATION} />;
}
return (
<Routes>
<Route path="/*" element={<EntityPageDocs entity={entity} />}>
{children}
</Route>
</Routes>
);
return element;
};