@geotab/zenith 1.20.0 → 1.21.0

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.
Files changed (53) hide show
  1. package/README.md +8 -0
  2. package/dist/dateRange/dateRange.d.ts +2 -0
  3. package/dist/dateRange/dateRange.js +109 -20
  4. package/dist/dropdown/dropdown.js +1 -1
  5. package/dist/filtersBar/components/filtersBarPeriodPicker/filtersBarPeriodPicker.d.ts +1 -0
  6. package/dist/filtersBar/components/filtersBarPeriodPicker/filtersBarPeriodPicker.js +1 -1
  7. package/dist/filtersBar/components/filtersBarPeriodPicker/getRangeOption.d.ts +28 -0
  8. package/dist/filtersBar/components/filtersBarPeriodPicker/getRangeOption.js +177 -1
  9. package/dist/groupsFilter/groupsFilter.js +24 -3
  10. package/dist/groupsFilter/groupsFilterAdvancedValue.d.ts +16 -0
  11. package/dist/groupsFilter/groupsFilterAdvancedValue.js +34 -0
  12. package/dist/header/components/basicToolbar/basicToolbar.js +1 -1
  13. package/dist/index.css +88 -1
  14. package/dist/pagination/pagination.d.ts +1 -0
  15. package/dist/pagination/pagination.js +13 -4
  16. package/dist/table/children/useTableChildren.d.ts +1 -1
  17. package/dist/table/children/useTableChildren.js +4 -3
  18. package/dist/table/table.js +1 -1
  19. package/dist/utils/localization/translations/cs-json.d.ts +2 -0
  20. package/dist/utils/localization/translations/cs-json.js +3 -1
  21. package/dist/utils/localization/translations/de-json.d.ts +2 -0
  22. package/dist/utils/localization/translations/de-json.js +3 -1
  23. package/dist/utils/localization/translations/en-json.d.ts +7 -0
  24. package/dist/utils/localization/translations/en-json.js +8 -1
  25. package/dist/utils/localization/translations/es-json.d.ts +2 -0
  26. package/dist/utils/localization/translations/es-json.js +3 -1
  27. package/dist/utils/localization/translations/fr-FR-json.d.ts +2 -0
  28. package/dist/utils/localization/translations/fr-FR-json.js +3 -1
  29. package/dist/utils/localization/translations/fr-json.d.ts +2 -0
  30. package/dist/utils/localization/translations/fr-json.js +3 -1
  31. package/dist/utils/localization/translations/id-json.d.ts +2 -0
  32. package/dist/utils/localization/translations/id-json.js +3 -1
  33. package/dist/utils/localization/translations/it-json.d.ts +2 -0
  34. package/dist/utils/localization/translations/it-json.js +3 -1
  35. package/dist/utils/localization/translations/ja-json.d.ts +2 -0
  36. package/dist/utils/localization/translations/ja-json.js +3 -1
  37. package/dist/utils/localization/translations/ms-json.d.ts +2 -0
  38. package/dist/utils/localization/translations/ms-json.js +3 -1
  39. package/dist/utils/localization/translations/nl-json.d.ts +2 -0
  40. package/dist/utils/localization/translations/nl-json.js +3 -1
  41. package/dist/utils/localization/translations/pl-json.d.ts +2 -0
  42. package/dist/utils/localization/translations/pl-json.js +3 -1
  43. package/dist/utils/localization/translations/pt-BR-json.d.ts +2 -0
  44. package/dist/utils/localization/translations/pt-BR-json.js +3 -1
  45. package/dist/utils/localization/translations/sv-json.d.ts +2 -0
  46. package/dist/utils/localization/translations/sv-json.js +3 -1
  47. package/dist/utils/localization/translations/th-json.d.ts +2 -0
  48. package/dist/utils/localization/translations/th-json.js +3 -1
  49. package/dist/utils/localization/translations/tr-json.d.ts +2 -0
  50. package/dist/utils/localization/translations/tr-json.js +3 -1
  51. package/dist/utils/localization/translations/zh-Hans-json.d.ts +2 -0
  52. package/dist/utils/localization/translations/zh-Hans-json.js +3 -1
  53. package/package.json +3 -3
package/README.md CHANGED
@@ -40,6 +40,14 @@ Zenith library provides components defined in Zenith Design System. It includes
40
40
 
41
41
  ## Change log
42
42
 
43
+ ## 1.21.0
44
+
45
+ * Implement `DateRange` with stepper
46
+ * Implement GroupsFilter selection placeholder for advanced groups filter case
47
+ * Fix table scroll position with pagination
48
+ * Fix incorrect clear button disabled state
49
+ * Update Header's title max-width
50
+
43
51
  ## 1.20.0
44
52
 
45
53
  * New component `Chart`
