-
Notifications
You must be signed in to change notification settings - Fork 145
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
Update to use dmc 0.15.1 #924
base: main
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, thank you so much, @AnnMarieW, for this PR and your detailed explanations here! 🚀 This is incredibly helpful.
We definitely plan to upgrade the dmc
version, and although we've removed other dmc
components, we'll likely always keep the DatePicker since it's the best available! 💯
I've left a few comments, but there's no rush to implement them. We probably won't merge this PR until next year. We were already planning to upgrade dmc
next year, but we wanted to check feasibility first. Your PR is fantastic for that! Everything seems to work fine, and it looks very feasible and straightforward from a code perspective. Thank you so much! 🙏
I'll have @nadijagraca and @petar-qb do some manual checks since they developed the component back then and probably remember better than me all the workarounds we added 😅 @nadijagraca, I'll create a separate ticket, but we need to change our CSS to match the new DatePicker CSS selectors, but that should be straight-forward hopefully!
Overall, I'm confident we can merge this PR next year though 👍 🚀
min: Optional[date] = Field(None, description="Start date for date picker.") | ||
max: Optional[date] = Field(None, description="End date for date picker.") | ||
value: Optional[Union[list[date], date]] = Field(None, description="Default date for date picker") | ||
title: str = Field("", description="Title to be displayed.") | ||
|
||
# Could probably delete the `range` arg, but keeping it makes it backwards compatible |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! The range
argument is definitely a bit redundant if we ever want to introduce the type
argument of the new dmc.DatePickerInput
as well. Options would then include: "default", "range", "multiple" in which case this boolean argument doesn't make much sense as you could then also define it via the type
directly, but probably better to keep it for backwards compatibility even though it might be double-defined then.
Let's leave it in for now and discuss when @antonymilne is back 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Antony previously mentioned the concept of a "multiple" option for the DatePicker in #318 (comment).
At this point, I believe we don't need to support the "multiple" mode yet, as it represents a niche use case. If we decide to implement this feature, we should also consider extending similar functionality to other components, such as vm.Slider. This would align with broader discussions about restructuring our components (See -> #318 (comment))).
For now, the range
property seems to address the requirements effectively.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, perfect! I didn't know he commented on this already. Let's leave it as is then, and @AnnMarieW you could delete this line then: date_range_picker_kwargs = {"allowSingleDateInRange": True} if self.range else {}
I don't think it's needed anymore since that is controlled by the type
argument now instead of allowSingleDateInRange
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should always include allowSingleDateInRange=True,
in the dmc.DatePickerInput
configuration. It will enable that a single date can be selected when range=True
(so type="range"
), and will have no effect when range=False
(so type="default"
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, but then let's specify it directly as allowSingleDateInRange=True
instead of adding that line 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little confused by this - not sure what props to update 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All that is needed is to delete the following line:
date_range_picker_kwargs = {"allowSingleDateInRange": True} if self.range else {}
and insert allowSingleDateInRange: True
directly to the dmc.DatePickerInput
configuration like in this suggestion comment.
# clientside callback is required as a workaround when the date-picker is overflowing its parent container | ||
# if there is not enough space. Caused by another workaround for this issue: | ||
# https://github.com/snehilvj/dash-mantine-components/issues/219 | ||
clientside_callback( | ||
ClientsideFunction(namespace="date_picker", function_name="update_date_picker_position"), | ||
output=Output(self.id, "dropdownPosition"), | ||
inputs=Input(self.id, "n_clicks"), | ||
) | ||
|
||
date_picker_class = dmc.DateRangePicker if self.range else dmc.DatePicker | ||
|
||
# dropdownPosition must be set to bottom-start as a workaround for issue: | ||
# https://github.com/snehilvj/dash-mantine-components/issues/219 | ||
# clearable must be set to False as a workaround for issue: | ||
# https://github.com/snehilvj/dash-mantine-components/issues/212 | ||
# maxDate must be increased by one day, and later on disabledDates must be set as maxDate + 1 day | ||
# as a workaround for issue: https://github.com/snehilvj/dash-mantine-components/issues/230 | ||
date_picker = date_picker_class( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Saw that all of these issues have been fixed in the mantine repository @AnnMarieW - this is amazing! 🥳
@nadijagraca @petar-qb - could you double-check manually if all of the issues we've faced initially are solved now? I remember for one of the bugs, we had to add the datepicker to the right side and then change screen sizes etc. I don't know if there were other scenarios like that which need manual checking. You will know best 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some testing with various configuration inputs, I can say that all our previous workaround solutions are unnecessary as dmc.DatePickerInput
handles them all internally 🎉 Here's the example of our workaround solutions.
- maxDate=self.max + datetime.timedelta(days=1) if self.max else None,
- dropdownPosition="bottom-start",
- clearable=False,
- disabledDates=self.max + datetime.timedelta(days=1) if self.max else None,
Thanks for the review and I look forward to working on this more next year!
As far as styling goes -- it's changed quite substantially starting in V0.14. No need to go into details now, but a couple things to note:
|
Co-authored-by: Li Nguyen <90609403+huong-li-nguyen@users.noreply.github.com>
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AnnMarieW, thank you for such great work ❤️ I really like dmc.DatePickerInput
!
I left a few comments, but this PR is close to being merged in my opinion 🎉
P.S. You can paste the code from the PR description you wrote directly to vizro-core/examples/scratch_dev/app.py
file, and make it easier for other reviewers to test the change 😃.
min: Optional[date] = Field(None, description="Start date for date picker.") | ||
max: Optional[date] = Field(None, description="End date for date picker.") | ||
value: Optional[Union[list[date], date]] = Field(None, description="Default date for date picker") | ||
title: str = Field("", description="Title to be displayed.") | ||
|
||
# Could probably delete the `range` arg, but keeping it makes it backwards compatible |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Antony previously mentioned the concept of a "multiple" option for the DatePicker in #318 (comment).
At this point, I believe we don't need to support the "multiple" mode yet, as it represents a niche use case. If we decide to implement this feature, we should also consider extending similar functionality to other components, such as vm.Slider. This would align with broader discussions about restructuring our components (See -> #318 (comment))).
For now, the range
property seems to address the requirements effectively.
# clientside callback is required as a workaround when the date-picker is overflowing its parent container | ||
# if there is not enough space. Caused by another workaround for this issue: | ||
# https://github.com/snehilvj/dash-mantine-components/issues/219 | ||
clientside_callback( | ||
ClientsideFunction(namespace="date_picker", function_name="update_date_picker_position"), | ||
output=Output(self.id, "dropdownPosition"), | ||
inputs=Input(self.id, "n_clicks"), | ||
) | ||
|
||
date_picker_class = dmc.DateRangePicker if self.range else dmc.DatePicker | ||
|
||
# dropdownPosition must be set to bottom-start as a workaround for issue: | ||
# https://github.com/snehilvj/dash-mantine-components/issues/219 | ||
# clearable must be set to False as a workaround for issue: | ||
# https://github.com/snehilvj/dash-mantine-components/issues/212 | ||
# maxDate must be increased by one day, and later on disabledDates must be set as maxDate + 1 day | ||
# as a workaround for issue: https://github.com/snehilvj/dash-mantine-components/issues/230 | ||
date_picker = date_picker_class( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some testing with various configuration inputs, I can say that all our previous workaround solutions are unnecessary as dmc.DatePickerInput
handles them all internally 🎉 Here's the example of our workaround solutions.
- maxDate=self.max + datetime.timedelta(days=1) if self.max else None,
- dropdownPosition="bottom-start",
- clearable=False,
- disabledDates=self.max + datetime.timedelta(days=1) if self.max else None,
for more information, see https://pre-commit.ci
@AnnMarieW Can you paste the code from the PR description you wrote, directly to |
Unit tests should not be too hard to fix. There are only three tests that are failing:
You can fix You can run unit tests with the following command from your terminal (ensure to call it from If you need any help with this, please let us know and we will be happy to jump in for the help. 😃 |
This commit is to show how to style Mantine componets with a Vizro style. It uses the To fine tune the datepicker, it's best to use Mantine's Style API. I deleted the datepicker.css file because most of the selectors have changed. Also, it's not possible to style the calendar with the The ideal way to style the calendar is to use Mantine |
# maxDate must be increased by one day, and later on disabledDates must be set as maxDate + 1 day | ||
# as a workaround for issue: https://github.com/snehilvj/dash-mantine-components/issues/230 | ||
date_picker = date_picker_class( | ||
date_picker = dmc.DatePickerInput( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This suggestion is only used as a reference from another comment.
date_picker = dmc.DatePickerInput( | |
date_picker = dmc.DatePickerInput( | |
id=self.id, | |
minDate=self.min, | |
value=init_value, | |
maxDate=self.max, | |
persistence=True, | |
persistence_type="session", | |
type="range" if self.range else "default", | |
className="datepicker", | |
# removes the default red color for weekend days | |
styles={"day": {"color": "var(--mantine-color-text"}}, | |
allowSingleDateInRange: True, | |
) |
This is a draft PR. For details, please refer to the discussion in #905
TO DO:
Test Code
Notice
I acknowledge and agree that, by checking this box and clicking "Submit Pull Request":