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

Merged
merged 98 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 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
bea7bac
Show the start date and end date fields only when custom is selected
cpathipa Dec 17, 2024
4ff411b
Add calendar icon to DateTimePicker component
cpathipa Dec 18, 2024
510485a
code cleanup and adjust tests
cpathipa Dec 18, 2024
0cf080f
Update packages/manager/src/components/DatePicker/DateTimeRangePicker…
cpathipa Dec 18, 2024
729c184
update components
cpathipa Dec 18, 2024
727c59c
Organize and additional prop support to DateTimeRangePicker component
cpathipa Dec 18, 2024
9ebfb7f
Code cleanup
cpathipa Dec 18, 2024
25dc1e5
Merge remote-tracking branch 'origin/develop' into M3-8936
cpathipa Jan 7, 2025
e856275
PR feedback - @coliu-akamai
cpathipa Jan 7, 2025
15d9134
Move styles to theme level
cpathipa Jan 8, 2025
132ed74
Revert "Move styles to theme level"
cpathipa Jan 8, 2025
69355ac
code cleanup
cpathipa Jan 8, 2025
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))
42 changes: 35 additions & 7 deletions packages/manager/src/components/DatePicker/DateTimePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Divider } from '@linode/ui';
import { InputAdornment, TextField } from '@linode/ui';
import { Box } from '@linode/ui';
import { TextField } from '@linode/ui';
import CalendarTodayIcon from '@mui/icons-material/CalendarToday';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, the MUI calendar icon is being used, but it will be replaced with the SVG provided by the UX.

