@synerise/ds-factors 1.11.10 → 1.11.12
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/README.md +43 -27
- 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 +34 -34
|
@@ -1,81 +1,92 @@
|
|
|
1
|
-
import styled from
|
|
2
|
-
import Button from
|
|
3
|
-
import EmptyStateBase from
|
|
4
|
-
import Icon from
|
|
5
|
-
import
|
|
6
|
-
|
|
1
|
+
import styled from "styled-components";
|
|
2
|
+
import Button from "@synerise/ds-button";
|
|
3
|
+
import EmptyStateBase from "@synerise/ds-empty-states";
|
|
4
|
+
import Icon from "@synerise/ds-icon";
|
|
5
|
+
import ModalProxy from "@synerise/ds-modal";
|
|
6
|
+
const TextArea = /* @__PURE__ */ styled.textarea.withConfig({
|
|
7
7
|
displayName: "Arraystyles__TextArea",
|
|
8
8
|
componentId: "sc-9atgo7-0"
|
|
9
9
|
})(["width:100%;padding:8px 12px;"]);
|
|
10
|
-
|
|
10
|
+
const Modal = /* @__PURE__ */ styled(ModalProxy).withConfig({
|
|
11
11
|
displayName: "Arraystyles__Modal",
|
|
12
12
|
componentId: "sc-9atgo7-1"
|
|
13
|
-
})(["&&{top:50px;.ant-modal-content{height:", "vh;}}", "{height:calc(", "vh - 215px);min-height:auto;resize:none;font-family:'IBM Plex Mono Regular',monospace;&,&:focus{border:0;background:transparent;box-shadow:none;}}"],
|
|
14
|
-
|
|
15
|
-
}, TextArea, function (props) {
|
|
16
|
-
return props.viewportHeight;
|
|
17
|
-
});
|
|
18
|
-
export var EmptyState = styled(EmptyStateBase).withConfig({
|
|
13
|
+
})(["&&{top:50px;.ant-modal-content{height:", "vh;}}", "{height:calc(", "vh - 215px);min-height:auto;resize:none;font-family:'IBM Plex Mono Regular',monospace;&,&:focus{border:0;background:transparent;box-shadow:none;}}"], (props) => props.viewportHeight, TextArea, (props) => props.viewportHeight);
|
|
14
|
+
const EmptyState = /* @__PURE__ */ styled(EmptyStateBase).withConfig({
|
|
19
15
|
displayName: "Arraystyles__EmptyState",
|
|
20
16
|
componentId: "sc-9atgo7-2"
|
|
21
17
|
})(["margin:90px auto 120px;"]);
|
|
22
|
-
|
|
18
|
+
const TriggerButtonLabel = /* @__PURE__ */ styled.div.withConfig({
|
|
23
19
|
displayName: "Arraystyles__TriggerButtonLabel",
|
|
24
20
|
componentId: "sc-9atgo7-3"
|
|
25
21
|
})(["min-width:0;text-overflow:ellipsis;overflow:hidden;"]);
|
|
26
|
-
|
|
22
|
+
const TriggerButton = /* @__PURE__ */ styled(Button).withConfig({
|
|
27
23
|
displayName: "Arraystyles__TriggerButton",
|
|
28
24
|
componentId: "sc-9atgo7-4"
|
|
29
25
|
})(["max-width:100%;"]);
|
|
30
|
-
|
|
26
|
+
const ModalFooterLeftSide = /* @__PURE__ */ styled.div.withConfig({
|
|
31
27
|
displayName: "Arraystyles__ModalFooterLeftSide",
|
|
32
28
|
componentId: "sc-9atgo7-5"
|
|
33
29
|
})(["flex:1 1 100%;text-align:left;"]);
|
|
34
|
-
|
|
30
|
+
const ModalSubHeader = /* @__PURE__ */ styled.div.withConfig({
|
|
35
31
|
displayName: "Arraystyles__ModalSubHeader",
|
|
36
32
|
componentId: "sc-9atgo7-6"
|
|
37
33
|
})(["display:flex;justify-content:space-between;"]);
|
|
38
|
-
|
|
34
|
+
const ModalContentWrapper = /* @__PURE__ */ styled.div.withConfig({
|
|
39
35
|
displayName: "Arraystyles__ModalContentWrapper",
|
|
40
36
|
componentId: "sc-9atgo7-7"
|
|
41
37
|
})(["padding:24px;"]);
|
|
42
|
-
|
|
38
|
+
const Limit = /* @__PURE__ */ styled.div.withConfig({
|
|
43
39
|
displayName: "Arraystyles__Limit",
|
|
44
40
|
componentId: "sc-9atgo7-8"
|
|
45
41
|
})(["display:flex;gap:4px;align-items:center;"]);
|
|
46
|
-
|
|
42
|
+
const LimitPart = /* @__PURE__ */ styled.div.withConfig({
|
|
47
43
|
displayName: "Arraystyles__LimitPart",
|
|
48
44
|
componentId: "sc-9atgo7-9"
|
|
49
45
|
})([""]);
|
|
50
|
-
|
|
46
|
+
const SearchWrapper = /* @__PURE__ */ styled.div.withConfig({
|
|
51
47
|
displayName: "Arraystyles__SearchWrapper",
|
|
52
48
|
componentId: "sc-9atgo7-10"
|
|
53
49
|
})(["max-width:200px;min-width:32px;"]);
|
|
54
|
-
|
|
50
|
+
const RightSide = /* @__PURE__ */ styled.div.withConfig({
|
|
55
51
|
displayName: "Arraystyles__RightSide",
|
|
56
52
|
componentId: "sc-9atgo7-11"
|
|
57
53
|
})(["flex:1 1 auto;display:flex;justify-content:flex-end;align-items:center;gap:12px;"]);
|
|
58
|
-
|
|
54
|
+
const LeftSide = /* @__PURE__ */ styled.div.withConfig({
|
|
59
55
|
displayName: "Arraystyles__LeftSide",
|
|
60
56
|
componentId: "sc-9atgo7-12"
|
|
61
57
|
})(["flex:0 0 auto;text-align:left;"]);
|
|
62
|
-
|
|
58
|
+
const CreatorItemsList = /* @__PURE__ */ styled.div.withConfig({
|
|
63
59
|
displayName: "Arraystyles__CreatorItemsList",
|
|
64
60
|
componentId: "sc-9atgo7-13"
|
|
65
61
|
})(["display:flex;flex-direction:column;gap:12px;"]);
|
|
66
|
-
|
|
62
|
+
const DeleteIcon = /* @__PURE__ */ styled(Icon).withConfig({
|
|
67
63
|
displayName: "Arraystyles__DeleteIcon",
|
|
68
64
|
componentId: "sc-9atgo7-14"
|
|
69
|
-
})(["position:absolute;right:0;top:50%;transform:translateY(-50%);display:none;color:", ";&:hover{color:", ";}"],
|
|
70
|
-
|
|
71
|
-
}, function (props) {
|
|
72
|
-
return props.theme.palette['red-500'];
|
|
73
|
-
});
|
|
74
|
-
export var CollectorWrapper = styled.div.withConfig({
|
|
65
|
+
})(["position:absolute;right:0;top:50%;transform:translateY(-50%);display:none;color:", ";&:hover{color:", ";}"], (props) => props.theme.palette["red-600"], (props) => props.theme.palette["red-500"]);
|
|
66
|
+
const CollectorWrapper = /* @__PURE__ */ styled.div.withConfig({
|
|
75
67
|
displayName: "Arraystyles__CollectorWrapper",
|
|
76
68
|
componentId: "sc-9atgo7-15"
|
|
77
69
|
})(["padding:0 34px;margin-bottom:24px;"]);
|
|
78
|
-
|
|
70
|
+
const CreatorRow = /* @__PURE__ */ styled.div.withConfig({
|
|
79
71
|
displayName: "Arraystyles__CreatorRow",
|
|
80
72
|
componentId: "sc-9atgo7-16"
|
|
81
|
-
})(["padding:0 34px;position:relative;&:hover{", "{display:block;}}"], DeleteIcon);
|
|
73
|
+
})(["padding:0 34px;position:relative;&:hover{", "{display:block;}}"], DeleteIcon);
|
|
74
|
+
export {
|
|
75
|
+
CollectorWrapper,
|
|
76
|
+
CreatorItemsList,
|
|
77
|
+
CreatorRow,
|
|
78
|
+
DeleteIcon,
|
|
79
|
+
EmptyState,
|
|
80
|
+
LeftSide,
|
|
81
|
+
Limit,
|
|
82
|
+
LimitPart,
|
|
83
|
+
Modal,
|
|
84
|
+
ModalContentWrapper,
|
|
85
|
+
ModalFooterLeftSide,
|
|
86
|
+
ModalSubHeader,
|
|
87
|
+
RightSide,
|
|
88
|
+
SearchWrapper,
|
|
89
|
+
TextArea,
|
|
90
|
+
TriggerButton,
|
|
91
|
+
TriggerButtonLabel
|
|
92
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { RequiredProps } from '@synerise/ds-utils';
|
|
3
|
+
import { ArrayProps, ArrayValueElement, FactorsTexts } from '../../Factors.types';
|
|
4
4
|
export type ArrayModalProps<ItemType extends 'string' | 'number'> = RequiredProps<ArrayProps, 'itemType'> & {
|
|
5
5
|
visible?: boolean;
|
|
6
6
|
readOnly?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ArrayValueElement } from '../../Factors.types';
|
|
2
|
+
import { ArrayValueWithID } from './Array.types';
|
|
3
3
|
export declare const matchesSearchQuery: (item: string | number, searchQuery: string) => boolean;
|
|
4
4
|
export declare const arrayWithUUID: <ItemType extends "string" | "number">(items: ArrayValueElement<ItemType>[]) => ArrayValueWithID<ItemType>[];
|
|
5
5
|
export declare const sanitiseValues: (element: string) => string;
|
|
@@ -1,25 +1,28 @@
|
|
|
1
|
-
import { v4
|
|
2
|
-
|
|
1
|
+
import { v4 } from "uuid";
|
|
2
|
+
const matchesSearchQuery = (item, searchQuery) => {
|
|
3
3
|
return String(item).toLocaleLowerCase().includes(searchQuery.toLocaleLowerCase());
|
|
4
4
|
};
|
|
5
|
-
|
|
6
|
-
return items.map(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
});
|
|
5
|
+
const arrayWithUUID = (items) => {
|
|
6
|
+
return items.map((item) => ({
|
|
7
|
+
value: item,
|
|
8
|
+
id: v4()
|
|
9
|
+
}));
|
|
12
10
|
};
|
|
13
|
-
|
|
11
|
+
const sanitiseValues = (element) => {
|
|
14
12
|
return element.trim();
|
|
15
13
|
};
|
|
16
|
-
|
|
17
|
-
return sanitiseValues(value) ===
|
|
14
|
+
const isNumberAsString = (value) => {
|
|
15
|
+
return sanitiseValues(value) === `${parseFloat(sanitiseValues(value))}`;
|
|
18
16
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return "" + parseFloat(sanitiseValues(item));
|
|
23
|
-
});
|
|
17
|
+
const isArrayOfNumbersAsString = (array) => {
|
|
18
|
+
const sanitisedArray = array.map(sanitiseValues);
|
|
19
|
+
const comparisonArray = array.map((item) => `${parseFloat(sanitiseValues(item))}`);
|
|
24
20
|
return JSON.stringify(sanitisedArray) === JSON.stringify(comparisonArray);
|
|
25
|
-
};
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
arrayWithUUID,
|
|
24
|
+
isArrayOfNumbersAsString,
|
|
25
|
+
isNumberAsString,
|
|
26
|
+
matchesSearchQuery,
|
|
27
|
+
sanitiseValues
|
|
28
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { ArrayCollectorProps } from '../Array.types';
|
|
3
3
|
export declare const ArrayCollector: <ItemType extends "string" | "number">({ limit, itemType, arrayValueCount, texts, onConfirm, collectorSuggestions, }: ArrayCollectorProps<ItemType>) => React.JSX.Element;
|
|
@@ -1,113 +1,89 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect } from "react";
|
|
3
|
+
import { v4 } from "uuid";
|
|
4
|
+
import Collector from "@synerise/ds-collector";
|
|
5
|
+
import { COMMA } from "../Array.const.js";
|
|
6
|
+
import { CollectorWrapper } from "../Array.styles.js";
|
|
7
|
+
import { sanitiseValues, isArrayOfNumbersAsString, isNumberAsString } from "../Array.utils.js";
|
|
8
|
+
import { useCollector } from "../hooks/useCollector.js";
|
|
9
|
+
const ArrayCollector = ({
|
|
10
|
+
limit,
|
|
11
|
+
itemType,
|
|
12
|
+
arrayValueCount,
|
|
13
|
+
texts,
|
|
14
|
+
onConfirm,
|
|
15
|
+
collectorSuggestions
|
|
16
|
+
}) => {
|
|
17
|
+
const [collectorValues, setCollectorValues] = useState([]);
|
|
18
|
+
const {
|
|
19
|
+
disabled,
|
|
20
|
+
error,
|
|
21
|
+
errorMessage,
|
|
22
|
+
addEnabled,
|
|
23
|
+
setHasTypeError,
|
|
24
|
+
exceedsLimit
|
|
25
|
+
} = useCollector({
|
|
26
|
+
limit,
|
|
27
|
+
collectorCount: collectorValues.length,
|
|
28
|
+
arrayValueCount,
|
|
29
|
+
texts
|
|
30
|
+
});
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (itemType === "number") {
|
|
33
|
+
const plainValues = collectorValues.map((item) => sanitiseValues(item.value));
|
|
35
34
|
setHasTypeError(!isArrayOfNumbersAsString(plainValues));
|
|
36
35
|
}
|
|
37
36
|
}, [collectorValues, setHasTypeError, itemType]);
|
|
38
|
-
|
|
37
|
+
const handleCancel = () => {
|
|
39
38
|
setCollectorValues([]);
|
|
40
39
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
});
|
|
45
|
-
var hasExceededLimit = exceedsLimit(items.length);
|
|
40
|
+
const handleConfirm = (items) => {
|
|
41
|
+
const hasError = items.some((item) => item.hasError);
|
|
42
|
+
const hasExceededLimit = exceedsLimit(items.length);
|
|
46
43
|
if (!hasError && !hasExceededLimit) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
};
|
|
52
|
-
});
|
|
44
|
+
const rawItemValues = items.map((item) => ({
|
|
45
|
+
value: itemType === "number" ? Number(item.value) : item.value,
|
|
46
|
+
id: item.id
|
|
47
|
+
}));
|
|
53
48
|
onConfirm(rawItemValues);
|
|
54
49
|
setCollectorValues([]);
|
|
55
50
|
} else {
|
|
56
51
|
setCollectorValues(items);
|
|
57
52
|
}
|
|
58
53
|
};
|
|
59
|
-
|
|
54
|
+
const handleItemAdd = (text) => {
|
|
60
55
|
return {
|
|
61
|
-
value: sanitiseValues(
|
|
56
|
+
value: sanitiseValues(`${text}`),
|
|
62
57
|
type: itemType,
|
|
63
|
-
hasError: itemType ===
|
|
64
|
-
id:
|
|
58
|
+
hasError: itemType === "number" && !isNumberAsString(`${text}`),
|
|
59
|
+
id: v4()
|
|
65
60
|
};
|
|
66
61
|
};
|
|
67
|
-
|
|
68
|
-
setCollectorValues([
|
|
62
|
+
const handleItemSelect = (item) => {
|
|
63
|
+
setCollectorValues([...collectorValues, item]);
|
|
69
64
|
};
|
|
70
|
-
|
|
71
|
-
setCollectorValues(collectorValues.filter(
|
|
72
|
-
return collectorItem.id !== deselectedItem.id;
|
|
73
|
-
}));
|
|
65
|
+
const handleItemDeselect = (deselectedItem) => {
|
|
66
|
+
setCollectorValues(collectorValues.filter((collectorItem) => collectorItem.id !== deselectedItem.id));
|
|
74
67
|
};
|
|
75
|
-
|
|
76
|
-
setCollectorValues([
|
|
68
|
+
const handleMultipleItemSelect = (items) => {
|
|
69
|
+
setCollectorValues([...collectorValues, ...items]);
|
|
77
70
|
};
|
|
78
|
-
return
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
'data-testid': 'array-collector-add-button'
|
|
98
|
-
},
|
|
99
|
-
allowMultipleValues: true,
|
|
100
|
-
lookupConfig: {
|
|
101
|
-
display: 'value',
|
|
102
|
-
filter: 'value'
|
|
103
|
-
},
|
|
104
|
-
onItemDeselect: handleItemDeselect,
|
|
105
|
-
allowPaste: true,
|
|
106
|
-
suggestions: collectorSuggestions || [],
|
|
107
|
-
texts: {
|
|
108
|
-
add: texts.array.collectorAdd,
|
|
109
|
-
placeholder: texts.array.collectorPlaceholder,
|
|
110
|
-
cancel: texts.array.collectorCancel
|
|
111
|
-
}
|
|
112
|
-
}));
|
|
113
|
-
};
|
|
71
|
+
return /* @__PURE__ */ jsx(CollectorWrapper, { children: /* @__PURE__ */ jsx(Collector, { valuesSeparator: COMMA, error, errorText: errorMessage, onConfirm: addEnabled ? handleConfirm : void 0, onItemSelect: handleItemSelect, onMultipleItemsSelect: handleMultipleItemSelect, selected: collectorValues, onCancel: handleCancel, onItemAdd: handleItemAdd, allowCustomValue: true, disabled, cancelButtonProps: {
|
|
72
|
+
"data-testid": "array-collector-cancel-button"
|
|
73
|
+
}, addButtonProps: addEnabled ? {
|
|
74
|
+
"data-testid": "array-collector-add-button"
|
|
75
|
+
} : {
|
|
76
|
+
disabled: true,
|
|
77
|
+
"data-testid": "array-collector-add-button"
|
|
78
|
+
}, allowMultipleValues: true, lookupConfig: {
|
|
79
|
+
display: "value",
|
|
80
|
+
filter: "value"
|
|
81
|
+
}, onItemDeselect: handleItemDeselect, allowPaste: true, suggestions: collectorSuggestions || [], texts: {
|
|
82
|
+
add: texts.array.collectorAdd,
|
|
83
|
+
placeholder: texts.array.collectorPlaceholder,
|
|
84
|
+
cancel: texts.array.collectorCancel
|
|
85
|
+
} }) });
|
|
86
|
+
};
|
|
87
|
+
export {
|
|
88
|
+
ArrayCollector
|
|
89
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { ArrayCreatorProps } from '../Array.types';
|
|
3
3
|
export declare const ArrayCreator: <ItemType extends "string" | "number">({ value: arrayValue, searchQuery, itemType, onValueChange, limit, readOnly, texts, collectorSuggestions, }: ArrayCreatorProps<ItemType>) => React.JSX.Element;
|
|
@@ -1,81 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import { CloseM, InboxNoResultsL } from
|
|
4
|
-
import { Input } from
|
|
5
|
-
import InputNumber from
|
|
6
|
-
import Tooltip from
|
|
7
|
-
import
|
|
8
|
-
import { matchesSearchQuery } from
|
|
9
|
-
import { ArrayCollector } from
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return [].
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { CloseM, InboxNoResultsL } from "@synerise/ds-icon";
|
|
4
|
+
import { Input } from "@synerise/ds-input";
|
|
5
|
+
import InputNumber from "@synerise/ds-input-number";
|
|
6
|
+
import Tooltip from "@synerise/ds-tooltip";
|
|
7
|
+
import { ModalContentWrapper, CreatorItemsList, CreatorRow, DeleteIcon, EmptyState } from "../Array.styles.js";
|
|
8
|
+
import { matchesSearchQuery } from "../Array.utils.js";
|
|
9
|
+
import { ArrayCollector } from "./ArrayCollector.js";
|
|
10
|
+
const ArrayCreator = ({
|
|
11
|
+
value: arrayValue = [],
|
|
12
|
+
searchQuery,
|
|
13
|
+
itemType,
|
|
14
|
+
onValueChange,
|
|
15
|
+
limit,
|
|
16
|
+
readOnly,
|
|
17
|
+
texts,
|
|
18
|
+
collectorSuggestions
|
|
19
|
+
}) => {
|
|
20
|
+
const arrayReversed = useMemo(() => {
|
|
21
|
+
return [...arrayValue].reverse();
|
|
22
22
|
}, [arrayValue]);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}).reverse();
|
|
23
|
+
const handleItemChange = (valueIndex, newValue) => {
|
|
24
|
+
const updatedArray = arrayReversed.map((currentValue, index) => index === valueIndex ? {
|
|
25
|
+
...currentValue,
|
|
26
|
+
value: newValue
|
|
27
|
+
} : currentValue).reverse();
|
|
29
28
|
onValueChange(updatedArray);
|
|
30
29
|
};
|
|
31
|
-
|
|
32
|
-
onValueChange([
|
|
30
|
+
const handleItemRemove = (valueIndex) => {
|
|
31
|
+
onValueChange([...arrayReversed.slice(0, valueIndex), ...arrayReversed.slice(valueIndex + 1)].reverse());
|
|
33
32
|
};
|
|
34
|
-
|
|
35
|
-
onValueChange([
|
|
33
|
+
const handleConfirm = (rawItemValues) => {
|
|
34
|
+
onValueChange([...arrayValue, ...rawItemValues]);
|
|
36
35
|
};
|
|
37
|
-
|
|
38
|
-
return searchQuery ? arrayReversed.filter(
|
|
39
|
-
return matchesSearchQuery(item.value, searchQuery);
|
|
40
|
-
}) : arrayReversed;
|
|
36
|
+
const filteredItems = useMemo(() => {
|
|
37
|
+
return searchQuery ? arrayReversed.filter((item) => matchesSearchQuery(item.value, searchQuery)) : arrayReversed;
|
|
41
38
|
}, [searchQuery, arrayReversed]);
|
|
42
|
-
return
|
|
43
|
-
arrayValueCount: arrayValue.length,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
texts: texts,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}, itemType === 'string' ? /*#__PURE__*/React.createElement(Input, {
|
|
54
|
-
resetMargin: true,
|
|
55
|
-
readOnly: readOnly,
|
|
56
|
-
onChange: function onChange(event) {
|
|
57
|
-
return handleItemChange(index, event.target.value);
|
|
58
|
-
},
|
|
59
|
-
value: item.value
|
|
60
|
-
}) : /*#__PURE__*/React.createElement(InputNumber, {
|
|
61
|
-
raw: true,
|
|
62
|
-
readOnly: readOnly,
|
|
63
|
-
onChange: function onChange(changedValue) {
|
|
64
|
-
return changedValue && handleItemChange(index, changedValue);
|
|
65
|
-
},
|
|
66
|
-
value: item.value
|
|
67
|
-
}), !readOnly && /*#__PURE__*/React.createElement(Tooltip, {
|
|
68
|
-
title: texts.array.deleteItemTooltip
|
|
69
|
-
}, /*#__PURE__*/React.createElement(S.DeleteIcon, {
|
|
70
|
-
"data-testid": "ds-factors-array-remove-item",
|
|
71
|
-
onClick: function onClick() {
|
|
72
|
-
return handleItemRemove(index);
|
|
73
|
-
},
|
|
74
|
-
component: /*#__PURE__*/React.createElement(CloseM, null)
|
|
75
|
-
})));
|
|
76
|
-
})) : /*#__PURE__*/React.createElement(S.EmptyState, {
|
|
77
|
-
customIcon: /*#__PURE__*/React.createElement(InboxNoResultsL, null),
|
|
78
|
-
text: searchQuery ? texts.array.emptyResultsTitle : texts.array.emptyTitle,
|
|
79
|
-
label: searchQuery ? texts.array.emptyResultsDescription : texts.array.emptyDescription
|
|
80
|
-
})));
|
|
81
|
-
};
|
|
39
|
+
return /* @__PURE__ */ jsx(ModalContentWrapper, { children: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
40
|
+
!readOnly && /* @__PURE__ */ jsx(ArrayCollector, { arrayValueCount: arrayValue.length, limit, itemType, onConfirm: handleConfirm, texts, collectorSuggestions }),
|
|
41
|
+
filteredItems?.length ? /* @__PURE__ */ jsx(CreatorItemsList, { children: filteredItems.map((item, index) => /* @__PURE__ */ jsxs(CreatorRow, { "data-testid": "ds-factors-array-item", children: [
|
|
42
|
+
itemType === "string" ? /* @__PURE__ */ jsx(Input, { resetMargin: true, readOnly, onChange: (event) => handleItemChange(index, event.target.value), value: item.value }) : /* @__PURE__ */ jsx(InputNumber, { raw: true, readOnly, onChange: (changedValue) => changedValue && handleItemChange(index, changedValue), value: item.value }),
|
|
43
|
+
!readOnly && /* @__PURE__ */ jsx(Tooltip, { title: texts.array.deleteItemTooltip, children: /* @__PURE__ */ jsx(DeleteIcon, { "data-testid": "ds-factors-array-remove-item", onClick: () => handleItemRemove(index), component: /* @__PURE__ */ jsx(CloseM, {}) }) })
|
|
44
|
+
] }, item.id)) }) : /* @__PURE__ */ jsx(EmptyState, { customIcon: /* @__PURE__ */ jsx(InboxNoResultsL, {}), text: searchQuery ? texts.array.emptyResultsTitle : texts.array.emptyTitle, label: searchQuery ? texts.array.emptyResultsDescription : texts.array.emptyDescription })
|
|
45
|
+
] }) });
|
|
46
|
+
};
|
|
47
|
+
export {
|
|
48
|
+
ArrayCreator
|
|
49
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { ArrayLimitProps } from '../Array.types';
|
|
3
3
|
export declare const ArrayLimit: ({ limit, count, texts }: ArrayLimitProps) => React.JSX.Element;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { IconAlert } from
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return
|
|
10
|
-
iconAlert: true,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { IconAlert } from "@synerise/ds-alert";
|
|
3
|
+
import { Limit, LimitPart } from "../Array.styles.js";
|
|
4
|
+
const ArrayLimit = ({
|
|
5
|
+
limit,
|
|
6
|
+
count = 0,
|
|
7
|
+
texts
|
|
8
|
+
}) => {
|
|
9
|
+
return /* @__PURE__ */ jsxs(Limit, { children: [
|
|
10
|
+
/* @__PURE__ */ jsx(LimitPart, { children: count === limit ? /* @__PURE__ */ jsx(IconAlert, { iconAlert: true, type: "warning", message: texts.array.limitReached }) : texts.array.limitPrefix }),
|
|
11
|
+
/* @__PURE__ */ jsx(LimitPart, { children: ` ${count}/${limit}` })
|
|
12
|
+
] });
|
|
13
|
+
};
|
|
14
|
+
export {
|
|
15
|
+
ArrayLimit
|
|
16
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { ArrayModalProps } from '../Array.types';
|
|
3
3
|
export declare const ArrayModal: <ItemType extends "string" | "number">({ value, itemType, onApply, onCancel, visible, readOnly, texts, limit, collectorSuggestions, }: ArrayModalProps<ItemType>) => React.JSX.Element;
|