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): add support for date range and different date formats #1381

Closed
wants to merge 0 commits into from

Conversation

venkateshr06
Copy link
Contributor

@venkateshr06 venkateshr06 commented May 2, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • If applicable, have a visual design approval

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: CDE-1846

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Copy link
Contributor

github-actions bot commented May 2, 2024

👋 @venkateshr06,

  • 🙏 The Clarity team thanks you for opening a pull request
  • 🎉 The build for this PR has succeeded
  • 🔍 The PR is now ready for review
  • 🍿 In the meantime, view a preview of this PR
  • 🖐 You can always follow up here. If you're a VMware employee, you can also reach us on our internal Clarity Support space

Thank you,

🤖 Clarity Release Bot

@venkateshr06 venkateshr06 reopened this May 2, 2024
@kevinbuhmann kevinbuhmann changed the title feat(datepicker): Add Support for Date Range & different date formats feat(datepicker): add support for date range and different date formats May 2, 2024
Copy link
Contributor

github-actions bot commented May 6, 2024

This PR introduces visual changes: d57a180
If these changes are intended and correct, please cherry-pick the above commit to this PR.

git checkout main
git fetch https://github.com/vmware-clarity/ng-clarity.git d57a18077e0687e10b3f70205e5ef8e12e4a4276
git cherry-pick d57a18077e0687e10b3f70205e5ef8e12e4a4276
git push

@venkateshr06 venkateshr06 self-assigned this May 6, 2024
@venkateshr06 venkateshr06 marked this pull request as ready for review May 6, 2024 08:15
Copy link
Contributor

github-actions bot commented May 6, 2024

This PR introduces visual changes: 3450769
If these changes are intended and correct, please cherry-pick the above commit to this PR.

git checkout main
git fetch https://github.com/vmware-clarity/ng-clarity.git 34507699f33544178327dd1b5b734c6b7e9dac25
git cherry-pick 34507699f33544178327dd1b5b734c6b7e9dac25
git push

Copy link
Contributor

github-actions bot commented May 7, 2024

This PR introduces visual changes: 400af37
If these changes are intended and correct, please cherry-pick the above commit to this PR.

git checkout main
git fetch https://github.com/vmware-clarity/ng-clarity.git 400af3754208100aba0af43019a868580055606e
git cherry-pick 400af3754208100aba0af43019a868580055606e
git push

Copy link
Contributor

github-actions bot commented May 7, 2024

This PR introduces visual changes: 9b748ad
If these changes are intended and correct, please cherry-pick the above commit to this PR.

git checkout main
git fetch https://github.com/vmware-clarity/ng-clarity.git 9b748adec6d3e0bbae21cef7bc651750e87239e1
git cherry-pick 9b748adec6d3e0bbae21cef7bc651750e87239e1
git push

@venkateshr06 venkateshr06 requested a review from a team May 9, 2024 04:33
Copy link
Contributor

@Jinnie Jinnie left a 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/date-single-input.ts Outdated Show resolved Hide resolved
projects/angular/src/forms/common/abstract-container.ts Outdated Show resolved Hide resolved
projects/angular/src/forms/datepicker/date-input-base.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@Jinnie Jinnie left a 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-DE.ts Outdated Show resolved Hide resolved
</li>
<li>
<a [routerLink]="['./enhanced-date-picker']"
>Enhanced Date Picker
Copy link
Contributor

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.

projects/demo/src/app/datepicker/datepicker.demo.scss Outdated Show resolved Hide resolved
@kevinbuhmann
Copy link
Member

kevinbuhmann commented Jun 12, 2024

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.

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.

// and emit the control
this.additionalControls?.forEach((control: NgControl) => {
this.subscriptions.push(
control?.statusChanges?.subscribe(() => {
Copy link
Contributor

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.

Copy link
Contributor Author

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).

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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() {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@Jinnie Jinnie left a comment

Choose a reason for hiding this comment

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

A lot of code is duplicated between the date-range-start/end-input directives.

I would also like to have some UX input whether next/prev month grayed-out dates should be excluded from the range visualization, if it extends between adjacent months:
Screenshot 2024-06-13 at 14 26 25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants