From 8b97938e732b9ae008b4bc605938256bbd45bb0f Mon Sep 17 00:00:00 2001 From: vermilionAnd Date: Tue, 26 Sep 2023 09:37:56 +0800 Subject: [PATCH] fix(sinceRangePicker): change params --- src/past-time-picker/PastTimePicker.tsx | 4 ++++ src/past-time-picker/demos/PastTimePicker.stories.tsx | 5 ++++- src/past-time-picker/interfaces.ts | 1 + src/static-past-time-picker/SinceRangePicker.tsx | 2 +- src/static-past-time-picker/StaticPastTimePicker.tsx | 4 ++++ src/static-past-time-picker/interfaces.ts | 1 + src/static-past-time-picker/locales/en-US.ts | 1 + src/static-past-time-picker/locales/zh-CN.ts | 1 + 8 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/past-time-picker/PastTimePicker.tsx b/src/past-time-picker/PastTimePicker.tsx index b22a3d28aa..b3db7e10d5 100644 --- a/src/past-time-picker/PastTimePicker.tsx +++ b/src/past-time-picker/PastTimePicker.tsx @@ -35,6 +35,7 @@ const PastTimePicker = (props: PastTimePickerProps) => { style, showAbsDate = false, NotAvailableToday = false, + earliestApprove = false, allowReset = false, defaultTimeRange, ...restProps @@ -76,6 +77,7 @@ const PastTimePicker = (props: PastTimePickerProps) => { lastText, dayText, timeRangeText, + earliestInHistory, } = { ...defaultLocale, ...locale, @@ -108,6 +110,7 @@ const PastTimePicker = (props: PastTimePickerProps) => { 'day:15,1': last14DaysText, 'day:91,1': last90daysText, 'day:366,1': last365DaysText, + 'since:0': earliestInHistory, }; const humanizeTimeRange = (time: string, defaultString = timeRangeText) => { @@ -187,6 +190,7 @@ const PastTimePicker = (props: PastTimePickerProps) => { }; const content = () => ( ( ['day:2,1', 'day:8,1', 'day:15,1', 'day:31,1'].includes(s.value)} + quickOptionsFilter={(s: { value: string }) => + ['day:2,1', 'day:8,1', 'day:15,1', 'day:31,1', 'since:0'].includes(s.value) + } onSelect={(v) => action('selected value:')(v)} placeholder="时间范围" + earliestApprove /> ); diff --git a/src/past-time-picker/interfaces.ts b/src/past-time-picker/interfaces.ts index 6885a0e107..219a4ed3cf 100644 --- a/src/past-time-picker/interfaces.ts +++ b/src/past-time-picker/interfaces.ts @@ -20,4 +20,5 @@ export interface PastTimePickerProps NotAvailableToday?: boolean; allowReset?: boolean; defaultTimeRange?: string; + earliestApprove?: boolean; } diff --git a/src/static-past-time-picker/SinceRangePicker.tsx b/src/static-past-time-picker/SinceRangePicker.tsx index 3574921b1e..d63d7edca4 100644 --- a/src/static-past-time-picker/SinceRangePicker.tsx +++ b/src/static-past-time-picker/SinceRangePicker.tsx @@ -26,7 +26,7 @@ function SinceRangePicker({ const prefixCls = usePrefixCls('range-panel__header'); const [startDate, setStartDate] = React.useState(dates[0]); const [endKey, setEndKey] = React.useState( - endDateKeys[timeRange && timeRange.split(':')[0] === 'since' ? 0 : 1] || 0 + endDateKeys[timeRange && timeRange.split(':')[0] === 'since' ? 0 : 1] || 'today' ); const locale = useLocale('StaticPastTimePicker') || defaultLocale; diff --git a/src/static-past-time-picker/StaticPastTimePicker.tsx b/src/static-past-time-picker/StaticPastTimePicker.tsx index 2fa5821623..757770bf8f 100644 --- a/src/static-past-time-picker/StaticPastTimePicker.tsx +++ b/src/static-past-time-picker/StaticPastTimePicker.tsx @@ -22,6 +22,7 @@ function StaticPastTimePicker({ NotAvailableToday, allowReset, defaultTimeRange, + earliestApprove, ...rest }: StaticPastTimePickerProps) { const parseMode = (currentRange: string | undefined) => parseTimeMode(currentRange); @@ -53,6 +54,7 @@ function StaticPastTimePicker({ last90daysText, last180DaysText, last365DaysText, + earliestInHistory, } = { ...defaultLocale, ...locale, @@ -84,6 +86,8 @@ function StaticPastTimePicker({ { value: 'day:366,1', label: last365DaysText }, ]; + earliestApprove && quickOptions.push({ value: 'since:0', label: earliestInHistory }); + const handleOnSelect = (value: string) => { setCurrentRange(value); onSelect?.(value); diff --git a/src/static-past-time-picker/interfaces.ts b/src/static-past-time-picker/interfaces.ts index 6181668a04..e499d8df06 100644 --- a/src/static-past-time-picker/interfaces.ts +++ b/src/static-past-time-picker/interfaces.ts @@ -66,6 +66,7 @@ export interface StaticPastTimePickerProps extends Omit onSelect?: (timeRange: string) => void; onRangeSelect?: (dates: [Date, Date], index: number) => void; NotAvailableToday: boolean; + earliestApprove: boolean; } export interface RangePickerProps extends PickerProps { diff --git a/src/static-past-time-picker/locales/en-US.ts b/src/static-past-time-picker/locales/en-US.ts index 27815e2433..430364d146 100644 --- a/src/static-past-time-picker/locales/en-US.ts +++ b/src/static-past-time-picker/locales/en-US.ts @@ -34,6 +34,7 @@ export default { thisYearTextToToday: 'This year(to today)', thisYearTextToYesterday: 'This year(to yesterday)', lastYearText: 'Last Year', + earliestInHistory: 'Earliest in history', lastSomeHours: (text: Key) => `Last ${text} hour(s)`, last7DaysText: 'Previous 7 days', last14DaysText: 'Previous 14 days', diff --git a/src/static-past-time-picker/locales/zh-CN.ts b/src/static-past-time-picker/locales/zh-CN.ts index a6dda4887d..c480077388 100644 --- a/src/static-past-time-picker/locales/zh-CN.ts +++ b/src/static-past-time-picker/locales/zh-CN.ts @@ -34,6 +34,7 @@ export default { thisYearTextToToday: '今年(至今日)', thisYearTextToYesterday: '今年(至昨日)', lastYearText: '去年', + earliestInHistory: '历史最早', lastSomeHours: (text: Key) => `过去 ${text} 小时`, last7DaysText: '过去7天', last14DaysText: '过去14天',