Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(time-picker): error fix #2234

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 30 additions & 27 deletions src/static-past-time-picker/StaticPastTimePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback } from 'react';
import React, { useCallback, useMemo } from 'react';
import { usePrefixCls, useLocale } from '@gio-design/utils';
import { filter } from 'lodash';
import SelectList from '../list';
Expand Down Expand Up @@ -58,38 +58,41 @@
...locale,
};

const PICKER_OPTIONS: { label: string; value: TimeMode | 'quick' }[] = [
{ value: 'quick', label: quickPickerText },
const PICKER_OPTIONS: { label: string; value: TimeMode }[] = [
{ value: TimeMode.Quick, label: quickPickerText },
{ value: TimeMode.Since, label: sinceRangePickerText },
{ value: TimeMode.Relative, label: relativeRangePickerText },
{ value: TimeMode.Absolute, label: absoluteRangePickerText },
];

const localQuickOptions = [
{ value: 'day:1,0', label: todayText },
{ value: 'day:2,1', label: yesterdayText },
{ value: experimental ? 'week-lt-today:1,0' : 'week:1,0', label: thisWeekText },
{ value: 'week:2,1', label: lastWeekText },
{ value: experimental ? 'month-lt-today:1,0' : 'month:1,0', label: thisMonthText },
{ value: 'month:2,1', label: lastMonthText },
{ value: experimental ? 'quarter-lt-today:1,0' : 'quarter:1,0', label: thisQuarterText },
{ value: 'quarter:2,1', label: lastQuarterText },
{ value: experimental ? 'year-lt-today:1,0' : 'year:1,0', label: thisYearText },
{ value: 'year:2,1', label: lastYearText },
{ value: 'day:8,1', label: last7DaysText },
{ value: 'day:15,1', label: last14DaysText },
{ value: 'day:31,1', label: last30daysText },
{ value: 'day:91,1', label: last90daysText },
{ value: 'day:181,1', label: last180DaysText },
{ value: 'day:366,1', label: last365DaysText },
];
const options = quickOptions || localQuickOptions;
const localQuickOptions = useMemo(
() => [
{ value: 'day:1,0', label: todayText },
{ value: 'day:2,1', label: yesterdayText },
{ value: experimental ? 'week-lt-today:1,0' : 'week:1,0', label: thisWeekText },
{ value: 'week:2,1', label: lastWeekText },
{ value: experimental ? 'month-lt-today:1,0' : 'month:1,0', label: thisMonthText },
{ value: 'month:2,1', label: lastMonthText },
{ value: experimental ? 'quarter-lt-today:1,0' : 'quarter:1,0', label: thisQuarterText },
{ value: 'quarter:2,1', label: lastQuarterText },
{ value: experimental ? 'year-lt-today:1,0' : 'year:1,0', label: thisYearText },
{ value: 'year:2,1', label: lastYearText },
{ value: 'day:8,1', label: last7DaysText },
{ value: 'day:15,1', label: last14DaysText },
{ value: 'day:31,1', label: last30daysText },
{ value: 'day:91,1', label: last90daysText },
{ value: 'day:181,1', label: last180DaysText },
{ value: 'day:366,1', label: last365DaysText },
],
[]

Check failure on line 87 in src/static-past-time-picker/StaticPastTimePicker.tsx

View workflow job for this annotation

GitHub Actions / integration / Linting

React Hook useMemo has missing dependencies: 'experimental', 'last14DaysText', 'last180DaysText', 'last30daysText', 'last365DaysText', 'last7DaysText', 'last90daysText', 'lastMonthText', 'lastQuarterText', 'lastWeekText', 'lastYearText', 'thisMonthText', 'thisQuarterText', 'thisWeekText', 'thisYearText', 'todayText', and 'yesterdayText'. Either include them or remove the dependency array
);
const options = useMemo(() => quickOptions || localQuickOptions, [quickOptions, localQuickOptions]);

earliestApprove && options.push({ value: 'earliest', label: earliestInHistory });

const parseMode = useCallback((current: string | undefined) => parseTimeMode(current, options), [options]);
const originMode = parseMode(timeRange) ?? 'quick';
const [mode, setMode] = React.useState<string | undefined>(originMode);
const originMode = (parseMode(timeRange) ?? TimeMode.Quick) as TimeMode;
const [mode, setMode] = React.useState<TimeMode>(modes?.includes(originMode) ? originMode : TimeMode.Quick);

const handleOnSelect = (value: string) => {
setCurrentRange(value);
Expand All @@ -107,7 +110,7 @@
};

switch (currentMode) {
case 'quick':
case TimeMode.Quick:
return (
<QuickPicker
{...valueProps}
Expand All @@ -127,7 +130,7 @@
};

React.useEffect(() => {
setMode(parseMode(timeRange) ?? 'quick');
setMode(parseMode(timeRange) ?? TimeMode.Quick);
}, [timeRange, parseMode]);

return (
Expand All @@ -137,7 +140,7 @@
options={filter(PICKER_OPTIONS, (o) => o.value === 'quick' || modes.includes(o.value))}
value={mode}
onChange={(value) => {
setMode(value as string);
setMode(value as TimeMode);
}}
/>
</div>
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 @@ -21,6 +21,7 @@ export enum TimeMode {
Absolute = 'absolute',
Since = 'since',
Relative = 'relative',
Quick = 'quick',
}

interface ExperimentProps {
Expand Down
2 changes: 1 addition & 1 deletion src/static-past-time-picker/style/QuickPicker.less
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
.@{quick-picker-prefix-cls} {
&__list {
display: flex;
max-height: 300px;
max-height: 335px;
overflow-y: auto;
.@{list-prefix-cls} {
display: grid;
Expand Down
4 changes: 2 additions & 2 deletions src/static-past-time-picker/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export const parseTimeMode = (
return undefined;
}
if (options?.find((option) => option.value === timeRange)) {
return 'quick';
return TimeMode.Quick;
}
if (has(QUICK_MAPPING, timeRange)) {
return 'quick';
return TimeMode.Quick;
}
const items = timeRange.split(':');
switch (items[0]) {
Expand Down
Loading