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

[core] Rework DayPicker api #4783

Merged
merged 5 commits into from
May 10, 2022

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented May 6, 2022

Follow up on #4736 with a small potential bug fix.

  • Always pass an array of dates to DayPicker and rename is selectedDays instead of date
  • Rename onChange into onSelectedDayChange since it's not a callback of the value prop (we only pass the modified date and let the upper component decide how it impacts the list of selected days)

What's next

  • Test the DayPicker component independently of the context

@flaviendelangle flaviendelangle self-assigned this May 6, 2022
@@ -49,11 +45,12 @@ export interface ExportedDayPickerProps<TDate>
renderLoading?: () => React.ReactNode;
}

export interface DayPickerProps<TDate, TValue> extends ExportedDayPickerProps<TDate> {
export interface DayPickerProps<TDate> extends ExportedDayPickerProps<TDate> {
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 no longer rely on TValue, the component does not care what is the format, it always takes (TDate | null)[] as an input.

@@ -140,25 +137,15 @@ export function DayPicker<TDate, TValue>(props: DayPickerProps<TDate, TValue>) {
return;
}

// TODO possibly buggy line figure out and add tests
let finalDate: TDate;
if (date && !Array.isArray(date)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This check has moved in CalendarPicker where we now that it is not a range
This is fixing #4703 because we no longer do the bugger Array.isArray check.

.filter(Boolean)
.map((selectedDateItem) => selectedDateItem && utils.startOfDay(selectedDateItem));
const validSelectedDays = selectedDays
.filter((day): day is TDate => !!day)
Copy link
Member Author

Choose a reason for hiding this comment

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

.filter(Boolean) was not inferring the type so selectedDates still had the type (TDate | null)[] (which is why we were doing a useless boolean check below for the selected prop of renderDay

@@ -141,4 +141,38 @@ describe('<CalendarPicker />', () => {

expect(screen.getByText('2019/01')).toBeVisible();
});

it('should set time to be midnight when selecting a date without a previous date', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy paste of the tests of DayPicker since the tested logic now lives in CalendarPicker

I just changed the props to have the correct view and month rendered.

@mui-bot
Copy link

mui-bot commented May 6, 2022

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 262.9 508.1 350.4 361.56 94.227
Sort 100k rows ms 445.9 877.8 741.5 711.1 143.611
Select 100k rows ms 149.2 274.4 171.5 195.04 44.06
Deselect 100k rows ms 140.8 287.7 180.5 190.68 50.896

Generated by 🚫 dangerJS against 853508a

@flaviendelangle flaviendelangle marked this pull request as ready for review May 6, 2022 12:41
@flaviendelangle flaviendelangle added core Infrastructure work going on behind the scenes component: pickers This is the name of the generic UI component, not the React module! bug 🐛 Something doesn't work and removed core Infrastructure work going on behind the scenes labels May 6, 2022
@flaviendelangle flaviendelangle requested a review from DanailH May 6, 2022 12:43
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label May 9, 2022
@github-actions
Copy link

github-actions bot commented May 9, 2022

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label May 9, 2022
@DanailH
Copy link
Member

DanailH commented May 10, 2022

I checked it and it looks good. I also took the time to run it locally.
One note - since this is a breaking change (changing the API) I propose to add a small migration guide like we used to do for the DataGrid explaining what has changed in the PR so that whoever is doing the release can follow up and write the correct changelog.

@flaviendelangle flaviendelangle merged commit ca440c3 into mui:master May 10, 2022
@flaviendelangle flaviendelangle deleted the day-picker-format branch May 10, 2022 12:18
alexfauquette pushed a commit to alexfauquette/mui-x that referenced this pull request Aug 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: pickers This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants