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-8936] - Add Date Presets Functionality to Date Picker component. #11395

Draft
wants to merge 86 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
b274baf
unit test coverage for HostNameTableCell
cpathipa Jun 19, 2024
f958dab
Revert "unit test coverage for HostNameTableCell"
cpathipa Jun 19, 2024
5d0a476
Merge branch 'linode:develop' into develop
cpathipa Jun 25, 2024
93aab07
Merge branch 'linode:develop' into develop
cpathipa Jun 25, 2024
d7deb4f
Merge branch 'linode:develop' into develop
cpathipa Jul 1, 2024
a550f05
Merge branch 'linode:develop' into develop
cpathipa Jul 3, 2024
de0f63e
Merge branch 'linode:develop' into develop
cpathipa Jul 5, 2024
426c42c
Merge branch 'linode:develop' into develop
cpathipa Jul 17, 2024
3fb49a6
Merge branch 'linode:develop' into develop
cpathipa Jul 22, 2024
6c76508
Merge branch 'linode:develop' into develop
cpathipa Jul 24, 2024
1653a6b
Merge branch 'linode:develop' into develop
cpathipa Jul 25, 2024
00421cf
Merge branch 'linode:develop' into develop
cpathipa Jul 29, 2024
959730a
Merge branch 'linode:develop' into develop
cpathipa Jul 31, 2024
d9bd490
Merge branch 'linode:develop' into develop
cpathipa Jul 31, 2024
960415e
Merge branch 'linode:develop' into develop
cpathipa Aug 1, 2024
b9f4745
Merge branch 'linode:develop' into develop
cpathipa Aug 2, 2024
b0b9264
Merge branch 'linode:develop' into develop
cpathipa Aug 21, 2024
6c70559
Merge branch 'linode:develop' into develop
cpathipa Aug 28, 2024
96eb34d
Merge branch 'linode:develop' into develop
cpathipa Sep 3, 2024
74b1635
Merge branch 'linode:develop' into develop
cpathipa Sep 4, 2024
70d1422
Merge branch 'linode:develop' into develop
cpathipa Sep 5, 2024
342fd96
Merge branch 'linode:develop' into develop
cpathipa Sep 9, 2024
bfed239
Merge branch 'linode:develop' into develop
cpathipa Sep 13, 2024
8a19f9b
Merge branch 'linode:develop' into develop
cpathipa Sep 17, 2024
9e9c14f
Merge branch 'linode:develop' into develop
cpathipa Sep 17, 2024
a25728e
Merge branch 'linode:develop' into develop
cpathipa Sep 18, 2024
3196f2a
Merge branch 'linode:develop' into develop
cpathipa Sep 19, 2024
4794d04
Merge branch 'linode:develop' into develop
cpathipa Sep 23, 2024
e977a94
Merge branch 'linode:develop' into develop
cpathipa Sep 24, 2024
add3f10
Merge branch 'linode:develop' into develop
cpathipa Sep 24, 2024
2fafd33
Merge branch 'linode:develop' into develop
cpathipa Sep 25, 2024
b3463ae
Merge branch 'linode:develop' into develop
cpathipa Sep 26, 2024
a325e30
Merge branch 'linode:develop' into develop
cpathipa Sep 30, 2024
b1e2a51
chore: [M3-8662] - Update Github Actions actions (#11009)
bnussman-akamai Sep 26, 2024
1b0931b
Merge branch 'develop' of github.com:cpathipa/manager into develop
cpathipa Sep 30, 2024
9b2de1d
Merge branch 'linode:develop' into develop
cpathipa Sep 30, 2024
ff89c50
Merge branch 'linode:develop' into develop
cpathipa Oct 9, 2024
4dbe28d
Merge branch 'linode:develop' into develop
cpathipa Oct 11, 2024
b2b7d97
Merge branch 'linode:develop' into develop
cpathipa Oct 14, 2024
04514de
Merge branch 'linode:develop' into develop
cpathipa Oct 16, 2024
e343821
Merge branch 'linode:develop' into develop
cpathipa Oct 21, 2024
7fd4fa5
Merge branch 'linode:develop' into develop
cpathipa Oct 22, 2024
81ec4f8
Merge branch 'linode:develop' into develop
cpathipa Oct 22, 2024
4e25a94
Basci date picker component
cpathipa Oct 23, 2024
52a7276
Merge remote-tracking branch 'origin/develop' into M3-8611
cpathipa Oct 24, 2024
423f4b7
Test coverage for date picker component
cpathipa Oct 25, 2024
34f03e3
Merge remote-tracking branch 'origin/develop' into M3-8611
cpathipa Oct 30, 2024
f87fbce
DatePicker Stories
cpathipa Oct 31, 2024
f47f919
Custom DateTimePicker component
cpathipa Oct 31, 2024
2578b83
Reusable TimeZone Select Component
cpathipa Oct 31, 2024
43810e7
Create custom DateTimeRangePicker component
cpathipa Oct 31, 2024
fa7bd52
Merge remote-tracking branch 'origin/develop' into M3-8611
cpathipa Nov 6, 2024
3b6f981
Storybook for DateTimePicker
cpathipa Nov 6, 2024
9b10623
Fix tests and remove console warnings
cpathipa Nov 7, 2024
9d32d3d
Merge remote-tracking branch 'origin/develop' into M3-8611
cpathipa Nov 18, 2024
11d8780
changeset
cpathipa Nov 18, 2024
862134f
Merge remote-tracking branch 'origin/develop' into M3-8611
cpathipa Nov 19, 2024
2643bd6
Merge remote-tracking branch 'origin/develop' into M3-8611
cpathipa Nov 20, 2024
7aec8c9
Update packages/manager/src/components/DatePicker/DateTimeRangePicker…
cpathipa Nov 20, 2024
0c379a2
Adjust styles for DatePicker
cpathipa Nov 21, 2024
73e0a20
Merge branch 'M3-8611' of github.com:cpathipa/manager into M3-8611
cpathipa Nov 21, 2024
194b0d2
Adjust styles for DateTimePicker
cpathipa Nov 22, 2024
0ffaade
Merge remote-tracking branch 'origin/develop' into M3-8611
cpathipa Dec 2, 2024
b2d591f
update imports
cpathipa Dec 2, 2024
efcfe5c
Render time and timezone conditionally in DateTimePicker component
cpathipa Dec 2, 2024
2ca7adf
Move DatePicker to UI package
cpathipa Dec 3, 2024
31dc03e
Add DatePicker dependencies
cpathipa Dec 3, 2024
cd875be
Code cleanup
cpathipa Dec 4, 2024
5f35d70
PR feedback
cpathipa Dec 4, 2024
208b2a0
code cleanup
cpathipa Dec 4, 2024
d1c3fa1
Move DatePicker back to src/components
cpathipa Dec 4, 2024
6186d26
Reverting changes
cpathipa Dec 4, 2024
2cd8366
Code cleanup
cpathipa Dec 4, 2024
b8f2d73
Adjust broken tests
cpathipa Dec 4, 2024
51b1a29
Merge remote-tracking branch 'origin/develop' into M3-8611
cpathipa Dec 4, 2024
e523043
Update TimeZoneSelect.tsx
cpathipa Dec 4, 2024
f0dd5c0
Code cleanup
cpathipa Dec 9, 2024
9abec60
Add validation for start date agains end date.
cpathipa Dec 9, 2024
fa3e186
Adjust styles for TimePicker component.
cpathipa Dec 10, 2024
de2097b
Merge remote-tracking branch 'origin/M3-8611' into M3-8936
cpathipa Dec 10, 2024
006371e
Add the functionality to support Date Presets
cpathipa Dec 10, 2024
bf1133f
Merge remote-tracking branch 'origin/develop' into M3-8936
cpathipa Dec 13, 2024
8c465b2
Update presets functionality and add test coverage.
cpathipa Dec 16, 2024
ac59703
Merge remote-tracking branch 'origin/develop' into M3-8936
cpathipa Dec 16, 2024
555a0be
Added changeset: Add Date Presets Functionality to Date Picker component
cpathipa Dec 16, 2024
b5c3606
Persist the preset value
cpathipa Dec 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-11395-added-1734381247482.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Added
---

Add Date Presets Functionality to Date Picker component ([#11395](https://github.com/linode/manager/pull/11395))
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ const flags: Partial<Flags> = {
},
],
};
const { metrics, id, serviceType, dashboardName, region, resource } =
widgetDetails.linode;
const {
metrics,
id,
serviceType,
dashboardName,
region,
resource,
} = widgetDetails.linode;

const dashboard = dashboardFactory.build({
label: dashboardName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { DateTime } from 'luxon';
import * as React from 'react';

import { renderWithTheme } from 'src/utilities/testHelpers';
Expand Down Expand Up @@ -98,8 +99,287 @@ describe('DateTimeRangePicker Component', () => {
/>
);

// Set the end date-time to the 15th
const endDateField = screen.getByLabelText('End Date and Time');
await userEvent.click(endDateField);
await userEvent.click(screen.getByRole('gridcell', { name: '15' }));
await userEvent.click(screen.getByRole('button', { name: 'Apply' }));

// Set the start date-time to the 20th (which is earlier than the end date-time)
const startDateField = screen.getByLabelText('Start Date and Time');
await userEvent.click(startDateField);
await userEvent.click(screen.getByRole('gridcell', { name: '20' })); // Invalid date
await userEvent.click(screen.getByRole('button', { name: 'Apply' }));

// Confirm the custom error message is displayed for the start date
expect(screen.getByText('Custom start date error')).toBeInTheDocument();
expect(screen.getByText('Custom end date error')).toBeInTheDocument();
});

it('should set the date range for the last 24 hours when the "Last 24 Hours" preset is selected', async () => {
renderWithTheme(
<DateTimeRangePicker enablePresets={true} onChange={onChangeMock} />
);

// Open the presets dropdown
const presetsDropdown = screen.getByLabelText('Date Presets');
await userEvent.click(presetsDropdown);

// Select the "Last 24 Hours" option
const last24HoursOption = screen.getByText('Last 24 Hours');
await userEvent.click(last24HoursOption);

// Verify that onChange is called with the correct date range
const now = DateTime.now();
const expectedStartDateTime = now.minus({ hours: 24 });

const expectedEndDateTime = now;

const expectedStartDateValue = expectedStartDateTime.toFormat(
'yyyy-MM-dd HH:mm'
);
const expectedEndDateValue = expectedEndDateTime.toFormat(
'yyyy-MM-dd HH:mm'
);

expect(onChangeMock).toHaveBeenCalledWith(
expect.objectContaining({
day: expectedStartDateTime.day,
month: expectedStartDateTime.month,
year: expectedStartDateTime.year,
}),
expect.objectContaining({
day: expectedEndDateTime.day,
month: expectedEndDateTime.month,
year: expectedEndDateTime.year,
}),
null
);

// Verify that Date input fields has the correct date range
expect(
screen.getByRole('textbox', { name: 'Start Date and Time' })
).toHaveValue(expectedStartDateValue);
expect(
screen.getByRole('textbox', { name: 'End Date and Time' })
).toHaveValue(expectedEndDateValue);
});

it('should set the date range for the last 7 days when the "Last 7 Days" preset is selected', async () => {
renderWithTheme(
<DateTimeRangePicker enablePresets={true} onChange={onChangeMock} />
);

// Open the presets dropdown
const presetsDropdown = screen.getByLabelText('Date Presets');
await userEvent.click(presetsDropdown);

// Select the "Last 7 Days" option
const last7DaysOption = screen.getByText('Last 7 Days');
await userEvent.click(last7DaysOption);

// Verify that onChange is called with the correct date range
const now = DateTime.now();
const expectedStartDateTime = now.minus({ days: 7 });
const expectedEndDateTime = now;

const expectedStartDateValue = expectedStartDateTime.toFormat(
'yyyy-MM-dd HH:mm'
);
const expectedEndDateValue = expectedEndDateTime.toFormat(
'yyyy-MM-dd HH:mm'
);

expect(onChangeMock).toHaveBeenCalledWith(
expect.objectContaining({
day: expectedStartDateTime.day,
month: expectedStartDateTime.month,
year: expectedStartDateTime.year,
}),
expect.objectContaining({
day: expectedEndDateTime.day,
month: expectedEndDateTime.month,
year: expectedEndDateTime.year,
}),
null
);

// Verify that Date input fields have the correct date range
expect(
screen.getByRole('textbox', { name: 'Start Date and Time' })
).toHaveValue(expectedStartDateValue);
expect(
screen.getByRole('textbox', { name: 'End Date and Time' })
).toHaveValue(expectedEndDateValue);
});

it('should set the date range for the last 30 days when the "Last 30 Days" preset is selected', async () => {
renderWithTheme(
<DateTimeRangePicker enablePresets={true} onChange={onChangeMock} />
);

// Open the presets dropdown
const presetsDropdown = screen.getByLabelText('Date Presets');
await userEvent.click(presetsDropdown);

// Select the "Last 30 Days" option
const last30DaysOption = screen.getByText('Last 30 Days');
await userEvent.click(last30DaysOption);

const now = DateTime.now();
const expectedStartDateTime = now.minus({ days: 30 });
const expectedEndDateTime = now;

// Use the same format as the component for verification
const expectedStartDateValue = expectedStartDateTime.toFormat(
'yyyy-MM-dd HH:mm'
);
const expectedEndDateValue = expectedEndDateTime.toFormat(
'yyyy-MM-dd HH:mm'
);

// Verify that onChange is called with the correct date range
expect(onChangeMock).toHaveBeenCalledWith(
expect.objectContaining({
day: expectedStartDateTime.day,
month: expectedStartDateTime.month,
year: expectedStartDateTime.year,
}),
expect.objectContaining({
day: expectedEndDateTime.day,
month: expectedEndDateTime.month,
year: expectedEndDateTime.year,
}),
null
);

// Verify the input fields display the correct values
expect(
screen.getByRole('textbox', { name: 'Start Date and Time' })
).toHaveValue(expectedStartDateValue);
expect(
screen.getByRole('textbox', { name: 'End Date and Time' })
).toHaveValue(expectedEndDateValue);
});

it('should set the date range for this month when the "This Month" preset is selected', async () => {
renderWithTheme(
<DateTimeRangePicker enablePresets={true} onChange={onChangeMock} />
);

// Open the presets dropdown
const presetsDropdown = screen.getByLabelText('Date Presets');
await userEvent.click(presetsDropdown);

// Select the "This Month" option
const thisMonthOption = screen.getByText('This Month');
await userEvent.click(thisMonthOption);

const now = DateTime.now();
const expectedStartDateTime = now.startOf('month');
const expectedEndDateTime = now.endOf('month');

// Use the same format as the component for verification
const expectedStartDateValue = expectedStartDateTime.toFormat(
'yyyy-MM-dd HH:mm'
);
const expectedEndDateValue = expectedEndDateTime.toFormat(
'yyyy-MM-dd HH:mm'
);

// Verify that onChange is called with the correct date range
expect(onChangeMock).toHaveBeenCalledWith(
expect.objectContaining({
day: expectedStartDateTime.day,
month: expectedStartDateTime.month,
year: expectedStartDateTime.year,
}),
expect.objectContaining({
day: expectedEndDateTime.day,
month: expectedEndDateTime.month,
year: expectedEndDateTime.year,
}),
null
);

// Verify the input fields display the correct values
expect(
screen.getByRole('textbox', { name: 'Start Date and Time' })
).toHaveValue(expectedStartDateValue);
expect(
screen.getByRole('textbox', { name: 'End Date and Time' })
).toHaveValue(expectedEndDateValue);
});

it('should set the date range for last month when the "Last Month" preset is selected', async () => {
renderWithTheme(
<DateTimeRangePicker enablePresets={true} onChange={onChangeMock} />
);

// Open the presets dropdown
const presetsDropdown = screen.getByLabelText('Date Presets');
await userEvent.click(presetsDropdown);

// Select the "Last Month" option
const lastMonthOption = screen.getByText('Last Month');
await userEvent.click(lastMonthOption);

const now = DateTime.now();
const lastMonth = now.minus({ months: 1 });
const expectedStartDateTime = lastMonth.startOf('month');
const expectedEndDateTime = lastMonth.endOf('month');

// Use the same format as the component for verification
const expectedStartDateValue = expectedStartDateTime.toFormat(
'yyyy-MM-dd HH:mm'
);
const expectedEndDateValue = expectedEndDateTime.toFormat(
'yyyy-MM-dd HH:mm'
);

// Verify that onChange is called with the correct date range
expect(onChangeMock).toHaveBeenCalledWith(
expect.objectContaining({
day: expectedStartDateTime.day,
month: expectedStartDateTime.month,
year: expectedStartDateTime.year,
}),
expect.objectContaining({
day: expectedEndDateTime.day,
month: expectedEndDateTime.month,
year: expectedEndDateTime.year,
}),
null
);

// Verify the input fields display the correct values
expect(
screen.getByRole('textbox', { name: 'Start Date and Time' })
).toHaveValue(expectedStartDateValue);
expect(
screen.getByRole('textbox', { name: 'End Date and Time' })
).toHaveValue(expectedEndDateValue);
});

it('should display the date range fields with empty values when the "Custom Range" preset is selected', async () => {
renderWithTheme(
<DateTimeRangePicker enablePresets={true} onChange={onChangeMock} />
);

// Open the presets dropdown
const presetsDropdown = screen.getByLabelText('Date Presets');
await userEvent.click(presetsDropdown);

// Select the "Custom Range" option
const customRange = screen.getByText('Custom Range');
await userEvent.click(customRange);

// Verify the input fields display the correct values
expect(
screen.getByRole('textbox', { name: 'Start Date and Time' })
).toHaveValue('');
expect(
screen.getByRole('textbox', { name: 'End Date and Time' })
).toHaveValue('');
expect(screen.getByRole('button', { name: 'Presets' })).toBeInTheDocument();
});
});
Loading
Loading