UNPKG

@backstage/plugin-techdocs

Version:

The Backstage plugin that renders technical documentation for your components

83 lines (80 loc) 3.84 kB
import { jsx, jsxs } from 'react/jsx-runtime'; import { useMemo, Children } from 'react'; import { useOutlet } from 'react-router-dom'; import { Page, Progress } from '@backstage/core-components'; import { TECHDOCS_ADDONS_WRAPPER_KEY, TECHDOCS_ADDONS_KEY, TechDocsReaderPageProvider } from '@backstage/plugin-techdocs-react'; import { TechDocsReaderPageContent } from '../TechDocsReaderPageContent/TechDocsReaderPageContent.esm.js'; import { TechDocsReaderPageHeader } from '../TechDocsReaderPageHeader/TechDocsReaderPageHeader.esm.js'; import { TechDocsReaderPageSubheader } from '../TechDocsReaderPageSubheader/TechDocsReaderPageSubheader.esm.js'; import { rootDocsRouteRef } from '../../../routes.esm.js'; import { useRouteRefParams, getComponentData } from '@backstage/core-plugin-api'; import { CookieAuthRefreshProvider } from '@backstage/plugin-auth-react'; import { styled, useTheme, createTheme, ThemeProvider } from '@material-ui/core/styles'; import { useExternalRedirect } from './useExternalRedirect.esm.js'; const TechDocsReaderLayout = (props) => { const { withSearch, withHeader = true } = props; return /* @__PURE__ */ jsxs(Page, { themeId: "documentation", children: [ withHeader && /* @__PURE__ */ jsx(TechDocsReaderPageHeader, {}), /* @__PURE__ */ jsx(TechDocsReaderPageSubheader, {}), /* @__PURE__ */ jsx(TechDocsReaderPageContent, { withSearch }) ] }); }; const StyledPage = styled(Page)({ height: "inherit", overflowY: "visible" }); const TechDocsReaderPage = (props) => { const currentTheme = useTheme(); const readerPageTheme = useMemo( () => createTheme({ ...currentTheme, ...props.overrideThemeOptions || {} }), [currentTheme, props.overrideThemeOptions] ); const { kind, name, namespace } = useRouteRefParams(rootDocsRouteRef); const { children, entityRef = { kind, name, namespace } } = props; const outlet = useOutlet(); const memoizedEntityRef = useMemo( () => ({ kind: entityRef.kind, name: entityRef.name, namespace: entityRef.namespace }), [entityRef.kind, entityRef.name, entityRef.namespace] ); const { shouldShowProgress } = useExternalRedirect(memoizedEntityRef); const page = useMemo(() => { if (children) { return null; } const childrenList = outlet ? Children.toArray(outlet.props.children) : []; const grandChildren = childrenList.flatMap( (child) => child?.props?.children ?? [] ); return grandChildren.find( (grandChild) => !getComponentData(grandChild, TECHDOCS_ADDONS_WRAPPER_KEY) && !getComponentData(grandChild, TECHDOCS_ADDONS_KEY) ); }, [children, outlet]); if (shouldShowProgress) { return /* @__PURE__ */ jsx(Progress, {}); } if (!children) { return /* @__PURE__ */ jsx(ThemeProvider, { theme: readerPageTheme, children: /* @__PURE__ */ jsx(CookieAuthRefreshProvider, { pluginId: "techdocs", children: /* @__PURE__ */ jsx(TechDocsReaderPageProvider, { entityRef: memoizedEntityRef, children: page || /* @__PURE__ */ jsx(TechDocsReaderLayout, {}) }) }) }); } return /* @__PURE__ */ jsx(ThemeProvider, { theme: readerPageTheme, children: /* @__PURE__ */ jsx(CookieAuthRefreshProvider, { pluginId: "techdocs", children: /* @__PURE__ */ jsx(TechDocsReaderPageProvider, { entityRef: memoizedEntityRef, children: ({ metadata, entityMetadata, onReady }) => /* @__PURE__ */ jsx( StyledPage, { themeId: "documentation", className: "techdocs-reader-page", children: children instanceof Function ? children({ entityRef: memoizedEntityRef, techdocsMetadataValue: metadata.value, entityMetadataValue: entityMetadata.value, onReady }) : children } ) }) }) }); }; export { TechDocsReaderLayout, TechDocsReaderPage }; //# sourceMappingURL=TechDocsReaderPage.esm.js.map