From fb85b7a793c0b8a325f7ee836eeb316fbe4dd394 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sun, 4 Jun 2023 19:16:44 +0200 Subject: [PATCH] [docs-infra] Mandatory versions --- docs/pages/_app.js | 33 +++++++++++++++++---- docs/src/modules/components/AppNavDrawer.js | 30 +++++++++++-------- docs/src/modules/utils/useRouterExtra.ts | 18 +++++++++-- packages/markdown/parseMarkdown.js | 16 +++++----- 4 files changed, 70 insertions(+), 27 deletions(-) diff --git a/docs/pages/_app.js b/docs/pages/_app.js index 0b326438ef7362..d8f218cd318987 100644 --- a/docs/pages/_app.js +++ b/docs/pages/_app.js @@ -151,8 +151,8 @@ function AppWrapper(props) { if (product === 'material-ui') { return { - name: 'Material UI', metadata: 'MUI Core', + name: 'Material UI', versions: [ { text: `v${materialPkgJson.version}`, current: true }, { @@ -169,16 +169,16 @@ function AppWrapper(props) { if (product === 'joy-ui') { return { - name: 'Joy UI', metadata: 'MUI Core', + name: 'Joy UI', versions: [{ text: `v${joyPkgJson.version}`, current: true }], }; } if (product === 'system') { return { - name: 'MUI System', metadata: 'MUI Core', + name: 'MUI System', versions: [ { text: `v${systemPkgJson.version}`, current: true }, { text: 'v4', href: `https://v4.mui.com${languagePrefix}/system/basics/` }, @@ -192,13 +192,36 @@ function AppWrapper(props) { if (product === 'base') { return { - name: 'Base UI', metadata: 'MUI Core', + name: 'Base UI', versions: [{ text: `v${basePkgJson.version}`, current: true }], }; } - return null; // The identifier for X and Toolpad is handled by their own site + if (product === 'core') { + return { + metadata: '', + name: 'MUI Core', + versions: [ + { text: `v${materialPkgJson.version}`, current: true }, + { + text: 'View all versions', + href: `https://mui.com${languagePrefix}/versions/`, + }, + ], + }; + } + + return { + metadata: '', + name: 'Docs-infra', + versions: [ + { + text: 'v0.0.0', + href: `https://mui.com${languagePrefix}/versions/`, + }, + ], + }; }, [pageProps.userLanguage, product]); const pageContextValue = React.useMemo(() => { diff --git a/docs/src/modules/components/AppNavDrawer.js b/docs/src/modules/components/AppNavDrawer.js index 89776a4ea18529..8074fc6b5f904a 100644 --- a/docs/src/modules/components/AppNavDrawer.js +++ b/docs/src/modules/components/AppNavDrawer.js @@ -89,7 +89,8 @@ ProductDrawerButton.propTypes = { productName: PropTypes.string, }; -function ProductIdentifier({ name, metadata, versionSelector }) { +function ProductIdentifier(props) { + const { name, metadata, versionSelector } = props; return ( - {productIdentifier && ( - - )} + ({ @@ -425,6 +422,15 @@ export default function AppNavDrawer(props) { ); }, [onClose, pages, activePageParents, t, productIdentifier, anchorEl]); + if (process.env.NODE_ENV !== 'production') { + if (!productIdentifier) { + throw new Error('docs-infra: missing productIdentifier in PageContext'); + } + if (!productIdentifier.versions) { + throw new Error('docs-infra: missing productIdentifier.versions in PageContext'); + } + } + return (