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

feat(datepicker): step 3, excluding dates #219

Merged
merged 2 commits into from
Oct 3, 2023

Conversation

Leotheluck
Copy link
Contributor

Adding options to disable specific dates of the Datepicker.

New enum:
ODS_DATEPICKER_DAY: monday = 1, saturday = 6, etc.

New attributes:

datesDisabled?: Date[] (specific dates to disable)
daysOfWeekDisabled?: ODS_DATEPICKER_DAY[] (ex: monday, sunday disabled for all dates)
maxDate?: Date (maximum date selectable)
minDate?: Date (minimum date selectable)

@Leotheluck Leotheluck added the enhancement New feature or request label Sep 28, 2023
@Leotheluck Leotheluck requested a review from a team as a code owner September 28, 2023 07:28
@Leotheluck Leotheluck self-assigned this Sep 28, 2023
@@ -23,10 +23,17 @@ class OdsDatepickerController {
if (newValue === undefined || newValue === null || isNaN(newValue.getTime())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

you can add also || !this.validateValue(newValue) condition and remove the last else

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you create a function for add context like isValidValue


private validateValue(value?: Date) {
if (value) {
if (!this.component.maxDate || this.getMidnightDate(value).getTime() <= this.getMidnightDate(this.component.maxDate).getTime() ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

you should split your validation and avoid calling the same function (getMidnightDate) so many times, more like

if (!value) {
  return false;
}

const midnightDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()))

if (this.component.maxDate) {
  return <test max date>
}

if (this.component.minDate) {
  return <test max date>
}

...

@@ -23,10 +23,17 @@ class OdsDatepickerController {
if (newValue === undefined || newValue === null || isNaN(newValue.getTime())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you create a function for add context like isValidValue

defaultValue: null,
options: [null, new Date('1999-11-02'), new Date('2024-11-02')],
},
minDate: {
Copy link
Contributor

Choose a reason for hiding this comment

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

I have an error on storybook with the date
image
And when I select one the input not display the value

Copy link
Contributor

@astagnol astagnol left a comment

Choose a reason for hiding this comment

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

Capture d’écran 2023-09-28 à 11 56 34

In Storybook, it can be a bit confusing for users when they choose a min and/or max date and the selected value is not displayed. Still, it's working as expected but I think we should display the selected value in select.

@Leotheluck Leotheluck merged commit 3d86df2 into feat/datepicker Oct 3, 2023
Leotheluck added a commit that referenced this pull request Oct 3, 2023
* feat(datepicker): step 3, excluding dates

* feat(datepicker): step 3, excluding dates
@Leotheluck Leotheluck deleted the feat/datepicker-step-3 branch October 4, 2023 08:08
dpellier pushed a commit that referenced this pull request Oct 4, 2023
* feat(datepicker): step 3, excluding dates

* feat(datepicker): step 3, excluding dates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants