-
Notifications
You must be signed in to change notification settings - Fork 78
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): add support for date range and different date formats #1381
Conversation
Thank you, 🤖 Clarity Release Bot |
This PR introduces visual changes: d57a180
|
This PR introduces visual changes: 3450769
|
This PR introduces visual changes: 400af37
|
This PR introduces visual changes: 9b748ad
|
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, thanks for the great amount of work on this exciting feature and all the attention to fine details and various use-cases!
Reviewing this may take some more iterations, but right now I have some high level questions and concerns that we may further discuss offline.
My goals, as reviewer, are for now the following:
- Ensure we're not breaking current behavior/s and provide incremental API changes where possible.
- Make sure we are providing a solid and well structured architecture of the various sub-components.
- Validate agains the design requirements and guidelines.
First off, my biggest concern is that the implementation diverges too much from the initial specs that were presented to the team. This leads to unexpected scope explosion and features and architecture that were not synced on planning phase.
The changes on the abstract and other common classes bring concerns (explained in more detail in the lower comments). They bring (seemingly) unnecessary specificity to a high hierarchy level, and drag along changes in event model, subscriptions, validation and more.
The API and naming of the existing date picker has been change witch causes breaking changes, which we would prefer to avoid.
Some of the use-cases are not realistic - like the month range (without year). For example - if you select Feb to Sept it may make some sense, but what happens if you select Sept to Feb?
A large volume of commented code is left. I added comments to most, but not all cases, please check. Especially in tests, where it's not clear if these tests are obsolete, or just temporarily commented and still needs to get satisfied.
projects/angular/src/forms/datepicker/model/calendar-view.model.ts
Outdated
Show resolved
Hide resolved
projects/angular/src/forms/datepicker/providers/date-io.service.ts
Outdated
Show resolved
Hide resolved
projects/angular/src/forms/datepicker/providers/date-io.service.ts
Outdated
Show resolved
Hide resolved
projects/angular/src/forms/datepicker/providers/date-io.service.ts
Outdated
Show resolved
Hide resolved
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.
It would really be nice to have the dateFormat related work in a separate PR.
As it fights with default browser localization and provider-based localization we don't even know if we want it, or when we want it released and now it's tied to the range component.
And some more observations and first use impressions:
- Dragging a range, as opposed to sequential clicking, does not work. Not sure this is valid use case, but I hit it several times before understanding what happens. May need to sync with UX.
- Trying to only change the end date on already existing value resets the start date. UX comment needed.
- Sequentially clicking backwards, from later to earlier date, just resets the start date. UX comment needed.
- The dash (-) separating start and end date is too much closer to end date making it look like negative value instead of range. I know the technical reasons for this, but some reiteration with Design might help here.
- Nit: after selecting a range option, the next time you open the picker it shows "Custom range". Not critical, but would be nice if we could resolve back the range option and pre-select it if it's matching.
- Nit: If we violate validation restrictions in both fields we're receiving just one error message.
projects/demo/src/app/datepicker/datepicker-in-reactive-forms.html
Outdated
Show resolved
Hide resolved
projects/demo/src/app/datepicker/datepicker-date-input-explicit-wrapper.html
Outdated
Show resolved
Hide resolved
projects/demo/src/app/datepicker/datepicker-in-reactive-forms.ts
Outdated
Show resolved
Hide resolved
projects/demo/src/app/datepicker/datepicker-in-reactive-forms.ts
Outdated
Show resolved
Hide resolved
</li> | ||
<li> | ||
<a [routerLink]="['./enhanced-date-picker']" | ||
>Enhanced Date Picker |
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.
Maybe we should name it "Custom Date Format" or something in that direction. "Enhanced" is too broad.
I agree. These two features need to be separated. There is too much in this PR. These things should be reviewed and merged separately. And we might release one sooner than the other. Neither feature should held up by issues with the other. |
projects/angular/src/forms/common/if-control-state/if-control-state.service.ts
Outdated
Show resolved
Hide resolved
// and emit the control | ||
this.additionalControls?.forEach((control: NgControl) => { | ||
this.subscriptions.push( | ||
control?.statusChanges?.subscribe(() => { |
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.
If additional controls get changed, won't we need to unsubscribe from the previous statusChanges subscriptions before we register the new ones?
This may apply for the primary control subscriptions too, if my previous comment gets resolved.
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.
Set control is going to happen only once per control if I am not wrong. I doubt that we can change the control i mean replace the existing control with new one. It will happen when container itself is completely destroyed and recreated. Also this is an existing implementation which can be found in other file as well(select-container).
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.
Do you think it might become more explicit if we add take(1)?
We won't even need to add it to the subscriptions array if we do. We're using the take(1) approach in several components and services already.
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.
Totally agree, but since its an existing approach in all other files didn't change the approach. Need to do some research why it was added in this way. Hence keeping it in subscriptions mode as of now.
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.
My concern is that we're adding more subscriptions inside a subscribe block. This may lead to leaks. It should be okay to add take(1) here. It will make the code safer if it really only gets called once, or will throw explicit error if it unexpectedly gets called more than once, and save us tedious performance/memory-leak debugging.
this.triggerDoCheck(this.differ, this.ngControl); | ||
} | ||
|
||
triggerDoCheck(differ, ngControl) { |
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.
Why do we need this as separate public method? I don't see it used anywhere else.
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.
Basically added it as a separate methods in order to support Multiple Form controls(Primary & Additional Controls). Removed Purposefully Keyvalue differ for additional Controls now its added 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.
It's only called from the ngDoCheck method above. If you want to keep it for better code structure and readability, I am okay with this, but it can be private.
* Incase of date range error, both start & end date field valdiation has to be triggered | ||
* if either of the field gets updated | ||
*/ | ||
protected validateDateRange() { |
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 believe this belongs to the range specific children. They may have another common parent, that extends this class, to avoid code duplication between start and end, though.
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.
Yes, since both start date and end date component are using this kept in date-input-base component. Anyways I have wrapped it inside condition to check if its date range picker.
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.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: CDE-1846
What is the new behavior?
Does this PR introduce a breaking change?
Other information