From cdd85ff73674e250f3444f58c26a1d775ba5d228 Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 6 Nov 2025 11:00:17 +0800 Subject: [PATCH] chore: combe start or end change --- .../overview/time-range-picker/index.tsx | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/time-range-picker/index.tsx b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/time-range-picker/index.tsx index 45c0292d72..f6c3b18277 100644 --- a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/time-range-picker/index.tsx +++ b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/time-range-picker/index.tsx @@ -7,6 +7,8 @@ import { HourglassShape } from '@/app/components/base/icons/src/vender/other' import RangeSelector from './range-selector' import DatePicker from './date-picker' import dayjs from 'dayjs' +import { useI18N } from '@/context/i18n' +import { formatToLocalTime } from '@/utils/format' const today = dayjs() @@ -21,6 +23,8 @@ const TimeRangePicker: FC = ({ onSelect, queryDateFormat, }) => { + const { locale } = useI18N() + const [isCustomRange, setIsCustomRange] = useState(false) const [start, setStart] = useState(today) const [end, setEnd] = useState(today) @@ -38,19 +42,29 @@ const TimeRangePicker: FC = ({ }) }, [onSelect]) - const handleStartChange = useCallback((date?: Dayjs) => { - if (!date) return - setStart(date) - setIsCustomRange(true) - onSelect({ name: 'custom', query: { start: date.format(queryDateFormat), end: end.format(queryDateFormat) } }) - }, [end, onSelect, queryDateFormat]) + const handleDateChange = useCallback((type: 'start' | 'end') => { + return (date?: Dayjs) => { + if (!date) return + if (type === 'start' && date.isSame(start)) return + if (type === 'end' && date.isSame(end)) return + if (type === 'start') + setStart(date) + else + setEnd(date) - const handleEndChange = useCallback((date?: Dayjs) => { - if (!date) return - setEnd(date) - setIsCustomRange(true) - onSelect({ name: 'custom', query: { start: start.format(queryDateFormat), end: date.format(queryDateFormat) } }) - }, [start, onSelect, queryDateFormat]) + const currStart = type === 'start' ? date : start + const currEnd = type === 'end' ? date : end + onSelect({ + name: `${formatToLocalTime(currStart, locale, 'MMM D')} - ${formatToLocalTime(currEnd, locale, 'MMM D')}`, + query: { + start: currStart.format(queryDateFormat), + end: currEnd.format(queryDateFormat), + }, + }) + + setIsCustomRange(true) + } + }, []) return (
@@ -63,8 +77,8 @@ const TimeRangePicker: FC = ({
)