@datarobot/design-system 29.7.6 → 29.7.8

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 (35) hide show
  1. package/cjs/multiselect-searchable-list/multiselect-searchable-list.js +7 -1
  2. package/cjs/multiselect-searchable-list/selected-items-board.js +12 -1
  3. package/cjs/scheduler/index.d.ts +2 -2
  4. package/cjs/scheduler/index.js +6 -0
  5. package/cjs/scheduler/utils.d.ts +4 -0
  6. package/cjs/scheduler/utils.js +89 -0
  7. package/cjs/scheduler/utils.test.js +149 -0
  8. package/cjs/zoom-controls/zoom-controls.js +3 -3
  9. package/esm/multiselect-searchable-list/multiselect-searchable-list.js +7 -1
  10. package/esm/multiselect-searchable-list/selected-items-board.js +12 -1
  11. package/esm/scheduler/index.d.ts +2 -2
  12. package/esm/scheduler/index.js +2 -2
  13. package/esm/scheduler/utils.d.ts +4 -0
  14. package/esm/scheduler/utils.js +89 -1
  15. package/esm/scheduler/utils.test.js +147 -0
  16. package/esm/zoom-controls/zoom-controls.js +3 -3
  17. package/js/139/139.min.js +1 -1
  18. package/js/244/244.min.js +1 -1
  19. package/js/633/633.min.js +1 -1
  20. package/js/784/784.min.js +1 -1
  21. package/js/86/86.min.js +1 -1
  22. package/js/bundle/bundle.js +132 -19
  23. package/js/bundle/bundle.min.js +1 -1
  24. package/js/bundle/index.d.ts +5 -1
  25. package/js/src_locales_es_419_translation_json/src_locales_es_419_translation_json.js +1 -1
  26. package/js/src_locales_fr_translation_json/src_locales_fr_translation_json.js +1 -1
  27. package/js/src_locales_ja_translation_json/src_locales_ja_translation_json.js +1 -1
  28. package/js/src_locales_ko_translation_json/src_locales_ko_translation_json.js +1 -1
  29. package/js/src_locales_pt_BR_translation_json/src_locales_pt_BR_translation_json.js +1 -1
  30. package/locales/es_419/translation.json +3 -3
  31. package/locales/fr/translation.json +3 -3
  32. package/locales/ja/translation.json +3 -3
  33. package/locales/ko/translation.json +3 -3
  34. package/locales/pt_BR/translation.json +3 -3
  35. package/package.json +1 -1
