Skip to content

Commit

Permalink
fix(past-time-picker): fix since:0=> earliest (#2197)
Browse files Browse the repository at this point in the history
Signed-off-by: vermilionAnd <zhujiahong@growingio.com>
Co-authored-by: vermilionAnd <zhujiahong@growingio.com>
  • Loading branch information
zhuzilv and vermilionAnd committed Oct 10, 2023
1 parent f3d8908 commit 2633020
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/past-time-picker/PastTimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,25 @@ 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,
'yyyy/MM/dd'
)}`
: 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);
Expand Down
2 changes: 1 addition & 1 deletion src/past-time-picker/demos/PastTimePicker.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Quick.args = {
export const QuickOptionsFilter = () => (
<PastTimePicker
quickOptionsFilter={(s: { value: string }) =>
['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="时间范围"
Expand Down
2 changes: 1 addition & 1 deletion src/static-past-time-picker/StaticPastTimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/static-past-time-picker/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } = {
Expand Down

0 comments on commit 2633020

Please sign in to comment.