Skip to content

Commit

Permalink
[docs] Fix productId logic (#9451)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari authored Jun 26, 2023
1 parent 404e14d commit 904079d
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions docs/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,18 @@ function AppWrapper(props) {
const { children, emotionCache, pageProps } = props;

const router = useRouter();
const { productId, productCategoryId } = getProductInfoFromUrl(router.asPath);
const { productId: productIdRaw, productCategoryId } = getProductInfoFromUrl(router.asPath);
const { canonicalAs } = pathnameToLanguage(router.asPath);
let productId = productIdRaw;

// Not respecting URL convention, ad-hoc workaround
if (canonicalAs.startsWith('/x/api/data-grid/')) {
productId = 'x-data-grid';
} else if (canonicalAs.startsWith('/x/api/date-pickers/')) {
productId = 'x-date-pickers';
} else if (canonicalAs.startsWith('/x/api/charts/')) {
productId = 'x-charts';
}

React.useEffect(() => {
loadDependencies();
Expand All @@ -192,11 +203,8 @@ function AppWrapper(props) {
];
}

const { canonicalAs } = pathnameToLanguage(router.asPath);

const pageContextValue = React.useMemo(() => {
const { activePage, activePageParents } = findActivePage(pages, router.pathname);

const languagePrefix = pageProps.userLanguage === 'en' ? '' : `/${pageProps.userLanguage}`;

let productIdentifier = {
Expand All @@ -209,10 +217,7 @@ function AppWrapper(props) {
],
};

if (
canonicalAs.startsWith('/x/react-data-grid/') ||
canonicalAs.startsWith('/x/api/data-grid/')
) {
if (productId === 'x-data-grid') {
productIdentifier = {
metadata: 'MUI X',
name: 'Data Grid',
Expand All @@ -222,10 +227,7 @@ function AppWrapper(props) {
{ text: 'v4', href: `https://v4.mui.com${languagePrefix}/components/data-grid/` },
],
};
} else if (
canonicalAs.startsWith('/x/react-date-pickers/') ||
canonicalAs.startsWith('/x/api/date-pickers/')
) {
} else if (productId === 'x-date-pickers') {
productIdentifier = {
metadata: 'MUI X',
name: 'Date Pickers',
Expand All @@ -239,8 +241,14 @@ function AppWrapper(props) {
};
}

return { activePage, activePageParents, pages, productIdentifier };
}, [canonicalAs, pageProps.userLanguage, router.pathname]);
return {
activePage,
activePageParents,
pages,
productIdentifier,
productId,
};
}, [productId, pageProps.userLanguage, router.pathname]);

// Replicate change reverted in https://github.com/mui/material-ui/pull/35969/files#r1089572951
// Fixes playground styles in dark mode.
Expand Down

0 comments on commit 904079d

Please sign in to comment.