@@ -7,6 +7,7 @@ interface IDateRangeBase extends IZenComponentProps {
7
7
  options: TDateRangeOption[];
8
8
  className?: string;
9
9
  classNamePopup?: string;
10
+ classNameWrapper?: string;
10
11
  hasApplyButton?: boolean;
11
12
  type?: TButton;
12
13
  disabled?: boolean;
@@ -21,6 +22,7 @@ interface IDateRangeBase extends IZenComponentProps {
21
22
  lockStartDate?: string;
22
23
  id?: string;
23
24
  error?: string;
25
+ stepper?: boolean;
24
26
  }
25
27
  export interface IDateRange extends IDateRangeBase {
26
28
  defaultValue: IDateRangeValue;
@@ -22,6 +22,10 @@ const mobileSheet_1 = require("../mobileSheet/mobileSheet");
22
22
  const footerButtons_1 = require("../footerButtons/footerButtons");
23
23
  const useDriveClassName_1 = require("../utils/theme/useDriveClassName");
24
24
  const areMapsEqual_1 = require("./utils/areMapsEqual");
25
+ const iconChevronLeftSmall_1 = require("../icons/iconChevronLeftSmall");
26
+ const useDrive_1 = require("../utils/theme/useDrive");
27
+ const iconChevronRightSmall_1 = require("../icons/iconChevronRightSmall");
28
+ const alert_1 = require("../alert/alert");
25
29
  const parseLabel = (option, dateFormat, translate, toLacalFn) => {
26
30
  const localeFrom = toLacalFn(option.from);
27
31
  const localeTo = toLacalFn(option.to);
@@ -33,15 +37,20 @@ const parseLabel = (option, dateFormat, translate, toLacalFn) => {
33
37
  return `${(0, formatDate_1.formatDate)(localeFrom, dateFormat, translate)} - ${(0, formatDate_1.formatDate)(localeTo, dateFormat, translate)}`;
34
38
  };
35
39
  exports.parseLabel = parseLabel;
36
- const DateRange = ({ className, classNamePopup, defaultValue, value, onChange, options: optionsArg, type, id, disabled, dropDownTitle, hasApplyButton, disableFutureDates, disablePastDates, disableDatesBefore, disableDatesAfter, withCalendar, lockStartDate, lockEndDate, timeSelect, error, allowUnsetValue = false }) => {
40
+ // eslint-disable-next-line complexity
41
+ const DateRange = ({ className, classNamePopup, defaultValue, value, onChange, options: optionsArg, type, id, disabled, dropDownTitle, hasApplyButton, disableFutureDates, disablePastDates, disableDatesBefore, disableDatesAfter, withCalendar, lockStartDate, lockEndDate, timeSelect, error, allowUnsetValue = false, stepper = false, classNameWrapper }) => {
37
42
  var _a;
38
43
  const { translate } = (0, useLanguage_1.useLanguage)();
44
+ const [alertReason, setAlertReason] = (0, react_1.useState)("");
39
45
  const isMobile = (0, useMobile_1.useMobile)();
46
+ const isDrive = (0, useDrive_1.useDrive)();
47
+ const driveWrapperTriggerClassName = (0, useDriveClassName_1.useDriveClassName)("zen-date-range-wrapper");
40
48
  const drivePopupClassName = (0, useDriveClassName_1.useDriveClassName)("zen-date-range-popup");
41
- const driveWrapperClassName = (0, useDriveClassName_1.useDriveClassName)("zen-date-range-popup-wrapper");
49
+ const driveWrapperPopupClassName = (0, useDriveClassName_1.useDriveClassName)("zen-date-range-popup-wrapper");
42
50
  const [showMobileCalendar, setShowMobileCalendar] = (0, react_1.useState)(false);
43
51
  const { dateFormat, toLocalDateTime, toReverseOffsetDateTime, weekStartsOnSunday } = (0, react_1.useContext)(userFormatContext_1.userFormatContext);
44
52
  const optionsMap = (0, react_1.useMemo)(() => (0, getRangeOption_1.getOptionsPeriodMap)(optionsArg, translate, toLocalDateTime, weekStartsOnSunday ? "Sunday" : "Monday", toReverseOffsetDateTime), [optionsArg, toLocalDateTime, toReverseOffsetDateTime, translate, weekStartsOnSunday]);
53
+ const previousStepOption = (0, react_1.useRef)("");
45
54
  const [selectedRange, setSelectedRange] = (0, react_1.useState)((0, getRangeOption_1.getSelectedRangeFromValue)(optionsMap, value));
46
55
  const isDefaultState = !defaultValue && !selectedRange || (defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.label) === (selectedRange === null || selectedRange === void 0 ? void 0 : selectedRange.label);
47
56
  const isCustomDateOption = (selectedRange === null || selectedRange === void 0 ? void 0 : selectedRange.label) === dateRangeInner_1.CUSTOM_CALENDAR_ID;
@@ -54,14 +63,12 @@ const DateRange = ({ className, classNamePopup, defaultValue, value, onChange, o
54
63
  const calendarLabel = translate(dateRangeInner_1.CUSTOM_CALENDAR_ID);
55
64
  const getCustomRange = (0, react_1.useCallback)(() => ({ from: (prevSelection === null || prevSelection === void 0 ? void 0 : prevSelection.from) || new Date(), to: (prevSelection === null || prevSelection === void 0 ? void 0 : prevSelection.to) || new Date() }), [prevSelection]);
56
65
  const options = (0, react_1.useMemo)(() => (0, getRangeOption_1.getRangeOptionsArray)(optionsArg, translate, toLocalDateTime, weekStartsOnSunday ? "Sunday" : "Monday", toReverseOffsetDateTime, withCalendar || false, prevSelection && prevSelection.label === dateRangeInner_1.CUSTOM_CALENDAR_ID, prevSelection ? getCustomRange : undefined), [optionsArg, translate, toLocalDateTime, weekStartsOnSunday, toReverseOffsetDateTime, withCalendar, prevSelection, getCustomRange]);
66
+ const optionsMapRef = (0, react_1.useRef)(optionsMap);
67
+ const isEqualMaps = (0, react_1.useMemo)(() => (0, areMapsEqual_1.areMapsEqual)(optionsMapRef.current, optionsMap), [optionsMap]);
68
+ if (!isEqualMaps) {
69
+ optionsMapRef.current = optionsMap;
70
+ }
57
71
  const hasCustomOption = (0, react_1.useMemo)(() => options.find(option => option.id === dateRangeInner_1.CUSTOM_CALENDAR_ID) !== undefined, [options]);
58
- const currentLabel = (_a = (0, getRangeOption_1.getSelectedRangeFromValue)(optionsMap, value)) === null || _a === void 0 ? void 0 : _a.label;
59
- const cssClass = (0, classNames_1.classNames)([
60
- "zen-date-range",
61
- error ? "zen-date-range--error" : "",
62
- className !== null && className !== void 0 ? className : "",
63
- !defaultValue && !value || (defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.label) === currentLabel || type && type !== buttonType_1.ButtonType.Secondary ? "" : "zen-date-range--active"
64
- ]);
65
72
  const title = (0, react_1.useMemo)(() => dropDownTitle || translate("Date range"), [dropDownTitle, translate]);
66
73
  const toggleVisibility = (0, react_1.useCallback)(() => setIsOpen(currentIsOpen => !currentIsOpen), []);
67
74
  const getButtonLabel = (0, react_1.useCallback)((rangeValue) => {
@@ -77,11 +84,11 @@ const DateRange = ({ className, classNamePopup, defaultValue, value, onChange, o
77
84
  }, [dateFormat, options, translate, toLocalDateTime]);
78
85
  (0, react_1.useEffect)(() => {
79
86
  const currentValue = (0, getRangeOption_1.getSelectedRangeFromValue)(optionsMap, value);
80
- if ((prevSelection === null || prevSelection === void 0 ? void 0 : prevSelection.label) !== (currentValue === null || currentValue === void 0 ? void 0 : currentValue.label)) {
87
+ if ((prevSelection === null || prevSelection === void 0 ? void 0 : prevSelection.label) !== (currentValue === null || currentValue === void 0 ? void 0 : currentValue.label) || ((prevSelection === null || prevSelection === void 0 ? void 0 : prevSelection.from.getTime()) !== (currentValue === null || currentValue === void 0 ? void 0 : currentValue.from.getTime()) || (prevSelection === null || prevSelection === void 0 ? void 0 : prevSelection.to.getTime()) !== (currentValue === null || currentValue === void 0 ? void 0 : currentValue.to.getTime()))) {
81
88
  setSelectedRange(currentValue);
82
89
  setPrevSelection(currentValue);
83
90
  }
84
- }, [optionsMap, prevSelection === null || prevSelection === void 0 ? void 0 : prevSelection.label, value]);
91
+ }, [optionsMap, prevSelection === null || prevSelection === void 0 ? void 0 : prevSelection.from, prevSelection === null || prevSelection === void 0 ? void 0 : prevSelection.label, prevSelection === null || prevSelection === void 0 ? void 0 : prevSelection.to, value]);
85
92
  const handleDateRangeSelection = (0, react_1.useCallback)((newVal) => {
86
93
  var _a, _b;
87
94
  const selection = options.find(option => option.id === newVal);
@@ -95,6 +102,7 @@ const DateRange = ({ className, classNamePopup, defaultValue, value, onChange, o
95
102
  setSelectedRange(Object.assign({ label: selection.id }, newRange));
96
103
  !hasApplyButton && setPrevSelection(Object.assign({ label: selection.id }, newRange));
97
104
  !hasApplyButton && onChange(Object.assign({ label: selection.id }, newRange));
105
+ previousStepOption.current = "";
98
106
  }
99
107
  else {
100
108
  const startDateForNormalize = ((_a = selection === null || selection === void 0 ? void 0 : selection.getRange) === null || _a === void 0 ? void 0 : _a.call(selection)) && (selectedRange === null || selectedRange === void 0 ? void 0 : selectedRange.label) !== newVal ? selection.getRange().from.toISOString() : value === null || value === void 0 ? void 0 : value.from.toISOString();
@@ -125,6 +133,7 @@ const DateRange = ({ className, classNamePopup, defaultValue, value, onChange, o
125
133
  setShowMobileCalendar(false);
126
134
  if (isCustomDateOption) {
127
135
  handleRangeSelection();
136
+ previousStepOption.current = "";
128
137
  return;
129
138
  }
130
139
  selectedRange && onChange(selectedRange);
@@ -141,17 +150,26 @@ const DateRange = ({ className, classNamePopup, defaultValue, value, onChange, o
141
150
  !hasApplyButton && (defaultValue || allowUnsetValue) && onChange(defaultValue);
142
151
  !hasApplyButton && setIsOpen(false);
143
152
  setSelectedRange(defaultValue);
153
+ previousStepOption.current = "";
144
154
  (defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.label) === dateRangeInner_1.CUSTOM_CALENDAR_ID && !allowUnsetValue && setCustomDate({ from: defaultValue.from.toISOString(), to: defaultValue.to.toISOString() });
145
155
  setShowMobileCalendar(false);
146
156
  }, [allowUnsetValue, defaultValue, hasApplyButton, onChange]);
147
157
  const handleMobileBackClick = (0, react_1.useCallback)(() => {
148
158
  setShowMobileCalendar(false);
149
159
  }, []);
150
- const optionsMapRef = (0, react_1.useRef)(optionsMap);
151
- const isEqualMaps = (0, react_1.useMemo)(() => (0, areMapsEqual_1.areMapsEqual)(optionsMapRef.current, optionsMap), [optionsMap]);
152
- if (!isEqualMaps) {
153
- optionsMapRef.current = optionsMap;
154
- }
160
+ const handleStepperClick = (0, react_1.useCallback)((currentRange, isIncrease) => {
161
+ let step = previousStepOption.current ? previousStepOption.current : (0, getRangeOption_1.getDateRangeAdjustedStep)(translate, currentRange.label);
162
+ if (previousStepOption.current === "") {
163
+ previousStepOption.current = step;
164
+ }
165
+ else if (previousStepOption.current !== getRangeOption_1.DEFAULT_STEP_OPTION) {
166
+ step = previousStepOption.current;
167
+ }
168
+ const adjustFn = getRangeOption_1.dateRangeAdjustedFn[step];
169
+ const newValue = adjustFn(currentRange, isIncrease, toLocalDateTime, toReverseOffsetDateTime);
170
+ const labeledValue = (0, getRangeOption_1.getSelectedRangeFromValue)(optionsMap, newValue);
171
+ labeledValue && onChange(labeledValue);
172
+ }, [onChange, optionsMap, toLocalDateTime, toReverseOffsetDateTime, translate]);
155
173
  (0, react_1.useEffect)(() => {
156
174
  setCustomDate({ from: value === null || value === void 0 ? void 0 : value.from.toISOString(), to: value === null || value === void 0 ? void 0 : value.to.toISOString() });
157
175
  const currentValue = (0, getRangeOption_1.getSelectedRangeFromValue)(optionsMapRef.current, value);
@@ -174,8 +192,8 @@ const DateRange = ({ className, classNamePopup, defaultValue, value, onChange, o
174
192
  }
175
193
  return selectedRange.label === (value === null || value === void 0 ? void 0 : value.label) && customDate.from === value.from.toISOString() && customDate.to === value.to.toISOString();
176
194
  }, [customDate.from, customDate.to, hasApplyButton, isCustomDateOption, selectedRange === null || selectedRange === void 0 ? void 0 : selectedRange.label, value === null || value === void 0 ? void 0 : value.from, value === null || value === void 0 ? void 0 : value.label, value === null || value === void 0 ? void 0 : value.to]);
177
- const memoizedDesktopView = (0, react_1.useMemo)(() => (0, jsx_runtime_1.jsx)(controlledPopup_1.ControlledPopup, { className: (0, classNames_1.classNames)(["zen-date-range-popup-wrapper", driveWrapperClassName || ""]), ariaLabel: translate("Date range"), useTrapFocusWithTrigger: "on", role: "dialog", triggerRef: triggerRef, onOpenChange: setIsOpen, shouldHoldScroll: true, isOpen: isOpen, recalculateOnScroll: true, children: (0, jsx_runtime_1.jsxs)("div", { className: (0, classNames_1.classNames)(["zen-date-range-popup", drivePopupClassName || "", classNamePopup !== null && classNamePopup !== void 0 ? classNamePopup : ""]), children: [(0, jsx_runtime_1.jsx)("div", { className: "zen-date-range-popup__header", children: title }), component, (0, jsx_runtime_1.jsxs)("div", { className: "zen-date-range-popup__footer", children: [(0, jsx_runtime_1.jsx)(button_1.Button, { className: "zen-date-range-popup__button-clear", type: buttonType_1.ButtonType.Tertiary, disabled: isDefaultState, onClick: handleClearClick, children: translate("Clear") }), (!isCustomDateOption && hasApplyButton) &&
178
- (0, jsx_runtime_1.jsx)(button_1.Button, { className: "zen-date-range-popup__button-reset", type: buttonType_1.ButtonType.Secondary, onClick: handleCancelClick, children: translate("Cancel") }), (isCustomDateOption || hasApplyButton) && (0, jsx_runtime_1.jsx)(button_1.Button, { className: "zen-date-range-popup__button-apply", type: buttonType_1.ButtonType.Primary, disabled: (isCustomDateOption && (!customDate.from || !customDate.to)) || isValueNotChanged || !selectedRange, onClick: handleApplyClick, children: translate("Apply") })] })] }) }), [classNamePopup, component, customDate.from, customDate.to, drivePopupClassName, driveWrapperClassName, handleApplyClick, handleCancelClick, handleClearClick, hasApplyButton, isCustomDateOption, isDefaultState, isOpen, isValueNotChanged, selectedRange, title, translate]);
195
+ const memoizedDesktopView = (0, react_1.useMemo)(() => (0, jsx_runtime_1.jsx)(controlledPopup_1.ControlledPopup, { className: (0, classNames_1.classNames)(["zen-date-range-popup-wrapper", driveWrapperPopupClassName || ""]), ariaLabel: translate("Date range"), useTrapFocusWithTrigger: "on", role: "dialog", triggerRef: triggerRef, onOpenChange: setIsOpen, shouldHoldScroll: true, isOpen: isOpen, recalculateOnScroll: true, children: (0, jsx_runtime_1.jsxs)("div", { className: (0, classNames_1.classNames)(["zen-date-range-popup", drivePopupClassName || "", classNamePopup !== null && classNamePopup !== void 0 ? classNamePopup : ""]), children: [(0, jsx_runtime_1.jsx)("div", { className: "zen-date-range-popup__header", children: title }), component, (0, jsx_runtime_1.jsxs)("div", { className: "zen-date-range-popup__footer", children: [(0, jsx_runtime_1.jsx)(button_1.Button, { className: "zen-date-range-popup__button-clear", type: buttonType_1.ButtonType.Tertiary, disabled: isDefaultState, onClick: handleClearClick, children: translate("Clear") }), (!isCustomDateOption && hasApplyButton) &&
196
+ (0, jsx_runtime_1.jsx)(button_1.Button, { className: "zen-date-range-popup__button-reset", type: buttonType_1.ButtonType.Secondary, onClick: handleCancelClick, children: translate("Cancel") }), (isCustomDateOption || hasApplyButton) && (0, jsx_runtime_1.jsx)(button_1.Button, { className: "zen-date-range-popup__button-apply", type: buttonType_1.ButtonType.Primary, disabled: (isCustomDateOption && (!customDate.from || !customDate.to)) || isValueNotChanged || !selectedRange, onClick: handleApplyClick, children: translate("Apply") })] })] }) }), [classNamePopup, component, customDate.from, customDate.to, drivePopupClassName, driveWrapperPopupClassName, handleApplyClick, handleCancelClick, handleClearClick, hasApplyButton, isCustomDateOption, isDefaultState, isOpen, isValueNotChanged, selectedRange, title, translate]);
179
197
  const memoizedMobileFooter = (0, react_1.useMemo)(() => {
180
198
  const clearButton = (0, jsx_runtime_1.jsx)(button_1.Button, { type: buttonType_1.ButtonType.Tertiary, disabled: isDefaultState, onClick: handleClearClick, children: translate("Clear") });
181
199
  const cancelButton = hasApplyButton && !showMobileCalendar ? (0, jsx_runtime_1.jsx)(button_1.Button, { type: buttonType_1.ButtonType.Secondary, onClick: handleCancelClick, children: translate("Cancel") }) : null;
@@ -185,6 +203,39 @@ const DateRange = ({ className, classNamePopup, defaultValue, value, onChange, o
185
203
  }, [customDate.from, customDate.to, handleApplyClick, handleCancelClick, handleClearClick, hasApplyButton, isCustomDateOption, isDefaultState, isValueNotChanged, selectedRange,
186
204
  showMobileCalendar, translate]);
187
205
  const memoizedMobileView = (0, react_1.useMemo)(() => (0, jsx_runtime_1.jsxs)(mobileSheet_1.MobileSheet, { className: (0, classNames_1.classNames)(["zen-date-range-mobile-sheet", classNamePopup ? `${classNamePopup}--mobile-sheet` : ""]), label: translate("Date range"), triggerRef: triggerRef, isOpen: isOpen, onHidePanel: memoizedHandleClose, onCloseClick: memoizedHandleClose, useTrapFocusWithTrigger: true, isBackVisible: showMobileCalendar, onBackClick: handleMobileBackClick, children: [(0, jsx_runtime_1.jsx)(mobileSheet_1.MobileSheet.Title, { children: showMobileCalendar ? calendarLabel : title }), (0, jsx_runtime_1.jsx)(mobileSheet_1.MobileSheet.Content, { children: component }), (0, jsx_runtime_1.jsx)(mobileSheet_1.MobileSheet.Footer, { children: memoizedMobileFooter })] }), [calendarLabel, classNamePopup, component, handleMobileBackClick, isOpen, memoizedHandleClose, memoizedMobileFooter, showMobileCalendar, title, translate]);
206
+ const checkIsRangeDisable = (0, react_1.useCallback)((isIncrease) => {
207
+ if (!selectedRange) {
208
+ return true;
209
+ }
210
+ const step = previousStepOption.current ? previousStepOption.current : (0, getRangeOption_1.getDateRangeAdjustedStep)(translate, selectedRange.label);
211
+ const adjustFn = getRangeOption_1.dateRangeAdjustedFn[step];
212
+ const newValue = adjustFn({ from: selectedRange.from, to: selectedRange.to }, isIncrease, toLocalDateTime, toReverseOffsetDateTime);
213
+ const normalizeNewValue = (0, normalizeDates_1.normalizeDates)(newValue.from.toISOString(), newValue.to.toISOString(), disableFutureDates, disablePastDates, disableDatesBefore, disableDatesAfter);
214
+ return newValue.from.getTime() !== new Date(normalizeNewValue.from).getTime() || newValue.to.getTime() !== new Date(normalizeNewValue.to).getTime();
215
+ }, [disableDatesAfter, disableDatesBefore, disableFutureDates, disablePastDates, selectedRange, toLocalDateTime, toReverseOffsetDateTime, translate]);
216
+ const increaseRange = (0, react_1.useCallback)(() => {
217
+ const isDateDisabled = checkIsRangeDisable(true);
218
+ if (isDateDisabled) {
219
+ setAlertReason(selectedRange ? "NotAvailable" : "NoSelection");
220
+ return;
221
+ }
222
+ selectedRange && handleStepperClick(selectedRange, true);
223
+ }, [checkIsRangeDisable, handleStepperClick, selectedRange]);
224
+ const decreaseRange = (0, react_1.useCallback)(() => {
225
+ const isDateDisabled = checkIsRangeDisable(false);
226
+ if (isDateDisabled) {
227
+ setAlertReason(selectedRange ? "NotAvailable" : "NoSelection");
228
+ return;
229
+ }
230
+ selectedRange && handleStepperClick(selectedRange, false);
231
+ }, [checkIsRangeDisable, handleStepperClick, selectedRange]);
232
+ const handleCloseAlert = (0, react_1.useCallback)(() => {
233
+ setAlertReason("");
234
+ }, []);
235
+ const handleUnavailableRangeAlert = (0, react_1.useCallback)(() => {
236
+ setAlertReason("");
237
+ setIsOpen(true);
238
+ }, []);
188
239
  (0, react_1.useEffect)(() => {
189
240
  if (!isOpen && prevIsOpenRef.current) {
190
241
  setTimeout(() => {
@@ -194,7 +245,38 @@ const DateRange = ({ className, classNamePopup, defaultValue, value, onChange, o
194
245
  }
195
246
  prevIsOpenRef.current = isOpen;
196
247
  }, [isOpen]);
197
- return (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(textIconButton_1.TextIconButton, { htmlType: "button", icon: iconCalendar_1.IconCalendar, iconPosition: textIconButton_1.ButtonIconPosition.Start, className: cssClass, type: type, disabled: disabled, onClick: toggleVisibility, ref: triggerRef, children: getButtonLabel((0, getRangeOption_1.getSelectedRangeFromValue)(optionsMap, value)) }), isMobile ? memoizedMobileView : memoizedDesktopView, (0, jsx_runtime_1.jsx)(formFieldError_1.FormFieldError, { error: error })] });
248
+ const buttonLabel = (0, react_1.useMemo)(() => getButtonLabel((0, getRangeOption_1.getSelectedRangeFromValue)(optionsMap, value)), [getButtonLabel, optionsMap, value]);
249
+ const currentLabel = (_a = (0, getRangeOption_1.getSelectedRangeFromValue)(optionsMap, value)) === null || _a === void 0 ? void 0 : _a.label;
250
+ const cssClass = (0, classNames_1.classNames)([
251
+ "zen-date-range",
252
+ error ? "zen-date-range--error" : "",
253
+ className !== null && className !== void 0 ? className : "",
254
+ stepper ? "zen-date-range--with-stepper" : "",
255
+ stepper && currentLabel === dateRangeInner_1.CUSTOM_CALENDAR_ID && buttonLabel.length > 20 ? "zen-date-range--with-stepper-custom" : "",
256
+ !defaultValue && !value || (defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.label) === currentLabel || type && type !== buttonType_1.ButtonType.Secondary ? "" : "zen-date-range--active"
257
+ ]);
258
+ const popupTriggerComponent = (0, react_1.useMemo)(() => (0, jsx_runtime_1.jsx)(textIconButton_1.TextIconButton, { htmlType: "button", icon: iconCalendar_1.IconCalendar, iconPosition: textIconButton_1.ButtonIconPosition.Start, className: cssClass, type: type, disabled: disabled, onClick: toggleVisibility, ref: triggerRef, children: buttonLabel }), [cssClass, type, disabled, toggleVisibility, buttonLabel]);
259
+ const memoizedAlertData = (0, react_1.useMemo)(() => {
260
+ if (alertReason === "NotAvailable") {
261
+ return {
262
+ header: translate("Date range not available"),
263
+ text: translate("Some of the dates you selected aren’t available. Please try a different range.")
264
+ };
265
+ }
266
+ if (alertReason === "NoSelection") {
267
+ return {
268
+ header: translate("Choose your date range"),
269
+ text: translate("Please select the dates you want to view.")
270
+ };
271
+ }
272
+ return { header: "", text: "" };
273
+ }, [alertReason, translate]);
274
+ return (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [stepper ? (0, jsx_runtime_1.jsxs)("div", { className: (0, classNames_1.classNames)(["zen-date-range-wrapper", driveWrapperTriggerClassName || "", classNameWrapper || ""]), children: [(0, jsx_runtime_1.jsx)("button", { type: "button", onClick: decreaseRange, className: (0, classNames_1.classNames)(["zen-date-range__stepper", "zen-date-range__stepper--left"]), title: translate("Previous"), children: (0, jsx_runtime_1.jsx)(iconChevronLeftSmall_1.IconChevronLeftSmall, { size: isDrive ? "huge" : "large" }) }), popupTriggerComponent, (0, jsx_runtime_1.jsx)("button", { type: "button", onClick: increaseRange, className: (0, classNames_1.classNames)(["zen-date-range__stepper", "zen-date-range__stepper--right"]), title: translate("Next"), children: (0, jsx_runtime_1.jsx)(iconChevronRightSmall_1.IconChevronRightSmall, { size: isDrive ? "huge" : "large" }) })] }) : popupTriggerComponent, isMobile ? memoizedMobileView : memoizedDesktopView, (0, jsx_runtime_1.jsx)(formFieldError_1.FormFieldError, { error: error }), stepper ? (0, jsx_runtime_1.jsx)(alert_1.Alert, { isOpen: alertReason !== "", header: memoizedAlertData.header, text: memoizedAlertData.text, onClose: handleCloseAlert, type: "warning", buttons: {
275
+ primary: {
276
+ text: translate("Choose dates"),
277
+ onClick: handleUnavailableRangeAlert
278
+ }
279
+ } }) : null] });
198
280
  };
199
281
  exports.DateRange = DateRange;
200
282
  exports.TRANSLATIONS = [
@@ -204,5 +286,12 @@ exports.TRANSLATIONS = [
204
286
  "Cancel",
205
287
  "Apply",
206
288
  "Reset",
207
- "Today"
289
+ "Today",
290
+ "Next",
291
+ "Previous",
292
+ "Choose dates",
293
+ "Date range not available",
294
+ "Choose your date range",
295
+ "Some of the dates you selected aren’t available. Please try a different range.",
296
+ "Please select the dates you want to view."
208
297
  ];
@@ -330,7 +330,7 @@ const Dropdown = ({ className, classNamePopup, getData, errorHandler, dataItems,
330
330
  if (currentAllSelected !== undefined && state.defaultValueIsAllSelected !== undefined && state.defaultValueIsAllSelected) {
331
331
  return currentAllSelected === state.defaultValueIsAllSelected;
332
332
  }
333
- return isStringsTheSame;
333
+ return currentAllSelected !== undefined ? state.defaultValueIsAllSelected === currentAllSelected && isStringsTheSame : isStringsTheSame;
334
334
  }, [currentAllSelected, forceSelection, multiselect, state.defaultValue, state.defaultValueIsAllSelected, state.selectedIds]);
335
335
  const memoizedIsApplyButtonDisabled = (0, react_1.useMemo)(() => (0, dropdownHelper_1.compareStringsArrays)(state.globalSelectedIds, state.selectedIds)
336
336
  && (isFullSelectionMode ? state.globalIsAllSelected === state.isAllSelected : true), [isFullSelectionMode, state.globalIsAllSelected, state.globalSelectedIds, state.isAllSelected, state.selectedIds]);
@@ -25,6 +25,7 @@ interface IFiltersBarDateRangePickerBase extends Pick<IButton, "type" | "disable
25
25
  classNamePopup?: string;
26
26
  disableDatesBefore?: string;
27
27
  disableDatesAfter?: string;
28
+ stepper?: boolean;
28
29
  }
29
30
  interface IFiltersBarDateRangePicker extends IFiltersBarDateRangePickerBase {
30
31
  allowUnsetValue?: false;
@@ -87,7 +87,7 @@ const FiltersBarPeriodPicker = ({ props, hasApplyButton, className, useSidePanel
87
87
  const range = (0, react_1.useMemo)(() => ({ from: customDate.from, to: customDate.to }), [customDate.from, customDate.to]);
88
88
  const component = (0, react_1.useMemo)(() => (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(DateRangeInnerMemo, { id: `${id}-daterange`, options: options, onOptionSelect: handleDateRangeSelection, onCalendarSelect: hasCustomOption ? handleCustomDate : undefined, selection: selectedRange === null || selectedRange === void 0 ? void 0 : selectedRange.label, range: range, timeSelect: timeSelect, disableFutureDates: disableFutureDates, disablePastDates: disablePastDates, disableDatesBefore: disableDatesBefore, disableDatesAfter: disableDatesAfter }) }), [id, options, handleDateRangeSelection, hasCustomOption, handleCustomDate, selectedRange === null || selectedRange === void 0 ? void 0 : selectedRange.label, range, timeSelect, disableFutureDates, disablePastDates, disableDatesBefore, disableDatesAfter]);
89
89
  const popup = (0, react_1.useMemo)(() => {
90
- const commonProps = Object.assign(Object.assign({}, props), { hasApplyButton: useSidePanelView ? false : props.hasApplyButton || hasApplyButton, id: id, className: (0, classNames_1.classNames)(["zen-filters-bar-period-picker", useSidePanelView ? "zen-filters-bar-period-picker--full-width" : "", className !== null && className !== void 0 ? className : ""]), classNamePopup: (0, classNames_1.classNames)(["zen-filters-bar-period-picker__popup", useSidePanelView ? "zen-filters-bar-period-picker__popup--full-width" : "", classNamePopup || ""]), options: optionsArg });
90
+ const commonProps = Object.assign(Object.assign({}, props), { hasApplyButton: useSidePanelView ? false : props.hasApplyButton || hasApplyButton, id: id, className: (0, classNames_1.classNames)(["zen-filters-bar-period-picker", useSidePanelView ? "zen-filters-bar-period-picker--full-width" : "", className !== null && className !== void 0 ? className : ""]), classNamePopup: (0, classNames_1.classNames)(["zen-filters-bar-period-picker__popup", useSidePanelView ? "zen-filters-bar-period-picker__popup--full-width" : "", classNamePopup || ""]), classNameWrapper: (0, classNames_1.classNames)([useSidePanelView ? "zen-filters-bar-period-picker-wrapper" : ""]), options: optionsArg });
91
91
  return props.allowUnsetValue ? (0, jsx_runtime_1.jsx)(dateRange_1.DateRange, Object.assign({}, commonProps, { value: state, onChange: onChange, defaultValue: defaultState, allowUnsetValue: true })) : (0, jsx_runtime_1.jsx)(dateRange_1.DateRange, Object.assign({}, commonProps, { value: state, onChange: onChange, defaultValue: defaultState, allowUnsetValue: false }));
92
92
  }, [props, useSidePanelView, id, className, classNamePopup, optionsArg, state, onChange, defaultState, hasApplyButton]);
93
93
  if (!options.length && !hasCustomOption) {
@@ -40,4 +40,32 @@ export declare const getSelectedRangeFromValue: (optionsMap: Map<string, IDateRa
40
40
  from: Date;
41
41
  to: Date;
42
42
  } | undefined;
43
+ export declare const MONTH_STEP_OPTION = "month_step_option";
44
+ export declare const PERIOD_STEP_OPTION = "period_step_option";
45
+ export declare const DEFAULT_STEP_OPTION = "default_step_option";
46
+ export declare const YEAR_STEP_OPTION = "year_step_option";
47
+ export declare const QUARTER_STEP_OPTION = "quarter_step_option";
48
+ export declare const getDateRangeAdjustedStep: (translate: (s: string) => string, label?: string) => "default_step_option" | "month_step_option" | "quarter_step_option" | "year_step_option" | "period_step_option";
49
+ export declare const dateRangeAdjustedFn: {
50
+ month_step_option: (dateRange: IDateRange, increase: boolean, toLocalDateTime: (date: Date | string) => Date, toReverseOffsetDateTime: (d: Date | string) => Date) => {
51
+ from: Date;
52
+ to: Date;
53
+ };
54
+ year_step_option: (dateRange: IDateRange, increase: boolean, _: any, _1: any) => {
55
+ from: Date;
56
+ to: Date;
57
+ };
58
+ quarter_step_option: (dateRange: IDateRange, increase: boolean, toLocalDateTime: (date: Date | string) => Date, toReverseOffsetDateTime: (d: Date | string) => Date) => {
59
+ from: Date;
60
+ to: Date;
61
+ };
62
+ period_step_option: (dateRange: IDateRange, increase: boolean, toLocalDateTime: (date: Date | string) => Date, toReverseOffsetDateTime: (d: Date | string) => Date) => {
63
+ from: Date;
64
+ to: Date;
65
+ };
66
+ default_step_option: (dateRange: IDateRange, increase: boolean, toLocalDateTime: (date: Date | string) => Date, toReverseOffsetDateTime: (d: Date | string) => Date) => {
67
+ from: Date;
68
+ to: Date;
69
+ };
70
+ };
43
71
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSelectedRangeFromValue = exports.getOptionsPeriodMap = exports.getRangeOptionsArray = exports.getRangeOption = void 0;
3
+ exports.dateRangeAdjustedFn = exports.getDateRangeAdjustedStep = exports.QUARTER_STEP_OPTION = exports.YEAR_STEP_OPTION = exports.DEFAULT_STEP_OPTION = exports.PERIOD_STEP_OPTION = exports.MONTH_STEP_OPTION = exports.getSelectedRangeFromValue = exports.getOptionsPeriodMap = exports.getRangeOptionsArray = exports.getRangeOption = void 0;
4
4
  const dateRangeUtils_1 = require("../../../dateRange/dateRangeUtils");
5
5
  const dateRangeInner_1 = require("../../../dateRangeInner/dateRangeInner");
6
6
  const options = {
@@ -113,3 +113,179 @@ const getSelectedRangeFromValue = (optionsMap, value) => {
113
113
  };
114
114
  };
115
115
  exports.getSelectedRangeFromValue = getSelectedRangeFromValue;
116
+ const adjustDateRange = (dateRange, increase, toLocalDateTime, toReverseOffsetDateTime) => {
117
+ const { from, to } = dateRange;
118
+ const interval = to.getTime() - from.getTime();
119
+ let newFrom;
120
+ let newTo;
121
+ const fromToLocalDateTime = toLocalDateTime(from);
122
+ const toToLocalDateTime = toLocalDateTime(to);
123
+ if (!increase) {
124
+ // Decrease logic
125
+ newTo = new Date(fromToLocalDateTime);
126
+ newTo.setDate(fromToLocalDateTime.getDate() - 1);
127
+ newTo.setHours(toToLocalDateTime.getHours());
128
+ newTo.setMinutes(toToLocalDateTime.getMinutes());
129
+ newTo.setSeconds(toToLocalDateTime.getSeconds());
130
+ newTo.setMilliseconds(toToLocalDateTime.getMilliseconds());
131
+ newFrom = new Date(newTo.getTime() - interval);
132
+ }
133
+ else {
134
+ // Increase logic
135
+ newFrom = new Date(toToLocalDateTime);
136
+ newFrom.setDate(toToLocalDateTime.getDate() + 1);
137
+ newFrom.setHours(fromToLocalDateTime.getHours());
138
+ newFrom.setMinutes(fromToLocalDateTime.getMinutes());
139
+ newFrom.setSeconds(fromToLocalDateTime.getSeconds());
140
+ newFrom.setMilliseconds(fromToLocalDateTime.getMilliseconds());
141
+ newTo = new Date(newFrom.getTime() + interval);
142
+ }
143
+ return { from: toReverseOffsetDateTime(newFrom), to: toReverseOffsetDateTime(newTo) };
144
+ };
145
+ const adjustDateRangeMonth = (dateRange, increase, toLocalDateTime, toReverseOffsetDateTime) => {
146
+ const { from, to } = dateRange;
147
+ let newFrom;
148
+ let newTo;
149
+ const fromToLocalDateTime = toLocalDateTime(from);
150
+ const toToLocalDateTime = toLocalDateTime(to);
151
+ const fromMonth = fromToLocalDateTime.getMonth();
152
+ const fromYear = fromToLocalDateTime.getFullYear();
153
+ const toMonth = toToLocalDateTime.getMonth();
154
+ const toYear = toToLocalDateTime.getFullYear();
155
+ // Calculate the number of months in the original range
156
+ const monthsDifference = (toYear - fromYear) * 12 + (toMonth - fromMonth) + 1;
157
+ if (!increase) {
158
+ // Decrease
159
+ let newFromMonth = fromMonth - monthsDifference;
160
+ let newFromYear = fromYear;
161
+ while (newFromMonth < 0) {
162
+ newFromMonth += 12;
163
+ newFromYear--;
164
+ }
165
+ newFrom = new Date(newFromYear, newFromMonth, 1); // First day of the month
166
+ let newToMonth = toMonth - monthsDifference;
167
+ let newToYear = toYear;
168
+ while (newToMonth < 0) {
169
+ newToMonth += 12;
170
+ newToYear--;
171
+ }
172
+ // Get the last day of the month for newTo
173
+ const nextMonth = new Date(newToYear, newToMonth + 1, 1);
174
+ newTo = new Date(nextMonth.getTime() - (24 * 60 * 60 * 1000));
175
+ }
176
+ else {
177
+ // Increase
178
+ let newFromMonth = fromMonth + monthsDifference;
179
+ let newFromYear = fromYear;
180
+ while (newFromMonth >= 12) {
181
+ newFromMonth -= 12;
182
+ newFromYear++;
183
+ }
184
+ newFrom = new Date(newFromYear, newFromMonth, 1); // First day of the month
185
+ let newToMonth = toMonth + monthsDifference;
186
+ let newToYear = toYear;
187
+ while (newToMonth >= 12) {
188
+ newToMonth -= 12;
189
+ newToYear++;
190
+ }
191
+ // Get the last day of the month for newTo
192
+ const nextMonth = new Date(newToYear, newToMonth + 1, 1);
193
+ newTo = new Date(nextMonth.getTime() - (24 * 60 * 60 * 1000));
194
+ }
195
+ // Preserve original time components
196
+ newFrom.setHours(fromToLocalDateTime.getHours());
197
+ newFrom.setMinutes(fromToLocalDateTime.getMinutes());
198
+ newFrom.setSeconds(fromToLocalDateTime.getSeconds());
199
+ newFrom.setMilliseconds(fromToLocalDateTime.getMilliseconds());
200
+ newTo.setHours(toToLocalDateTime.getHours());
201
+ newTo.setMinutes(toToLocalDateTime.getMinutes());
202
+ newTo.setSeconds(toToLocalDateTime.getSeconds());
203
+ newTo.setMilliseconds(toToLocalDateTime.getMilliseconds());
204
+ return { from: toReverseOffsetDateTime(newFrom), to: toReverseOffsetDateTime(newTo) };
205
+ };
206
+ const adjustDateRangeQuarter = (dateRange, increase, toLocalDateTime, toReverseOffsetDateTime) => {
207
+ const { from, to } = dateRange;
208
+ const quarterStartMonth = [0, 3, 6, 9]; // January, April, July, October
209
+ const fromToLocalDateTime = toLocalDateTime(from);
210
+ const toToLocalDateTime = toLocalDateTime(to);
211
+ const fromMonth = fromToLocalDateTime.getMonth();
212
+ const fromYear = fromToLocalDateTime.getFullYear();
213
+ let newFrom;
214
+ let newTo;
215
+ const monthsInQuarter = 3;
216
+ const currentQuarterIndex = quarterStartMonth.findIndex(month => month === fromMonth);
217
+ if (!increase) {
218
+ // Previous Quarter
219
+ const newFromMonth = currentQuarterIndex === 0 ? 9 : quarterStartMonth[currentQuarterIndex - 1];
220
+ const newFromYear = currentQuarterIndex === 0 ? fromYear - 1 : fromYear;
221
+ newFrom = new Date(newFromYear, newFromMonth, fromToLocalDateTime.getDate(), fromToLocalDateTime.getHours(), fromToLocalDateTime.getMinutes(), fromToLocalDateTime.getSeconds(), fromToLocalDateTime.getMilliseconds());
222
+ newTo = new Date(newFromYear, newFromMonth + monthsInQuarter - 1, newFromMonth === 0 || newFromMonth === 9 ? 31 : 30, toToLocalDateTime.getHours(), toToLocalDateTime.getMinutes(), toToLocalDateTime.getSeconds(), toToLocalDateTime.getMilliseconds());
223
+ }
224
+ else {
225
+ // Next Quarter
226
+ const newFromMonth = currentQuarterIndex === 3 ? 0 : quarterStartMonth[currentQuarterIndex + 1];
227
+ const newFromYear = currentQuarterIndex === 3 ? fromYear + 1 : fromYear;
228
+ newFrom = new Date(newFromYear, newFromMonth, fromToLocalDateTime.getDate(), fromToLocalDateTime.getHours(), fromToLocalDateTime.getMinutes(), fromToLocalDateTime.getSeconds(), fromToLocalDateTime.getMilliseconds());
229
+ newTo = new Date(newFromYear, newFromMonth + monthsInQuarter - 1, newFromMonth === 0 || newFromMonth === 9 ? 31 : 30, toToLocalDateTime.getHours(), toToLocalDateTime.getMinutes(), toToLocalDateTime.getSeconds(), toToLocalDateTime.getMilliseconds());
230
+ }
231
+ return { from: toReverseOffsetDateTime(newFrom), to: toReverseOffsetDateTime(newTo) };
232
+ };
233
+ const adjustDateRangeYear = (dateRange, increase, _, _1) => {
234
+ const { from, to } = dateRange;
235
+ let newFrom;
236
+ let newTo;
237
+ const fromYear = from.getFullYear();
238
+ const toYear = to.getFullYear();
239
+ if (!increase) {
240
+ const previousFromYear = fromYear - 1;
241
+ const previousToYear = toYear - 1;
242
+ newFrom = new Date(from);
243
+ newFrom.setFullYear(previousFromYear);
244
+ newTo = new Date(to);
245
+ newTo.setFullYear(previousToYear);
246
+ }
247
+ else {
248
+ const nextFromYear = fromYear + 1;
249
+ const nextToYear = toYear + 1;
250
+ newFrom = new Date(from);
251
+ newFrom.setFullYear(nextFromYear);
252
+ newTo = new Date(to);
253
+ newTo.setFullYear(nextToYear);
254
+ }
255
+ return { from: newFrom, to: newTo };
256
+ };
257
+ exports.MONTH_STEP_OPTION = "month_step_option";
258
+ exports.PERIOD_STEP_OPTION = "period_step_option";
259
+ exports.DEFAULT_STEP_OPTION = "default_step_option";
260
+ exports.YEAR_STEP_OPTION = "year_step_option";
261
+ exports.QUARTER_STEP_OPTION = "quarter_step_option";
262
+ const getDateRangeAdjustedStep = (translate, label) => {
263
+ const monthsAdjusted = ["LastMonth", "ThisMonth", "NextMonth", "LastThreeMonths", translate("This month"), translate("Last month"), translate("Next month"), translate("Last 3 months")];
264
+ const periodAdjusted = ["Today", "Yesterday", "ThisWeek", "NextWeek", "LastWeek", "LastSevenDays", "LastThirtyDays", translate("Today"), translate("Yesterday"), translate("This week"), translate("Next week"), translate("Last week"), translate("Last 7 days"), translate("Last 30 days")];
265
+ const yearAdjusted = ["LastYear", "ThisYear", "LastTwelveMonths", translate("Last 12 months"), translate("Last year"), translate("This year")];
266
+ const quarterAdjusted = ["ThisQuarter", "LastQuarter", translate("This quarter"), translate("Last quarter")];
267
+ if (!label) {
268
+ return exports.DEFAULT_STEP_OPTION;
269
+ }
270
+ if (monthsAdjusted.includes(label)) {
271
+ return exports.MONTH_STEP_OPTION;
272
+ }
273
+ if (quarterAdjusted.includes(label)) {
274
+ return exports.QUARTER_STEP_OPTION;
275
+ }
276
+ if (yearAdjusted.includes(label)) {
277
+ return exports.YEAR_STEP_OPTION;
278
+ }
279
+ if (periodAdjusted.includes(label)) {
280
+ return exports.PERIOD_STEP_OPTION;
281
+ }
282
+ return exports.DEFAULT_STEP_OPTION;
283
+ };
284
+ exports.getDateRangeAdjustedStep = getDateRangeAdjustedStep;
285
+ exports.dateRangeAdjustedFn = {
286
+ [exports.MONTH_STEP_OPTION]: adjustDateRangeMonth,
287
+ [exports.YEAR_STEP_OPTION]: adjustDateRangeYear,
288
+ [exports.QUARTER_STEP_OPTION]: adjustDateRangeQuarter,
289
+ [exports.PERIOD_STEP_OPTION]: adjustDateRange,
290
+ [exports.DEFAULT_STEP_OPTION]: adjustDateRange
291
+ };
@@ -25,6 +25,7 @@ const uiStateActionType_1 = require("./uiStateReducer/uiStateActionType");
25
25
  const classNames_1 = require("../commonHelpers/classNames/classNames");
26
26
  const advancedGroupsFilter_1 = require("../advancedGroupsFilter/advancedGroupsFilter");
27
27
  const useLanguage_1 = require("../utils/localization/useLanguage");
28
+ const groupsFilterAdvancedValue_1 = require("./groupsFilterAdvancedValue");
28
29
  const GroupsFilter = ({ fullSize, className, dataLoader, errorHandler, isWithColor, onChange, initialFilterState, options = {}, listLimit = 500 }) => {
29
30
  const { translate } = (0, useLanguage_1.useLanguage)();
30
31
  const [groupPlaceHolder, setGroupPlaceHolder] = (0, react_1.useState)(options.placeholder || translate("Groups"));
@@ -35,7 +36,7 @@ const GroupsFilter = ({ fullSize, className, dataLoader, errorHandler, isWithCol
35
36
  const triggerRef = (0, react_1.useRef)(null);
36
37
  const menuRef = (0, react_1.useRef)(null);
37
38
  const prevInitialState = (0, react_1.useRef)(initialFilterState);
38
- const blocksMap = [["builtInGroups", "userGroups"], ["advancedGroups", "builtInGroups", "userGroups"], ["builtInGroups", "userGroups"]];
39
+ const blocksMap = (0, react_1.useMemo)(() => [["builtInGroups", "userGroups"], ["advancedGroups", "builtInGroups", "userGroups"], ["builtInGroups", "userGroups"]], []);
39
40
  const onOptionsToggle = () => { dispatchUiState({ type: uiStateActionType_1.UiStateActionType.ToggleOpen, payload: undefined }); };
40
41
  const handleSetStep = (0, react_1.useCallback)((newStep) => {
41
42
  uiState.step !== groupsFilterInterfaces_1.FilterMenuStep.CurrentlySelected && dispatchUiState({ type: uiStateActionType_1.UiStateActionType.ClearUncheckedState, payload: undefined });
@@ -146,9 +147,29 @@ const GroupsFilter = ({ fullSize, className, dataLoader, errorHandler, isWithCol
146
147
  });
147
148
  }, [dataLoader, errorHandler]);
148
149
  (0, react_1.useEffect)(() => {
150
+ const step = uiState.step;
151
+ if (step !== groupsFilterInterfaces_1.FilterMenuStep.CurrentlySelected) {
152
+ return;
153
+ }
154
+ const groupsBlocks = (0, groupsFilterAdvancedValue_1.getAdvancedFilterValue)({
155
+ blocks: blocksMap[uiState.step],
156
+ state,
157
+ isWithColor: isWithColor || false,
158
+ uncheckedItems: uiState.step === groupsFilterInterfaces_1.FilterMenuStep.CurrentlySelected ? uiState.uncheckedAdjustmentIds : [],
159
+ uncheckedAdvancedState: uiState.step === groupsFilterInterfaces_1.FilterMenuStep.CurrentlySelected ? uiState.uncheckedAdvancedState : undefined,
160
+ listLimit
161
+ });
162
+ const label = (0, groupsFilterAdvancedValue_1.getAdvancedLabel)({ groupsBlocks });
149
163
  const selectedValues = dataItems.filter((item) => { var _a; return (_a = state.frozenState.simpleFilterState) === null || _a === void 0 ? void 0 : _a.find((id) => id === item.id); }).map((item) => item.name);
150
- setGroupPlaceHolder(selectedValues.length > 0 ? selectedValues.join(", ") : options.placeholder || translate("Groups"));
151
- }, [dataItems, state.frozenState.simpleFilterState, translate, options.placeholder]);
164
+ const selectedValuesLabel = selectedValues.join(` ${translate(state.frozenState.relation)} `);
165
+ if (!label && !selectedValuesLabel) {
166
+ setGroupPlaceHolder(options.placeholder || translate("Groups"));
167
+ return;
168
+ }
169
+ const separator = `${label && selectedValuesLabel ? ` ${translate(state.frozenState.relation)} ` : ""}`;
170
+ setGroupPlaceHolder(`${label}${separator}${selectedValuesLabel}`);
171
+ }, [uiState.searchValue, uiState.step, blocksMap, state, isWithColor, listLimit, uiState.currentAdjustmentId,
172
+ uiState.uncheckedAdjustmentIds, uiState.uncheckedAdvancedState, dataItems, options.placeholder, translate]);
152
173
  const getGroupsBox = () => (0, jsx_runtime_1.jsx)(groupsFilterBox_1.GroupsFilterBox, { step: uiState.step, currentId: uiState.currentAdjustmentId, isWithColor: isWithColor || false, state: state, search: uiState.searchValue, blocks: uiState.searchValue && uiState.step === groupsFilterInterfaces_1.FilterMenuStep.Initial ? [] : blocksMap[uiState.step], onChange: uiState.step === groupsFilterInterfaces_1.FilterMenuStep.CurrentlySelected ? handleCheckboxItemAdjustmentClick : handleCheckboxChange, onClick: handleCheckboxItemClick, uncheckedItems: uiState.step === groupsFilterInterfaces_1.FilterMenuStep.CurrentlySelected ? uiState.uncheckedAdjustmentIds : [], uncheckedAdvancedState: uiState.step === groupsFilterInterfaces_1.FilterMenuStep.CurrentlySelected ? uiState.uncheckedAdvancedState : undefined, listLimit: listLimit });
153
174
  const onSideWideChange = (newState) => { dispatchState({ type: stateActionType_1.StateActionType.SideWide, payload: newState }); };
154
175
  const onRelationChange = (newRelation) => { dispatchState({ type: stateActionType_1.StateActionType.Relation, payload: newRelation }); };
@@ -0,0 +1,16 @@
1
+ import { ICheckboxListWithActionOption } from "./groupsFilterBox";
2
+ import { IFilterState } from "./groupsFilterInterfaces";
3
+ import { TValueOptions, TValueOptionsSelected } from "./groupsFilterStatesHelper";
4
+ import { IGroupsFilterState } from "./stateReducer/stateReducer";
5
+ export declare const getAdvancedFilterValue: ({ blocks, state, isWithColor, uncheckedItems, uncheckedAdvancedState, listLimit }: {
6
+ blocks: TValueOptions[] | TValueOptionsSelected[];
7
+ state: IGroupsFilterState;
8
+ isWithColor: boolean;
9
+ uncheckedItems: string[];
10
+ uncheckedAdvancedState?: IFilterState;
11
+ listLimit: number;
12
+ }) => ICheckboxListWithActionOption[][];
13
+ export interface IGetAdvancedLabelInput {
14
+ groupsBlocks: ICheckboxListWithActionOption[][];
15
+ }
16
+ export declare const getAdvancedLabel: ({ groupsBlocks }: IGetAdvancedLabelInput) => string;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAdvancedLabel = exports.getAdvancedFilterValue = void 0;
4
+ const groupsFilterStatesHelper_1 = require("./groupsFilterStatesHelper");
5
+ const getAdvancedFilterValue = ({ blocks, state, isWithColor, uncheckedItems, uncheckedAdvancedState, listLimit }) => {
6
+ const getGroupsMenuValue = (limit, value) => {
7
+ if (!value || value !== "advancedGroups") {
8
+ return [];
9
+ }
10
+ const result = (0, groupsFilterStatesHelper_1.createCurrentlySelectedOptions)(state, value, isWithColor || false, uncheckedItems, limit, uncheckedAdvancedState);
11
+ return result;
12
+ };
13
+ const groupsBlocks = blocks.map((val) => getGroupsMenuValue(listLimit, val)).filter((el) => el.length);
14
+ return groupsBlocks;
15
+ };
16
+ exports.getAdvancedFilterValue = getAdvancedFilterValue;
17
+ const getAdvancedLabel = ({ groupsBlocks }) => {
18
+ const combinedLabel = groupsBlocks.reduce((outerAccumulator, group) => {
19
+ const groupLabel = group.reduce((innerAccumulator, item) => {
20
+ if (item.label) {
21
+ const updatedAccumulator = innerAccumulator + item.label;
22
+ return updatedAccumulator;
23
+ }
24
+ return innerAccumulator;
25
+ }, "");
26
+ if (!groupLabel) {
27
+ return outerAccumulator;
28
+ }
29
+ const updatedAccumulator = outerAccumulator + groupLabel;
30
+ return updatedAccumulator;
31
+ }, "");
32
+ return combinedLabel;
33
+ };
34
+ exports.getAdvancedLabel = getAdvancedLabel;