From 461078a0cbd311de34183745e507af967ebdae4e Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 6 Nov 2025 11:26:02 +0800 Subject: [PATCH] feat: support direct choose date --- .../time-range-picker/date-picker.tsx | 2 ++ .../date-picker/index.tsx | 25 ++++++++++++------- .../base/date-and-time-picker/types.ts | 1 + 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/time-range-picker/date-picker.tsx b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/time-range-picker/date-picker.tsx index dbc8fd45c3..51452a4e0b 100644 --- a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/time-range-picker/date-picker.tsx +++ b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/time-range-picker/date-picker.tsx @@ -43,6 +43,7 @@ const DatePicker: FC = ({ renderTrigger={renderDate} needTimePicker={false} onClear={noop} + noConfirm /> - = ({ renderTrigger={renderDate} needTimePicker={false} onClear={noop} + noConfirm /> diff --git a/web/app/components/base/date-and-time-picker/date-picker/index.tsx b/web/app/components/base/date-and-time-picker/date-picker/index.tsx index 3540bdecc8..5e19522898 100644 --- a/web/app/components/base/date-and-time-picker/date-picker/index.tsx +++ b/web/app/components/base/date-and-time-picker/date-picker/index.tsx @@ -36,6 +36,7 @@ const DatePicker = ({ renderTrigger, triggerWrapClassName, popupZIndexClassname = 'z-[11]', + noConfirm, getIsDateDisabled, }: DatePickerProps) => { const { t } = useTranslation() @@ -121,11 +122,20 @@ const DatePicker = ({ setCurrentDate(currentDate.clone().subtract(1, 'month')) }, [currentDate]) + const handleConfirmDate = (passedInSelectedDate?: Dayjs) => { + // passedInSelectedDate may be a click event when noConfirm is false + const nextDate = (dayjs.isDayjs(passedInSelectedDate) ? passedInSelectedDate : selectedDate) + onChange(nextDate ? nextDate.tz(timezone) : undefined) + setIsOpen(false) + } + const handleDateSelect = useCallback((day: Dayjs) => { const newDate = cloneTime(day, selectedDate || getDateWithTimezone({ timezone })) setCurrentDate(newDate) setSelectedDate(newDate) - }, [selectedDate, timezone]) + if (noConfirm) + handleConfirmDate(newDate) + }, [selectedDate, timezone, noConfirm, handleConfirmDate]) const handleSelectCurrentDate = () => { const newDate = getDateWithTimezone({ timezone }) @@ -135,12 +145,6 @@ const DatePicker = ({ setIsOpen(false) } - const handleConfirmDate = () => { - // debugger - onChange(selectedDate ? selectedDate.tz(timezone) : undefined) - setIsOpen(false) - } - const handleClickTimePicker = () => { if (view === ViewType.date) { setView(ViewType.time) @@ -292,7 +296,7 @@ const DatePicker = ({ {/* Footer */} { - [ViewType.date, ViewType.time].includes(view) ? ( + [ViewType.date, ViewType.time].includes(view) && !noConfirm && ( - ) : ( + ) + } + { + ![ViewType.date, ViewType.time].includes(view) && ( React.ReactNode minuteFilter?: (minutes: string[]) => string[] popupZIndexClassname?: string + noConfirm?: boolean getIsDateDisabled?: (date: Dayjs) => boolean }