@synerise/ds-date-range-picker 2.3.2 → 2.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/CLAUDE.md +62 -33
- package/README.md +26 -13
- package/dist/AddonCollapse/AddonCollapse.types.d.ts +4 -4
- package/dist/DateRangePicker.types.d.ts +39 -19
- package/dist/Footer/Footer.types.d.ts +3 -2
- package/dist/RangeFilter/Filters/DailyFilter/DailyFilter.d.ts +5 -6
- package/dist/RangeFilter/Filters/MonthlyFilter/MonthlyFilter.types.d.ts +3 -2
- package/dist/RangeFilter/Filters/WeeklyFilter/WeeklyFilter.d.ts +2 -1
- package/dist/RangeFilter/Filters/WeeklyFilter/WeeklyFilter.types.d.ts +1 -5
- package/dist/RangeFilter/Filters/new/Filters.types.d.ts +2 -0
- package/dist/RangeFilter/Filters/new/Monthly/Monthly.d.ts +1 -1
- package/dist/RangeFilter/Filters/new/Monthly/Monthly.js +10 -45
- package/dist/RangeFilter/Filters/new/Monthly/Monthly.types.d.ts +9 -4
- package/dist/RangeFilter/Filters/new/Monthly/utils.d.ts +1 -1
- package/dist/RangeFilter/Filters/new/Weekly/Weekly.d.ts +1 -1
- package/dist/RangeFilter/Filters/new/Weekly/Weekly.js +10 -44
- package/dist/RangeFilter/Filters/new/Weekly/Weekly.types.d.ts +7 -3
- package/dist/RangeFilter/Filters/new/Weekly/utils.d.ts +1 -1
- package/dist/RangeFilter/Filters/new/filters.spec.constants.d.ts +15 -15
- package/dist/RangeFilter/Filters/new/hooks/useShiftAndControlKeys.js +9 -4
- package/dist/RangeFilter/RangeFilter.js +30 -47
- package/dist/RangeFilter/RangeFilter.types.d.ts +82 -42
- package/dist/RangeFilter/Shared/AddButton/AddButton.types.d.ts +2 -2
- package/dist/RangeFilter/Shared/FilterDropdown/FilterDropdown.types.d.ts +3 -3
- package/dist/RangeFilter/Shared/RangeFilterStatus/RangeFilterStatus.js +1 -1
- package/dist/RangeFilter/Shared/RangeFilterStatus/RangeFilterStatus.types.d.ts +2 -2
- package/dist/RangeFilter/Shared/SelectionCount/SelectionCount.types.d.ts +2 -2
- package/dist/RangeFilter/Shared/SelectionHint/SelectionHint.d.ts +3 -3
- package/dist/RangeFilter/Shared/TimeWindow/Day/Day.types.d.ts +2 -2
- package/dist/RangeFilter/Shared/TimeWindow/Grid/Grid.types.d.ts +3 -3
- package/dist/RangeFilter/Shared/TimeWindow/Header/Header.d.ts +4 -4
- package/dist/RangeFilter/Shared/TimeWindow/RangeActions/RangeActions.types.d.ts +4 -4
- package/dist/RangeFilter/Shared/TimeWindow/RangeFormContainer/RangeForm/RangeForm.types.d.ts +2 -2
- package/dist/RangeFilter/Shared/TimeWindow/TimeWindow.js +2 -1
- package/dist/RangeFilter/Shared/TimeWindow/TimeWindow.types.d.ts +4 -4
- package/dist/RangeFilter/constants.d.ts +19 -17
- package/dist/RangeFilter/constants.js +14 -21
- package/dist/RangeFilter/utils.d.ts +27 -24
- package/dist/RangeFilter/utils.js +124 -131
- package/dist/RangePickerInput/RangePickerInput.types.d.ts +3 -2
- package/dist/RawDateRangePicker.d.ts +2 -2
- package/dist/RawDateRangePicker.js +2 -1
- package/dist/RelativeRangePicker/Elements/CustomRangeForm/CustomRangeForm.d.ts +1 -1
- package/dist/RelativeRangePicker/Elements/CustomRangeForm/CustomRangeForm.js +1 -2
- package/dist/RelativeRangePicker/Elements/CustomRangeForm/CustomRangeForm.types.d.ts +0 -1
- package/dist/RelativeRangePicker/Elements/ModeDropdown/ModeDropdown.types.d.ts +0 -3
- package/dist/RelativeRangePicker/Elements/RangeButtons/RangeButtons.types.d.ts +2 -3
- package/dist/RelativeRangePicker/Elements/RangeDropdown/RangeDropdown.js +1 -1
- package/dist/RelativeRangePicker/Elements/RangeDropdown/RangeDropdown.types.d.ts +1 -1
- package/dist/RelativeRangePicker/Elements/TimestampRange/TimestampDuration/TimestampDuration.types.d.ts +7 -5
- package/dist/RelativeRangePicker/Elements/TimestampRange/TimestampRange.js +19 -15
- package/dist/RelativeRangePicker/Elements/TimestampRange/TimestampRange.types.d.ts +2 -2
- package/dist/RelativeRangePicker/RelativeRangePicker.js +9 -9
- package/dist/RelativeRangePicker/RelativeRangePicker.types.d.ts +1 -2
- package/dist/RelativeRangePicker/utils/findMatchingPreset.utils.d.ts +8 -11
- package/dist/RelativeRangePicker/utils/index.d.ts +0 -1
- package/dist/RelativeRangePicker/utils/index.js +0 -2
- package/dist/constants.d.ts +14 -14
- package/dist/constants.js +2 -4
- package/dist/date.types.d.ts +52 -25
- package/dist/dateUtils/isSinceRange.d.ts +3 -0
- package/dist/dateUtils/isSinceRange.js +4 -0
- package/dist/dateUtils/relativeToAbsolute.d.ts +2 -2
- package/dist/index.d.ts +14 -3
- package/dist/index.js +13 -1
- package/dist/utils.d.ts +1 -1
- package/package.json +21 -21
- package/dist/RelativeRangePicker/utils/isAbsolute.utils.d.ts +0 -2
- package/dist/RelativeRangePicker/utils/isAbsolute.utils.js +0 -5
|
@@ -34,14 +34,16 @@ const Monthly = ({
|
|
|
34
34
|
onChange = NOOP,
|
|
35
35
|
timeFormat,
|
|
36
36
|
valueFormatOptions,
|
|
37
|
-
value,
|
|
37
|
+
value: schedule,
|
|
38
38
|
timePickerProps,
|
|
39
39
|
disabled,
|
|
40
40
|
texts,
|
|
41
41
|
periodType = DAYS_OF_PERIOD_ENUM.DAY_OF_MONTH,
|
|
42
42
|
countedFrom = COUNTED_FROM_ENUM.BEGINNING,
|
|
43
|
-
errorTexts
|
|
43
|
+
errorTexts: scheduleErrors
|
|
44
44
|
}) => {
|
|
45
|
+
const value = schedule;
|
|
46
|
+
const errorTexts = scheduleErrors;
|
|
45
47
|
const intl = useIntl();
|
|
46
48
|
const allTexts = useMemo(() => getDefaultTexts(intl, false, texts), [texts, intl]);
|
|
47
49
|
const defaultDayValue = useMemo(() => ({
|
|
@@ -101,10 +103,7 @@ const Monthly = ({
|
|
|
101
103
|
onChange(scheduleToUpdate);
|
|
102
104
|
}, [onChange]);
|
|
103
105
|
useEffect(() => {
|
|
104
|
-
const entriesWithActiveDaysValue = activeDays.length ? Object.keys(value).filter((id) => activeDays.every((day) => (
|
|
105
|
-
// @ts-expect-error - requires type refactor
|
|
106
|
-
!!value[id][day] && haveActiveDaysCommonRange(value[id], activeDays)
|
|
107
|
-
))) : [];
|
|
106
|
+
const entriesWithActiveDaysValue = activeDays.length ? Object.keys(value).filter((id) => activeDays.every((day) => !!value[id][day] && haveActiveDaysCommonRange(value[id], activeDays))) : [];
|
|
108
107
|
removeEmptyEntries(value);
|
|
109
108
|
setFilteredSchedule(entriesWithActiveDaysValue);
|
|
110
109
|
}, [value, activeDays, removeEmptyEntries]);
|
|
@@ -114,7 +113,6 @@ const Monthly = ({
|
|
|
114
113
|
if (dayKey instanceof Array) {
|
|
115
114
|
dayKey.forEach((day) => {
|
|
116
115
|
updatedSchedule[guid][day] = {
|
|
117
|
-
// @ts-expect-error - requires type refactor
|
|
118
116
|
...value[guid][day],
|
|
119
117
|
restricted: true,
|
|
120
118
|
start: start ? dayjs(start).format(DEFAULT_TIME_FORMAT) : void 0,
|
|
@@ -124,7 +122,6 @@ const Monthly = ({
|
|
|
124
122
|
});
|
|
125
123
|
} else {
|
|
126
124
|
updatedSchedule[guid][dayKey] = {
|
|
127
|
-
// @ts-expect-error - requires type refactor
|
|
128
125
|
...value[guid][dayKey],
|
|
129
126
|
restricted: true,
|
|
130
127
|
start: start ? dayjs(start).format(DEFAULT_TIME_FORMAT) : void 0,
|
|
@@ -144,7 +141,6 @@ const Monthly = ({
|
|
|
144
141
|
const updatedSchedule = value;
|
|
145
142
|
dayKeys.forEach((day) => {
|
|
146
143
|
updatedSchedule[guid][day] = {
|
|
147
|
-
// @ts-expect-error - requires type refactor
|
|
148
144
|
...value[guid][day],
|
|
149
145
|
mode: selectedMode
|
|
150
146
|
};
|
|
@@ -237,10 +233,7 @@ const Monthly = ({
|
|
|
237
233
|
}, [activeDays, getDayLabel, isDayRestricted, disabled, intl, handleToggleDay, removeDaySelection, allTexts]);
|
|
238
234
|
const handleRangeAdd = useCallback(() => {
|
|
239
235
|
const updatedDay = {};
|
|
240
|
-
const guid = Object.keys(value).find((key) => (
|
|
241
|
-
// @ts-expect-error - requires type refactor
|
|
242
|
-
activeDays.every((day) => value[key][day] === void 0)
|
|
243
|
-
));
|
|
236
|
+
const guid = Object.keys(value).find((key) => activeDays.every((day) => value[key][day] === void 0));
|
|
244
237
|
activeDays.forEach((day) => {
|
|
245
238
|
updatedDay[day] = defaultDayValue;
|
|
246
239
|
});
|
|
@@ -258,40 +251,12 @@ const Monthly = ({
|
|
|
258
251
|
const canAddRange = canAddAnotherRange(value, activeDays, maxEntries);
|
|
259
252
|
const isAnyDaySelected = activeDays.length > 0;
|
|
260
253
|
const shouldRenderAddButton = isAnyDaySelected && filteredSchedule.length < maxEntries && canAddRange && !disabled;
|
|
261
|
-
const getErrorTextsForFormRow = (guid) =>
|
|
262
|
-
return activeDays.length === 1 && errorTexts && errorTexts[guid] && // @ts-expect-error - requires type refactor
|
|
263
|
-
errorTexts[guid][activeDays[0]];
|
|
264
|
-
};
|
|
254
|
+
const getErrorTextsForFormRow = (guid) => activeDays.length === 1 ? errorTexts?.[guid]?.[activeDays[0]] : void 0;
|
|
265
255
|
return /* @__PURE__ */ jsxs(NewFilterContainer, { ref, children: [
|
|
266
256
|
/* @__PURE__ */ jsx(Grid, { reverseGroup: 0, onUnselectAll: handleUnselectAll, onSelectAll: handleSelectAll, showUnselectAll: Boolean(activeDays.length), showSelectAll: allKeys.length > activeDays.length, renderDay, keys: allKeys, days: EMPTY_OBJECT, intl, numberOfDays: 7, numberOfDaysPerRow: 7, texts: allTexts, title: renderGridTitle(activeDays.length), ...getGridSettings() }),
|
|
267
|
-
isAnyDaySelected && filteredSchedule.map((guid, index) => /* @__PURE__ */ jsx(
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
days: EMPTY_OBJECT,
|
|
271
|
-
errorTexts: getErrorTextsForFormRow(guid),
|
|
272
|
-
onChange: NOOP,
|
|
273
|
-
onDayTimeChange: (dayValue, dayKey) => {
|
|
274
|
-
handleDayTimeChange(dayValue, dayKey, guid);
|
|
275
|
-
},
|
|
276
|
-
texts: allTexts,
|
|
277
|
-
onMultipleDayTimeChange: (dates) => handleDayTimeChange(dates, activeDays, guid),
|
|
278
|
-
dayKeys: activeDays,
|
|
279
|
-
getDayLabel,
|
|
280
|
-
activeDays,
|
|
281
|
-
getDayValue: (dayKey) => getDayValue(dayKey, guid),
|
|
282
|
-
onRangeDelete: disabled ? void 0 : () => handleRangeDelete(guid, activeDays),
|
|
283
|
-
onModeChange: (mode) => handleModeChange(mode, activeDays, guid),
|
|
284
|
-
valueSelectionModes: valueSelectionMode,
|
|
285
|
-
hideHeader: index !== 0,
|
|
286
|
-
renderSuffix: RENDER_EMPTY_NODE_FN,
|
|
287
|
-
timePickerProps,
|
|
288
|
-
timeFormat,
|
|
289
|
-
valueFormatOptions,
|
|
290
|
-
disabled,
|
|
291
|
-
monthlyFilterPeriod: periodType
|
|
292
|
-
},
|
|
293
|
-
`value-range-${guid}`
|
|
294
|
-
)),
|
|
257
|
+
isAnyDaySelected && filteredSchedule.map((guid, index) => /* @__PURE__ */ jsx(RangeFormContainer, { days: EMPTY_OBJECT, errorTexts: getErrorTextsForFormRow(guid), onChange: NOOP, onDayTimeChange: (dayValue, dayKey) => {
|
|
258
|
+
handleDayTimeChange(dayValue, dayKey, guid);
|
|
259
|
+
}, texts: allTexts, onMultipleDayTimeChange: (dates) => handleDayTimeChange(dates, activeDays, guid), dayKeys: activeDays, getDayLabel, activeDays, getDayValue: (dayKey) => getDayValue(dayKey, guid), onRangeDelete: disabled ? void 0 : () => handleRangeDelete(guid, activeDays), onModeChange: (mode) => handleModeChange(mode, activeDays, guid), valueSelectionModes: valueSelectionMode, hideHeader: index !== 0, renderSuffix: RENDER_EMPTY_NODE_FN, timePickerProps, timeFormat, valueFormatOptions, disabled, monthlyFilterPeriod: periodType }, `value-range-${guid}`)),
|
|
295
260
|
isAnyDaySelected && !canAddRange && /* @__PURE__ */ jsx(SelectionHint, { message: allTexts.maximumRanges }),
|
|
296
261
|
shouldRenderAddButton && /* @__PURE__ */ jsx(AddButton, { label: allTexts.addTime, onClick: handleRangeAdd }),
|
|
297
262
|
!isAnyDaySelected && !disabled && /* @__PURE__ */ jsx(SelectionHint, { message: allTexts.selectDaysDescription })
|
|
@@ -5,17 +5,22 @@ import { DateLimitMode } from '../../../Shared/TimeWindow/RangeFormContainer/Ran
|
|
|
5
5
|
import { FilterErrorType } from '../../../Shared/TimeWindow/RangeFormContainer/RangeFormContainer.types';
|
|
6
6
|
import { DayOptions } from '../../../Shared/TimeWindow/TimeWindow.types';
|
|
7
7
|
import { FilterBaseProps } from '../Filters.types';
|
|
8
|
-
export type MonthlyScheduleDayValue = DayOptions & {
|
|
8
|
+
export type MonthlyScheduleDayValue = Omit<DayOptions, 'start' | 'stop'> & {
|
|
9
|
+
/** `undefined` once the time is cleared in the form */
|
|
10
|
+
start?: string;
|
|
11
|
+
stop?: string;
|
|
9
12
|
mode: DateLimitMode;
|
|
10
13
|
};
|
|
11
14
|
export type MonthlySchedule = {
|
|
12
|
-
[guid: string]: Record<DayOfMonthIndex, MonthlyScheduleDayValue
|
|
15
|
+
[guid: string]: Partial<Record<DayOfMonthIndex, MonthlyScheduleDayValue>>;
|
|
13
16
|
};
|
|
14
|
-
|
|
17
|
+
/** 0–30 by day of the month; with the WEEK period, 0–34 (week × 7 + weekday) */
|
|
18
|
+
export type DayOfMonthIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34;
|
|
15
19
|
export type MonthlyProps = {
|
|
16
20
|
value: MonthlySchedule;
|
|
21
|
+
/** Per range (`guid`), the errors of each day's time inputs */
|
|
17
22
|
errorTexts?: {
|
|
18
|
-
[guid: string]: FilterErrorType
|
|
23
|
+
[guid: string]: Partial<Record<DayOfMonthIndex, FilterErrorType>>;
|
|
19
24
|
};
|
|
20
25
|
periodType: DAYS_OF_PERIOD_ENUM;
|
|
21
26
|
countedFrom: COUNTED_FROM_ENUM;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DayKey } from '../../../Shared/TimeWindow/TimeWindow.types';
|
|
2
2
|
import { DayOfMonthIndex, MonthlySchedule, MonthlyScheduleDayValue } from './Monthly.types';
|
|
3
3
|
export declare const range: (start: number, stop: number) => number[];
|
|
4
|
-
export declare const haveActiveDaysCommonRange: (days: Record<DayOfMonthIndex, MonthlyScheduleDayValue
|
|
4
|
+
export declare const haveActiveDaysCommonRange: (days: Partial<Record<DayOfMonthIndex, MonthlyScheduleDayValue>>, activeDaysArray: DayKey[]) => boolean;
|
|
5
5
|
export declare const canAddAnotherRange: (schedule: MonthlySchedule, activeDays: DayKey[], maxRanges?: number) => boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { WeeklyProps } from './Weekly.types';
|
|
3
|
-
declare const Weekly: ({ maxEntries, valueSelectionMode, onChange, timeFormat, valueFormatOptions, value, texts, timePickerProps, disabled, errorTexts, }: WeeklyProps) => React.JSX.Element;
|
|
3
|
+
declare const Weekly: ({ maxEntries, valueSelectionMode, onChange, timeFormat, valueFormatOptions, value: schedule, texts, timePickerProps, disabled, errorTexts: scheduleErrors, }: WeeklyProps) => React.JSX.Element;
|
|
4
4
|
export default Weekly;
|
|
@@ -33,12 +33,14 @@ const Weekly = ({
|
|
|
33
33
|
onChange = NOOP,
|
|
34
34
|
timeFormat,
|
|
35
35
|
valueFormatOptions,
|
|
36
|
-
value,
|
|
36
|
+
value: schedule,
|
|
37
37
|
texts,
|
|
38
38
|
timePickerProps,
|
|
39
39
|
disabled,
|
|
40
|
-
errorTexts
|
|
40
|
+
errorTexts: scheduleErrors
|
|
41
41
|
}) => {
|
|
42
|
+
const value = schedule;
|
|
43
|
+
const errorTexts = scheduleErrors;
|
|
42
44
|
const intl = useIntl();
|
|
43
45
|
const allTexts = useMemo(() => getDefaultTexts(intl, false, texts), [texts, intl]);
|
|
44
46
|
const defaultDayValue = useMemo(() => ({
|
|
@@ -59,10 +61,7 @@ const Weekly = ({
|
|
|
59
61
|
const allKeys = useMemo(() => isSundayFirstWeekDay ? US_NOTATION_WEEK_DAYS_INDEXES : EU_NOTATION_WEEK_DAYS_INDEXES, [isSundayFirstWeekDay]);
|
|
60
62
|
useEffect(() => {
|
|
61
63
|
removeEmptyEntries(value);
|
|
62
|
-
const entriesWithActiveDaysValue = activeDays.length ? Object.keys(value).filter((id) => activeDays.every((day) => (
|
|
63
|
-
// @ts-expect-error - requires type refactor
|
|
64
|
-
!!value[id][day] && haveActiveDaysCommonRange(value[id], activeDays)
|
|
65
|
-
))) : [];
|
|
64
|
+
const entriesWithActiveDaysValue = activeDays.length ? Object.keys(value).filter((id) => activeDays.every((day) => !!value[id][day] && haveActiveDaysCommonRange(value[id], activeDays))) : [];
|
|
66
65
|
setFilteredSchedule(entriesWithActiveDaysValue);
|
|
67
66
|
}, [value, activeDays]);
|
|
68
67
|
const handleDayTimeChange = useCallback((dayValue, dayKey, guid) => {
|
|
@@ -72,7 +71,6 @@ const Weekly = ({
|
|
|
72
71
|
dayKey.forEach((day) => {
|
|
73
72
|
if (guid in updatedSchedule) {
|
|
74
73
|
updatedSchedule[guid][day] = {
|
|
75
|
-
// @ts-expect-error - requires type refactor
|
|
76
74
|
...value[guid][day],
|
|
77
75
|
restricted: true,
|
|
78
76
|
start: start ? dayjs(start).format(DEFAULT_TIME_FORMAT) : void 0,
|
|
@@ -83,7 +81,6 @@ const Weekly = ({
|
|
|
83
81
|
});
|
|
84
82
|
} else if (guid in updatedSchedule) {
|
|
85
83
|
updatedSchedule[guid][dayKey] = {
|
|
86
|
-
// @ts-expect-error - requires type refactor
|
|
87
84
|
...value[guid][dayKey],
|
|
88
85
|
restricted: true,
|
|
89
86
|
start: start ? dayjs(start).format(DEFAULT_TIME_FORMAT) : void 0,
|
|
@@ -103,7 +100,6 @@ const Weekly = ({
|
|
|
103
100
|
const updatedSchedule = value;
|
|
104
101
|
dayKeys.forEach((day) => {
|
|
105
102
|
updatedSchedule[guid][day] = {
|
|
106
|
-
// @ts-expect-error - requires type refactor
|
|
107
103
|
...value[guid][day],
|
|
108
104
|
mode: selectedMode
|
|
109
105
|
};
|
|
@@ -182,10 +178,7 @@ const Weekly = ({
|
|
|
182
178
|
}, [activeDays, getDayLabel, isDayRestricted, disabled, intl, handleToggleDay, removeDaySelection, allTexts]);
|
|
183
179
|
const handleRangeAdd = useCallback(() => {
|
|
184
180
|
const updatedDay = {};
|
|
185
|
-
const guid = Object.keys(value).find((key) => (
|
|
186
|
-
// @ts-expect-error - requires type refactor
|
|
187
|
-
activeDays.every((day) => value[key][day] === void 0)
|
|
188
|
-
));
|
|
181
|
+
const guid = Object.keys(value).find((key) => activeDays.every((day) => value[key][day] === void 0));
|
|
189
182
|
activeDays.forEach((day) => {
|
|
190
183
|
updatedDay[day] = defaultDayValue;
|
|
191
184
|
});
|
|
@@ -203,39 +196,12 @@ const Weekly = ({
|
|
|
203
196
|
const canAddRange = canAddAnotherRange(value, activeDays, maxEntries);
|
|
204
197
|
const isAnyDaySelected = activeDays.length > 0;
|
|
205
198
|
const shouldRenderAddButton = isAnyDaySelected && filteredSchedule.length < maxEntries && canAddRange && !disabled;
|
|
206
|
-
const getErrorTextsForFormRow = (guid) =>
|
|
207
|
-
return activeDays.length === 1 && errorTexts && errorTexts[guid] && // @ts-expect-error - requires type refactor
|
|
208
|
-
errorTexts[guid][activeDays[0]];
|
|
209
|
-
};
|
|
199
|
+
const getErrorTextsForFormRow = (guid) => activeDays.length === 1 ? errorTexts?.[guid]?.[activeDays[0]] : void 0;
|
|
210
200
|
return /* @__PURE__ */ jsxs(NewFilterContainer, { ref, children: [
|
|
211
201
|
/* @__PURE__ */ jsx(Grid, { reverseGroup: 0, onUnselectAll: handleUnselectAll, onSelectAll: handleSelectAll, showUnselectAll: Boolean(activeDays.length), showSelectAll: allKeys.length > activeDays.length, renderDay, keys: allKeys, days: EMPTY_OBJECT, intl, numberOfDays: 7, texts: allTexts, title: renderGridTitle(activeDays.length) }),
|
|
212
|
-
isAnyDaySelected && filteredSchedule.map((guid, index) => /* @__PURE__ */ jsx(
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
days: EMPTY_OBJECT,
|
|
216
|
-
onChange: NOOP,
|
|
217
|
-
errorTexts: getErrorTextsForFormRow(guid),
|
|
218
|
-
onDayTimeChange: (dayValue, dayKey) => {
|
|
219
|
-
handleDayTimeChange(dayValue, dayKey, guid);
|
|
220
|
-
},
|
|
221
|
-
texts: allTexts,
|
|
222
|
-
onMultipleDayTimeChange: (dates) => handleDayTimeChange(dates, activeDays, guid),
|
|
223
|
-
dayKeys: activeDays,
|
|
224
|
-
getDayLabel,
|
|
225
|
-
activeDays,
|
|
226
|
-
getDayValue: (dayKey) => getDayValue(dayKey, guid),
|
|
227
|
-
onRangeDelete: disabled ? void 0 : () => handleRangeDelete(guid, activeDays),
|
|
228
|
-
onModeChange: (mode) => handleModeChange(mode, activeDays, guid),
|
|
229
|
-
valueSelectionModes: valueSelectionMode,
|
|
230
|
-
hideHeader: index !== 0,
|
|
231
|
-
renderSuffix: RENDER_EMPTY_NODE_FN,
|
|
232
|
-
timePickerProps,
|
|
233
|
-
timeFormat,
|
|
234
|
-
valueFormatOptions,
|
|
235
|
-
disabled
|
|
236
|
-
},
|
|
237
|
-
`value-range-${guid}`
|
|
238
|
-
)),
|
|
202
|
+
isAnyDaySelected && filteredSchedule.map((guid, index) => /* @__PURE__ */ jsx(RangeFormContainer, { days: EMPTY_OBJECT, onChange: NOOP, errorTexts: getErrorTextsForFormRow(guid), onDayTimeChange: (dayValue, dayKey) => {
|
|
203
|
+
handleDayTimeChange(dayValue, dayKey, guid);
|
|
204
|
+
}, texts: allTexts, onMultipleDayTimeChange: (dates) => handleDayTimeChange(dates, activeDays, guid), dayKeys: activeDays, getDayLabel, activeDays, getDayValue: (dayKey) => getDayValue(dayKey, guid), onRangeDelete: disabled ? void 0 : () => handleRangeDelete(guid, activeDays), onModeChange: (mode) => handleModeChange(mode, activeDays, guid), valueSelectionModes: valueSelectionMode, hideHeader: index !== 0, renderSuffix: RENDER_EMPTY_NODE_FN, timePickerProps, timeFormat, valueFormatOptions, disabled }, `value-range-${guid}`)),
|
|
239
205
|
isAnyDaySelected && !canAddRange && /* @__PURE__ */ jsx(SelectionHint, { message: allTexts.maximumRanges }),
|
|
240
206
|
shouldRenderAddButton && /* @__PURE__ */ jsx(AddButton, { "data-testid": "drp-filter-add-range", label: allTexts.addTime, onClick: handleRangeAdd }),
|
|
241
207
|
!isAnyDaySelected && !disabled && /* @__PURE__ */ jsx(SelectionHint, { message: allTexts.selectDaysDescription })
|
|
@@ -4,17 +4,21 @@ import { DateLimitMode } from '../../../Shared/TimeWindow/RangeFormContainer/Ran
|
|
|
4
4
|
import { FilterErrorType } from '../../../Shared/TimeWindow/RangeFormContainer/RangeFormContainer.types';
|
|
5
5
|
import { DayOptions } from '../../../Shared/TimeWindow/TimeWindow.types';
|
|
6
6
|
import { FilterBaseProps } from '../Filters.types';
|
|
7
|
-
export type WeeklyScheduleDayValue = DayOptions & {
|
|
7
|
+
export type WeeklyScheduleDayValue = Omit<DayOptions, 'start' | 'stop'> & {
|
|
8
|
+
/** `undefined` once the time is cleared in the form */
|
|
9
|
+
start?: string;
|
|
10
|
+
stop?: string;
|
|
8
11
|
mode: DateLimitMode;
|
|
9
12
|
};
|
|
10
13
|
export type WeeklySchedule = {
|
|
11
|
-
[guid: string]: Record<DayOfWeekIndex, WeeklyScheduleDayValue
|
|
14
|
+
[guid: string]: Partial<Record<DayOfWeekIndex, WeeklyScheduleDayValue>>;
|
|
12
15
|
};
|
|
13
16
|
export type DayOfWeekIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
14
17
|
export type WeeklyProps = {
|
|
15
18
|
value: WeeklySchedule;
|
|
19
|
+
/** Per range (`guid`), the errors of each day's time inputs */
|
|
16
20
|
errorTexts?: {
|
|
17
|
-
[guid: string]: FilterErrorType
|
|
21
|
+
[guid: string]: Partial<Record<DayOfWeekIndex, FilterErrorType>>;
|
|
18
22
|
};
|
|
19
23
|
onChange: (value: WeeklyProps['value']) => void;
|
|
20
24
|
texts?: Partial<Texts>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DayKey } from '../../../Shared/TimeWindow/TimeWindow.types';
|
|
2
2
|
import { DayOfWeekIndex, WeeklySchedule, WeeklyScheduleDayValue } from './Weekly.types';
|
|
3
3
|
export declare const range: (start: number, stop: number) => number[];
|
|
4
|
-
export declare const haveActiveDaysCommonRange: (days: Record<DayOfWeekIndex, WeeklyScheduleDayValue
|
|
4
|
+
export declare const haveActiveDaysCommonRange: (days: Partial<Record<DayOfWeekIndex, WeeklyScheduleDayValue>>, activeDaysArray: DayKey[]) => boolean;
|
|
5
5
|
export declare const canAddAnotherRange: (schedule: WeeklySchedule, activeDays: DayKey[], maxRanges?: number) => boolean;
|
|
6
6
|
export declare const removeEmptyEntries: (weeklySchedule: WeeklySchedule) => void;
|
|
@@ -37,7 +37,7 @@ export declare const MONTHLY_SCHEDULE_TEST_DATA: ({
|
|
|
37
37
|
restricted: boolean;
|
|
38
38
|
start: string;
|
|
39
39
|
stop: string;
|
|
40
|
-
mode: import('
|
|
40
|
+
mode: import('../../..').DateLimitMode;
|
|
41
41
|
};
|
|
42
42
|
3: {
|
|
43
43
|
display?: boolean;
|
|
@@ -45,7 +45,7 @@ export declare const MONTHLY_SCHEDULE_TEST_DATA: ({
|
|
|
45
45
|
restricted: boolean;
|
|
46
46
|
start: string;
|
|
47
47
|
stop: string;
|
|
48
|
-
mode: import('
|
|
48
|
+
mode: import('../../..').DateLimitMode;
|
|
49
49
|
};
|
|
50
50
|
4: {
|
|
51
51
|
display?: boolean;
|
|
@@ -53,7 +53,7 @@ export declare const MONTHLY_SCHEDULE_TEST_DATA: ({
|
|
|
53
53
|
restricted: boolean;
|
|
54
54
|
start: string;
|
|
55
55
|
stop: string;
|
|
56
|
-
mode: import('
|
|
56
|
+
mode: import('../../..').DateLimitMode;
|
|
57
57
|
};
|
|
58
58
|
2?: undefined;
|
|
59
59
|
};
|
|
@@ -101,7 +101,7 @@ export declare const MONTHLY_SCHEDULE_TEST_DATA: ({
|
|
|
101
101
|
restricted: boolean;
|
|
102
102
|
start: string;
|
|
103
103
|
stop: string;
|
|
104
|
-
mode: import('
|
|
104
|
+
mode: import('../../..').DateLimitMode;
|
|
105
105
|
};
|
|
106
106
|
2: {
|
|
107
107
|
display?: boolean;
|
|
@@ -109,7 +109,7 @@ export declare const MONTHLY_SCHEDULE_TEST_DATA: ({
|
|
|
109
109
|
restricted: boolean;
|
|
110
110
|
start: string;
|
|
111
111
|
stop: string;
|
|
112
|
-
mode: import('
|
|
112
|
+
mode: import('../../..').DateLimitMode;
|
|
113
113
|
};
|
|
114
114
|
4: {
|
|
115
115
|
display?: boolean;
|
|
@@ -117,7 +117,7 @@ export declare const MONTHLY_SCHEDULE_TEST_DATA: ({
|
|
|
117
117
|
restricted: boolean;
|
|
118
118
|
start: string;
|
|
119
119
|
stop: string;
|
|
120
|
-
mode: import('
|
|
120
|
+
mode: import('../../..').DateLimitMode;
|
|
121
121
|
};
|
|
122
122
|
3?: undefined;
|
|
123
123
|
};
|
|
@@ -164,7 +164,7 @@ export declare const WEEKLY_SCHEDULE_VALUE: {
|
|
|
164
164
|
restricted: boolean;
|
|
165
165
|
start: string;
|
|
166
166
|
stop: string;
|
|
167
|
-
mode: import('
|
|
167
|
+
mode: import('../../..').DateLimitMode;
|
|
168
168
|
};
|
|
169
169
|
3: {
|
|
170
170
|
display?: boolean;
|
|
@@ -172,7 +172,7 @@ export declare const WEEKLY_SCHEDULE_VALUE: {
|
|
|
172
172
|
restricted: boolean;
|
|
173
173
|
start: string;
|
|
174
174
|
stop: string;
|
|
175
|
-
mode: import('
|
|
175
|
+
mode: import('../../..').DateLimitMode;
|
|
176
176
|
};
|
|
177
177
|
4: {
|
|
178
178
|
display?: boolean;
|
|
@@ -180,7 +180,7 @@ export declare const WEEKLY_SCHEDULE_VALUE: {
|
|
|
180
180
|
restricted: boolean;
|
|
181
181
|
start: string;
|
|
182
182
|
stop: string;
|
|
183
|
-
mode: import('
|
|
183
|
+
mode: import('../../..').DateLimitMode;
|
|
184
184
|
};
|
|
185
185
|
};
|
|
186
186
|
};
|
|
@@ -212,7 +212,7 @@ export declare const WEEKLY_SCHEDULE_TEST_DATA: ({
|
|
|
212
212
|
restricted: boolean;
|
|
213
213
|
start: string;
|
|
214
214
|
stop: string;
|
|
215
|
-
mode: import('
|
|
215
|
+
mode: import('../../..').DateLimitMode;
|
|
216
216
|
};
|
|
217
217
|
3: {
|
|
218
218
|
display?: boolean;
|
|
@@ -220,7 +220,7 @@ export declare const WEEKLY_SCHEDULE_TEST_DATA: ({
|
|
|
220
220
|
restricted: boolean;
|
|
221
221
|
start: string;
|
|
222
222
|
stop: string;
|
|
223
|
-
mode: import('
|
|
223
|
+
mode: import('../../..').DateLimitMode;
|
|
224
224
|
};
|
|
225
225
|
4: {
|
|
226
226
|
display?: boolean;
|
|
@@ -228,7 +228,7 @@ export declare const WEEKLY_SCHEDULE_TEST_DATA: ({
|
|
|
228
228
|
restricted: boolean;
|
|
229
229
|
start: string;
|
|
230
230
|
stop: string;
|
|
231
|
-
mode: import('
|
|
231
|
+
mode: import('../../..').DateLimitMode;
|
|
232
232
|
};
|
|
233
233
|
};
|
|
234
234
|
};
|
|
@@ -274,7 +274,7 @@ export declare const WEEKLY_SCHEDULE_TEST_DATA: ({
|
|
|
274
274
|
restricted: boolean;
|
|
275
275
|
start: string;
|
|
276
276
|
stop: string;
|
|
277
|
-
mode: import('
|
|
277
|
+
mode: import('../../..').DateLimitMode;
|
|
278
278
|
};
|
|
279
279
|
3: {
|
|
280
280
|
display?: boolean;
|
|
@@ -282,7 +282,7 @@ export declare const WEEKLY_SCHEDULE_TEST_DATA: ({
|
|
|
282
282
|
restricted: boolean;
|
|
283
283
|
start: string;
|
|
284
284
|
stop: string;
|
|
285
|
-
mode: import('
|
|
285
|
+
mode: import('../../..').DateLimitMode;
|
|
286
286
|
};
|
|
287
287
|
4: {
|
|
288
288
|
display?: boolean;
|
|
@@ -290,7 +290,7 @@ export declare const WEEKLY_SCHEDULE_TEST_DATA: ({
|
|
|
290
290
|
restricted: boolean;
|
|
291
291
|
start: string;
|
|
292
292
|
stop: string;
|
|
293
|
-
mode: import('
|
|
293
|
+
mode: import('../../..').DateLimitMode;
|
|
294
294
|
};
|
|
295
295
|
};
|
|
296
296
|
};
|
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
const KEYS = {
|
|
3
|
+
SHIFT: "Shift",
|
|
4
|
+
COMMAND: "Meta",
|
|
5
|
+
CONTROL: "Control"
|
|
6
|
+
};
|
|
2
7
|
const useShiftAndControlKeys = (ref) => {
|
|
3
8
|
const [controlPressed, setControlPressed] = React.useState(false);
|
|
4
9
|
const [shiftPressed, setShiftPressed] = React.useState(false);
|
|
5
10
|
React.useEffect(() => {
|
|
6
11
|
if (ref?.current) {
|
|
7
12
|
ref.current.addEventListener("keydown", (e) => {
|
|
8
|
-
if (e.key ===
|
|
13
|
+
if (e.key === KEYS.SHIFT) {
|
|
9
14
|
setShiftPressed(true);
|
|
10
15
|
setControlPressed(false);
|
|
11
16
|
}
|
|
12
|
-
if (e.key ===
|
|
17
|
+
if (e.key === KEYS.CONTROL || e.key === KEYS.COMMAND) {
|
|
13
18
|
setControlPressed(true);
|
|
14
19
|
setShiftPressed(false);
|
|
15
20
|
}
|
|
16
21
|
});
|
|
17
22
|
ref.current.addEventListener("keyup", (e) => {
|
|
18
|
-
if (e.key ===
|
|
23
|
+
if (e.key === KEYS.SHIFT) {
|
|
19
24
|
setShiftPressed(false);
|
|
20
25
|
}
|
|
21
|
-
if (e.key ===
|
|
26
|
+
if (e.key === KEYS.CONTROL || e.key === KEYS.COMMAND) {
|
|
22
27
|
setControlPressed(false);
|
|
23
28
|
}
|
|
24
29
|
});
|
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
-
import cloneDeep from "lodash.clonedeep";
|
|
3
2
|
import React from "react";
|
|
4
3
|
import { injectIntl } from "react-intl";
|
|
5
4
|
import Button from "@synerise/ds-button";
|
|
6
5
|
import ButtonGroup from "@synerise/ds-button-group";
|
|
7
6
|
import { generateUuid } from "@synerise/ds-utils";
|
|
8
7
|
import { getDefaultTexts } from "../utils.js";
|
|
9
|
-
import {
|
|
8
|
+
import { TYPES, TYPES_DATA } from "./constants.js";
|
|
10
9
|
import { Container, Header, Title, Body, MainComponentWrapper, Footer, FooterSeparator } from "./RangeFilter.styles.js";
|
|
11
10
|
import FilterDropdown from "./Shared/FilterDropdown/FilterDropdown.js";
|
|
12
11
|
import SaveFilterForm from "./Shared/SaveFilterForm/SaveFilterForm.js";
|
|
13
|
-
import { normalizeValue, addSuffixToDuplicate, denormalizeValue, isValidValue } from "./utils.js";
|
|
14
|
-
|
|
12
|
+
import { normalizeValue, defaultFilterValue, addSuffixToDuplicate, denormalizeValue, isValidValue } from "./utils.js";
|
|
13
|
+
import { DEFAULT_RANGE_END, DEFAULT_RANGE_START } from "./Filters/new/constants.js";
|
|
14
|
+
const DEFAULT_VALUE = {
|
|
15
|
+
type: TYPES.DAILY,
|
|
16
|
+
nestingType: "IN_PLACE",
|
|
17
|
+
from: DEFAULT_RANGE_START,
|
|
18
|
+
to: DEFAULT_RANGE_END,
|
|
19
|
+
inverted: false
|
|
20
|
+
};
|
|
21
|
+
const filterState = (filter) => ({
|
|
22
|
+
[filter.type]: filter
|
|
23
|
+
});
|
|
24
|
+
class RangeFilter extends React.PureComponent {
|
|
15
25
|
constructor(props) {
|
|
16
26
|
super(props);
|
|
17
27
|
this.componentDidUpdate = () => {
|
|
@@ -38,8 +48,8 @@ const _RangeFilter = class _RangeFilter extends React.PureComponent {
|
|
|
38
48
|
const {
|
|
39
49
|
activeType
|
|
40
50
|
} = state;
|
|
41
|
-
const filter = state[
|
|
42
|
-
onApply && onApply(normalizeValue(filter));
|
|
51
|
+
const filter = state[activeType];
|
|
52
|
+
onApply && filter && onApply(normalizeValue(filter));
|
|
43
53
|
};
|
|
44
54
|
this.handleCancel = () => {
|
|
45
55
|
const {
|
|
@@ -52,14 +62,12 @@ const _RangeFilter = class _RangeFilter extends React.PureComponent {
|
|
|
52
62
|
state
|
|
53
63
|
} = this;
|
|
54
64
|
const previousValue = state[type];
|
|
55
|
-
const previousDefinition = previousValue?.definition;
|
|
56
65
|
this.setState({
|
|
57
66
|
activeType: type,
|
|
58
|
-
|
|
59
|
-
definition: previousDefinition || cloneDeep(TYPES_DATA[type].definition),
|
|
67
|
+
...filterState(previousValue ? {
|
|
60
68
|
...previousValue,
|
|
61
69
|
type
|
|
62
|
-
}
|
|
70
|
+
} : defaultFilterValue(type))
|
|
63
71
|
});
|
|
64
72
|
};
|
|
65
73
|
this.handleRangeCopy = (range) => {
|
|
@@ -100,16 +108,15 @@ const _RangeFilter = class _RangeFilter extends React.PureComponent {
|
|
|
100
108
|
this.handleSavedFilterSelect = (selected) => {
|
|
101
109
|
this.setState({
|
|
102
110
|
activeType: selected.type,
|
|
103
|
-
|
|
111
|
+
...filterState(selected)
|
|
104
112
|
});
|
|
105
113
|
};
|
|
106
114
|
const allowedFilterTypes = props?.allowedFilterTypes?.length ? props?.allowedFilterTypes : Object.keys(TYPES);
|
|
107
|
-
const
|
|
115
|
+
const value = props.value ?? DEFAULT_VALUE;
|
|
116
|
+
const valueType = allowedFilterTypes.includes(value.type) ? value.type : allowedFilterTypes[0];
|
|
108
117
|
this.state = {
|
|
109
118
|
activeType: valueType,
|
|
110
|
-
[
|
|
111
|
-
...denormalizeValue(props.value)
|
|
112
|
-
}
|
|
119
|
+
[valueType]: denormalizeValue(value)
|
|
113
120
|
};
|
|
114
121
|
}
|
|
115
122
|
render() {
|
|
@@ -121,9 +128,7 @@ const _RangeFilter = class _RangeFilter extends React.PureComponent {
|
|
|
121
128
|
rangeClipboard
|
|
122
129
|
} = state;
|
|
123
130
|
const activeValue = state[activeType];
|
|
124
|
-
const
|
|
125
|
-
definition
|
|
126
|
-
} = activeValue;
|
|
131
|
+
const definition = activeValue?.definition;
|
|
127
132
|
const Component = activeType && TYPES_DATA[activeType] && TYPES_DATA[activeType].component;
|
|
128
133
|
const {
|
|
129
134
|
intl,
|
|
@@ -147,27 +152,12 @@ const _RangeFilter = class _RangeFilter extends React.PureComponent {
|
|
|
147
152
|
] }),
|
|
148
153
|
/* @__PURE__ */ jsxs(Body, { children: [
|
|
149
154
|
buttonSource.length > 1 && /* @__PURE__ */ jsx(ButtonGroup, { fullWidth: true, size: "large", children: buttonSource.map((key) => /* @__PURE__ */ jsx(Button, { type: activeType === key ? "primary" : void 0, onClick: () => this.handleTypeChange(key), children: allTexts[key.toLowerCase()] }, key)) }),
|
|
150
|
-
/* @__PURE__ */ jsx(MainComponentWrapper, { children: Component && /* @__PURE__ */ jsx(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
value: definition,
|
|
157
|
-
onChange: (def) => {
|
|
158
|
-
const updatedFilter = {
|
|
159
|
-
[activeType]: {
|
|
160
|
-
...activeValue,
|
|
161
|
-
definition: def
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
this.setState(updatedFilter);
|
|
165
|
-
},
|
|
166
|
-
onRangeCopy: this.handleRangeCopy,
|
|
167
|
-
rangeClipboard,
|
|
168
|
-
valueSelectionModes
|
|
169
|
-
}
|
|
170
|
-
) })
|
|
155
|
+
/* @__PURE__ */ jsx(MainComponentWrapper, { children: Component && activeValue && definition && /* @__PURE__ */ jsx(Component, { intl, texts: allTexts, rangeDisplayMode, value: definition, onChange: (def) => {
|
|
156
|
+
this.setState(filterState({
|
|
157
|
+
...activeValue,
|
|
158
|
+
definition: def
|
|
159
|
+
}));
|
|
160
|
+
}, onRangeCopy: this.handleRangeCopy, rangeClipboard, valueSelectionModes }) })
|
|
171
161
|
] }),
|
|
172
162
|
!hideFooter && /* @__PURE__ */ jsxs(Footer, { "data-testid": "range-filter-footer", children: [
|
|
173
163
|
savedFilters && onFilterSave && /* @__PURE__ */ jsx(SaveFilterForm, { texts: allTexts, onFilterSave: this.handleFilterSave }),
|
|
@@ -177,14 +167,7 @@ const _RangeFilter = class _RangeFilter extends React.PureComponent {
|
|
|
177
167
|
] })
|
|
178
168
|
] });
|
|
179
169
|
}
|
|
180
|
-
}
|
|
181
|
-
_RangeFilter.defaultProps = {
|
|
182
|
-
value: {
|
|
183
|
-
type: TYPES.DAILY,
|
|
184
|
-
...TYPES_DATA.DAILY.definition
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
let RangeFilter = _RangeFilter;
|
|
170
|
+
}
|
|
188
171
|
const RangeFilter$1 = injectIntl(RangeFilter);
|
|
189
172
|
export {
|
|
190
173
|
RangeFilter$1 as default
|