import { Grid, Popover } from '@mui/material';
import { AdapterLuxon } from '@mui/x-date-pickers/AdapterLuxon';
import { DateCalendar } from '@mui/x-date-pickers/DateCalendar';
Expand Down Expand Up @@ -66,7 +67,7 @@ export const DateTimePicker = ({
onApply,
onCancel,
onChange,
placeholder = 'yyyy-MM-dd HH:mm',
placeholder = 'Select Date',
showTime = true,
showTimeZone = true,
sx,
Expand All @@ -75,13 +76,22 @@ export const DateTimePicker = ({
value = null,
}: DateTimePickerProps) => {
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);

// Current and original states
const [selectedDateTime, setSelectedDateTime] = useState<DateTime | null>(
value
);
const [selectedTimeZone, setSelectedTimeZone] = useState<null | string>(
timeZoneSelectProps.value || null
);

const [originalDateTime, setOriginalDateTime] = useState<DateTime | null>(
value
);
const [originalTimeZone, setOriginalTimeZone] = useState<null | string>(
timeZoneSelectProps.value || null
);

const TimePickerFieldProps: TextFieldProps = {
label: timeSelectProps?.label ?? 'Select Time',
noMarginTop: true,
Expand Down Expand Up @@ -115,6 +125,8 @@ export const DateTimePicker = ({

const handleApply = () => {
setAnchorEl(null);
setOriginalDateTime(selectedDateTime);
setOriginalTimeZone(selectedTimeZone);
onChange(selectedDateTime);

if (onApply) {
Expand All @@ -124,6 +136,9 @@ export const DateTimePicker = ({

const handleClose = () => {
setAnchorEl(null);
setSelectedDateTime(originalDateTime);
setSelectedTimeZone(originalTimeZone);

if (onCancel) {
onCancel();
}
Expand All @@ -139,16 +154,32 @@ export const DateTimePicker = ({
<LocalizationProvider dateAdapter={AdapterLuxon}>
<Box sx={{ minWidth: '300px', ...sx }}>
<TextField
InputProps={{
readOnly: true,
startAdornment: (
<InputAdornment position="start">
<CalendarTodayIcon
sx={{
color: '#c2c2ca !important',
fontSize: '20px !important',
left: '8px',
position: 'absolute',
Comment on lines +162 to +166
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this will be removed when replacing MUI calendar icon with give SVG.

}}
/>
</InputAdornment>
),
sx: { paddingLeft: '32px' },
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible to use theme spacing instead of hardcoding values? eg theme.spacing(4)

Copy link
Contributor

Choose a reason for hiding this comment

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

@cpathipa Let's use the Calendar design tokens for all the styling here. You will have to add it to the light/dark theme index files and expose it here if you need to use those tokens at the component level. You could also apply them at the theme level under MuiDateField

}}
value={
selectedDateTime
? `${selectedDateTime.toFormat(format)}${
selectedTimeZone ? ` (${selectedTimeZone})` : ''
}`
: ''
}
InputProps={{ readOnly: true }}
errorText={errorText}
label={label}
noMarginTop
onClick={(event) => setAnchorEl(event.currentTarget)}
placeholder={placeholder}
/>
Expand Down Expand Up @@ -247,10 +278,6 @@ export const DateTimePicker = ({
<Divider />
<Box display="flex" justifyContent="flex-end">
<ActionsPanel
primaryButtonProps={{
label: 'Apply',
onClick: handleApply,
}}
secondaryButtonProps={{
buttonType: 'outlined',
label: 'Cancel',
Expand All @@ -260,6 +287,7 @@ export const DateTimePicker = ({
marginBottom: theme.spacing(1),
marginRight: theme.spacing(2),
})}
primaryButtonProps={{ label: 'Apply', onClick: handleApply }}
/>
</Box>
</Popover>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,61 +10,111 @@ type Story = StoryObj<typeof DateTimeRangePicker>;

export const Default: Story = {
args: {
endDateErrorMessage: '',
endDateTimeValue: null,
endLabel: 'End Date and Time',
endDateProps: {
errorMessage: '',
label: 'End Date and Time',
placeholder: '',
showTimeZone: false,
value: null,
},
format: 'yyyy-MM-dd HH:mm',
onChange: action('DateTime range changed'),
showEndTimeZone: true,
showStartTimeZone: true,
startDateErrorMessage: '',
startDateTimeValue: null,
startLabel: 'Start Date and Time',
startTimeZoneValue: null,
presetsProps: {
defaultValue: { label: '', value: '' },
enablePresets: true,
label: '',
placeholder: '',
},
startDateProps: {
errorMessage: '',
label: 'Start Date and Time',
placeholder: '',
showTimeZone: true,
timeZoneValue: null,
value: null,
},
sx: {},
},
render: (args) => <DateTimeRangePicker {...args} />,
};

export const WithInitialValues: Story = {
args: {
endDateTimeValue: DateTime.now(),
endLabel: 'End Date and Time',
endDateProps: {
label: 'End Date and Time',
showTimeZone: true,
value: DateTime.now(),
},
format: 'yyyy-MM-dd HH:mm',
onChange: action('DateTime range changed'),
showEndTimeZone: true,
showStartTimeZone: true,
startDateTimeValue: DateTime.now().minus({ days: 1 }),
startLabel: 'Start Date and Time',
startTimeZoneValue: 'America/New_York',
presetsProps: {
defaultValue: { label: 'Last 7 Days', value: '7days' },
enablePresets: true,
label: 'Time Range',
placeholder: 'Select Range',
},
startDateProps: {
label: 'Start Date and Time',
showTimeZone: true,
timeZoneValue: 'America/New_York',
value: DateTime.now().minus({ days: 1 }),
},
sx: {},
},
};

export const WithCustomErrors: Story = {
args: {
endDateErrorMessage: 'End date must be after the start date.',
endDateTimeValue: DateTime.now().minus({ days: 1 }),
endLabel: 'Custom End Label',
endDateProps: {
errorMessage: 'End date must be after the start date.',
label: 'Custom End Label',
placeholder: '',
showTimeZone: false,
value: DateTime.now().minus({ days: 1 }),
},
format: 'yyyy-MM-dd HH:mm',
onChange: action('DateTime range changed'),
startDateErrorMessage: 'Start date must be before the end date.',
startDateTimeValue: DateTime.now().minus({ days: 2 }),
startLabel: 'Custom Start Label',
presetsProps: {
defaultValue: { label: '', value: '' },
enablePresets: true,
label: '',
placeholder: '',
},
startDateProps: {
errorMessage: 'Start date must be before the end date.',
label: 'Start Date and Time',
placeholder: '',
showTimeZone: true,
timeZoneValue: null,
value: DateTime.now().minus({ days: 2 }),
},
},
};

const meta: Meta<typeof DateTimeRangePicker> = {
argTypes: {
endDateErrorMessage: {
control: 'text',
description: 'Custom error message for invalid end date',
},
endDateTimeValue: {
control: 'date',
description: 'Initial or controlled value for the end date-time',
},
endLabel: {
control: 'text',
description: 'Custom label for the end date-time picker',
endDateProps: {
errorMessage: {
control: 'text',
description: 'Custom error message for invalid end date',
},
label: {
control: 'text',
description: 'Custom label for the end date-time picker',
},
placeholder: {
control: 'text',
description: 'Placeholder for the end date-time',
},
showTimeZone: {
control: 'boolean',
description:
'Whether to show the timezone selector for the end date picker',
},
value: {
control: 'date',
description: 'Initial or controlled value for the end date-time',
},
},
format: {
control: 'text',
Expand All @@ -74,41 +124,67 @@ const meta: Meta<typeof DateTimeRangePicker> = {
action: 'DateTime range changed',
description: 'Callback when the date-time range changes',
},
showEndTimeZone: {
control: 'boolean',
description:
'Whether to show the timezone selector for the end date picker',
},
showStartTimeZone: {
control: 'boolean',
description:
'Whether to show the timezone selector for the start date picker',
},
startDateErrorMessage: {
control: 'text',
description: 'Custom error message for invalid start date',
},
startDateTimeValue: {
control: 'date',
description: 'Initial or controlled value for the start date-time',
presetsProps: {
defaultValue: {
label: {
control: 'text',
description: 'Default value label for the presets field',
},
value: {
control: 'text',
description: 'Default value for the presets field',
},
},
enablePresets: {
control: 'boolean',
description:
'If true, shows the date presets field instead of the date pickers',
},
label: {
control: 'text',
description: 'Label for the presets dropdown',
},
placeholder: {
control: 'text',
description: 'Placeholder for the presets dropdown',
},
},
startLabel: {
control: 'text',
description: 'Custom label for the start date-time picker',
},
startTimeZoneValue: {
control: 'text',
description: 'Initial or controlled value for the start timezone',
startDateProps: {
errorMessage: {
control: 'text',
description: 'Custom error message for invalid start date',
},
placeholder: {
control: 'text',
description: 'Placeholder for the start date-time',
},
showTimeZone: {
control: 'boolean',
description:
'Whether to show the timezone selector for the start date picker',
},
startLabel: {
control: 'text',
description: 'Custom label for the start date-time picker',
},
timeZoneValue: {
control: 'text',
description: 'Initial or controlled value for the start timezone',
},
value: {
control: 'date',
description: 'Initial or controlled value for the start date-time',
},
},
sx: {
control: 'object',
description: 'Styles to apply to the root element',
},
},
args: {
endLabel: 'End Date and Time',
endDateProps: { label: 'End Date and Time' },
format: 'yyyy-MM-dd HH:mm',
startLabel: 'Start Date and Time',
startDateProps: { label: 'Start Date and Time' },
},
component: DateTimeRangePicker,
title: 'Components/DatePicker/DateTimeRangePicker',
Expand Down
Loading
Loading