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] Fix parsing of x-date-pickers-pro demo adapter imports #11628

Merged
merged 1 commit into from
Jan 10, 2024
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
19 changes: 19 additions & 0 deletions docs/src/modules/utils/postProcessImport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,23 @@ describe('postProcessImport', () => {
});
});
});

describe('@mui/x-date-pickers-pro imports', () => {
const ALL_ADAPTERS = [
...ADAPTERS,
'AdapterDateFnsJalali',
'AdapterMomentHijri',
'AdapterMomentJalaali',
];
ALL_ADAPTERS.forEach((adapter) => {
it('should provide correct adapter', () => {
const resolvedDep = postProcessImport(`@mui/x-date-pickers-pro/${adapter}`);

const expectedLibrary = ADAPTER_TO_LIBRARY[adapter];
expect(resolvedDep).to.deep.equal({
[expectedLibrary]: DATE_ADAPTER_VERSIONS[expectedLibrary],
});
});
});
});
});
2 changes: 1 addition & 1 deletion docs/src/modules/utils/postProcessImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const ADAPTER_TO_LIBRARY: Record<string, string> = {
AdapterMomentJalaali: 'moment-jalaali',
};

const PICKERS_ADAPTER_REGEX = /^@mui\/(lab|x-date-pickers)\/(?<adapterName>Adapter.*)/;
const PICKERS_ADAPTER_REGEX = /^@mui\/(lab|x-date-pickers(?:-pro)?)\/(?<adapterName>Adapter.*)/;
Copy link
Member Author

Choose a reason for hiding this comment

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

We could go with the following if you think that it makes the code more readable. 🤔

Suggested change
const PICKERS_ADAPTER_REGEX = /^@mui\/(lab|x-date-pickers(?:-pro)?)\/(?<adapterName>Adapter.*)/;
const PICKERS_ADAPTER_REGEX = /^@mui\/(lab|x-date-pickers|x-date-pickers-pro)\/(?<adapterName>Adapter.*)/;

Copy link
Member

Choose a reason for hiding this comment

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

I'm honestly fine with both, it's not a regexp we need to tweak regularly

Copy link
Member

Choose a reason for hiding this comment

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

Agree with @flaviendelangle ... both are fine


export const postProcessImport = (importName: string): Record<string, string> | null => {
// e.g. date-fns
Expand Down
Loading