UNPKG

@backstage/plugin-techdocs

Version:

The Backstage plugin that renders technical documentation for your components

68 lines (65 loc) 2.35 kB
import { jsxs, jsx } from 'react/jsx-runtime'; import { Routes, Route, useRoutes } from 'react-router-dom'; import { EntityPageDocs } from './EntityPageDocs.esm.js'; import { TechDocsIndexPage } from './home/components/TechDocsIndexPage.esm.js'; import { TechDocsReaderPage } from './reader/components/TechDocsReaderPage/TechDocsReaderPage.esm.js'; import { useEntity, MissingAnnotationEmptyState } from '@backstage/plugin-catalog-react'; import { TECHDOCS_ANNOTATION, TECHDOCS_EXTERNAL_ANNOTATION } from '@backstage/plugin-techdocs-common'; const isTechDocsAvailable = (entity) => Boolean(entity?.metadata?.annotations?.[TECHDOCS_ANNOTATION]) || Boolean(entity?.metadata?.annotations?.[TECHDOCS_EXTERNAL_ANNOTATION]); const Router = () => { return /* @__PURE__ */ jsxs(Routes, { children: [ /* @__PURE__ */ jsx(Route, { path: "/", element: /* @__PURE__ */ jsx(TechDocsIndexPage, {}) }), /* @__PURE__ */ jsx( Route, { path: "/:namespace/:kind/:name/*", element: /* @__PURE__ */ jsx(TechDocsReaderPage, {}) } ) ] }); }; const TechDocsReaderRouter = (props) => { const { children } = props; const element = useRoutes([ { path: "*", element: /* @__PURE__ */ jsx(TechDocsReaderPage, {}), children: [ { path: "*", element: children } ] } ]); return element; }; const EmbeddedDocsRouter = (props) => { const { children, emptyState, withSearch = true } = props; const { entity } = useEntity(); const element = useRoutes([ { path: "/*", element: /* @__PURE__ */ jsx(EntityPageDocs, { entity, withSearch }), children: [ { path: "*", element: children } ] } ]); const projectId = entity.metadata.annotations?.[TECHDOCS_ANNOTATION] || entity.metadata.annotations?.[TECHDOCS_EXTERNAL_ANNOTATION]; if (!projectId) { return emptyState ?? /* @__PURE__ */ jsx(MissingAnnotationEmptyState, { annotation: [TECHDOCS_ANNOTATION] }); } return element; }; const LegacyEmbeddedDocsRouter = ({ children, withSearch = true }) => { return /* @__PURE__ */ jsx(EmbeddedDocsRouter, { children, withSearch }); }; export { EmbeddedDocsRouter, LegacyEmbeddedDocsRouter, Router, TechDocsReaderRouter, isTechDocsAvailable }; //# sourceMappingURL=Router.esm.js.map