From bbd85e0e98e0e9cfa8a81aede69d58f50755a5cb Mon Sep 17 00:00:00 2001 From: vermilionAnd Date: Tue, 10 Oct 2023 10:36:59 +0800 Subject: [PATCH] fix(past-time-picker): fix since:0=> earliest Signed-off-by: vermilionAnd --- src/past-time-picker/PastTimePicker.tsx | 10 +++++----- src/past-time-picker/demos/PastTimePicker.stories.tsx | 2 +- src/static-past-time-picker/StaticPastTimePicker.tsx | 2 +- src/static-past-time-picker/constant.ts | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/past-time-picker/PastTimePicker.tsx b/src/past-time-picker/PastTimePicker.tsx index 5f661710f1..f48f2ee014 100644 --- a/src/past-time-picker/PastTimePicker.tsx +++ b/src/past-time-picker/PastTimePicker.tsx @@ -111,16 +111,16 @@ const PastTimePicker = (props: PastTimePickerProps) => { 'day:15,1': last14DaysText, 'day:91,1': last90daysText, 'day:366,1': last365DaysText, - 'since:0': earliestInHistory, + earliest: earliestInHistory, }; const humanizeTimeRange = (time: string, defaultString = timeRangeText) => { - if (!time || time.split(':').length !== 2) { + if (!time) { return defaultString; } if (has(QUICK_MAPPING, time)) { const [startTime, endTime] = parseQuickDate(time); - const showSinceZero = time === 'since:0' ? earliestInHistoryEcho : `${get(QUICK_MAPPING, time)}`; + const showSinceZero = time === 'earliest' ? earliestInHistoryEcho : `${get(QUICK_MAPPING, time)}`; return showAbsDate ? `${get(QUICK_MAPPING, time)} | ${parseFnsTimeZone(startTime, 'yyyy/MM/dd')}-${parseFnsTimeZone( endTime, @@ -128,8 +128,8 @@ const PastTimePicker = (props: PastTimePickerProps) => { )}` : showSinceZero; } - const items = time.split(':'); - const times = items[1].split(',').map((str) => parseInt(str, 10)); + const items = time?.split(':'); + const times = items[1]?.split(',').map((str) => parseInt(str, 10)); if (items[0] === 'since') { const start = parseFnsTimeZone(times[0], 'yyyy/MM/dd'); const [startTime, endTime] = parseStartAndEndDate(time); diff --git a/src/past-time-picker/demos/PastTimePicker.stories.tsx b/src/past-time-picker/demos/PastTimePicker.stories.tsx index 82bad6243c..3a4df9840e 100644 --- a/src/past-time-picker/demos/PastTimePicker.stories.tsx +++ b/src/past-time-picker/demos/PastTimePicker.stories.tsx @@ -33,7 +33,7 @@ Quick.args = { export const QuickOptionsFilter = () => ( - ['day:2,1', 'day:8,1', 'day:15,1', 'day:31,1', 'since:0'].includes(s.value) + ['day:2,1', 'day:8,1', 'day:15,1', 'day:31,1', 'earliest'].includes(s.value) } onSelect={(v) => action('selected value:')(v)} placeholder="时间范围" diff --git a/src/static-past-time-picker/StaticPastTimePicker.tsx b/src/static-past-time-picker/StaticPastTimePicker.tsx index 757770bf8f..cda54ac77e 100644 --- a/src/static-past-time-picker/StaticPastTimePicker.tsx +++ b/src/static-past-time-picker/StaticPastTimePicker.tsx @@ -86,7 +86,7 @@ function StaticPastTimePicker({ { value: 'day:366,1', label: last365DaysText }, ]; - earliestApprove && quickOptions.push({ value: 'since:0', label: earliestInHistory }); + earliestApprove && quickOptions.push({ value: 'earliest', label: earliestInHistory }); const handleOnSelect = (value: string) => { setCurrentRange(value); diff --git a/src/static-past-time-picker/constant.ts b/src/static-past-time-picker/constant.ts index c604d71508..6531782a26 100644 --- a/src/static-past-time-picker/constant.ts +++ b/src/static-past-time-picker/constant.ts @@ -29,7 +29,7 @@ export const QUICK_MAPPING = { 'day:15,1': '过去 14 天', 'day:91,1': '过去 90 天', 'day:366,1': '过去 365 天', - 'since:0': '历史最早', + earliest: '历史最早', }; export const END_DATE_MAPPING: { [key: string]: string } = {