@synerise/ds-factors 1.11.11 → 1.11.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/FactorTypeSelector/FactorTypeSelector.d.ts +2 -2
- package/dist/FactorTypeSelector/FactorTypeSelector.js +37 -58
- package/dist/FactorTypeSelector/FactorTypeSelector.styles.d.ts +18 -18
- package/dist/FactorTypeSelector/FactorTypeSelector.styles.js +10 -10
- package/dist/FactorValue/Array/Array.const.js +8 -3
- package/dist/FactorValue/Array/Array.d.ts +2 -2
- package/dist/FactorValue/Array/Array.js +45 -57
- package/dist/FactorValue/Array/Array.styles.d.ts +39 -39
- package/dist/FactorValue/Array/Array.styles.js +44 -33
- package/dist/FactorValue/Array/Array.types.d.ts +3 -3
- package/dist/FactorValue/Array/Array.types.js +1 -1
- package/dist/FactorValue/Array/Array.utils.d.ts +2 -2
- package/dist/FactorValue/Array/Array.utils.js +21 -18
- package/dist/FactorValue/Array/components/ArrayCollector.d.ts +2 -2
- package/dist/FactorValue/Array/components/ArrayCollector.js +70 -94
- package/dist/FactorValue/Array/components/ArrayCreator.d.ts +2 -2
- package/dist/FactorValue/Array/components/ArrayCreator.js +43 -75
- package/dist/FactorValue/Array/components/ArrayLimit.d.ts +2 -2
- package/dist/FactorValue/Array/components/ArrayLimit.js +16 -14
- package/dist/FactorValue/Array/components/ArrayModal.d.ts +2 -2
- package/dist/FactorValue/Array/components/ArrayModal.js +78 -143
- package/dist/FactorValue/Array/components/ArrayRaw.d.ts +2 -2
- package/dist/FactorValue/Array/components/ArrayRaw.js +47 -58
- package/dist/FactorValue/Array/components/CopyButton.d.ts +2 -2
- package/dist/FactorValue/Array/components/CopyButton.js +20 -30
- package/dist/FactorValue/Array/hooks/useCollector.d.ts +3 -3
- package/dist/FactorValue/Array/hooks/useCollector.js +21 -22
- package/dist/FactorValue/Date/Date.d.ts +2 -2
- package/dist/FactorValue/Date/Date.js +38 -53
- package/dist/FactorValue/DateRange/DateRange.d.ts +2 -2
- package/dist/FactorValue/DateRange/DateRange.js +26 -41
- package/dist/FactorValue/DynamicKey/DynamicKey.d.ts +2 -2
- package/dist/FactorValue/DynamicKey/DynamicKey.js +37 -66
- package/dist/FactorValue/DynamicKey/DynamicKey.style.d.ts +2 -2
- package/dist/FactorValue/DynamicKey/DynamicKey.style.js +10 -8
- package/dist/FactorValue/FactorValue.d.ts +2 -2
- package/dist/FactorValue/FactorValue.js +68 -70
- package/dist/FactorValue/FactorValue.style.d.ts +1 -1
- package/dist/FactorValue/FactorValue.style.js +20 -20
- package/dist/FactorValue/Formula/Formula.d.ts +2 -2
- package/dist/FactorValue/Formula/Formula.js +36 -54
- package/dist/FactorValue/Formula/Formula.styles.d.ts +1 -1
- package/dist/FactorValue/Formula/Formula.styles.js +6 -5
- package/dist/FactorValue/Formula/FormulaModal.d.ts +2 -2
- package/dist/FactorValue/Formula/FormulaModal.js +27 -42
- package/dist/FactorValue/Number/NumberInput.d.ts +2 -2
- package/dist/FactorValue/Number/NumberInput.js +21 -31
- package/dist/FactorValue/Parameter/Parameter.constants.d.ts +1 -1
- package/dist/FactorValue/Parameter/Parameter.constants.js +27 -13
- package/dist/FactorValue/Parameter/Parameter.d.ts +2 -2
- package/dist/FactorValue/Parameter/Parameter.js +82 -127
- package/dist/FactorValue/Parameter/Parameter.style.d.ts +28 -28
- package/dist/FactorValue/Parameter/Parameter.style.js +34 -31
- package/dist/FactorValue/Parameter/Parameter.types.d.ts +2 -2
- package/dist/FactorValue/Parameter/Parameter.types.js +1 -1
- package/dist/FactorValue/Parameter/ParameterDropdown.d.ts +2 -2
- package/dist/FactorValue/Parameter/ParameterDropdown.js +155 -226
- package/dist/FactorValue/Parameter/ParameterDropdownItem.d.ts +3 -3
- package/dist/FactorValue/Parameter/ParameterDropdownItem.js +27 -33
- package/dist/FactorValue/Parameter/useGroups.d.ts +2 -2
- package/dist/FactorValue/Parameter/useGroups.js +30 -42
- package/dist/FactorValue/Parameter/utils.d.ts +2 -2
- package/dist/FactorValue/Parameter/utils.js +22 -17
- package/dist/FactorValue/RelativeDate/RelativeDate.const.d.ts +1 -1
- package/dist/FactorValue/RelativeDate/RelativeDate.const.js +12 -5
- package/dist/FactorValue/RelativeDate/RelativeDate.d.ts +2 -2
- package/dist/FactorValue/RelativeDate/RelativeDate.js +57 -88
- package/dist/FactorValue/RelativeDate/RelativeDate.utils.d.ts +1 -1
- package/dist/FactorValue/RelativeDate/RelativeDate.utils.js +14 -10
- package/dist/FactorValue/RelativeDate/RelativeDateDropdown.d.ts +2 -2
- package/dist/FactorValue/RelativeDate/RelativeDateDropdown.js +56 -87
- package/dist/FactorValue/RelativeDate/RelativeDateDropdown.styles.d.ts +7 -7
- package/dist/FactorValue/RelativeDate/RelativeDateDropdown.styles.js +23 -20
- package/dist/FactorValue/Text/Text.d.ts +2 -2
- package/dist/FactorValue/Text/Text.js +56 -121
- package/dist/FactorValue/Text/Text.styles.d.ts +3 -3
- package/dist/FactorValue/Text/Text.styles.js +11 -10
- package/dist/FactorValue/Text/TextModal.d.ts +2 -2
- package/dist/FactorValue/Text/TextModal.js +19 -33
- package/dist/Factors.d.ts +2 -2
- package/dist/Factors.js +95 -132
- package/dist/Factors.types.d.ts +9 -9
- package/dist/Factors.types.js +8 -3
- package/dist/hooks/useTexts.d.ts +2 -2
- package/dist/hooks/useTexts.js +287 -291
- package/dist/index.js +7 -6
- package/dist/modules.d.js +1 -1
- package/dist/modules.d.ts +0 -0
- package/dist/style/Factors.style.d.ts +1 -1
- package/dist/style/Factors.style.js +10 -11
- package/package.json +32 -32
|
@@ -1,64 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var itemIsParameterGroup = function itemIsParameterGroup(item) {
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
const itemIsParameterGroup = (item) => {
|
|
4
3
|
return Boolean(item);
|
|
5
4
|
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return group.defaultGroup;
|
|
10
|
-
});
|
|
5
|
+
const useGroups = (items, groups, renderEmptyGroups) => {
|
|
6
|
+
const defaultTab = useMemo(() => {
|
|
7
|
+
const defaultIndex = groups?.findIndex((group) => group.defaultGroup);
|
|
11
8
|
return defaultIndex || 0;
|
|
12
9
|
}, [groups]);
|
|
13
|
-
|
|
10
|
+
const visibleGroups = useMemo(() => {
|
|
14
11
|
if (renderEmptyGroups) {
|
|
15
12
|
return groups;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return !(group.allowEmpty || index === 0);
|
|
21
|
-
}).map(function (group) {
|
|
22
|
-
return group.id;
|
|
23
|
-
});
|
|
24
|
-
var groupsToSkip = groupIds == null ? void 0 : groupIds.filter(function (groupId) {
|
|
25
|
-
return !(items != null && items.find(function (item) {
|
|
26
|
-
return item.groupId === groupId;
|
|
27
|
-
}));
|
|
28
|
-
});
|
|
29
|
-
var cleanGroups = groups == null ? void 0 : groups.map(function (group) {
|
|
14
|
+
const groupIds = groups?.map((group) => group.subGroups || group).flat().filter((group, index) => !(group.allowEmpty || index === 0)).map((group) => group.id);
|
|
15
|
+
const groupsToSkip = groupIds?.filter((groupId) => !items?.find((item) => item.groupId === groupId));
|
|
16
|
+
const cleanGroups = groups?.map((group) => {
|
|
30
17
|
if (group.subGroups && group.subGroups.length) {
|
|
31
|
-
|
|
32
|
-
return !(groupsToSkip != null && groupsToSkip.includes(subGroup.id));
|
|
33
|
-
});
|
|
18
|
+
const filteredSubGroups = group.subGroups.filter((subGroup) => !groupsToSkip?.includes(subGroup.id));
|
|
34
19
|
switch (filteredSubGroups.length) {
|
|
35
20
|
case 0:
|
|
36
|
-
return
|
|
21
|
+
return void 0;
|
|
37
22
|
case 1:
|
|
38
|
-
return
|
|
39
|
-
|
|
40
|
-
|
|
23
|
+
return {
|
|
24
|
+
...filteredSubGroups[0],
|
|
25
|
+
icon: void 0
|
|
26
|
+
};
|
|
41
27
|
default:
|
|
42
|
-
return
|
|
28
|
+
return {
|
|
29
|
+
...group,
|
|
43
30
|
subGroups: filteredSubGroups
|
|
44
|
-
}
|
|
31
|
+
};
|
|
45
32
|
}
|
|
46
33
|
}
|
|
47
|
-
return groupsToSkip
|
|
34
|
+
return groupsToSkip?.includes(group.id) ? void 0 : group;
|
|
48
35
|
}).filter(itemIsParameterGroup);
|
|
49
36
|
return cleanGroups;
|
|
50
37
|
}, [groups, items, renderEmptyGroups]);
|
|
51
|
-
|
|
52
|
-
return
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
icon: group.icon
|
|
56
|
-
};
|
|
38
|
+
const tabs = useMemo(() => {
|
|
39
|
+
return visibleGroups?.map((group) => ({
|
|
40
|
+
label: group.name,
|
|
41
|
+
icon: group.icon
|
|
57
42
|
})) || [];
|
|
58
43
|
}, [visibleGroups]);
|
|
59
44
|
return {
|
|
60
|
-
visibleGroups
|
|
61
|
-
tabs
|
|
62
|
-
defaultTab
|
|
45
|
+
visibleGroups,
|
|
46
|
+
tabs,
|
|
47
|
+
defaultTab
|
|
63
48
|
};
|
|
64
|
-
};
|
|
49
|
+
};
|
|
50
|
+
export {
|
|
51
|
+
useGroups
|
|
52
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ParameterGroup } from '../../Factors.types';
|
|
2
|
+
import { DividerItem, DropdownItem, MixedDropdownItemProps, ParameterDropdownTitleProps, TitleItem } from './Parameter.types';
|
|
3
3
|
export declare const groupItems: (dropdownItems: DropdownItem<ParameterGroup>[], activeGroup: ParameterGroup | undefined) => (DropdownItem<ParameterGroup> | TitleItem | DividerItem)[];
|
|
4
4
|
export declare const isListTitle: (element?: MixedDropdownItemProps) => element is ParameterDropdownTitleProps;
|
|
5
5
|
export declare const isDivider: (item: MixedDropdownItemProps | TitleItem | DividerItem) => item is DividerItem;
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
for (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
const NO_GROUP_NAME = "NO_GROUP_NAME";
|
|
2
|
+
const groupItems = (dropdownItems, activeGroup) => {
|
|
3
|
+
const itemsNumber = dropdownItems.length;
|
|
4
|
+
const groupedItems = {};
|
|
5
|
+
let resultItems = [];
|
|
6
|
+
for (let i = 0; i < itemsNumber; i += 1) {
|
|
7
|
+
const item = dropdownItems[i];
|
|
8
|
+
const groupName = item.item.groupName || NO_GROUP_NAME;
|
|
9
|
+
const group = groupedItems[groupName] || [];
|
|
10
10
|
group.push(item);
|
|
11
11
|
groupedItems[groupName] = group;
|
|
12
12
|
}
|
|
13
|
-
Object.keys(groupedItems).forEach(
|
|
13
|
+
Object.keys(groupedItems).forEach((key, index) => {
|
|
14
14
|
if (key !== NO_GROUP_NAME && !activeGroup) {
|
|
15
15
|
if (index > 0) {
|
|
16
16
|
resultItems.push({
|
|
17
|
-
type:
|
|
17
|
+
type: "divider"
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
resultItems.push({
|
|
21
|
-
type:
|
|
21
|
+
type: "title",
|
|
22
22
|
title: key
|
|
23
23
|
});
|
|
24
24
|
}
|
|
@@ -26,9 +26,14 @@ export var groupItems = function groupItems(dropdownItems, activeGroup) {
|
|
|
26
26
|
});
|
|
27
27
|
return resultItems;
|
|
28
28
|
};
|
|
29
|
-
|
|
30
|
-
return element.title !==
|
|
29
|
+
const isListTitle = (element) => {
|
|
30
|
+
return element.title !== void 0;
|
|
31
|
+
};
|
|
32
|
+
const isDivider = (item) => {
|
|
33
|
+
return item.type === "divider";
|
|
34
|
+
};
|
|
35
|
+
export {
|
|
36
|
+
groupItems,
|
|
37
|
+
isDivider,
|
|
38
|
+
isListTitle
|
|
31
39
|
};
|
|
32
|
-
export var isDivider = function isDivider(item) {
|
|
33
|
-
return item.type === 'divider';
|
|
34
|
-
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RelativeDateUnit, RelativeTimeRelation } from '../../Factors.types';
|
|
2
2
|
export declare const INTERVALS: RelativeDateUnit[];
|
|
3
3
|
export declare const BEFORE: RelativeTimeRelation;
|
|
4
4
|
export declare const AFTER: RelativeTimeRelation;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
const INTERVALS = ["SECONDS", "MINUTES", "HOURS", "DAYS", "WEEKS", "MONTHS", "YEARS"];
|
|
2
|
+
const BEFORE = "BEFORE";
|
|
3
|
+
const AFTER = "AFTER";
|
|
4
|
+
const TIME_RELATIONS = [BEFORE, AFTER];
|
|
5
|
+
const DEFAULT_VALUE = 1;
|
|
6
|
+
export {
|
|
7
|
+
AFTER,
|
|
8
|
+
BEFORE,
|
|
9
|
+
DEFAULT_VALUE,
|
|
10
|
+
INTERVALS,
|
|
11
|
+
TIME_RELATIONS
|
|
12
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { FactorValueComponentProps } from '../../Factors.types';
|
|
3
3
|
declare const RelativeDateInput: ({ value, onChange, texts: allTexts, opened, onActivate, error, allowClear, readOnly, triggerValueFormatter, getPopupContainerOverride, availableUnits, uncontrolledComponent, }: FactorValueComponentProps) => React.JSX.Element;
|
|
4
4
|
export default RelativeDateInput;
|
|
@@ -1,114 +1,83 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var theme = useTheme();
|
|
32
|
-
var texts = allTexts.relativeDate;
|
|
33
|
-
useEffect(function () {
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect, useCallback, useMemo } from "react";
|
|
3
|
+
import { useTheme } from "@synerise/ds-core";
|
|
4
|
+
import Dropdown from "@synerise/ds-dropdown";
|
|
5
|
+
import Icon, { AngleDownS, Close3S } from "@synerise/ds-icon";
|
|
6
|
+
import { getPopupContainer } from "@synerise/ds-utils";
|
|
7
|
+
import { defaultTriggerModifier } from "./RelativeDate.utils.js";
|
|
8
|
+
import { RelativeDateDropdown } from "./RelativeDateDropdown.js";
|
|
9
|
+
import { IconWrapper, ChevronIcon, ClearIcon, Trigger } from "./RelativeDateDropdown.styles.js";
|
|
10
|
+
const RelativeDateInput = ({
|
|
11
|
+
value,
|
|
12
|
+
onChange,
|
|
13
|
+
texts: allTexts,
|
|
14
|
+
opened,
|
|
15
|
+
onActivate,
|
|
16
|
+
error,
|
|
17
|
+
allowClear,
|
|
18
|
+
readOnly = false,
|
|
19
|
+
triggerValueFormatter,
|
|
20
|
+
getPopupContainerOverride,
|
|
21
|
+
availableUnits,
|
|
22
|
+
uncontrolledComponent
|
|
23
|
+
}) => {
|
|
24
|
+
const [isOpen, setIsOpen] = useState(opened);
|
|
25
|
+
const [localValue, setLocalValue] = useState(() => value);
|
|
26
|
+
const theme = useTheme();
|
|
27
|
+
const {
|
|
28
|
+
relativeDate: texts
|
|
29
|
+
} = allTexts;
|
|
30
|
+
useEffect(() => {
|
|
34
31
|
if (!uncontrolledComponent) {
|
|
35
32
|
setLocalValue(value);
|
|
36
33
|
}
|
|
37
34
|
}, [value, uncontrolledComponent]);
|
|
38
|
-
|
|
35
|
+
const handleOpenChange = useCallback((open) => {
|
|
39
36
|
if (open) {
|
|
40
37
|
onActivate && onActivate();
|
|
41
38
|
}
|
|
42
39
|
setIsOpen(open);
|
|
43
40
|
}, [onActivate]);
|
|
44
|
-
|
|
41
|
+
const handleApply = useCallback((date) => {
|
|
45
42
|
onChange(date);
|
|
46
43
|
handleOpenChange(false);
|
|
47
44
|
}, [onChange, handleOpenChange]);
|
|
48
|
-
|
|
49
|
-
onChange(
|
|
45
|
+
const handleClear = useCallback(() => {
|
|
46
|
+
onChange(void 0);
|
|
50
47
|
}, [onChange]);
|
|
51
|
-
|
|
48
|
+
const handleOpen = useCallback(() => {
|
|
52
49
|
setIsOpen(true);
|
|
53
50
|
}, []);
|
|
54
|
-
|
|
51
|
+
const handleClose = useCallback(() => {
|
|
55
52
|
setIsOpen(false);
|
|
56
53
|
}, []);
|
|
57
|
-
|
|
54
|
+
const triggerValue = useMemo(() => {
|
|
58
55
|
if (!localValue) {
|
|
59
|
-
return
|
|
56
|
+
return void 0;
|
|
60
57
|
}
|
|
61
58
|
return triggerValueFormatter ? triggerValueFormatter(localValue) : defaultTriggerModifier(localValue, texts);
|
|
62
59
|
}, [texts, localValue, triggerValueFormatter]);
|
|
63
|
-
|
|
60
|
+
const icon = useMemo(() => {
|
|
64
61
|
if (!localValue || !allowClear) {
|
|
65
|
-
return
|
|
66
|
-
component: /*#__PURE__*/React.createElement(AngleDownS, null),
|
|
67
|
-
onClick: handleOpen
|
|
68
|
-
});
|
|
62
|
+
return /* @__PURE__ */ jsx(Icon, { component: /* @__PURE__ */ jsx(AngleDownS, {}), onClick: handleOpen });
|
|
69
63
|
}
|
|
70
|
-
return
|
|
71
|
-
onClick: handleOpen,
|
|
72
|
-
component:
|
|
73
|
-
})
|
|
74
|
-
onClick: handleClear,
|
|
75
|
-
color: theme.palette['red-600'],
|
|
76
|
-
component: /*#__PURE__*/React.createElement(Close3S, null)
|
|
77
|
-
}));
|
|
64
|
+
return /* @__PURE__ */ jsxs(IconWrapper, { children: [
|
|
65
|
+
/* @__PURE__ */ jsx(ChevronIcon, { onClick: handleOpen, component: /* @__PURE__ */ jsx(AngleDownS, {}) }),
|
|
66
|
+
/* @__PURE__ */ jsx(ClearIcon, { onClick: handleClear, color: theme.palette["red-600"], component: /* @__PURE__ */ jsx(Close3S, {}) })
|
|
67
|
+
] });
|
|
78
68
|
}, [localValue, allowClear, handleClear, handleOpen, theme.palette]);
|
|
79
|
-
|
|
80
|
-
return
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
stretchToFit: true
|
|
87
|
-
},
|
|
88
|
-
autoResizeProps: {
|
|
89
|
-
placeholderIsMinWidth: true
|
|
90
|
-
},
|
|
91
|
-
placeholder: texts.triggerPlaceholder,
|
|
92
|
-
value: triggerValue,
|
|
93
|
-
icon1: !readOnly ? icon : undefined
|
|
94
|
-
});
|
|
69
|
+
const trigger = useMemo(() => {
|
|
70
|
+
return /* @__PURE__ */ jsx(Trigger, { "data-testid": "ds-factors-relative-date-trigger", error, readOnly: true, autoResize: {
|
|
71
|
+
minWidth: "123px",
|
|
72
|
+
stretchToFit: true
|
|
73
|
+
}, autoResizeProps: {
|
|
74
|
+
placeholderIsMinWidth: true
|
|
75
|
+
}, placeholder: texts.triggerPlaceholder, value: triggerValue, icon1: !readOnly ? icon : void 0 });
|
|
95
76
|
}, [error, triggerValue, readOnly, icon, texts.triggerPlaceholder]);
|
|
96
|
-
return readOnly ? trigger :
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
popoverProps: {
|
|
103
|
-
testId: 'factors-relative-date'
|
|
104
|
-
},
|
|
105
|
-
overlay: /*#__PURE__*/React.createElement(RelativeDateDropdown, {
|
|
106
|
-
onApply: handleApply,
|
|
107
|
-
onCancel: handleClose,
|
|
108
|
-
value: localValue,
|
|
109
|
-
texts: texts,
|
|
110
|
-
availableUnits: availableUnits
|
|
111
|
-
})
|
|
112
|
-
}, trigger);
|
|
77
|
+
return readOnly ? trigger : /* @__PURE__ */ jsx(Dropdown, { getPopupContainer: getPopupContainerOverride || getPopupContainer, open: isOpen, onOpenChange: handleOpenChange, asChild: false, size: 420, popoverProps: {
|
|
78
|
+
testId: "factors-relative-date"
|
|
79
|
+
}, overlay: /* @__PURE__ */ jsx(RelativeDateDropdown, { onApply: handleApply, onCancel: handleClose, value: localValue, texts, availableUnits }), children: trigger });
|
|
80
|
+
};
|
|
81
|
+
export {
|
|
82
|
+
RelativeDateInput as default
|
|
113
83
|
};
|
|
114
|
-
export default RelativeDateInput;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RelativeDateFactorTexts, RelativeDateFactorTextsString, RelativeDateValueType } from '../../Factors.types';
|
|
2
2
|
export declare const getTranslation: (texts: RelativeDateFactorTextsString, key: string) => string;
|
|
3
3
|
export declare const defaultTriggerModifier: (value: RelativeDateValueType, texts: RelativeDateFactorTexts) => string;
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { RelativeDateKeysString } from
|
|
2
|
-
|
|
3
|
-
return [].
|
|
1
|
+
import { RelativeDateKeysString } from "../../Factors.types.js";
|
|
2
|
+
const isTextsKey = (key) => {
|
|
3
|
+
return [...RelativeDateKeysString].includes(key);
|
|
4
4
|
};
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const getTranslation = (texts, key) => {
|
|
6
|
+
const lowercaseKey = key.toLowerCase();
|
|
7
7
|
return isTextsKey(lowercaseKey) ? texts[lowercaseKey] : key;
|
|
8
8
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return absValue
|
|
13
|
-
};
|
|
9
|
+
const defaultTriggerModifier = (value, texts) => {
|
|
10
|
+
const relation = value.temporalModifier < 0 ? texts.before : texts.after;
|
|
11
|
+
const absValue = Math.abs(value.temporalModifier);
|
|
12
|
+
return `${absValue} ${getTranslation(texts, value.temporalUnit).toLocaleLowerCase()} ${relation.toLocaleLowerCase()} ${texts.currentDatetime}`;
|
|
13
|
+
};
|
|
14
|
+
export {
|
|
15
|
+
defaultTriggerModifier,
|
|
16
|
+
getTranslation
|
|
17
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { RelativeDateFactorTexts, RelativeDateUnit, RelativeDateValueType } from '../../Factors.types';
|
|
3
3
|
type RelativeDateDropdownProps = {
|
|
4
4
|
value?: RelativeDateValueType;
|
|
5
5
|
texts: RelativeDateFactorTexts;
|
|
@@ -1,97 +1,66 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect, useMemo } from "react";
|
|
3
|
+
import Button from "@synerise/ds-button";
|
|
4
|
+
import { InputGroup } from "@synerise/ds-input";
|
|
5
|
+
import InputNumber from "@synerise/ds-input-number";
|
|
6
|
+
import Select from "@synerise/ds-select/dist/Select";
|
|
7
|
+
import { BEFORE, INTERVALS, DEFAULT_VALUE, TIME_RELATIONS, AFTER } from "./RelativeDate.const.js";
|
|
8
|
+
import { getTranslation } from "./RelativeDate.utils.js";
|
|
9
|
+
import { RelativeDateDropdownWrapper, RelativeDateCurrentLabel, RelativeDateDropdownFooter } from "./RelativeDateDropdown.styles.js";
|
|
10
|
+
const getRelationForModifier = (value) => {
|
|
10
11
|
return value < 0 ? BEFORE : AFTER;
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
setTemporalUnit = _useState2[1];
|
|
27
|
-
var _useState3 = useState(defaultModifier),
|
|
28
|
-
temporalModifier = _useState3[0],
|
|
29
|
-
setTemporalModifier = _useState3[1];
|
|
30
|
-
useEffect(function () {
|
|
13
|
+
const RelativeDateDropdown = ({
|
|
14
|
+
onApply,
|
|
15
|
+
onCancel,
|
|
16
|
+
value: relativeDateValue,
|
|
17
|
+
texts,
|
|
18
|
+
availableUnits
|
|
19
|
+
}) => {
|
|
20
|
+
const defaultTimeRelation = relativeDateValue ? getRelationForModifier(relativeDateValue.temporalModifier) : BEFORE;
|
|
21
|
+
const defaultTemporalUnit = relativeDateValue?.temporalUnit || (availableUnits?.length ? availableUnits : INTERVALS)[0];
|
|
22
|
+
const defaultModifier = Math.abs(relativeDateValue?.temporalModifier || DEFAULT_VALUE);
|
|
23
|
+
const [timeRelation, setTimeRelation] = useState(defaultTimeRelation);
|
|
24
|
+
const [temporalUnit, setTemporalUnit] = useState(defaultTemporalUnit);
|
|
25
|
+
const [temporalModifier, setTemporalModifier] = useState(defaultModifier);
|
|
26
|
+
useEffect(() => {
|
|
31
27
|
setTimeRelation(relativeDateValue ? getRelationForModifier(relativeDateValue.temporalModifier) : BEFORE);
|
|
32
|
-
setTemporalUnit(
|
|
33
|
-
setTemporalModifier(Math.abs(
|
|
28
|
+
setTemporalUnit(relativeDateValue?.temporalUnit || INTERVALS[0]);
|
|
29
|
+
setTemporalModifier(Math.abs(relativeDateValue?.temporalModifier || DEFAULT_VALUE));
|
|
34
30
|
}, [relativeDateValue]);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
const isApplyEnabled = temporalModifier && temporalUnit !== void 0;
|
|
32
|
+
const handleApply = () => {
|
|
33
|
+
const finalModifier = timeRelation === BEFORE ? -temporalModifier : temporalModifier;
|
|
38
34
|
isApplyEnabled && onApply({
|
|
39
35
|
temporalModifier: finalModifier,
|
|
40
|
-
temporalUnit
|
|
36
|
+
temporalUnit
|
|
41
37
|
});
|
|
42
38
|
};
|
|
43
|
-
|
|
44
|
-
return (availableUnits
|
|
45
|
-
return /*#__PURE__*/React.createElement(Select.Option, {
|
|
46
|
-
key: intervalOption,
|
|
47
|
-
value: intervalOption
|
|
48
|
-
}, getTranslation(texts, intervalOption));
|
|
49
|
-
});
|
|
39
|
+
const temporalUnitOptions = useMemo(() => {
|
|
40
|
+
return (availableUnits?.length ? availableUnits : INTERVALS).map((intervalOption) => /* @__PURE__ */ jsx(Select.Option, { value: intervalOption, children: getTranslation(texts, intervalOption) }, intervalOption));
|
|
50
41
|
}, [texts, availableUnits]);
|
|
51
|
-
|
|
52
|
-
return TIME_RELATIONS.map(
|
|
53
|
-
return /*#__PURE__*/React.createElement(Select.Option, {
|
|
54
|
-
key: option,
|
|
55
|
-
value: option
|
|
56
|
-
}, getTranslation(texts, option));
|
|
57
|
-
});
|
|
42
|
+
const timeRelationOptions = useMemo(() => {
|
|
43
|
+
return TIME_RELATIONS.map((option) => /* @__PURE__ */ jsx(Select.Option, { value: option, children: getTranslation(texts, option) }, option));
|
|
58
44
|
}, [texts]);
|
|
59
|
-
return
|
|
60
|
-
"data-testid": "ds-factors-relative-date-dropdown"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}, temporalUnitOptions)), /*#__PURE__*/React.createElement(Select, {
|
|
82
|
-
value: timeRelation,
|
|
83
|
-
"data-testid": "ds-factors-relative-date-relation",
|
|
84
|
-
defaultValue: defaultTimeRelation,
|
|
85
|
-
onChange: function onChange(newTimeRelation) {
|
|
86
|
-
setTimeRelation(newTimeRelation);
|
|
87
|
-
},
|
|
88
|
-
dropdownMatchSelectWidth: false
|
|
89
|
-
}, timeRelationOptions), /*#__PURE__*/React.createElement(S.RelativeDateCurrentLabel, null, texts.currentDatetime)), /*#__PURE__*/React.createElement(S.RelativeDateDropdownFooter, null, /*#__PURE__*/React.createElement(Button, {
|
|
90
|
-
type: "ghost",
|
|
91
|
-
onClick: onCancel
|
|
92
|
-
}, texts.cancel), /*#__PURE__*/React.createElement(Button, {
|
|
93
|
-
type: "primary",
|
|
94
|
-
onClick: handleApply,
|
|
95
|
-
disabled: !isApplyEnabled
|
|
96
|
-
}, texts.apply)));
|
|
97
|
-
};
|
|
45
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
46
|
+
/* @__PURE__ */ jsxs(RelativeDateDropdownWrapper, { "data-testid": "ds-factors-relative-date-dropdown", children: [
|
|
47
|
+
/* @__PURE__ */ jsxs(InputGroup, { resetMargin: true, compact: true, children: [
|
|
48
|
+
/* @__PURE__ */ jsx(InputNumber, { "data-testid": "ds-factors-relative-date-modifier", defaultValue: 1, min: 1, raw: true, value: temporalModifier, onChange: (newTemporalModifier) => newTemporalModifier && setTemporalModifier(newTemporalModifier) }),
|
|
49
|
+
/* @__PURE__ */ jsx(Select, { value: temporalUnit, "data-testid": "ds-factors-relative-date-unit", defaultValue: defaultTemporalUnit, onChange: (newTemporalUnit) => {
|
|
50
|
+
setTemporalUnit(newTemporalUnit);
|
|
51
|
+
}, dropdownMatchSelectWidth: false, children: temporalUnitOptions })
|
|
52
|
+
] }),
|
|
53
|
+
/* @__PURE__ */ jsx(Select, { value: timeRelation, "data-testid": "ds-factors-relative-date-relation", defaultValue: defaultTimeRelation, onChange: (newTimeRelation) => {
|
|
54
|
+
setTimeRelation(newTimeRelation);
|
|
55
|
+
}, dropdownMatchSelectWidth: false, children: timeRelationOptions }),
|
|
56
|
+
/* @__PURE__ */ jsx(RelativeDateCurrentLabel, { children: texts.currentDatetime })
|
|
57
|
+
] }),
|
|
58
|
+
/* @__PURE__ */ jsxs(RelativeDateDropdownFooter, { children: [
|
|
59
|
+
/* @__PURE__ */ jsx(Button, { type: "ghost", onClick: onCancel, children: texts.cancel }),
|
|
60
|
+
/* @__PURE__ */ jsx(Button, { type: "primary", onClick: handleApply, disabled: !isApplyEnabled, children: texts.apply })
|
|
61
|
+
] })
|
|
62
|
+
] });
|
|
63
|
+
};
|
|
64
|
+
export {
|
|
65
|
+
RelativeDateDropdown
|
|
66
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const RelativeDateDropdownWrapper: import(
|
|
3
|
-
export declare const RelativeDateDropdownFooter: import(
|
|
4
|
-
export declare const RelativeDateCurrentLabel: import(
|
|
5
|
-
export declare const IconWrapper: import(
|
|
6
|
-
export declare const ClearIcon: import(
|
|
7
|
-
export declare const ChevronIcon: import(
|
|
1
|
+
import { StyledInput } from '@synerise/ds-input';
|
|
2
|
+
export declare const RelativeDateDropdownWrapper: import('styled-components').StyledComponent<"div", any, {}, never>;
|
|
3
|
+
export declare const RelativeDateDropdownFooter: import('styled-components').StyledComponent<"div", any, {}, never>;
|
|
4
|
+
export declare const RelativeDateCurrentLabel: import('styled-components').StyledComponent<"div", any, {}, never>;
|
|
5
|
+
export declare const IconWrapper: import('styled-components').StyledComponent<"div", any, {}, never>;
|
|
6
|
+
export declare const ClearIcon: import('styled-components').StyledComponent<import('react').ForwardRefExoticComponent<import('@synerise/ds-icon').BaseIconProps & Omit<import('react').HTMLAttributes<HTMLDivElement>, keyof import('@synerise/ds-icon').BaseIconProps> & import('@synerise/ds-utils').DataAttributes & import('react').RefAttributes<HTMLDivElement>>, any, {}, never>;
|
|
7
|
+
export declare const ChevronIcon: import('styled-components').StyledComponent<import('react').ForwardRefExoticComponent<import('@synerise/ds-icon').BaseIconProps & Omit<import('react').HTMLAttributes<HTMLDivElement>, keyof import('@synerise/ds-icon').BaseIconProps> & import('@synerise/ds-utils').DataAttributes & import('react').RefAttributes<HTMLDivElement>>, any, {}, never>;
|
|
8
8
|
export declare const Trigger: StyledInput;
|