Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Test products search #31351

Merged
merged 9 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/data/base/components/button/button.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
product: base
title: React button unstyled
githubLabel: 'component: button'
---

# Button unstyled

<p class="description">Buttons allow users to take actions, and make choices, with a single tap.</p>

## Basic usage

## Customizing the root element

## Complex customization

## `useButton` hook
5 changes: 5 additions & 0 deletions docs/data/base/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ const pages = [
title: 'Components',
icon: 'ToggleOnIcon',
children: [
{
pathname: '/base/components/inputs',
subheader: 'inputs',
children: [{ pathname: '/base/react-button', title: 'Button' }],
},
{
pathname: '/base/components/navigation',
subheader: 'navigation',
Expand Down
22 changes: 22 additions & 0 deletions docs/data/joy/components/button/button.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
product: joy-ui
title: React Button component
---

# Button

<p class="description">Buttons allow users to take actions, and make choices, with a single tap.</p>

## Variants

## Colors

## Sizes

## Icon

## Loading

## Upload

## Third-party routing library
14 changes: 14 additions & 0 deletions docs/data/joy/pages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const pages = [
{
pathname: '/joy-ui/react-',
title: 'Components',
icon: 'ToggleOnIcon',
children: [
{
pathname: '/joy-ui/react-button',
},
],
},
];

export default pages;
4 changes: 4 additions & 0 deletions docs/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
import pages from 'docs/src/pages';
import basePages from 'docs/data/base/pages';
import materialPages from 'docs/data/material/pages';
import joyPages from 'docs/data/joy/pages';
import systemPages from 'docs/data/system/pages';
import PageContext from 'docs/src/modules/components/PageContext';
import GoogleAnalytics from 'docs/src/modules/components/GoogleAnalytics';
Expand Down Expand Up @@ -191,6 +192,9 @@ function AppWrapper(props) {
if (asPathWithoutLang.startsWith('/material-ui')) {
productPages = materialPages;
}
if (asPathWithoutLang.startsWith('/joy-ui')) {
productPages = joyPages;
}
if (asPathWithoutLang.startsWith('/system') && FEATURE_TOGGLE.enable_system_scope) {
productPages = systemPages;
}
Expand Down
11 changes: 11 additions & 0 deletions docs/pages/base/react-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from 'react';
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
import {
demos,
docs,
demoComponents,
} from 'docs/data/base/components/button/button.md?@mui/markdown';

export default function Page() {
return <MarkdownDocs demos={demos} docs={docs} demoComponents={demoComponents} />;
}
11 changes: 11 additions & 0 deletions docs/pages/joy-ui/react-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from 'react';
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
import {
demos,
docs,
demoComponents,
} from 'docs/data/joy/components/button/button.md?@mui/markdown';

export default function Page() {
return <MarkdownDocs demos={demos} docs={docs} demoComponents={demoComponents} />;
}
1 change: 1 addition & 0 deletions docs/src/featureToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ module.exports = {
enable_redirects: false, // related to new structure change
enable_mui_base_scope: true, // will be enabled after the migration
enable_system_scope: false, // will be enabled after the migration
enable_joy_scope: true,
};
25 changes: 21 additions & 4 deletions docs/src/modules/components/AppNavDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import KeyboardArrowRight from '@mui/icons-material/KeyboardArrowRight';
import materialPkgJson from '../../../../packages/mui-material/package.json';
import basePkgJson from '../../../../packages/mui-base/package.json';
import systemPkgJson from '../../../../packages/mui-system/package.json';
import joyPkgJson from '../../../../packages/mui-joy/package.json';

const savedScrollTop = {};

Expand Down Expand Up @@ -188,16 +189,22 @@ function ProductDrawerButton(props) {
/>
<LinksWrapper>
<Link
href={ROUTES.baseDocs}
href={ROUTES.materialDocs}
// eslint-disable-next-line material-ui/no-hardcoded-labels
>
MUI Base <KeyboardArrowRight fontSize="small" />
Material UI <KeyboardArrowRight fontSize="small" />
</Link>
<Link
href={ROUTES.materialDocs}
href={ROUTES.joyDocs}
// eslint-disable-next-line material-ui/no-hardcoded-labels
>
Material UI <KeyboardArrowRight fontSize="small" />
Joy UI <KeyboardArrowRight fontSize="small" />
</Link>
<Link
href={ROUTES.baseDocs}
// eslint-disable-next-line material-ui/no-hardcoded-labels
>
MUI Base <KeyboardArrowRight fontSize="small" />
</Link>
<Link
href={ROUTES.systemDocs}
Expand Down Expand Up @@ -428,6 +435,7 @@ function AppNavDrawer(props) {
const isProductScoped =
router.asPath.startsWith('/x') ||
router.asPath.startsWith('/material-ui') ||
router.asPath.startsWith('/joy-ui') ||
(router.asPath.startsWith('/system') && FEATURE_TOGGLE.enable_system_scope) ||
router.asPath.startsWith('/base');
Comment on lines 436 to 440
Copy link
Member

@oliviertassinari oliviertassinari Mar 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting, so the current direction for the product names that I can infer from the URLs is:

  • MUI X
  • Material UI
  • Joy UI
  • MUI System
  • MUI Base

Alright, sounds good 👍


Expand Down Expand Up @@ -571,6 +579,15 @@ function AppNavDrawer(props) {
])}
/>
)}
{router.asPath.startsWith('/joy-ui/') && (
<ProductIdentifier
name="Joy UI"
metadata="MUI Core"
versionSelector={renderVersionSelector([
{ text: `v${joyPkgJson.version}`, current: true },
])}
/>
)}
{router.asPath.startsWith('/system/') && FEATURE_TOGGLE.enable_system_scope && (
<ProductIdentifier
name="MUI System"
Expand Down
35 changes: 33 additions & 2 deletions docs/src/modules/components/AppSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ReactDOMServer from 'react-dom/server';
import PropTypes from 'prop-types';
import NextLink from 'next/link';
import { DocSearchModal, useDocSearchKeyboardEvents } from '@docsearch/react';
import Chip from '@mui/material/Chip';
import ArticleRoundedIcon from '@mui/icons-material/ArticleRounded';
import ToggleOffRoundedIcon from '@mui/icons-material/ToggleOffRounded';
import EditRoundedIcon from '@mui/icons-material/EditRounded';
Expand All @@ -19,6 +20,7 @@ import { useTranslate, useUserLanguage } from 'docs/src/modules/utils/i18n';
import useLazyCSS from 'docs/src/modules/utils/useLazyCSS';
import { useRouter } from 'next/router';
import { isNewLocation } from 'docs/src/modules/utils/replaceUrl';
import getUrlProduct from 'docs/src/modules/utils/getUrlProduct';

const SearchButton = styled('button')(({ theme }) => {
return {
Expand Down Expand Up @@ -156,17 +158,44 @@ const NewStartScreen = () => {
function DocSearcHit(props) {
const { children, hit } = props;

function displayTag(pathname) {
if (!pathname.match(/^\/(material-ui|joy-ui|base|x\/(react-data-grid|api))\//)) {
return null;
}
let text = '';
if (pathname.startsWith('/material-ui/')) {
text = 'Material UI';
}
if (pathname.startsWith('/joy-ui/')) {
text = 'Joy UI';
}
if (pathname.startsWith('/base/')) {
text = 'MUI Base';
}
return <Chip label={text} size="small" sx={{ mr: 1 }} />;
}

if (hit.pathname) {
return (
<Link href={hit.pathname} as={hit.as}>
<Link
href={hit.pathname}
as={hit.as}
sx={{ display: 'flex !important', '& .DocSearch-Hit-Container': { flex: 1, minWidth: 0 } }}
>
{children}
{displayTag(hit.pathname)}
</Link>
);
}

// DocSearch stores the old results in its cache
// hit.pathname won't be defined for them.
return <Link href={hit.url}>{children}</Link>;
return (
<Link href={hit.url}>
{children}
{displayTag(hit.pathname)}
</Link>
);
}

DocSearcHit.propTypes = {
Expand All @@ -193,6 +222,7 @@ export default function AppSearch() {
}, [setIsOpen]);
const router = useRouter();
const isNewDocStructure = isNewLocation(router.asPath);
const productSpace = getUrlProduct(router.asPath);

const keyboardNavigator = {
navigate({ item }) {
Expand Down Expand Up @@ -296,6 +326,7 @@ export default function AppSearch() {
indexName="material-ui"
searchParameters={{
facetFilters: ['version:master', facetFilterLanguage],
optionalFilters: isNewDocStructure ? [`product:${productSpace}`] : [],
}}
placeholder={search}
transformItems={(items) => {
Expand Down
29 changes: 29 additions & 0 deletions docs/src/modules/utils/getUrlProduct.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { expect } from 'chai';
import getUrlProduct from './getUrlProduct';

describe('getUrlProduct', () => {
it('get material-ui', () => {
expect(getUrlProduct('/material-ui/react-button/')).to.equal('material-ui');
expect(getUrlProduct('/zh/material-ui/react-button/')).to.equal('material-ui');
});

it('get base', () => {
expect(getUrlProduct('/base/react-button-unstyled/')).to.equal('base');
expect(getUrlProduct('/zh/base/react-button-unstyled/')).to.equal('base');
});

it('get joy-ui', () => {
expect(getUrlProduct('/joy-ui/react-button/')).to.equal('joy-ui');
expect(getUrlProduct('/zh/joy-ui/react-button/')).to.equal('joy-ui');
});

it('get data-grid', () => {
expect(getUrlProduct('/x/react-data-grid/components')).to.equal('data-grid');
expect(getUrlProduct('/zh/x/react-data-grid/components')).to.equal('data-grid');
});

it('get date-picker', () => {
expect(getUrlProduct('/x/react-date-picker/components')).to.equal('date-picker');
expect(getUrlProduct('/zh/x/react-date-picker/components')).to.equal('date-picker');
});
});
7 changes: 7 additions & 0 deletions docs/src/modules/utils/getUrlProduct.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function getUrlProduct(asPath: string) {
const urlWithoutLang = asPath.replace(/^\/[a-zA-Z]{2}\//, '/');
if (urlWithoutLang.startsWith('/x')) {
return urlWithoutLang.replace('/x/react-', '').replace(/\/.*/, '');
}
return urlWithoutLang.replace(/^\/([^/]+)\/.*/, '$1');
}
1 change: 1 addition & 0 deletions docs/src/modules/utils/replaceHtmlLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export default function replaceHtmlLinks(html: string, asPath: string) {
asPath = asPath.replace(/^\/[a-z]{2}\//, '/');
if (
asPath.startsWith('/material-ui/') ||
asPath.startsWith('/joy-ui/') ||
asPath.startsWith('/x/') ||
asPath.startsWith('/base/') ||
(FEATURE_TOGGLE.enable_system_scope && asPath.startsWith('/system'))
Expand Down
1 change: 1 addition & 0 deletions docs/src/modules/utils/replaceUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function isNewLocation(url: string) {
url.startsWith('/x') ||
url.startsWith('/material-ui') ||
url.startsWith('/base') ||
url.startsWith('/joy-ui') ||
(FEATURE_TOGGLE.enable_system_scope && url.startsWith('/system'))
);
}
Expand Down
1 change: 1 addition & 0 deletions docs/src/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const ROUTES = {
handbook: 'https://mui-org.notion.site/Handbook-f086d47e10794d5e839aef9dc67f324b',
baseDocs: '/base/getting-started/installation/',
materialDocs: '/material-ui/getting-started/installation/',
joyDocs: '/joy-ui/react-button/',
systemDocs: '/system/basics/',
materialIcons: FEATURE_TOGGLE.enable_redirects
? '/material-ui/material-icons/'
Expand Down