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: [M3-8611]- New DatePicker Component #11151

Merged
merged 84 commits into from
Dec 12, 2024
Merged

Conversation

cpathipa
Copy link
Contributor

@cpathipa cpathipa commented Oct 23, 2024

Description 📝

This PR introduces an new Date picker component an abstraction of MUI date picker

Changes 🔄

List any change relevant to the reviewer.

  • New DatePicker Component
  • New DateTimePicker Component
  • New DateTimeRangePicker Component

Preview 📷

Include a screenshot or screen recording of the change

DateTimePicker DateTimeRangePicker DatePicker
image image image

How to test 🧪

Verification steps

(How to verify changes)

  • Checkout the branch and run Storybook
  • Verify the datepicker components

As an Author I have considered 🤔

Check all that apply

  • 👀 Doing a self review
  • ❔ Our contribution guidelines
  • 🤏 Splitting feature into small PRs
  • ➕ Adding a changeset
  • 🧪 Providing/Improving test coverage
  • 🔐 Removing all sensitive information from the code and PR description
  • 🚩 Using a feature flag to protect the release
  • 👣 Providing comprehensive reproduction steps
  • 📑 Providing or updating our documentation
  • 🕛 Scheduling a pair reviewing session
  • 📱 Providing mobile support
  • ♿ Providing accessibility support

cpathipa added 30 commits June 19, 2024 09:06
@cpathipa
Copy link
Contributor Author

cpathipa commented Dec 9, 2024

@coliu-akamai Looks like the issue is with the AutoComplete component. I'm seeing a similar error for RegionSelect, ImageSelect, LinodeSelect as well in the Storybook. I will create a separate ticket to address this. The DatePicker components are working as expected in Storybook when rendered without TimeZoneSelect (which uses AutoComplete). For now, DatePickers in Storybook renders with ShowTimeZone set to false. To test the component with TimeZoneSelect, I recommend using the component in CM.

Copy link
Member

@bnussman-akamai bnussman-akamai left a comment

Choose a reason for hiding this comment

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

Unexpected behavior when typing in the TextField

If I click into the TextField and type the number 2, the cursor jumps to the end of the Text Field. It feels a bit unexpected. Is this something we can try to improve?

Screen.Recording.2024-12-09.at.3.23.59.PM.mov
Unexpected spacing around the "Ok" button

There is a lot of spacing around this button? Can we do anything about that?
Screenshot 2024-12-09 at 3 22 56 PM

'& .MuiDayCalendar-weekDayLabel': {
fontSize: '0.875rem',
},
'& .MuiPickersCalendarHeader-label': {
Copy link
Member

Choose a reason for hiding this comment

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

This seems like stuff that belongs in the MUI theme. Can we move styles like this into light.ts? Seems like this might help

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Moving these to foundations/themes/light.ts is not reflecting in the Storybook component but is working in the CM app. I will address this in the following PR for the DateRange Picker - M3-8990.

@cpathipa
Copy link
Contributor Author

cpathipa commented Dec 10, 2024

Unexpected behavior when typing in the TextField
If I click into the TextField and type the number 2, the cursor jumps to the end of the Text Field. It feels a bit unexpected. Is this something we can try to improve?

Screen.Recording.2024-12-09.at.3.23.59.PM.mov
Unexpected spacing around the "Ok" button
There is a lot of spacing around this button? Can we do anything about that? Screenshot 2024-12-09 at 3 22 56 PM

@bnussman-akamai Thank you for the through check.

  1. Adjusted the styles for TimePicker component.
    image

  2. DatePicker field typing issue - This issue is happening only with the DatePicker component and appears to be a browser-specific issue occurring only in Safari. It works as expected in Chrome. I believe the issue is related to the TextField component that we pass to the MUI DatePicker component. I tried using debounce, but the issue still persists. It seems this may require work on the TextField component. I will address this in the following PR.

Chrome: Working as expected in Chrome.

DatePicker-Typing.mov

Following PR's will address the below enhancements for the Date Range Picker Components.

  1. Moving the DatePicker to UI package - M3-8988
  2. Improve DatePicker input filed interaction when typing in Safari. - M3-8990

const newHour = newTime.hour;
const newMinute = newTime.minute;

if (typeof newHour === 'number' && typeof newMinute === 'number') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious, are these not being inferred to where we need this check?

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, I may have overthought this and taken a more defensive approach. In this context, we can safely rely on the Luxon DateTime object and expect hour and minute to always be numbers. I've simplified the logic accordingly. -
1ab71f9

}
};

const handleEndDateTimeChange = (newEnd: DateTime | null) => {
Copy link
Contributor

@jaalah-akamai jaalah-akamai Dec 11, 2024

Choose a reason for hiding this comment

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

At the moment, this is the biggest issue I see at the moment. Context: #11151 (comment)

const [endDateTime, setEndDateTime] = useState<DateTime | null>(
endDateTimeValue
);
const [error, setError] = useState<string>();
Copy link
Contributor

@jaalah-akamai jaalah-akamai Dec 11, 2024

Choose a reason for hiding this comment

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

Yea I agree - it wouldn't actually be too much of a lift if we removed the useState hooks and relied entirely on props for values and change handling. The only downside when it comes to storybook is that we would need some sort of wrapper that manages the state (similar to how things are now) for testing/demos in storybook or something. Context: #11151 (comment)

@cpathipa cpathipa added the Add'tl Approval Needed Waiting on another approval! label Dec 11, 2024
Copy link
Contributor

@coliu-akamai coliu-akamai left a comment

Choose a reason for hiding this comment

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

Spoke async about tackling some enhancements in further PRs, including about the cancel/apply buttons - thanks Chandra!

if we don't plan on tackling the autocomplete storybook issue here, we should open up a ticket for it

Copy link
Contributor

@hana-akamai hana-akamai left a comment

Choose a reason for hiding this comment

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

Is it intentional that the DatePicker component lets the user type the date but the DateTimePicker and DateTimeRangePicker don't let you?

value: null,
};

