@geotab/zenith 3.17.1-beta.3 → 3.17.1
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/dist/datePickerCommon/hooks/useDateRangeRaw/useDateRangeRawCore.d.ts +7 -1
- package/dist/datePickerCommon/hooks/useDateRangeRaw/useDateRangeRawCore.js +5 -5
- package/dist/dateRangeRawNew/hooks/useDateRangeNewParts.d.ts +7 -1
- package/dist/dateRangeRawNew/hooks/useDateRangeNewParts.js +24 -15
- package/dist/dateRangeRawNew/hooks/useDateRangeRawNew.js +2 -2
- package/dist/dateRangeRawNew/hooks/useRangeEntry.js +31 -4
- package/esm/datePickerCommon/hooks/useDateRangeRaw/useDateRangeRawCore.d.ts +7 -1
- package/esm/datePickerCommon/hooks/useDateRangeRaw/useDateRangeRawCore.js +5 -5
- package/esm/dateRangeRawNew/hooks/useDateRangeNewParts.d.ts +7 -1
- package/esm/dateRangeRawNew/hooks/useDateRangeNewParts.js +24 -15
- package/esm/dateRangeRawNew/hooks/useDateRangeRawNew.js +2 -2
- package/esm/dateRangeRawNew/hooks/useRangeEntry.js +31 -4
- package/package.json +1 -1
|
@@ -60,7 +60,13 @@ export declare const useDateRangeRawCore: (props: TWithDefaultOptions<TDateRange
|
|
|
60
60
|
datesValidation: (val: any) => boolean;
|
|
61
61
|
isDatesValid: import("react").RefObject<boolean>;
|
|
62
62
|
previousStepOption: import("react").RefObject<string>;
|
|
63
|
-
handleDateRangeSelection: (newVal: string
|
|
63
|
+
handleDateRangeSelection: (newVal: string, transformRange?: (range: {
|
|
64
|
+
from: Date;
|
|
65
|
+
to: Date;
|
|
66
|
+
}) => {
|
|
67
|
+
from: Date;
|
|
68
|
+
to: Date;
|
|
69
|
+
}) => void;
|
|
64
70
|
handleApplyClick: () => void;
|
|
65
71
|
handleCancelClick: () => void;
|
|
66
72
|
handleClearClick: () => void;
|
|
@@ -219,12 +219,12 @@ const useDateRangeRawCore = (props, behavior) => {
|
|
|
219
219
|
}, [isOpen, isStaleCustomDraft, prevSelection]);
|
|
220
220
|
const handleDateRangeSelection = (0, react_1.useCallback)(
|
|
221
221
|
// eslint-disable-next-line complexity
|
|
222
|
-
newVal => {
|
|
223
|
-
var _a, _b;
|
|
222
|
+
(newVal, transformRange) => {
|
|
223
|
+
var _a, _b, _c;
|
|
224
224
|
const selection = options.find(option => option.id === newVal);
|
|
225
225
|
newVal === customCalendarId_1.CUSTOM_CALENDAR_ID && setShowMobileCalendar(true);
|
|
226
226
|
if (selection && newVal !== customCalendarId_1.CUSTOM_CALENDAR_ID && selection.getRange) {
|
|
227
|
-
const range = selection.getRange();
|
|
227
|
+
const range = (_a = transformRange === null || transformRange === void 0 ? void 0 : transformRange(selection.getRange())) !== null && _a !== void 0 ? _a : selection.getRange();
|
|
228
228
|
const normalizedDates = (0, normalizeDates_1.normalizeDates)(range.from.toISOString(), range.to.toISOString(), disableFutureDates, disablePastDates, disableDatesBefore, disableDatesAfter);
|
|
229
229
|
const newRange = newVal === customCalendarId_1.CUSTOM_CALENDAR_ID ? {
|
|
230
230
|
from: new Date(normalizedDates.from),
|
|
@@ -242,8 +242,8 @@ const useDateRangeRawCore = (props, behavior) => {
|
|
|
242
242
|
}, newRange)));
|
|
243
243
|
previousStepOption.current = "";
|
|
244
244
|
} else {
|
|
245
|
-
const startDateForNormalize = ((
|
|
246
|
-
const endDateForNormalize = ((
|
|
245
|
+
const startDateForNormalize = ((_b = selection === null || selection === void 0 ? void 0 : selection.getRange) === null || _b === void 0 ? void 0 : _b.call(selection)) && (selectedRange === null || selectedRange === void 0 ? void 0 : selectedRange.label) !== newVal ? selection.getRange().from : value === null || value === void 0 ? void 0 : value.from;
|
|
246
|
+
const endDateForNormalize = ((_c = selection === null || selection === void 0 ? void 0 : selection.getRange) === null || _c === void 0 ? void 0 : _c.call(selection)) && (selectedRange === null || selectedRange === void 0 ? void 0 : selectedRange.label) !== newVal ? selection.getRange().to : value === null || value === void 0 ? void 0 : value.to;
|
|
247
247
|
if (!datesValidation(startDateForNormalize === undefined && endDateForNormalize === undefined ? undefined : {
|
|
248
248
|
from: startDateForNormalize,
|
|
249
249
|
to: endDateForNormalize
|
|
@@ -12,7 +12,13 @@ interface IUseDateRangeNewParts {
|
|
|
12
12
|
setShowMobileCalendar: (isVisible: boolean) => void;
|
|
13
13
|
/** What was last applied; closing without Apply goes back to it. */
|
|
14
14
|
prevSelection: IDateRangeValue | undefined;
|
|
15
|
-
selectOption: (optionId: string
|
|
15
|
+
selectOption: (optionId: string, transformRange?: (range: {
|
|
16
|
+
from: Date;
|
|
17
|
+
to: Date;
|
|
18
|
+
}) => {
|
|
19
|
+
from: Date;
|
|
20
|
+
to: Date;
|
|
21
|
+
}) => void;
|
|
16
22
|
segmentedTriggerRef: RefObject<HTMLElement | null>;
|
|
17
23
|
hasApplyButton: boolean;
|
|
18
24
|
defaultValue?: IDateRangeValue;
|
|
@@ -68,28 +68,37 @@ const useDateRangeNewParts = ({ isOpen, setIsOpen, isMobile, customDate, setCust
|
|
|
68
68
|
const { rebaseToDay } = rangeEntry;
|
|
69
69
|
const handleOptionSelect = (0, react_1.useCallback)((optionId) => {
|
|
70
70
|
const before = customDate;
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
if (!timeSelect || optionId === customCalendarId_1.CUSTOM_CALENDAR_ID || !before.from || !before.to) {
|
|
72
|
+
selectOption(optionId);
|
|
73
73
|
return;
|
|
74
|
+
}
|
|
74
75
|
const { from: timeFrom, to: timeTo } = before;
|
|
75
76
|
const keepTime = (range) => ({
|
|
76
|
-
from:
|
|
77
|
-
to:
|
|
77
|
+
from: new Date(rebaseToDay(range.from.toISOString(), timeFrom, false)),
|
|
78
|
+
to: new Date(rebaseToDay(range.to.toISOString(), timeTo, true))
|
|
78
79
|
});
|
|
79
80
|
// Kept times that leave no range (13:00 to 13:00 on a single-day preset, or an end before the start) would make a
|
|
80
81
|
// range a form cannot take, so the preset keeps its own whole day then.
|
|
81
|
-
const isEmpty = (range) => (0, rangeOrder_1.isEndBeforeStart)(range.from, range.to) ||
|
|
82
|
-
|
|
83
|
-
const kept = keepTime(
|
|
84
|
-
return isEmpty(kept) ?
|
|
82
|
+
const isEmpty = (range) => (0, rangeOrder_1.isEndBeforeStart)(range.from.toISOString(), range.to.toISOString()) || range.from.getTime() === range.to.getTime();
|
|
83
|
+
selectOption(optionId, range => {
|
|
84
|
+
const kept = keepTime(range);
|
|
85
|
+
return isEmpty(kept) ? range : kept;
|
|
85
86
|
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
87
|
+
if (hasApplyButton) {
|
|
88
|
+
setCustomDate(current => {
|
|
89
|
+
if (!current.from || !current.to)
|
|
90
|
+
return current;
|
|
91
|
+
const kept = keepTime({ from: new Date(current.from), to: new Date(current.to) });
|
|
92
|
+
return isEmpty(kept) ? current : { from: kept.from.toISOString(), to: kept.to.toISOString() };
|
|
93
|
+
});
|
|
94
|
+
setSelectedRange(current => {
|
|
95
|
+
if (!current)
|
|
96
|
+
return current;
|
|
97
|
+
const kept = keepTime(current);
|
|
98
|
+
return isEmpty(kept) ? current : Object.assign(Object.assign({}, current), { from: kept.from, to: kept.to });
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}, [customDate, hasApplyButton, rebaseToDay, selectOption, setCustomDate, setSelectedRange, timeSelect]);
|
|
93
102
|
// The new picker only compares the dates: the pills are not a selection of their own, any draft is a custom range.
|
|
94
103
|
const isDraftUnchanged = (0, react_1.useMemo)(() => customDate.from === ((0, getRangeOption_1.isDateValid)(value === null || value === void 0 ? void 0 : value.from) ? value.from.toISOString() : undefined) &&
|
|
95
104
|
customDate.to === ((0, getRangeOption_1.isDateValid)(value === null || value === void 0 ? void 0 : value.to) ? value.to.toISOString() : undefined), [customDate.from, customDate.to, value === null || value === void 0 ? void 0 : value.from, value === null || value === void 0 ? void 0 : value.to]);
|
|
@@ -305,12 +305,12 @@ const useDateRangeRawNew = props => {
|
|
|
305
305
|
// Opened with no value, the draft starts on the default, or on today; Clear puts it back there rather than to nothing.
|
|
306
306
|
const handleClear = (0, react_1.useCallback)(() => {
|
|
307
307
|
handleClearClick();
|
|
308
|
-
if (!hasApplyButton || defaultValue
|
|
308
|
+
if (!hasApplyButton || defaultValue) return;
|
|
309
309
|
const fallback = getFallbackRange();
|
|
310
310
|
if (!fallback) return;
|
|
311
311
|
setSelectedRange(fallback.labeled);
|
|
312
312
|
setCustomDate(fallback.draft);
|
|
313
|
-
}, [defaultValue, getFallbackRange, handleClearClick, hasApplyButton, setCustomDate, setSelectedRange
|
|
313
|
+
}, [defaultValue, getFallbackRange, handleClearClick, hasApplyButton, setCustomDate, setSelectedRange]);
|
|
314
314
|
// The chip's X has no popup to press Apply in. With an Apply button the core only resets the draft, so the X reports the reset itself:
|
|
315
315
|
// the default, or nothing when the value may be unset. Without one the core already does. The footer's Clear stays staged.
|
|
316
316
|
const {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useRangeEntry = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
+
const dateUtils_1 = require("../../calendar/dateUtils");
|
|
5
6
|
const customCalendarId_1 = require("../../datePickerCommon/utils/customCalendarId");
|
|
6
7
|
const toEditableFormat_1 = require("../../datePickerNew/components/dateSegmentInput/utils/toEditableFormat");
|
|
7
8
|
const toEditableTimeFormat_1 = require("../../datePickerNew/components/dateSegmentInput/utils/toEditableTimeFormat");
|
|
@@ -62,13 +63,39 @@ const useRangeEntry = ({ customDate, setCustomDate, setSelectedRange, isOpen, lo
|
|
|
62
63
|
}, [customDate, lockEndDate, lockStartDate, markCustom, raiseAdjustment, rebaseToDay, setCustomDate, toLocalDateTime, toReverseOffsetDateTime]);
|
|
63
64
|
// A range edited by hand, dates typed or a time picked, is put in order and a locked end is kept; the banner says when an end moved.
|
|
64
65
|
const commitEdited = (0, react_1.useCallback)((next) => {
|
|
66
|
+
var _a, _b;
|
|
65
67
|
const { range: ordered, adjusted } = (0, rangeOrder_1.resolveRangeOrder)(customDate, (0, pinLockedEnds_1.pinLockedEnds)(next, lockStartDate, lockEndDate), rebaseToDay);
|
|
66
68
|
const locked = (0, applyRangeLocks_1.applyRangeLocks)(customDate, ordered, lockStartDate, lockEndDate);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
const start = locked.from ? new Date(locked.from) : undefined;
|
|
70
|
+
const end = locked.to ? new Date(locked.to) : undefined;
|
|
71
|
+
const crossesDisabledPeriod = start &&
|
|
72
|
+
end &&
|
|
73
|
+
(0, dateUtils_1.isDifferentPeriod)(toReverseOffsetDateTime(start), toReverseOffsetDateTime(end), disableFutureDates, disablePastDates, disableDatesBefore, disableDatesAfter);
|
|
74
|
+
const startChanged = locked.from !== customDate.from;
|
|
75
|
+
const validRange = crossesDisabledPeriod
|
|
76
|
+
? startChanged && !lockStartDate
|
|
77
|
+
? (0, dateUtils_1.getValidDatesForEnd)(toReverseOffsetDateTime, end, start, disableFutureDates, disablePastDates, disableDatesBefore, disableDatesAfter)
|
|
78
|
+
: (0, dateUtils_1.getValidDatesForStart)(toReverseOffsetDateTime, start, end, disableFutureDates, disablePastDates, disableDatesBefore, disableDatesAfter)
|
|
79
|
+
: undefined;
|
|
80
|
+
const committed = validRange ? { from: (_a = validRange.start) === null || _a === void 0 ? void 0 : _a.toISOString(), to: (_b = validRange.end) === null || _b === void 0 ? void 0 : _b.toISOString() } : locked;
|
|
81
|
+
setCustomDate(committed);
|
|
82
|
+
markCustom(committed);
|
|
69
83
|
// The banner says an end moved, so it is raised only for an edit that was kept.
|
|
70
|
-
raiseAdjustment(
|
|
71
|
-
}, [
|
|
84
|
+
raiseAdjustment(committed === customDate ? undefined : adjusted, committed);
|
|
85
|
+
}, [
|
|
86
|
+
customDate,
|
|
87
|
+
disableDatesAfter,
|
|
88
|
+
disableDatesBefore,
|
|
89
|
+
disableFutureDates,
|
|
90
|
+
disablePastDates,
|
|
91
|
+
lockEndDate,
|
|
92
|
+
lockStartDate,
|
|
93
|
+
markCustom,
|
|
94
|
+
raiseAdjustment,
|
|
95
|
+
rebaseToDay,
|
|
96
|
+
setCustomDate,
|
|
97
|
+
toReverseOffsetDateTime
|
|
98
|
+
]);
|
|
72
99
|
// A time picked for one end (mobile). Unlike picking a day, the typed time replaces the end's own.
|
|
73
100
|
const handleTimeSelect = (0, react_1.useCallback)((field, timeText) => {
|
|
74
101
|
const current = customDate[field];
|
|
@@ -60,7 +60,13 @@ export declare const useDateRangeRawCore: (props: TWithDefaultOptions<TDateRange
|
|
|
60
60
|
datesValidation: (val: any) => boolean;
|
|
61
61
|
isDatesValid: import("react").RefObject<boolean>;
|
|
62
62
|
previousStepOption: import("react").RefObject<string>;
|
|
63
|
-
handleDateRangeSelection: (newVal: string
|
|
63
|
+
handleDateRangeSelection: (newVal: string, transformRange?: (range: {
|
|
64
|
+
from: Date;
|
|
65
|
+
to: Date;
|
|
66
|
+
}) => {
|
|
67
|
+
from: Date;
|
|
68
|
+
to: Date;
|
|
69
|
+
}) => void;
|
|
64
70
|
handleApplyClick: () => void;
|
|
65
71
|
handleCancelClick: () => void;
|
|
66
72
|
handleClearClick: () => void;
|
|
@@ -211,12 +211,12 @@ export const useDateRangeRawCore = (props, behavior) => {
|
|
|
211
211
|
}, [isOpen, isStaleCustomDraft, prevSelection]);
|
|
212
212
|
const handleDateRangeSelection = useCallback(
|
|
213
213
|
// eslint-disable-next-line complexity
|
|
214
|
-
newVal => {
|
|
215
|
-
var _a, _b;
|
|
214
|
+
(newVal, transformRange) => {
|
|
215
|
+
var _a, _b, _c;
|
|
216
216
|
const selection = options.find(option => option.id === newVal);
|
|
217
217
|
newVal === CUSTOM_CALENDAR_ID && setShowMobileCalendar(true);
|
|
218
218
|
if (selection && newVal !== CUSTOM_CALENDAR_ID && selection.getRange) {
|
|
219
|
-
const range = selection.getRange();
|
|
219
|
+
const range = (_a = transformRange === null || transformRange === void 0 ? void 0 : transformRange(selection.getRange())) !== null && _a !== void 0 ? _a : selection.getRange();
|
|
220
220
|
const normalizedDates = normalizeDates(range.from.toISOString(), range.to.toISOString(), disableFutureDates, disablePastDates, disableDatesBefore, disableDatesAfter);
|
|
221
221
|
const newRange = newVal === CUSTOM_CALENDAR_ID ? {
|
|
222
222
|
from: new Date(normalizedDates.from),
|
|
@@ -234,8 +234,8 @@ export const useDateRangeRawCore = (props, behavior) => {
|
|
|
234
234
|
}, newRange)));
|
|
235
235
|
previousStepOption.current = "";
|
|
236
236
|
} else {
|
|
237
|
-
const startDateForNormalize = ((
|
|
238
|
-
const endDateForNormalize = ((
|
|
237
|
+
const startDateForNormalize = ((_b = selection === null || selection === void 0 ? void 0 : selection.getRange) === null || _b === void 0 ? void 0 : _b.call(selection)) && (selectedRange === null || selectedRange === void 0 ? void 0 : selectedRange.label) !== newVal ? selection.getRange().from : value === null || value === void 0 ? void 0 : value.from;
|
|
238
|
+
const endDateForNormalize = ((_c = selection === null || selection === void 0 ? void 0 : selection.getRange) === null || _c === void 0 ? void 0 : _c.call(selection)) && (selectedRange === null || selectedRange === void 0 ? void 0 : selectedRange.label) !== newVal ? selection.getRange().to : value === null || value === void 0 ? void 0 : value.to;
|
|
239
239
|
if (!datesValidation(startDateForNormalize === undefined && endDateForNormalize === undefined ? undefined : {
|
|
240
240
|
from: startDateForNormalize,
|
|
241
241
|
to: endDateForNormalize
|
|
@@ -12,7 +12,13 @@ interface IUseDateRangeNewParts {
|
|
|
12
12
|
setShowMobileCalendar: (isVisible: boolean) => void;
|
|
13
13
|
/** What was last applied; closing without Apply goes back to it. */
|
|
14
14
|
prevSelection: IDateRangeValue | undefined;
|
|
15
|
-
selectOption: (optionId: string
|
|
15
|
+
selectOption: (optionId: string, transformRange?: (range: {
|
|
16
|
+
from: Date;
|
|
17
|
+
to: Date;
|
|
18
|
+
}) => {
|
|
19
|
+
from: Date;
|
|
20
|
+
to: Date;
|
|
21
|
+
}) => void;
|
|
16
22
|
segmentedTriggerRef: RefObject<HTMLElement | null>;
|
|
17
23
|
hasApplyButton: boolean;
|
|
18
24
|
defaultValue?: IDateRangeValue;
|
|
@@ -65,28 +65,37 @@ export const useDateRangeNewParts = ({ isOpen, setIsOpen, isMobile, customDate,
|
|
|
65
65
|
const { rebaseToDay } = rangeEntry;
|
|
66
66
|
const handleOptionSelect = useCallback((optionId) => {
|
|
67
67
|
const before = customDate;
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
if (!timeSelect || optionId === CUSTOM_CALENDAR_ID || !before.from || !before.to) {
|
|
69
|
+
selectOption(optionId);
|
|
70
70
|
return;
|
|
71
|
+
}
|
|
71
72
|
const { from: timeFrom, to: timeTo } = before;
|
|
72
73
|
const keepTime = (range) => ({
|
|
73
|
-
from:
|
|
74
|
-
to:
|
|
74
|
+
from: new Date(rebaseToDay(range.from.toISOString(), timeFrom, false)),
|
|
75
|
+
to: new Date(rebaseToDay(range.to.toISOString(), timeTo, true))
|
|
75
76
|
});
|
|
76
77
|
// Kept times that leave no range (13:00 to 13:00 on a single-day preset, or an end before the start) would make a
|
|
77
78
|
// range a form cannot take, so the preset keeps its own whole day then.
|
|
78
|
-
const isEmpty = (range) => isEndBeforeStart(range.from, range.to) ||
|
|
79
|
-
|
|
80
|
-
const kept = keepTime(
|
|
81
|
-
return isEmpty(kept) ?
|
|
79
|
+
const isEmpty = (range) => isEndBeforeStart(range.from.toISOString(), range.to.toISOString()) || range.from.getTime() === range.to.getTime();
|
|
80
|
+
selectOption(optionId, range => {
|
|
81
|
+
const kept = keepTime(range);
|
|
82
|
+
return isEmpty(kept) ? range : kept;
|
|
82
83
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
84
|
+
if (hasApplyButton) {
|
|
85
|
+
setCustomDate(current => {
|
|
86
|
+
if (!current.from || !current.to)
|
|
87
|
+
return current;
|
|
88
|
+
const kept = keepTime({ from: new Date(current.from), to: new Date(current.to) });
|
|
89
|
+
return isEmpty(kept) ? current : { from: kept.from.toISOString(), to: kept.to.toISOString() };
|
|
90
|
+
});
|
|
91
|
+
setSelectedRange(current => {
|
|
92
|
+
if (!current)
|
|
93
|
+
return current;
|
|
94
|
+
const kept = keepTime(current);
|
|
95
|
+
return isEmpty(kept) ? current : Object.assign(Object.assign({}, current), { from: kept.from, to: kept.to });
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}, [customDate, hasApplyButton, rebaseToDay, selectOption, setCustomDate, setSelectedRange, timeSelect]);
|
|
90
99
|
// The new picker only compares the dates: the pills are not a selection of their own, any draft is a custom range.
|
|
91
100
|
const isDraftUnchanged = useMemo(() => customDate.from === (isDateValid(value === null || value === void 0 ? void 0 : value.from) ? value.from.toISOString() : undefined) &&
|
|
92
101
|
customDate.to === (isDateValid(value === null || value === void 0 ? void 0 : value.to) ? value.to.toISOString() : undefined), [customDate.from, customDate.to, value === null || value === void 0 ? void 0 : value.from, value === null || value === void 0 ? void 0 : value.to]);
|
|
@@ -297,12 +297,12 @@ export const useDateRangeRawNew = props => {
|
|
|
297
297
|
// Opened with no value, the draft starts on the default, or on today; Clear puts it back there rather than to nothing.
|
|
298
298
|
const handleClear = useCallback(() => {
|
|
299
299
|
handleClearClick();
|
|
300
|
-
if (!hasApplyButton || defaultValue
|
|
300
|
+
if (!hasApplyButton || defaultValue) return;
|
|
301
301
|
const fallback = getFallbackRange();
|
|
302
302
|
if (!fallback) return;
|
|
303
303
|
setSelectedRange(fallback.labeled);
|
|
304
304
|
setCustomDate(fallback.draft);
|
|
305
|
-
}, [defaultValue, getFallbackRange, handleClearClick, hasApplyButton, setCustomDate, setSelectedRange
|
|
305
|
+
}, [defaultValue, getFallbackRange, handleClearClick, hasApplyButton, setCustomDate, setSelectedRange]);
|
|
306
306
|
// The chip's X has no popup to press Apply in. With an Apply button the core only resets the draft, so the X reports the reset itself:
|
|
307
307
|
// the default, or nothing when the value may be unset. Without one the core already does. The footer's Clear stays staged.
|
|
308
308
|
const {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useCallback, useMemo } from "react";
|
|
2
|
+
import { getValidDatesForEnd, getValidDatesForStart, isDifferentPeriod } from "../../calendar/dateUtils";
|
|
2
3
|
import { CUSTOM_CALENDAR_ID } from "../../datePickerCommon/utils/customCalendarId";
|
|
3
4
|
import { toEditableFormat } from "../../datePickerNew/components/dateSegmentInput/utils/toEditableFormat";
|
|
4
5
|
import { toEditableTimeFormat } from "../../datePickerNew/components/dateSegmentInput/utils/toEditableTimeFormat";
|
|
@@ -59,13 +60,39 @@ export const useRangeEntry = ({ customDate, setCustomDate, setSelectedRange, isO
|
|
|
59
60
|
}, [customDate, lockEndDate, lockStartDate, markCustom, raiseAdjustment, rebaseToDay, setCustomDate, toLocalDateTime, toReverseOffsetDateTime]);
|
|
60
61
|
// A range edited by hand, dates typed or a time picked, is put in order and a locked end is kept; the banner says when an end moved.
|
|
61
62
|
const commitEdited = useCallback((next) => {
|
|
63
|
+
var _a, _b;
|
|
62
64
|
const { range: ordered, adjusted } = resolveRangeOrder(customDate, pinLockedEnds(next, lockStartDate, lockEndDate), rebaseToDay);
|
|
63
65
|
const locked = applyRangeLocks(customDate, ordered, lockStartDate, lockEndDate);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
const start = locked.from ? new Date(locked.from) : undefined;
|
|
67
|
+
const end = locked.to ? new Date(locked.to) : undefined;
|
|
68
|
+
const crossesDisabledPeriod = start &&
|
|
69
|
+
end &&
|
|
70
|
+
isDifferentPeriod(toReverseOffsetDateTime(start), toReverseOffsetDateTime(end), disableFutureDates, disablePastDates, disableDatesBefore, disableDatesAfter);
|
|
71
|
+
const startChanged = locked.from !== customDate.from;
|
|
72
|
+
const validRange = crossesDisabledPeriod
|
|
73
|
+
? startChanged && !lockStartDate
|
|
74
|
+
? getValidDatesForEnd(toReverseOffsetDateTime, end, start, disableFutureDates, disablePastDates, disableDatesBefore, disableDatesAfter)
|
|
75
|
+
: getValidDatesForStart(toReverseOffsetDateTime, start, end, disableFutureDates, disablePastDates, disableDatesBefore, disableDatesAfter)
|
|
76
|
+
: undefined;
|
|
77
|
+
const committed = validRange ? { from: (_a = validRange.start) === null || _a === void 0 ? void 0 : _a.toISOString(), to: (_b = validRange.end) === null || _b === void 0 ? void 0 : _b.toISOString() } : locked;
|
|
78
|
+
setCustomDate(committed);
|
|
79
|
+
markCustom(committed);
|
|
66
80
|
// The banner says an end moved, so it is raised only for an edit that was kept.
|
|
67
|
-
raiseAdjustment(
|
|
68
|
-
}, [
|
|
81
|
+
raiseAdjustment(committed === customDate ? undefined : adjusted, committed);
|
|
82
|
+
}, [
|
|
83
|
+
customDate,
|
|
84
|
+
disableDatesAfter,
|
|
85
|
+
disableDatesBefore,
|
|
86
|
+
disableFutureDates,
|
|
87
|
+
disablePastDates,
|
|
88
|
+
lockEndDate,
|
|
89
|
+
lockStartDate,
|
|
90
|
+
markCustom,
|
|
91
|
+
raiseAdjustment,
|
|
92
|
+
rebaseToDay,
|
|
93
|
+
setCustomDate,
|
|
94
|
+
toReverseOffsetDateTime
|
|
95
|
+
]);
|
|
69
96
|
// A time picked for one end (mobile). Unlike picking a day, the typed time replaces the end's own.
|
|
70
97
|
const handleTimeSelect = useCallback((field, timeText) => {
|
|
71
98
|
const current = customDate[field];
|