@@ -34,6 +34,12 @@ const MultiselectSearchableList = ({
34
34
  const {
35
35
  t
36
36
  } = (0, _useTranslation.useTranslation)();
37
+ const getSelectedItemsMessageDefault = itemsLength => itemsLength === 1 ? t('{{itemsLength}} item selected', {
38
+ itemsLength
39
+ }) : t('{{itemsLength}} items selected', {
40
+ itemsLength
41
+ });
42
+ const selectedItemsMessageFn = selectedItemsMessage || getSelectedItemsMessageDefault;
37
43
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
38
44
  className: "multiselect-items-list",
39
45
  "test-id": "multiselect-items-list",
@@ -49,7 +55,7 @@ const MultiselectSearchableList = ({
49
55
  listKey: ({
50
56
  id
51
57
  }) => id,
52
- header: selectedItemsMessage(selectedItems.length),
58
+ header: selectedItemsMessageFn(selectedItems.length),
53
59
  onItemRemove: onSelectToggle,
54
60
  onClearAll: onClearAll,
55
61
  clearAllText: clearAllText ?? t('Clear all'),
@@ -8,6 +8,7 @@ var _react = _interopRequireWildcard(require("react"));
8
8
  var _faChevronDown = require("@fortawesome/free-solid-svg-icons/faChevronDown");
9
9
  var _faChevronUp = require("@fortawesome/free-solid-svg-icons/faChevronUp");
10
10
  var _faCircleXmark = require("@fortawesome/free-solid-svg-icons/faCircleXmark");
11
+ var _useTranslation = require("../hooks/use-translation");
11
12
  var _fontAwesomeIcon = require("../font-awesome-icon");
12
13
  var _button = require("../button");
13
14
  var _jsxRuntime = require("react/jsx-runtime");
@@ -23,9 +24,18 @@ function SelectedItemsBoard({
23
24
  clearAllText,
24
25
  removeText
25
26
  }) {
27
+ const {
28
+ t
29
+ } = (0, _useTranslation.useTranslation)();
26
30
  const [isExpanded, toggleExpanded] = (0, _react.useState)(true);
31
+ const getSelectedItemsMessageDefault = itemsLength => itemsLength === 1 ? t('{{itemsLength}} item selected', {
32
+ itemsLength
33
+ }) : t('{{itemsLength}} items selected', {
34
+ itemsLength
35
+ });
36
+
27
37
  // not in default props because it depends on items length
28
- const headerContent = header || getDefaultHeaderText?.(items.length);
38
+ const headerContent = header || getDefaultHeaderText?.(items.length) || getSelectedItemsMessageDefault(items.length);
29
39
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
30
40
  className: "selected-items-board",
31
41
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("header", {
@@ -47,6 +57,7 @@ function SelectedItemsBoard({
47
57
  "test-id": "selected-items-board-item-label",
48
58
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
49
59
  className: "item-display-label",
60
+ "test-id": item?.testId,
50
61
  children: displayLabel(item, index)
51
62
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.Button, {
52
63
  testId: "selected-items-board-remove-item-btn",
@@ -1,6 +1,6 @@
1
1
  import { Scheduler } from './scheduler';
2
2
  import { DEFAULT_SCHEDULE, FREQUENCIES, DEFAULT_SCHEDULES, SWITCHER_TYPES, TAB_KEYS } from './constants';
3
- import { getFrequency } from './utils';
3
+ import { getFrequency, useGetScheduleString } from './utils';
4
4
  export type { ScheduleValidity, Schedule, DateItem, Months, LabelTexts, Frequency, } from './constants';
5
5
  export type { SchedulerProps } from './scheduler';
6
- export { Scheduler, getFrequency, DEFAULT_SCHEDULE, FREQUENCIES, DEFAULT_SCHEDULES, SWITCHER_TYPES, TAB_KEYS, };
6
+ export { Scheduler, getFrequency, useGetScheduleString, DEFAULT_SCHEDULE, FREQUENCIES, DEFAULT_SCHEDULES, SWITCHER_TYPES, TAB_KEYS, };
@@ -45,6 +45,12 @@ Object.defineProperty(exports, "getFrequency", {
45
45
  return _utils.getFrequency;
46
46
  }
47
47
  });
48
+ Object.defineProperty(exports, "useGetScheduleString", {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _utils.useGetScheduleString;
52
+ }
53
+ });
48
54
  var _scheduler = require("./scheduler");
49
55
  var _constants = require("./constants");
50
56
  var _utils = require("./utils");
@@ -1,4 +1,8 @@
1
1
  import { Frequency, Schedule, ScheduleValidity } from './constants';
2
2
  export declare const stringToArrayOfNumbersOrAll: (value?: string | number) => (number | "*")[];
3
3
  export declare function useArrayOfRangedNumbersOrAllValidator(): ({ min, max, values, allowAll, }: ScheduleValidity) => ScheduleValidity | undefined;
4
+ export declare function useGetScheduleString(): (schedule: Schedule, stringOptions?: {
5
+ complexScheduleString?: string | null;
6
+ timeStandardString?: string | null;
7
+ }) => string | null;
4
8
  export declare function getFrequency({ minute, hour, month, dayOfMonth, dayOfWeek, }: Schedule): Frequency | undefined;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.getFrequency = getFrequency;
7
7
  exports.stringToArrayOfNumbersOrAll = void 0;
8
8
  exports.useArrayOfRangedNumbersOrAllValidator = useArrayOfRangedNumbersOrAllValidator;
9
+ exports.useGetScheduleString = useGetScheduleString;
9
10
  var _message = require("../message");
10
11
  var _useTranslation = require("../hooks/use-translation");
11
12
  var _constants = require("./constants");
@@ -62,6 +63,94 @@ function useArrayOfRangedNumbersOrAllValidator() {
62
63
  return validity;
63
64
  };
64
65
  }
66
+ function useGetScheduleString() {
67
+ const {
68
+ t
69
+ } = (0, _useTranslation.useTranslation)();
70
+ const months = (0, _constants.useMonths)();
71
+ const daysOfWeek = (0, _constants.useDaysOfWeek)();
72
+ return (schedule, stringOptions = {}) => {
73
+ const {
74
+ complexScheduleString = t('Complex schedule'),
75
+ timeStandardString = t('(UTC)')
76
+ } = stringOptions;
77
+ const scheduleStringTimeStandard = timeStandardString ? ` ${timeStandardString}` : '';
78
+ switch (getFrequency(schedule)) {
79
+ case _constants.FREQUENCIES.HOURLY:
80
+ return schedule?.minute?.[0] === 1 ? t('Hourly at {{minutes}} minute past the hour', {
81
+ minutes: schedule.minute[0].toString()
82
+ }) : t('Hourly at {{minutes}} minutes past the hour', {
83
+ minutes: schedule?.minute?.[0].toString()
84
+ });
85
+ case _constants.FREQUENCIES.DAILY:
86
+ return `${t('Daily at {{hour}}:{{minutes}}', {
87
+ hour: schedule?.hour?.[0].toString().padStart(2, '0'),
88
+ minutes: schedule?.minute?.[0].toString().padStart(2, '0')
89
+ })}${scheduleStringTimeStandard}`;
90
+ case _constants.FREQUENCIES.WEEKLY:
91
+ {
92
+ const options = {
93
+ hour: schedule?.hour?.[0].toString().padStart(2, '0'),
94
+ minutes: schedule?.minute?.[0].toString().padStart(2, '0'),
95
+ day: daysOfWeek.find(d => d.index === schedule?.dayOfWeek?.[0])?.label
96
+ };
97
+ const weeklyString = schedule?.dayOfWeek?.length === 1 ? t('Weekly on {{day}} at {{hour}}:{{minutes}}', {
98
+ ...options
99
+ }) : t('Weekly on multiple days at {{hour}}:{{minutes}}', {
100
+ ...options
101
+ });
102
+ return `${weeklyString}${scheduleStringTimeStandard}`;
103
+ }
104
+ case _constants.FREQUENCIES.MONTHLY:
105
+ {
106
+ const options = {
107
+ hour: schedule?.hour?.[0].toString().padStart(2, '0'),
108
+ minutes: schedule?.minute?.[0].toString().padStart(2, '0'),
109
+ day: schedule?.dayOfMonth?.[0],
110
+ days: schedule?.dayOfMonth?.join(', ') // day 1, 2, 3
111
+ };
112
+ const monthlyString = schedule?.dayOfMonth?.length === 1 ? t('Monthly on day {{day}} at {{hour}}:{{minutes}}', {
113
+ ...options
114
+ }) : t('Monthly on days {{days}} at {{hour}}:{{minutes}}', {
115
+ ...options
116
+ });
117
+ return `${monthlyString}${scheduleStringTimeStandard}`;
118
+ }
119
+ case _constants.FREQUENCIES.QUARTERLY:
120
+ {
121
+ const options = {
122
+ hour: schedule?.hour?.[0].toString().padStart(2, '0'),
123
+ minutes: schedule?.minute?.[0].toString().padStart(2, '0'),
124
+ day: schedule?.dayOfMonth?.[0],
125
+ days: schedule?.dayOfMonth?.join(', ') // day 1, 2, 3
126
+ };
127
+ const quarterlyString = schedule?.dayOfMonth?.length === 1 ? t('Quarterly on day {{day}} at {{hour}}:{{minutes}}', {
128
+ ...options
129
+ }) : t('Quarterly on days {{days}} at {{hour}}:{{minutes}}', {
130
+ ...options
131
+ });
132
+ return `${quarterlyString}${scheduleStringTimeStandard}`;
133
+ }
134
+ case _constants.FREQUENCIES.YEARLY:
135
+ {
136
+ const options = {
137
+ hour: schedule?.hour?.[0].toString().padStart(2, '0'),
138
+ minutes: schedule?.minute?.[0].toString().padStart(2, '0'),
139
+ day: schedule?.dayOfMonth?.[0],
140
+ month: Object.values(months).find(m => m.index === schedule?.month?.[0])?.label
141
+ };
142
+ const yearlyString = Math.max(schedule?.month?.length ?? 0, schedule?.dayOfMonth?.length ?? 0) ? t('Yearly on {{month}} {{day}} at {{hour}}:{{minutes}}', {
143
+ ...options
144
+ }) : t('Yearly on multiple dates at {{hour}}:{{minutes}}', {
145
+ ...options
146
+ });
147
+ return `${yearlyString}${scheduleStringTimeStandard}`;
148
+ }
149
+ default:
150
+ return complexScheduleString;
151
+ }
152
+ };
153
+ }
65
154
  function hasSameItems(arr1, arr2) {
66
155
  return arr1.length === arr2?.length && arr1.every(item1 => {
67
156
  return arr2.find(item2 => item2 === item1);
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+
3
+ var _react = require("@testing-library/react");
4
+ var _utils = require("./utils");
5
+ describe('useGetScheduleString', function () {
6
+ describe('Schedule strings', function () {
7
+ const createSchedule = (partialSchedule = {}) => ({
8
+ minute: ['*'],
9
+ hour: ['*'],
10
+ dayOfMonth: ['*'],
11
+ month: ['*'],
12
+ dayOfWeek: ['*'],
13
+ ...partialSchedule
14
+ });
15
+ const testSchedules = [{
16
+ schedule: createSchedule({
17
+ minute: [15, 45],
18
+ month: [1, 4, 8, 12]
19
+ }),
20
+ expectedScheduleString: 'Complex schedule',
21
+ hasTimeStandard: false
22
+ }, {
23
+ schedule: createSchedule({
24
+ minute: [1]
25
+ }),
26
+ expectedScheduleString: 'Hourly at 1 minute past the hour',
27
+ hasTimeStandard: false
28
+ }, {
29
+ schedule: createSchedule({
30
+ minute: [5]
31
+ }),
32
+ expectedScheduleString: 'Hourly at 5 minutes past the hour',
33
+ hasTimeStandard: false
34
+ }, {
35
+ schedule: createSchedule({
36
+ hour: [12],
37
+ minute: [30]
38
+ }),
39
+ expectedScheduleString: 'Daily at 12:30',
40
+ hasTimeStandard: true
41
+ }, {
42
+ schedule: createSchedule({
43
+ dayOfWeek: [1],
44
+ hour: [12],
45
+ minute: [30]
46
+ }),
47
+ expectedScheduleString: 'Weekly on Monday at 12:30',
48
+ hasTimeStandard: true
49
+ }, {
50
+ schedule: createSchedule({
51
+ dayOfWeek: [1, 2],
52
+ hour: [12],
53
+ minute: [30]
54
+ }),
55
+ expectedScheduleString: 'Weekly on multiple days at 12:30',
56
+ hasTimeStandard: true
57
+ }, {
58
+ schedule: createSchedule({
59
+ dayOfMonth: [1],
60
+ hour: [6],
61
+ minute: [45]
62
+ }),
63
+ expectedScheduleString: 'Monthly on day 1 at 06:45',
64
+ hasTimeStandard: true
65
+ }, {
66
+ schedule: createSchedule({
67
+ dayOfMonth: [1, 2],
68
+ hour: [6],
69
+ minute: [45]
70
+ }),
71
+ expectedScheduleString: 'Monthly on days 1, 2 at 06:45',
72
+ hasTimeStandard: true
73
+ }, {
74
+ schedule: createSchedule({
75
+ month: [1, 4, 7, 10],
76
+ dayOfMonth: [1],
77
+ hour: [1],
78
+ minute: [30]
79
+ }),
80
+ expectedScheduleString: 'Quarterly on day 1 at 01:30',
81
+ hasTimeStandard: true
82
+ }, {
83
+ schedule: createSchedule({
84
+ month: [1, 4, 7, 10],
85
+ dayOfMonth: [1, 15],
86
+ hour: [1],
87
+ minute: [30]
88
+ }),
89
+ expectedScheduleString: 'Quarterly on days 1, 15 at 01:30',
90
+ hasTimeStandard: true
91
+ }, {
92
+ schedule: createSchedule({
93
+ dayOfMonth: [1],
94
+ month: [6],
95
+ hour: [17],
96
+ minute: [0]
97
+ }),
98
+ expectedScheduleString: 'Yearly on June 1 at 17:00',
99
+ hasTimeStandard: true
100
+ }];
101
+ describe('Default time standard (UTC)', function () {
102
+ testSchedules.forEach(function ({
103
+ schedule,
104
+ expectedScheduleString,
105
+ hasTimeStandard
106
+ }) {
107
+ const expectedString = `${expectedScheduleString}${hasTimeStandard ? ' (UTC)' : ''}`;
108
+ it(`should generate "${expectedString}"`, function () {
109
+ const {
110
+ result
111
+ } = (0, _react.renderHook)(() => (0, _utils.useGetScheduleString)()(schedule));
112
+ expect(result.current).toBe(`${expectedString}`);
113
+ });
114
+ });
115
+ });
116
+ describe('Alternate time standard (EST)', function () {
117
+ testSchedules.forEach(function ({
118
+ schedule,
119
+ expectedScheduleString,
120
+ hasTimeStandard
121
+ }) {
122
+ const expectedString = `${expectedScheduleString}${hasTimeStandard ? ' (EST)' : ''}`;
123
+ it(`should generate "${expectedString}"`, function () {
124
+ const {
125
+ result
126
+ } = (0, _react.renderHook)(() => (0, _utils.useGetScheduleString)()(schedule, {
127
+ timeStandardString: '(EST)'
128
+ }));
129
+ expect(result.current).toBe(`${expectedString}`);
130
+ });
131
+ });
132
+ });
133
+ describe('No time standard (locale time)', function () {
134
+ testSchedules.forEach(function ({
135
+ schedule,
136
+ expectedScheduleString
137
+ }) {
138
+ it(`should generate "${expectedScheduleString}"`, function () {
139
+ const {
140
+ result
141
+ } = (0, _react.renderHook)(() => (0, _utils.useGetScheduleString)()(schedule, {
142
+ timeStandardString: null
143
+ }));
144
+ expect(result.current).toBe(expectedScheduleString);
145
+ });
146
+ });
147
+ });
148
+ });
149
+ });
@@ -39,9 +39,9 @@ function ZoomControls({
39
39
  const {
40
40
  t
41
41
  } = (0, _useTranslation.useTranslation)();
42
- const zoomInTextWithDefault = zoomInText ?? t('Zoom In');
43
- const zoomOutTextWithDefault = zoomOutText ?? t('Zoom Out');
44
- const resetTextWithDefault = resetText ?? t('Reset Zoom');
42
+ const zoomInTextWithDefault = zoomInText ?? t('Zoom in');
43
+ const zoomOutTextWithDefault = zoomOutText ?? t('Zoom out');
44
+ const resetTextWithDefault = resetText ?? t('Reset zoom');
45
45
  if (hidden) {
46
46
  return null;
47
47
  }
@@ -27,6 +27,12 @@ const MultiselectSearchableList = ({
27
27
  const {
28
28
  t
29
29
  } = useTranslation();
30
+ const getSelectedItemsMessageDefault = itemsLength => itemsLength === 1 ? t('{{itemsLength}} item selected', {
31
+ itemsLength
32
+ }) : t('{{itemsLength}} items selected', {
33
+ itemsLength
34
+ });
35
+ const selectedItemsMessageFn = selectedItemsMessage || getSelectedItemsMessageDefault;
30
36
  return /*#__PURE__*/_jsx("div", {
31
37
  className: "multiselect-items-list",
32
38
  "test-id": "multiselect-items-list",
@@ -42,7 +48,7 @@ const MultiselectSearchableList = ({
42
48
  listKey: ({
43
49
  id
44
50
  }) => id,
45
- header: selectedItemsMessage(selectedItems.length),
51
+ header: selectedItemsMessageFn(selectedItems.length),
46
52
  onItemRemove: onSelectToggle,
47
53
  onClearAll: onClearAll,
48
54
  clearAllText: clearAllText ?? t('Clear all'),
@@ -2,6 +2,7 @@ import React, { useState } from 'react';
2
2
  import { faChevronDown } from '@fortawesome/free-solid-svg-icons/faChevronDown';
3
3
  import { faChevronUp } from '@fortawesome/free-solid-svg-icons/faChevronUp';
4
4
  import { faCircleXmark } from '@fortawesome/free-solid-svg-icons/faCircleXmark';
5
+ import { useTranslation } from '../hooks/use-translation';
5
6
  import { FontAwesomeIcon } from '../font-awesome-icon';
6
7
  import { Button, ACCENT_TYPES } from '../button';
7
8
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
@@ -16,9 +17,18 @@ export default function SelectedItemsBoard({
16
17
  clearAllText,
17
18
  removeText
18
19
  }) {
20
+ const {
21
+ t
22
+ } = useTranslation();
19
23
  const [isExpanded, toggleExpanded] = useState(true);
24
+ const getSelectedItemsMessageDefault = itemsLength => itemsLength === 1 ? t('{{itemsLength}} item selected', {
25
+ itemsLength
26
+ }) : t('{{itemsLength}} items selected', {
27
+ itemsLength
28
+ });
29
+
20
30
  // not in default props because it depends on items length
21
- const headerContent = header || getDefaultHeaderText?.(items.length);
31
+ const headerContent = header || getDefaultHeaderText?.(items.length) || getSelectedItemsMessageDefault(items.length);
22
32
  return /*#__PURE__*/_jsxs("div", {
23
33
  className: "selected-items-board",
24
34
  children: [/*#__PURE__*/_jsx("header", {
@@ -40,6 +50,7 @@ export default function SelectedItemsBoard({
40
50
  "test-id": "selected-items-board-item-label",
41
51
  children: [/*#__PURE__*/_jsx("div", {
42
52
  className: "item-display-label",
53
+ "test-id": item?.testId,
43
54
  children: displayLabel(item, index)
44
55
  }), /*#__PURE__*/_jsx(Button, {
45
56
  testId: "selected-items-board-remove-item-btn",
@@ -1,6 +1,6 @@
1
1
  import { Scheduler } from './scheduler';
2
2
  import { DEFAULT_SCHEDULE, FREQUENCIES, DEFAULT_SCHEDULES, SWITCHER_TYPES, TAB_KEYS } from './constants';
3
- import { getFrequency } from './utils';
3
+ import { getFrequency, useGetScheduleString } from './utils';
4
4
  export type { ScheduleValidity, Schedule, DateItem, Months, LabelTexts, Frequency, } from './constants';
5
5
  export type { SchedulerProps } from './scheduler';
6
- export { Scheduler, getFrequency, DEFAULT_SCHEDULE, FREQUENCIES, DEFAULT_SCHEDULES, SWITCHER_TYPES, TAB_KEYS, };
6
+ export { Scheduler, getFrequency, useGetScheduleString, DEFAULT_SCHEDULE, FREQUENCIES, DEFAULT_SCHEDULES, SWITCHER_TYPES, TAB_KEYS, };
@@ -1,4 +1,4 @@
1
1
  import { Scheduler } from './scheduler';
2
2
  import { DEFAULT_SCHEDULE, FREQUENCIES, DEFAULT_SCHEDULES, SWITCHER_TYPES, TAB_KEYS } from './constants';
3
- import { getFrequency } from './utils';
4
- export { Scheduler, getFrequency, DEFAULT_SCHEDULE, FREQUENCIES, DEFAULT_SCHEDULES, SWITCHER_TYPES, TAB_KEYS };
3
+ import { getFrequency, useGetScheduleString } from './utils';
4
+ export { Scheduler, getFrequency, useGetScheduleString, DEFAULT_SCHEDULE, FREQUENCIES, DEFAULT_SCHEDULES, SWITCHER_TYPES, TAB_KEYS };
@@ -1,4 +1,8 @@
1
1
  import { Frequency, Schedule, ScheduleValidity } from './constants';
2
2
  export declare const stringToArrayOfNumbersOrAll: (value?: string | number) => (number | "*")[];
3
3
  export declare function useArrayOfRangedNumbersOrAllValidator(): ({ min, max, values, allowAll, }: ScheduleValidity) => ScheduleValidity | undefined;
4
+ export declare function useGetScheduleString(): (schedule: Schedule, stringOptions?: {
5
+ complexScheduleString?: string | null;
6
+ timeStandardString?: string | null;
7
+ }) => string | null;
4
8
  export declare function getFrequency({ minute, hour, month, dayOfMonth, dayOfWeek, }: Schedule): Frequency | undefined;
@@ -1,6 +1,6 @@
1
1
  import { MESSAGE_TYPES } from '../message';
2
2
  import { useTranslation } from '../hooks/use-translation';
3
- import { FREQUENCIES } from './constants';
3
+ import { FREQUENCIES, useDaysOfWeek, useMonths } from './constants';
4
4
  export const stringToArrayOfNumbersOrAll = value => String(value)?.split(',').filter(item => item === '*' || !Number.isNaN(parseInt(item))).map(item => item === '*' ? item : Number(item));
5
5
  export function useArrayOfRangedNumbersOrAllValidator() {
6
6
  const {
@@ -53,6 +53,94 @@ export function useArrayOfRangedNumbersOrAllValidator() {
53
53
  return validity;
54
54
  };
55
55
  }
56
+ export function useGetScheduleString() {
57
+ const {
58
+ t
59
+ } = useTranslation();
60
+ const months = useMonths();
61
+ const daysOfWeek = useDaysOfWeek();
62
+ return (schedule, stringOptions = {}) => {
63
+ const {
64
+ complexScheduleString = t('Complex schedule'),
65
+ timeStandardString = t('(UTC)')
66
+ } = stringOptions;
67
+ const scheduleStringTimeStandard = timeStandardString ? ` ${timeStandardString}` : '';
68
+ switch (getFrequency(schedule)) {
69
+ case FREQUENCIES.HOURLY:
70
+ return schedule?.minute?.[0] === 1 ? t('Hourly at {{minutes}} minute past the hour', {
71
+ minutes: schedule.minute[0].toString()
72
+ }) : t('Hourly at {{minutes}} minutes past the hour', {
73
+ minutes: schedule?.minute?.[0].toString()
74
+ });
75
+ case FREQUENCIES.DAILY:
76
+ return `${t('Daily at {{hour}}:{{minutes}}', {
77
+ hour: schedule?.hour?.[0].toString().padStart(2, '0'),
78
+ minutes: schedule?.minute?.[0].toString().padStart(2, '0')
79
+ })}${scheduleStringTimeStandard}`;
80
+ case FREQUENCIES.WEEKLY:
81
+ {
82
+ const options = {
83
+ hour: schedule?.hour?.[0].toString().padStart(2, '0'),
84
+ minutes: schedule?.minute?.[0].toString().padStart(2, '0'),
85
+ day: daysOfWeek.find(d => d.index === schedule?.dayOfWeek?.[0])?.label
86
+ };
87
+ const weeklyString = schedule?.dayOfWeek?.length === 1 ? t('Weekly on {{day}} at {{hour}}:{{minutes}}', {
88
+ ...options
89
+ }) : t('Weekly on multiple days at {{hour}}:{{minutes}}', {
90
+ ...options
91
+ });
92
+ return `${weeklyString}${scheduleStringTimeStandard}`;
93
+ }
94
+ case FREQUENCIES.MONTHLY:
95
+ {
96
+ const options = {
97
+ hour: schedule?.hour?.[0].toString().padStart(2, '0'),
98
+ minutes: schedule?.minute?.[0].toString().padStart(2, '0'),
99
+ day: schedule?.dayOfMonth?.[0],
100
+ days: schedule?.dayOfMonth?.join(', ') // day 1, 2, 3
101
+ };
102
+ const monthlyString = schedule?.dayOfMonth?.length === 1 ? t('Monthly on day {{day}} at {{hour}}:{{minutes}}', {
103
+ ...options
104
+ }) : t('Monthly on days {{days}} at {{hour}}:{{minutes}}', {
105
+ ...options
106
+ });
107
+ return `${monthlyString}${scheduleStringTimeStandard}`;
108
+ }
109
+ case FREQUENCIES.QUARTERLY:
110
+ {
111
+ const options = {
112
+ hour: schedule?.hour?.[0].toString().padStart(2, '0'),
113
+ minutes: schedule?.minute?.[0].toString().padStart(2, '0'),
114
+ day: schedule?.dayOfMonth?.[0],
115
+ days: schedule?.dayOfMonth?.join(', ') // day 1, 2, 3
116
+ };
117
+ const quarterlyString = schedule?.dayOfMonth?.length === 1 ? t('Quarterly on day {{day}} at {{hour}}:{{minutes}}', {
118
+ ...options
119
+ }) : t('Quarterly on days {{days}} at {{hour}}:{{minutes}}', {
120
+ ...options
121
+ });
122
+ return `${quarterlyString}${scheduleStringTimeStandard}`;
123
+ }
124
+ case FREQUENCIES.YEARLY:
125
+ {
126
+ const options = {
127
+ hour: schedule?.hour?.[0].toString().padStart(2, '0'),
128
+ minutes: schedule?.minute?.[0].toString().padStart(2, '0'),
129
+ day: schedule?.dayOfMonth?.[0],
130
+ month: Object.values(months).find(m => m.index === schedule?.month?.[0])?.label
131
+ };
132
+ const yearlyString = Math.max(schedule?.month?.length ?? 0, schedule?.dayOfMonth?.length ?? 0) ? t('Yearly on {{month}} {{day}} at {{hour}}:{{minutes}}', {
133
+ ...options
134
+ }) : t('Yearly on multiple dates at {{hour}}:{{minutes}}', {
135
+ ...options
136
+ });
137
+ return `${yearlyString}${scheduleStringTimeStandard}`;
138
+ }
139
+ default:
140
+ return complexScheduleString;
141
+ }
142
+ };
143
+ }
56
144
  function hasSameItems(arr1, arr2) {
57
145
  return arr1.length === arr2?.length && arr1.every(item1 => {
58
146
  return arr2.find(item2 => item2 === item1);