describe('DatePicker', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a test for typing the date in the input?

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, I tried to cover this test but faced an issue because the TextField component currently allows free-form typing. Addressing this would require updating our TextField component to support a date type field or exploring alternative approaches to handle date-specific input more effectively. This also, involves in restricting free from typing on the input field. I will create a separate ticket to tackle this.

  it.only('should handle typing a date and pressing Enter', async () => {
    renderWithTheme(<DatePicker {...props} />);

    const datePickerField = screen.getByRole('textbox', {
      name: 'Select a date',
    });

    // Select all text and clear with Backspace
    await userEvent.click(datePickerField);

    // Type a valid date into the input field
    await userEvent.type(datePickerField, '2024-10-25');

    // Simulate pressing Enter
    await userEvent.keyboard('{Enter}');

    // Verify that the field value is updated
    expect(datePickerField).toHaveValue('2024-10-25');
  });

value={selectedDateTime || null}
{...dateCalendarProps}
// TODO: Move styling customization to global theme styles.
sx={(theme: Theme) => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make the scrollbar thinner with something like scrollbar-width: thin; and remove the scrollbar for the AM/PM column?

Screen.Recording.2024-12-11.at.3.27.17.PM.mov

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This UX is going to change in the followup PR's where it will be one modal with Calendar and time. I will get this cosmetic change included as part of that.

packages/ui/package.json Show resolved Hide resolved
packages/manager/src/components/DatePicker/DatePicker.tsx Outdated Show resolved Hide resolved
@bnussman-akamai bnussman-akamai added Approved Multiple approvals and ready to merge! and removed Add'tl Approval Needed Waiting on another approval! labels Dec 12, 2024
Copy link
Contributor Author

@cpathipa cpathipa left a comment

Choose a reason for hiding this comment

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

@hana-akamai To make it simple we currently disabled type functionality in the DateTimePicker component.

packages/manager/src/components/DatePicker/DatePicker.tsx Outdated Show resolved Hide resolved
packages/ui/package.json Show resolved Hide resolved
value: null,
};

describe('DatePicker', () => {
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, I tried to cover this test but faced an issue because the TextField component currently allows free-form typing. Addressing this would require updating our TextField component to support a date type field or exploring alternative approaches to handle date-specific input more effectively. This also, involves in restricting free from typing on the input field. I will create a separate ticket to tackle this.

  it.only('should handle typing a date and pressing Enter', async () => {
    renderWithTheme(<DatePicker {...props} />);

    const datePickerField = screen.getByRole('textbox', {
      name: 'Select a date',
    });

    // Select all text and clear with Backspace
    await userEvent.click(datePickerField);

    // Type a valid date into the input field
    await userEvent.type(datePickerField, '2024-10-25');

    // Simulate pressing Enter
    await userEvent.keyboard('{Enter}');

    // Verify that the field value is updated
    expect(datePickerField).toHaveValue('2024-10-25');
  });

value={selectedDateTime || null}
{...dateCalendarProps}
// TODO: Move styling customization to global theme styles.
sx={(theme: Theme) => ({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This UX is going to change in the followup PR's where it will be one modal with Calendar and time. I will get this cosmetic change included as part of that.

@cpathipa cpathipa requested a review from hana-akamai December 12, 2024 19:07
@linode-gh-bot
Copy link
Collaborator

Cloud Manager UI test results

🎉 465 passing tests on test run #35 ↗︎

❌ Failing✅ Passing↪️ Skipped🕐 Duration
0 Failing465 Passing2 Skipped101m 31s

@cpathipa cpathipa merged commit 518d85d into linode:develop Dec 12, 2024
23 checks passed
Copy link

cypress bot commented Dec 12, 2024

Cloud Manager E2E    Run #6963

Run Properties:  status check failed Failed #6963  •  git commit 518d85d037: feat: [M3-8611]- New DatePicker Component (#11151)
Project Cloud Manager E2E
Branch Review develop
Run status status check failed Failed #6963
Run duration 33m 11s
Commit git commit 518d85d037: feat: [M3-8611]- New DatePicker Component (#11151)
Committer cpathipa
View all properties for this run ↗︎

Test results
Tests that failed  Failures 2
Tests that were flaky  Flaky 2
Tests that did not run due to a developer annotating a test with .skip  Pending 2
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 467
View all changes introduced in this branch ↗︎

Tests for review

Failed  cypress/e2e/core/linodes/rebuild-linode.spec.ts • 2 failed tests

View Output Video

Test Artifacts
rebuild linode > rebuilds a linode from Community StackScript Screenshots Video
rebuild linode > rebuilds a linode from Account StackScript Screenshots Video
Flakiness  clone-linode.spec.ts • 1 flaky test

View Output Video

Test Artifacts
clone linode > can clone a Linode from Linode details page Screenshots Video
Flakiness  linode-config.spec.ts • 1 flaky test

View Output Video

Test Artifacts
Linode Config management > End-to-End > Clones a config Screenshots Video

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved Multiple approvals and ready to merge! Date Range Picker
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants