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

E&A Date Picker (Part One) - Integration and usage within the E&A Timeline header #1044

Closed
wants to merge 15 commits into from

Conversation

dzole0311
Copy link
Collaborator

@dzole0311 dzole0311 commented Jul 10, 2024

Related Ticket: #979

Description of Changes

The PR integrates the USWDS date picker into the E&A timeline. To reduce code review complexity, the changes here are:

  1. Integration of the react-uswds DatePicker in the veda-ui
  2. Replacement of the current timeline DatePicker with the new one
  3. Layout changes of the timeline header to match the designs (ie. placement of the datepickers)

Next:

  1. Changes for the timeline playheads + fix for the date picker to expand up/down based on the screen space
  2. Date picker aligns with the temporal density of the dataset(s): [E & A] Date picker aligns with temporal density #990

Notes & Questions About Changes

I discovered a few limitations of the DatePicker from react-uswds while working on this. For example, if we want to toggle the Calendar via a custom trigger or set a different Calendar mode (day, month, year) based on the temporal density of the datasets, we will have to do it programmatically. The library currently doesn't expose ref, nor props / methods to have more control over the component.

Validation / Testing

{Update with info on what can be manually validated in the Deploy Preview link for example "Validate style updates to selection modal do NOT affect cards"}

Copy link

netlify bot commented Jul 10, 2024

Deploy Preview for veda-ui ready!

Name Link
🔨 Latest commit 448551c
🔍 Latest deploy log https://app.netlify.com/sites/veda-ui/deploys/6690f3152956170008d6eb77
😎 Deploy Preview https://deploy-preview-1044--veda-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

@faustoperez faustoperez left a comment

Choose a reason for hiding this comment

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

Looking great Gjore!

One minor thing about the datepicker behaviour: can we align the selectable dates with the ones available on the active datasets:

  • Temporal resolution (daily, monthly, etc.)
  • Temporal extent (2000-present), for example
image

Thanks!

@dzole0311
Copy link
Collaborator Author

can we align the selectable dates with the ones available on the active datasets:

@faustoperez Yeah, I will work on that as we discussed but via this issue: #990. Tried to do it here, but I realized that I might introduce scope creep if I pull it in this sprint (and will make it hard to review the logic in one big PR).

// We have no reference to the internals of the react-uswds DatePicker, so we have to query for it's trigger.
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (datePickerRef.current) {
const button = datePickerRef.current.querySelector('button.usa-date-picker__button')! as HTMLButtonElement;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah I see. This is a sticky problem 😬 . Can we control the visibility of the calendar in this way? If we do a conditional render like {showCalendar && <DatePicker...>}, we will lose the access to this button. (Calendar is not toggling right now, it just re-renders when renderTriggerElement is pressed I think. )

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can't unfortunately, since the <Calendar /> comes coupled with the <DatePicker /> and we can't conditionally render only that component. So the only thing I could think of is programmatically toggling it via the usa-date-picker__button.

This gets trickier when we will have to show the MONTH_PICKER or the YEAR_PICKER based on the dataset time density, because these calendar modes exist as a local state in the Calendar. So the only solution I can think of is to click the picker button to open the calendar, then query and click either usa-date-picker__calendar__month-selection or usa-date-picker__calendar__year-selection to toggle the corresponding calendar mode depending on the time density 😰

I opened two issues on react-uswds side:

Copy link
Collaborator

@hanbyul-here hanbyul-here Jul 12, 2024

Choose a reason for hiding this comment

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

Throwing some ideas here. (It might be a terrible idea) Can it be something that we can solve by overwriting the style? I feel like they (calendar trigger element for both uswds date picker and our date picker) are eventually doing the same thing, showing the date, and then a button to trigger the calendar. (I understand our original design wants the whole thing to be a button to trigger - including the text- but maybe we can adjust the design a bit to accommodate USWDS system?)

ex. overwriting the text input style, calendar icon (to show the caret) here?

Screenshot 2024-07-12 at 10 57 42 AM

Maybe we can at least leave the button to trigger and overwrite the style?

Screenshot 2024-07-12 at 10 57 48 AM

Which will be roughly like this - #1047

Orrr 🤔 is this a good component to write React components for our own just using uswds style?

Copy link
Collaborator Author

@dzole0311 dzole0311 Jul 15, 2024

Choose a reason for hiding this comment

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

Thanks for the idea @hanbyul-here. As you pointed out, we will need to do a lot of manual triggering if we want to sync the calendar with the time density of the dataset, which I think is very error prone.

is this a good component to write React components for our own just using uswds style

Yes, I think so. We need a more robust approach but at the same time not to reinvent the wheel (e.g. implementing basic date picker functionality from scratch). What do you think about using react-calendar (https://www.npmjs.com/package/react-calendar)?

Here's a PR with it: #1048 and here's the deployment:

We could override some of the styles using uswds mixins / functions: https://github.com/NASA-IMPACT/veda-ui/pull/1048/files#diff-88b2701907396a34bbe38997d6970f2f6824389dbefe1dcc112a5fdfaa35d811R24

Also:

  • It works well with Tippy
  • It has out-of-the-box config for showing only the month or year calendar view (it's the maxDetail), so it will save us a lot of time

Any opinions on this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeh, I Agree that we should not invent the wheel. I will vote for using ReactCalendar for now 👍

@hanbyul-here
Copy link
Collaborator

Thanks for making the PR in phases. I think this is a lesson for us that it is not very easy to pick only speicific parts of the components from USWDS.

I wonder if what we need is just a Calendar component that the DatePicker component uses. This component is not being exported from the USWDS React library, but it might be a simpler feature request for their end. I can't think of any better approach than how you are doing to control the DatePicker now, but I left a comment on the code about visibility control.

There are some items that I noticed:

  1. When I turn on the compare mode, and then open the datepicker, the layout collapses:
Screenshot 2024-07-11 at 2 32 10 PM
  1. Do we need moment dependency? We are already using date-fns (https://date-fns.org/) throughout the app and I wonder if we need another date management library.

@dzole0311
Copy link
Collaborator Author

I wonder if what we need is just a Calendar component that the DatePicker component uses

@hanbyul-here Yeah, I think so as well.

When I turn on the compare mode, and then open the datepicker, the layout collapses:

Thanks for spotting this, will fix.

Do we need moment dependency

Replaced with date-fns

@dzole0311
Copy link
Collaborator Author

Closing this one as work continued here: #1048

@dzole0311 dzole0311 closed this Jul 17, 2024
sandrahoang686 added a commit that referenced this pull request Jul 17, 2024
**Related Ticket:** _{link related ticket here}_

### Description of Changes
We're introducing a more flexible calendar component which will use some
USWDS design tokens and icons. The change is made based on this
discussion:
#1044 (comment)

### Notes & Questions About Changes
_{Add additonal notes and outstanding questions here related to changes
in this pull request}_

### Validation / Testing
_{Update with info on what can be manually validated in the Deploy
Preview link for example "Validate style updates to selection modal do
NOT affect cards"}_
@hanbyul-here hanbyul-here mentioned this pull request Jul 18, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants