-
Notifications
You must be signed in to change notification settings - Fork 56
feat: refactor date picker components and remove deprecated code #3003
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
base: develop
Are you sure you want to change the base?
Changes from 2 commits
c3f78af
c787c72
e632f6f
2c04ae6
9a2a895
017b9cc
2aa9be3
e637ba9
94b04db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,45 +17,56 @@ | |||||||||||||
| /* eslint-disable react/prop-types */ | ||||||||||||||
| import moment from 'moment' | ||||||||||||||
|
|
||||||||||||||
| import { InfoBlock, SelectPicker } from '@devtron-labs/devtron-fe-common-lib' | ||||||||||||||
| import { | ||||||||||||||
| ComponentSizeType, | ||||||||||||||
| DATE_TIME_FORMATS, | ||||||||||||||
| DateTimePicker, | ||||||||||||||
| InfoBlock, | ||||||||||||||
| SelectPicker, | ||||||||||||||
| } from '@devtron-labs/devtron-fe-common-lib' | ||||||||||||||
|
|
||||||||||||||
| import { SingleDatePickerComponent } from '../../../../components/common' | ||||||||||||||
| import { MomentDateFormat } from '../../../../config' | ||||||||||||||
| import { getDateInMilliseconds, getOptions } from './apiToken.utils' | ||||||||||||||
| import { ExpirationDateProps } from './types' | ||||||||||||||
|
|
||||||||||||||
| const ExpirationDate = ({ selectedExpirationDate, onChangeSelectFormData, handleDatesChange, customDate }) => ( | ||||||||||||||
| const ExpirationDate = ({ | ||||||||||||||
| selectedExpirationDate, | ||||||||||||||
| onChangeSelectFormData, | ||||||||||||||
| handleDatesChange, | ||||||||||||||
| customDate, | ||||||||||||||
| }: ExpirationDateProps) => ( | ||||||||||||||
| <div className="w-100"> | ||||||||||||||
| <div className="flex left bottom dc__gap-16"> | ||||||||||||||
| <div className="w-200"> | ||||||||||||||
| <SelectPicker | ||||||||||||||
| <SelectPicker<number | Date, false> | ||||||||||||||
| label="Expiration" | ||||||||||||||
| required | ||||||||||||||
| inputId="token-expiry-duration" | ||||||||||||||
| value={selectedExpirationDate} | ||||||||||||||
| options={getOptions(customDate)} | ||||||||||||||
| classNamePrefix="select-token-expiry-duration" | ||||||||||||||
| onChange={onChangeSelectFormData} | ||||||||||||||
| size={ComponentSizeType.large} | ||||||||||||||
| /> | ||||||||||||||
| </div> | ||||||||||||||
|
|
||||||||||||||
| {selectedExpirationDate.label !== 'Custom' && selectedExpirationDate.label !== 'No expiration' && ( | ||||||||||||||
| <span className="fs-13 fw-4 cn-9"> | ||||||||||||||
| <span>This token will expire on</span> | ||||||||||||||
| {moment(getDateInMilliseconds(selectedExpirationDate.value)).format(MomentDateFormat)} | ||||||||||||||
| {moment(getDateInMilliseconds(selectedExpirationDate.value)).format( | ||||||||||||||
| DATE_TIME_FORMATS.DD_MMM_YYYY_HH_MM, | ||||||||||||||
| )} | ||||||||||||||
|
Comment on lines
+55
to
+57
|
||||||||||||||
| {moment(getDateInMilliseconds(selectedExpirationDate.value)).format( | |
| DATE_TIME_FORMATS.DD_MMM_YYYY_HH_MM, | |
| )} | |
| {typeof selectedExpirationDate.value === 'number' | |
| ? moment(getDateInMilliseconds(selectedExpirationDate.value)).format(DATE_TIME_FORMATS.DD_MMM_YYYY_HH_MM) | |
| : ''} |
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DateTimePicker component is missing the hideTimeSelect prop. Since this is for selecting an expiration date (not time), the time selection should be hidden for consistency with other date pickers in the codebase and to avoid confusion.
Add:
<DateTimePicker
id="expiration-date-picker"
date={customDate}
onChange={handleDatesChange}
isTodayBlocked
hideTimeSelect
/>| isTodayBlocked | |
| isTodayBlocked | |
| hideTimeSelect |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,6 +26,7 @@ import ExpirationDate from './ExpirationDate' | |||||||||||||||||||||||||
| import GenerateActionButton from './GenerateActionButton' | ||||||||||||||||||||||||||
| import GenerateModal from './GenerateModal' | ||||||||||||||||||||||||||
| import { updateGeneratedAPIToken } from './service' | ||||||||||||||||||||||||||
| import { ExpirationDateProps, ExpirationDateSelectOptionType } from './types' | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const RegeneratedModal = ({ | ||||||||||||||||||||||||||
| close, | ||||||||||||||||||||||||||
|
|
@@ -38,7 +39,7 @@ const RegeneratedModal = ({ | |||||||||||||||||||||||||
| }: RegenerateModalType) => { | ||||||||||||||||||||||||||
| const [loader, setLoader] = useState(false) | ||||||||||||||||||||||||||
| const [showGenerateModal, setShowGenerateModal] = useState(false) | ||||||||||||||||||||||||||
| const [selectedExpirationDate, setSelectedExpirationDate] = useState<{ label: string; value: number }>({ | ||||||||||||||||||||||||||
| const [selectedExpirationDate, setSelectedExpirationDate] = useState<ExpirationDateSelectOptionType>({ | ||||||||||||||||||||||||||
| label: '30 days', | ||||||||||||||||||||||||||
| value: 30, | ||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||
|
|
@@ -48,18 +49,22 @@ const RegeneratedModal = ({ | |||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| const [invalidCustomDate, setInvalidCustomDate] = useState(false) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const onChangeSelectFormData = (selectedOption: { label: string; value: number }) => { | ||||||||||||||||||||||||||
| setRegeneratedExpireAtInMs(selectedOption.value === 0 ? 0 : getDateInMilliseconds(selectedOption.value)) | ||||||||||||||||||||||||||
| const onChangeSelectFormData: ExpirationDateProps['onChangeSelectFormData'] = (selectedOption) => { | ||||||||||||||||||||||||||
| const parsedMilliseconds = selectedOption.value === 0 ? 0 : getDateInMilliseconds(selectedOption.value) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| setRegeneratedExpireAtInMs( | ||||||||||||||||||||||||||
| typeof selectedOption.value === 'number' ? parsedMilliseconds : selectedOption.value.valueOf(), | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
|
Comment on lines
+53
to
+57
|
||||||||||||||||||||||||||
| const parsedMilliseconds = selectedOption.value === 0 ? 0 : getDateInMilliseconds(selectedOption.value) | |
| setRegeneratedExpireAtInMs( | |
| typeof selectedOption.value === 'number' ? parsedMilliseconds : selectedOption.value.valueOf(), | |
| ) | |
| const parsedMilliseconds = selectedOption.value === 0 | |
| ? 0 | |
| : typeof selectedOption.value === 'number' | |
| ? getDateInMilliseconds(selectedOption.value) | |
| : selectedOption.value.valueOf() | |
| setRegeneratedExpireAtInMs(parsedMilliseconds) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { SelectPickerOptionType } from '@devtron-labs/devtron-fe-common-lib' | ||
|
|
||
| export type ExpirationDateSelectOptionType = SelectPickerOptionType<number | Date> | ||
|
|
||
| export interface ExpirationDateProps { | ||
| selectedExpirationDate: ExpirationDateSelectOptionType | ||
| onChangeSelectFormData: (value: ExpirationDateSelectOptionType) => void | ||
| handleDatesChange: (date: Date) => void | ||
| customDate: Date | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function
getDateInMillisecondsis being called withselectedOption.valuewhich can be either anumber(days) or aDateobject (when "Custom" is selected), but the function only accepts numbers. This will cause incorrect behavior.The logic should be: