Skip to content

Commit

Permalink
fix(sinceRangePicker): change params
Browse files Browse the repository at this point in the history
  • Loading branch information
vermilionAnd authored and jack0pan committed Sep 26, 2023
1 parent b058136 commit 8b97938
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/past-time-picker/PastTimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const PastTimePicker = (props: PastTimePickerProps) => {
style,
showAbsDate = false,
NotAvailableToday = false,
earliestApprove = false,
allowReset = false,
defaultTimeRange,
...restProps
Expand Down Expand Up @@ -76,6 +77,7 @@ const PastTimePicker = (props: PastTimePickerProps) => {
lastText,
dayText,
timeRangeText,
earliestInHistory,
} = {
...defaultLocale,
...locale,
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -187,6 +190,7 @@ const PastTimePicker = (props: PastTimePickerProps) => {
};
const content = () => (
<StaticPastTimePicker
earliestApprove={earliestApprove}
disabledDate={disabledDate}
modes={modes}
experimental={experimental}
Expand Down
5 changes: 4 additions & 1 deletion src/past-time-picker/demos/PastTimePicker.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ Quick.args = {
};
export const QuickOptionsFilter = () => (
<PastTimePicker
quickOptionsFilter={(s: { value: string }) => ['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
/>
);

Expand Down
1 change: 1 addition & 0 deletions src/past-time-picker/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ export interface PastTimePickerProps
NotAvailableToday?: boolean;
allowReset?: boolean;
defaultTimeRange?: string;
earliestApprove?: boolean;
}
2 changes: 1 addition & 1 deletion src/static-past-time-picker/SinceRangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function SinceRangePicker({
const prefixCls = usePrefixCls('range-panel__header');
const [startDate, setStartDate] = React.useState<Date | undefined>(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<typeof defaultLocale>('StaticPastTimePicker') || defaultLocale;

Expand Down
4 changes: 4 additions & 0 deletions src/static-past-time-picker/StaticPastTimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function StaticPastTimePicker({
NotAvailableToday,
allowReset,
defaultTimeRange,
earliestApprove,
...rest
}: StaticPastTimePickerProps) {
const parseMode = (currentRange: string | undefined) => parseTimeMode(currentRange);
Expand Down Expand Up @@ -53,6 +54,7 @@ function StaticPastTimePicker({
last90daysText,
last180DaysText,
last365DaysText,
earliestInHistory,
} = {
...defaultLocale,
...locale,
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/static-past-time-picker/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export interface StaticPastTimePickerProps extends Omit<PickerProps, 'onSelect'>
onSelect?: (timeRange: string) => void;
onRangeSelect?: (dates: [Date, Date], index: number) => void;
NotAvailableToday: boolean;
earliestApprove: boolean;
}

export interface RangePickerProps extends PickerProps {
Expand Down
1 change: 1 addition & 0 deletions src/static-past-time-picker/locales/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/static-past-time-picker/locales/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default {
thisYearTextToToday: '今年(至今日)',
thisYearTextToYesterday: '今年(至昨日)',
lastYearText: '去年',
earliestInHistory: '历史最早',
lastSomeHours: (text: Key) => `过去 ${text} 小时`,
last7DaysText: '过去7天',
last14DaysText: '过去14天',
Expand Down

0 comments on commit 8b97938

Please sign in to comment.