@synerise/ds-factors 1.2.2 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +29 -37
- package/dist/FactorValue/Array/Array.const.d.ts +1 -0
- package/dist/FactorValue/Array/Array.const.js +1 -0
- package/dist/FactorValue/Array/Array.d.ts +3 -0
- package/dist/FactorValue/Array/Array.js +72 -0
- package/dist/FactorValue/Array/Array.styles.d.ts +32 -0
- package/dist/FactorValue/Array/Array.styles.js +82 -0
- package/dist/FactorValue/Array/Array.types.d.ts +39 -0
- package/dist/FactorValue/Array/Array.types.js +1 -0
- package/dist/FactorValue/Array/Array.utils.d.ts +6 -0
- package/dist/FactorValue/Array/Array.utils.js +25 -0
- package/dist/FactorValue/Array/components/ArrayCollector.d.ts +3 -0
- package/dist/FactorValue/Array/components/ArrayCollector.js +112 -0
- package/dist/FactorValue/Array/components/ArrayCreator.d.ts +3 -0
- package/dist/FactorValue/Array/components/ArrayCreator.js +81 -0
- package/dist/FactorValue/Array/components/ArrayLimit.d.ts +3 -0
- package/dist/FactorValue/Array/components/ArrayLimit.js +14 -0
- package/dist/FactorValue/Array/components/ArrayModal.d.ts +3 -0
- package/dist/FactorValue/Array/components/ArrayModal.js +161 -0
- package/dist/FactorValue/Array/components/ArrayRaw.d.ts +3 -0
- package/dist/FactorValue/Array/components/ArrayRaw.js +69 -0
- package/dist/FactorValue/Array/components/CopyButton.d.ts +3 -0
- package/dist/FactorValue/Array/components/CopyButton.js +42 -0
- package/dist/FactorValue/Array/hooks/useCollector.d.ts +17 -0
- package/dist/FactorValue/Array/hooks/useCollector.js +40 -0
- package/dist/FactorValue/FactorValue.d.ts +1 -1
- package/dist/FactorValue/FactorValue.js +4 -2
- package/dist/FactorValue/Parameter/utils.d.ts +1 -1
- package/dist/Factors.d.ts +1 -1
- package/dist/Factors.js +4 -1
- package/dist/Factors.types.d.ts +37 -4
- package/dist/hooks/useTexts.d.ts +1 -1
- package/dist/hooks/useTexts.js +86 -0
- package/package.json +32 -23
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { IconAlert } from '@synerise/ds-alert';
|
|
3
|
+
import Button, { ButtonToggle } from '@synerise/ds-button';
|
|
4
|
+
import ButtonGroup from '@synerise/ds-button-group';
|
|
5
|
+
import Icon, { CodeM, EditM, TrashM } from '@synerise/ds-icon';
|
|
6
|
+
import { SearchInput } from '@synerise/ds-search';
|
|
7
|
+
import { useIsMounted } from '@synerise/ds-utils';
|
|
8
|
+
import * as S from '../Array.styles';
|
|
9
|
+
import { ArrayCreator } from './ArrayCreator';
|
|
10
|
+
import { ArrayRaw } from './ArrayRaw';
|
|
11
|
+
import { arrayWithUUID } from '../Array.utils';
|
|
12
|
+
import { ArrayLimit } from './ArrayLimit';
|
|
13
|
+
import { CopyButton } from './CopyButton';
|
|
14
|
+
import { MODAL_VIEWPORT_HEIGHT } from '../Array.const';
|
|
15
|
+
export var ArrayModal = function ArrayModal(_ref) {
|
|
16
|
+
var value = _ref.value,
|
|
17
|
+
itemType = _ref.itemType,
|
|
18
|
+
onApply = _ref.onApply,
|
|
19
|
+
onCancel = _ref.onCancel,
|
|
20
|
+
visible = _ref.visible,
|
|
21
|
+
readOnly = _ref.readOnly,
|
|
22
|
+
texts = _ref.texts,
|
|
23
|
+
limit = _ref.limit,
|
|
24
|
+
collectorSuggestions = _ref.collectorSuggestions;
|
|
25
|
+
var _useState = useState(arrayWithUUID(value || [])),
|
|
26
|
+
arrayValue = _useState[0],
|
|
27
|
+
setArrayValue = _useState[1];
|
|
28
|
+
var _useState2 = useState('creator'),
|
|
29
|
+
currentMode = _useState2[0],
|
|
30
|
+
setCurrentMode = _useState2[1];
|
|
31
|
+
var _useState3 = useState(''),
|
|
32
|
+
searchQuery = _useState3[0],
|
|
33
|
+
setSearchQuery = _useState3[1];
|
|
34
|
+
var _useState4 = useState(),
|
|
35
|
+
rawEditorError = _useState4[0],
|
|
36
|
+
setRawEditorError = _useState4[1];
|
|
37
|
+
var isMounted = useIsMounted();
|
|
38
|
+
useEffect(function () {
|
|
39
|
+
isMounted.current && setArrayValue(arrayWithUUID(value || []));
|
|
40
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
41
|
+
}, [value, isMounted]);
|
|
42
|
+
var handleRawEditorError = function handleRawEditorError(errorMessage) {
|
|
43
|
+
setRawEditorError(errorMessage);
|
|
44
|
+
};
|
|
45
|
+
var plainArrayValue = useMemo(function () {
|
|
46
|
+
return arrayValue.map(function (item) {
|
|
47
|
+
return item.value;
|
|
48
|
+
});
|
|
49
|
+
}, [arrayValue]);
|
|
50
|
+
var handleOk = useCallback(function () {
|
|
51
|
+
onApply(plainArrayValue);
|
|
52
|
+
setCurrentMode('creator');
|
|
53
|
+
}, [onApply, plainArrayValue]);
|
|
54
|
+
var handleCancel = useCallback(function () {
|
|
55
|
+
onCancel();
|
|
56
|
+
setArrayValue(arrayWithUUID(value || []));
|
|
57
|
+
setCurrentMode('creator');
|
|
58
|
+
}, [onCancel, value]);
|
|
59
|
+
var showClearButton = !!(arrayValue != null && arrayValue.length) && !readOnly;
|
|
60
|
+
var handleClear = useCallback(function () {
|
|
61
|
+
setArrayValue([]);
|
|
62
|
+
}, []);
|
|
63
|
+
var clearButton = useMemo(function () {
|
|
64
|
+
return /*#__PURE__*/React.createElement(S.ModalFooterLeftSide, null, showClearButton && /*#__PURE__*/React.createElement(Button, {
|
|
65
|
+
onClick: handleClear,
|
|
66
|
+
"data-testid": "array-modal-clear-button",
|
|
67
|
+
type: "custom-color-ghost",
|
|
68
|
+
color: "red",
|
|
69
|
+
mode: "icon-label"
|
|
70
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
71
|
+
component: /*#__PURE__*/React.createElement(TrashM, null)
|
|
72
|
+
}), texts.array.clearButtonLabel));
|
|
73
|
+
}, [showClearButton, texts.array.clearButtonLabel, handleClear]);
|
|
74
|
+
var handleSearchQueryChange = function handleSearchQueryChange(query) {
|
|
75
|
+
setSearchQuery(query || '');
|
|
76
|
+
};
|
|
77
|
+
var handleValueChange = useCallback(function (updatedArray) {
|
|
78
|
+
setArrayValue(updatedArray);
|
|
79
|
+
setSearchQuery('');
|
|
80
|
+
}, []);
|
|
81
|
+
var mainModalContent = useMemo(function () {
|
|
82
|
+
return currentMode === 'creator' ? /*#__PURE__*/React.createElement(ArrayCreator, {
|
|
83
|
+
texts: texts,
|
|
84
|
+
readOnly: readOnly,
|
|
85
|
+
itemType: itemType,
|
|
86
|
+
value: arrayValue,
|
|
87
|
+
limit: limit,
|
|
88
|
+
searchQuery: searchQuery,
|
|
89
|
+
onValueChange: handleValueChange,
|
|
90
|
+
collectorSuggestions: collectorSuggestions
|
|
91
|
+
}) : /*#__PURE__*/React.createElement(ArrayRaw, {
|
|
92
|
+
readOnly: readOnly,
|
|
93
|
+
onError: handleRawEditorError,
|
|
94
|
+
itemType: itemType,
|
|
95
|
+
limit: limit,
|
|
96
|
+
onValueChange: handleValueChange,
|
|
97
|
+
texts: texts,
|
|
98
|
+
value: arrayValue
|
|
99
|
+
});
|
|
100
|
+
}, [currentMode, texts, readOnly, itemType, arrayValue, limit, searchQuery, handleValueChange, collectorSuggestions]);
|
|
101
|
+
return /*#__PURE__*/React.createElement(S.Modal, {
|
|
102
|
+
size: "medium",
|
|
103
|
+
title: texts.array.modalTitle,
|
|
104
|
+
headerBottomBar: /*#__PURE__*/React.createElement(S.ModalSubHeader, null, /*#__PURE__*/React.createElement(S.LeftSide, null, /*#__PURE__*/React.createElement(ButtonGroup, {
|
|
105
|
+
compact: false
|
|
106
|
+
}, /*#__PURE__*/React.createElement(ButtonToggle, {
|
|
107
|
+
disabled: !!rawEditorError,
|
|
108
|
+
mode: "icon-label",
|
|
109
|
+
type: "ghost",
|
|
110
|
+
activated: currentMode === 'creator',
|
|
111
|
+
onClick: function onClick() {
|
|
112
|
+
return setCurrentMode('creator');
|
|
113
|
+
}
|
|
114
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
115
|
+
component: /*#__PURE__*/React.createElement(EditM, null)
|
|
116
|
+
}), " ", texts.array.creatorButtonLabel), /*#__PURE__*/React.createElement(ButtonToggle, {
|
|
117
|
+
mode: "icon-label",
|
|
118
|
+
activated: currentMode === 'raw',
|
|
119
|
+
type: "ghost",
|
|
120
|
+
onClick: function onClick() {
|
|
121
|
+
return setCurrentMode('raw');
|
|
122
|
+
}
|
|
123
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
124
|
+
component: /*#__PURE__*/React.createElement(CodeM, null)
|
|
125
|
+
}), " ", texts.array.rawButtonLabel))), /*#__PURE__*/React.createElement(S.RightSide, null, rawEditorError ? /*#__PURE__*/React.createElement(IconAlert, {
|
|
126
|
+
iconAlert: true,
|
|
127
|
+
type: "alert",
|
|
128
|
+
message: rawEditorError
|
|
129
|
+
}) : /*#__PURE__*/React.createElement(React.Fragment, null, limit && /*#__PURE__*/React.createElement(ArrayLimit, {
|
|
130
|
+
limit: limit,
|
|
131
|
+
count: arrayValue.length,
|
|
132
|
+
texts: texts
|
|
133
|
+
})), /*#__PURE__*/React.createElement(CopyButton, {
|
|
134
|
+
texts: texts,
|
|
135
|
+
copyValue: (plainArrayValue == null ? void 0 : plainArrayValue.join(',')) || ''
|
|
136
|
+
}), /*#__PURE__*/React.createElement(S.SearchWrapper, null, /*#__PURE__*/React.createElement(SearchInput, {
|
|
137
|
+
disabled: currentMode === 'raw',
|
|
138
|
+
closeOnClickOutside: true,
|
|
139
|
+
value: searchQuery,
|
|
140
|
+
onChange: handleSearchQueryChange,
|
|
141
|
+
onClear: handleSearchQueryChange,
|
|
142
|
+
placeholder: texts.array.searchPlaceholder,
|
|
143
|
+
clearTooltip: texts.array.searchClearTooltip
|
|
144
|
+
})))),
|
|
145
|
+
closable: true,
|
|
146
|
+
onOk: !rawEditorError ? handleOk : undefined,
|
|
147
|
+
onCancel: handleCancel,
|
|
148
|
+
open: visible,
|
|
149
|
+
texts: {
|
|
150
|
+
okButton: texts.modalApply,
|
|
151
|
+
cancelButton: texts.modalCancel
|
|
152
|
+
},
|
|
153
|
+
bodyStyle: {
|
|
154
|
+
padding: 0
|
|
155
|
+
},
|
|
156
|
+
footer: readOnly ? null : undefined,
|
|
157
|
+
prefix: clearButton,
|
|
158
|
+
viewportHeight: MODAL_VIEWPORT_HEIGHT,
|
|
159
|
+
maxViewportHeight: currentMode === 'creator' ? MODAL_VIEWPORT_HEIGHT : undefined
|
|
160
|
+
}, /*#__PURE__*/React.createElement(React.Fragment, null, mainModalContent));
|
|
161
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { arrayWithUUID, isArrayOfNumbersAsString, sanitiseValues } from '../Array.utils';
|
|
3
|
+
import * as S from '../Array.styles';
|
|
4
|
+
export var ArrayRaw = function ArrayRaw(_ref) {
|
|
5
|
+
var _ref$value = _ref.value,
|
|
6
|
+
value = _ref$value === void 0 ? [] : _ref$value,
|
|
7
|
+
itemType = _ref.itemType,
|
|
8
|
+
onValueChange = _ref.onValueChange,
|
|
9
|
+
readOnly = _ref.readOnly,
|
|
10
|
+
texts = _ref.texts,
|
|
11
|
+
limit = _ref.limit,
|
|
12
|
+
onError = _ref.onError;
|
|
13
|
+
var ref = useRef(null);
|
|
14
|
+
var plainValues = useMemo(function () {
|
|
15
|
+
return value.map(function (item) {
|
|
16
|
+
return item.value;
|
|
17
|
+
}).join(',');
|
|
18
|
+
}, [value]);
|
|
19
|
+
var _useState = useState(plainValues || ''),
|
|
20
|
+
textareaValue = _useState[0],
|
|
21
|
+
setTextareaValue = _useState[1];
|
|
22
|
+
useEffect(function () {
|
|
23
|
+
var _ref$current;
|
|
24
|
+
if (document.activeElement !== ((_ref$current = ref.current) == null || (_ref$current = _ref$current.resizableTextArea) == null ? void 0 : _ref$current.textArea)) {
|
|
25
|
+
setTextareaValue(plainValues || '');
|
|
26
|
+
}
|
|
27
|
+
}, [plainValues]);
|
|
28
|
+
var handleChange = function handleChange(event) {
|
|
29
|
+
var stringifiedValue = event.target.value;
|
|
30
|
+
setTextareaValue(stringifiedValue);
|
|
31
|
+
if (!stringifiedValue) {
|
|
32
|
+
onError(null);
|
|
33
|
+
onValueChange([]);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
var items = (stringifiedValue == null ? void 0 : stringifiedValue.split(',')) || [];
|
|
37
|
+
var sanitisedItems = items.map(sanitiseValues);
|
|
38
|
+
var lastItemIsDelimiter = sanitisedItems.at(sanitisedItems.length - 1) === '';
|
|
39
|
+
var itemsToValidate = lastItemIsDelimiter ? [].concat(sanitisedItems.slice(0, -1)) : sanitisedItems;
|
|
40
|
+
var exceedsLimit = limit && items.length > limit;
|
|
41
|
+
if (itemType === 'number' && !isArrayOfNumbersAsString(itemsToValidate)) {
|
|
42
|
+
onError(texts.array.numericValidationError);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (exceedsLimit) {
|
|
46
|
+
onError(texts.array.limitExceeded);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
onError(null);
|
|
50
|
+
if (itemType === 'string') {
|
|
51
|
+
onValueChange(arrayWithUUID(itemsToValidate));
|
|
52
|
+
} else {
|
|
53
|
+
onValueChange(arrayWithUUID(itemsToValidate.map(function (item) {
|
|
54
|
+
return parseFloat(item);
|
|
55
|
+
})));
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return /*#__PURE__*/React.createElement(S.TextArea, {
|
|
59
|
+
ref: ref,
|
|
60
|
+
"data-testid": "array-raw-textarea",
|
|
61
|
+
readOnly: readOnly,
|
|
62
|
+
spellCheck: "false",
|
|
63
|
+
autoCapitalize: "off",
|
|
64
|
+
autoCorrect: "off",
|
|
65
|
+
autoComplete: "off",
|
|
66
|
+
onChange: !readOnly ? handleChange : undefined,
|
|
67
|
+
value: textareaValue
|
|
68
|
+
});
|
|
69
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React, { useCallback, useState } from 'react';
|
|
2
|
+
import copy from 'copy-to-clipboard';
|
|
3
|
+
import Tooltip from '@synerise/ds-tooltip';
|
|
4
|
+
import Button from '@synerise/ds-button';
|
|
5
|
+
import Icon, { CopyClipboardM } from '@synerise/ds-icon';
|
|
6
|
+
export var CopyButton = function CopyButton(_ref) {
|
|
7
|
+
var copyValue = _ref.copyValue,
|
|
8
|
+
texts = _ref.texts;
|
|
9
|
+
var _useState = useState(false),
|
|
10
|
+
tooltipVisible = _useState[0],
|
|
11
|
+
setTooltipVisible = _useState[1];
|
|
12
|
+
var _useState2 = useState(texts.array.copyTooltip),
|
|
13
|
+
tooltipTitle = _useState2[0],
|
|
14
|
+
setTooltipTitle = _useState2[1];
|
|
15
|
+
var handleCopy = useCallback(function () {
|
|
16
|
+
if (copyValue && copy(copyValue)) {
|
|
17
|
+
setTooltipTitle(texts.array.copiedTooltip);
|
|
18
|
+
setTooltipVisible(true);
|
|
19
|
+
}
|
|
20
|
+
}, [copyValue, setTooltipTitle, texts.array.copiedTooltip]);
|
|
21
|
+
var handleMouseEnter = useCallback(function (event) {
|
|
22
|
+
event.stopPropagation();
|
|
23
|
+
setTooltipTitle(texts.array.copyTooltip);
|
|
24
|
+
setTooltipVisible(true);
|
|
25
|
+
}, [setTooltipVisible, texts.array]);
|
|
26
|
+
var handleMouseLeave = useCallback(function (event) {
|
|
27
|
+
event.stopPropagation();
|
|
28
|
+
setTooltipVisible(false);
|
|
29
|
+
}, [setTooltipVisible]);
|
|
30
|
+
return /*#__PURE__*/React.createElement(Tooltip, {
|
|
31
|
+
title: tooltipTitle,
|
|
32
|
+
visible: tooltipVisible
|
|
33
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
34
|
+
onClick: handleCopy,
|
|
35
|
+
type: "ghost",
|
|
36
|
+
mode: "single-icon",
|
|
37
|
+
onMouseEnter: handleMouseEnter,
|
|
38
|
+
onMouseLeave: handleMouseLeave
|
|
39
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
40
|
+
component: /*#__PURE__*/React.createElement(CopyClipboardM, null)
|
|
41
|
+
})));
|
|
42
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { FactorsTexts } from '../../../Factors.types';
|
|
3
|
+
type UseCollectorProps = {
|
|
4
|
+
limit?: number;
|
|
5
|
+
collectorCount: number;
|
|
6
|
+
arrayValueCount?: number;
|
|
7
|
+
texts: FactorsTexts;
|
|
8
|
+
};
|
|
9
|
+
export declare const useCollector: ({ limit, collectorCount, arrayValueCount, texts }: UseCollectorProps) => {
|
|
10
|
+
disabled: boolean;
|
|
11
|
+
error: boolean;
|
|
12
|
+
errorMessage: import("react").ReactNode;
|
|
13
|
+
setHasTypeError: import("react").Dispatch<import("react").SetStateAction<boolean>>;
|
|
14
|
+
exceedsLimit: (newItems: number) => boolean;
|
|
15
|
+
addEnabled: boolean;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useState, useCallback, useMemo } from 'react';
|
|
2
|
+
export var useCollector = function useCollector(_ref) {
|
|
3
|
+
var limit = _ref.limit,
|
|
4
|
+
collectorCount = _ref.collectorCount,
|
|
5
|
+
_ref$arrayValueCount = _ref.arrayValueCount,
|
|
6
|
+
arrayValueCount = _ref$arrayValueCount === void 0 ? 0 : _ref$arrayValueCount,
|
|
7
|
+
texts = _ref.texts;
|
|
8
|
+
var _useState = useState(false),
|
|
9
|
+
hasTypeError = _useState[0],
|
|
10
|
+
setHasTypeError = _useState[1];
|
|
11
|
+
var exceedsLimit = useCallback(function (newItems) {
|
|
12
|
+
if (limit) {
|
|
13
|
+
return newItems + arrayValueCount > limit;
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
}, [arrayValueCount, limit]);
|
|
17
|
+
var collectorExceedsLimit = useMemo(function () {
|
|
18
|
+
return exceedsLimit(collectorCount);
|
|
19
|
+
}, [exceedsLimit, collectorCount]);
|
|
20
|
+
var errorMessage = useMemo(function () {
|
|
21
|
+
if (hasTypeError) {
|
|
22
|
+
return texts.array.numericValidationError;
|
|
23
|
+
}
|
|
24
|
+
if (collectorExceedsLimit) {
|
|
25
|
+
return texts.array.limitExceeded;
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
}, [hasTypeError, collectorExceedsLimit, texts.array.limitExceeded, texts.array.numericValidationError]);
|
|
29
|
+
var addEnabled = useMemo(function () {
|
|
30
|
+
return !hasTypeError && !collectorExceedsLimit;
|
|
31
|
+
}, [hasTypeError, collectorExceedsLimit]);
|
|
32
|
+
return {
|
|
33
|
+
disabled: !!(limit && arrayValueCount >= limit),
|
|
34
|
+
error: !!errorMessage,
|
|
35
|
+
errorMessage: errorMessage,
|
|
36
|
+
setHasTypeError: setHasTypeError,
|
|
37
|
+
exceedsLimit: exceedsLimit,
|
|
38
|
+
addEnabled: addEnabled
|
|
39
|
+
};
|
|
40
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { FactorValueProps } from '../Factors.types';
|
|
3
|
-
declare const FactorValue: ({ selectedFactorType, value, onChangeValue, onParamsClick, selectedFactor, textType, parameters, autocompleteText, withoutTypeSelector, texts, formulaEditor, opened, loading, factorKey, preventAutoloadData, getPopupContainerOverride, onActivate, onDeactivate, error, inputProps, allowClear, readOnly, getMenuEntryProps, relativeDateProps, }: FactorValueProps) => React.JSX.Element;
|
|
3
|
+
declare const FactorValue: ({ selectedFactorType, value, onChangeValue, onParamsClick, selectedFactor, textType, parameters, autocompleteText, withoutTypeSelector, texts, formulaEditor, opened, loading, factorKey, preventAutoloadData, getPopupContainerOverride, onActivate, onDeactivate, error, inputProps, allowClear, readOnly, getMenuEntryProps, relativeDateProps, arrayProps, }: FactorValueProps) => React.JSX.Element;
|
|
4
4
|
export default FactorValue;
|
|
@@ -27,7 +27,8 @@ var FactorValue = function FactorValue(_ref) {
|
|
|
27
27
|
_ref$readOnly = _ref.readOnly,
|
|
28
28
|
readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
|
|
29
29
|
getMenuEntryProps = _ref.getMenuEntryProps,
|
|
30
|
-
relativeDateProps = _ref.relativeDateProps
|
|
30
|
+
relativeDateProps = _ref.relativeDateProps,
|
|
31
|
+
arrayProps = _ref.arrayProps;
|
|
31
32
|
var inputType = React.useMemo(function () {
|
|
32
33
|
if (!selectedFactor) {
|
|
33
34
|
return undefined;
|
|
@@ -45,6 +46,7 @@ var FactorValue = function FactorValue(_ref) {
|
|
|
45
46
|
parameters: ['parameter', 'contextParameter'].indexOf(selectedFactorType) >= 0 ? parameters : undefined,
|
|
46
47
|
withoutTypeSelector: withoutTypeSelector,
|
|
47
48
|
texts: texts,
|
|
49
|
+
arrayProps: arrayProps,
|
|
48
50
|
formulaEditor: formulaEditor,
|
|
49
51
|
opened: opened,
|
|
50
52
|
loading: loading,
|
|
@@ -59,7 +61,7 @@ var FactorValue = function FactorValue(_ref) {
|
|
|
59
61
|
getMenuEntryProps: getMenuEntryProps,
|
|
60
62
|
inputProps: inputProps
|
|
61
63
|
}, relativeDateProps));
|
|
62
|
-
}, [selectedFactor, factorKey, value, texts, onChangeValue, textType, selectedFactorType, autocompleteText, parameters, withoutTypeSelector, inputProps, formulaEditor, opened, loading, onParamsClick, preventAutoloadData, getPopupContainerOverride, onActivate, onDeactivate, error, allowClear, readOnly, getMenuEntryProps, relativeDateProps]);
|
|
64
|
+
}, [selectedFactor, factorKey, value, texts, onChangeValue, textType, selectedFactorType, autocompleteText, parameters, withoutTypeSelector, inputProps, arrayProps, formulaEditor, opened, loading, onParamsClick, preventAutoloadData, getPopupContainerOverride, onActivate, onDeactivate, error, allowClear, readOnly, getMenuEntryProps, relativeDateProps]);
|
|
63
65
|
return /*#__PURE__*/React.createElement(S.FactorInput, {
|
|
64
66
|
inputType: selectedFactorType,
|
|
65
67
|
inputTextType: textType,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParameterGroup } from 'Factors.types';
|
|
1
|
+
import type { ParameterGroup } from '../../Factors.types';
|
|
2
2
|
import { DropdownItem } from './Parameter.types';
|
|
3
3
|
import { DividerItem, TitleItem } from './ParameterDropdown';
|
|
4
4
|
export declare const groupItems: (dropdownItems: DropdownItem<ParameterGroup>[], activeGroup: ParameterGroup | undefined) => (DropdownItem<ParameterGroup> | TitleItem | DividerItem)[];
|
package/dist/Factors.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { DefinedFactorTypes, FactorsProps, SelectedFactorType } from './Factors.types';
|
|
3
3
|
export declare const FACTOR_TYPE_MAPPING: Record<DefinedFactorTypes, SelectedFactorType>;
|
|
4
|
-
declare const Factors: ({ selectedFactorType, setSelectedFactorType, onChangeValue, onParamsClick, value, defaultFactorType, textType, unavailableFactorTypes, availableFactorTypes, parameters, autocompleteText, allowClear, withoutTypeSelector, texts, formulaEditor, opened, loading, factorKey, preventAutoloadData, onActivate, onDeactivate, getPopupContainerOverride, customFactorValueComponents, error, inputProps, readOnly, getMenuEntryProps, }: FactorsProps) => React.JSX.Element;
|
|
4
|
+
declare const Factors: ({ selectedFactorType, setSelectedFactorType, onChangeValue, onParamsClick, value, defaultFactorType, textType, unavailableFactorTypes, availableFactorTypes, parameters, autocompleteText, allowClear, withoutTypeSelector, texts, formulaEditor, opened, loading, factorKey, preventAutoloadData, onActivate, onDeactivate, getPopupContainerOverride, customFactorValueComponents, error, inputProps, arrayProps, readOnly, getMenuEntryProps, }: FactorsProps) => React.JSX.Element;
|
|
5
5
|
export default Factors;
|
package/dist/Factors.js
CHANGED
|
@@ -14,6 +14,7 @@ import NumberInput from './FactorValue/Number/NumberInput';
|
|
|
14
14
|
import DateRangeInput from './FactorValue/DateRange/DateRange';
|
|
15
15
|
import RelativeDateInput from './FactorValue/RelativeDate/RelativeDate';
|
|
16
16
|
import { useTexts } from './hooks/useTexts';
|
|
17
|
+
import { Array } from './FactorValue/Array/Array';
|
|
17
18
|
export var FACTOR_TYPE_MAPPING = {
|
|
18
19
|
text: {
|
|
19
20
|
icon: /*#__PURE__*/React.createElement(TextM, null),
|
|
@@ -48,7 +49,7 @@ export var FACTOR_TYPE_MAPPING = {
|
|
|
48
49
|
array: {
|
|
49
50
|
icon: /*#__PURE__*/React.createElement(ListM, null),
|
|
50
51
|
name: 'Array',
|
|
51
|
-
component:
|
|
52
|
+
component: Array
|
|
52
53
|
},
|
|
53
54
|
date: {
|
|
54
55
|
icon: /*#__PURE__*/React.createElement(Calendar2M, null),
|
|
@@ -97,6 +98,7 @@ var Factors = function Factors(_ref) {
|
|
|
97
98
|
customFactorValueComponents = _ref.customFactorValueComponents,
|
|
98
99
|
error = _ref.error,
|
|
99
100
|
inputProps = _ref.inputProps,
|
|
101
|
+
arrayProps = _ref.arrayProps,
|
|
100
102
|
readOnly = _ref.readOnly,
|
|
101
103
|
getMenuEntryProps = _ref.getMenuEntryProps;
|
|
102
104
|
var allTexts = useTexts(texts);
|
|
@@ -148,6 +150,7 @@ var Factors = function Factors(_ref) {
|
|
|
148
150
|
texts: allTexts,
|
|
149
151
|
opened: opened,
|
|
150
152
|
inputProps: inputProps,
|
|
153
|
+
arrayProps: arrayProps,
|
|
151
154
|
loading: loading,
|
|
152
155
|
factorKey: factorKey,
|
|
153
156
|
preventAutoloadData: preventAutoloadData,
|
package/dist/Factors.types.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { ReactText, ReactNode, ComponentType } from 'react';
|
|
2
|
+
import type { CollectorValue } from '@synerise/ds-collector';
|
|
2
3
|
import type { DateFilter, RelativeUnits } from '@synerise/ds-date-range-picker/dist/date.types';
|
|
3
|
-
import type {
|
|
4
|
+
import type { DateRangePickerTexts as DateRangeTexts } from '@synerise/ds-date-range-picker';
|
|
4
5
|
import type { MenuItemProps } from '@synerise/ds-menu';
|
|
5
6
|
import type { AutoResizeProp, InputProps } from '@synerise/ds-input';
|
|
6
7
|
import type { InformationCardProps } from '@synerise/ds-information-card';
|
|
7
8
|
import type { ListItemProps } from '@synerise/ds-list-item';
|
|
8
9
|
import type { LiteralStringUnion, DeepPartial } from '@synerise/ds-utils';
|
|
10
|
+
import type { ArrayValueElement } from './FactorValue/Array/Array.types';
|
|
9
11
|
export declare const ALL_FACTOR_TYPES: readonly ["text", "number", "parameter", "contextParameter", "dynamicKey", "formula", "array", "date", "relativeDate", "dateRange"];
|
|
10
12
|
export type FactorType = LiteralStringUnion<typeof ALL_FACTOR_TYPES[number]>;
|
|
11
13
|
export type DefinedFactorTypes = typeof ALL_FACTOR_TYPES[number];
|
|
@@ -51,7 +53,9 @@ export type ParameterItem = {
|
|
|
51
53
|
disabled?: boolean;
|
|
52
54
|
excludeFromSearchResults?: boolean;
|
|
53
55
|
};
|
|
54
|
-
export type
|
|
56
|
+
export type ArrayItemType = 'string' | 'number';
|
|
57
|
+
export type ArrayValue = ArrayValueElement<'string'>[] | ArrayValueElement<'number'>[];
|
|
58
|
+
export type FactorValueType = string | number | null | Date | RelativeDateValueType | undefined | DynamicKeyValueType | FormulaValueType | ArrayValue | ParameterValueType | Partial<DateFilter>;
|
|
55
59
|
export type SelectedFactorType = {
|
|
56
60
|
name: string;
|
|
57
61
|
icon: ReactNode;
|
|
@@ -89,6 +93,29 @@ export type FactorsTexts = {
|
|
|
89
93
|
buttonPlaceholder: string;
|
|
90
94
|
defaultName: string;
|
|
91
95
|
};
|
|
96
|
+
array: {
|
|
97
|
+
triggerLabel: ReactNode;
|
|
98
|
+
modalTitle: ReactNode;
|
|
99
|
+
emptyTitle: ReactNode;
|
|
100
|
+
emptyDescription: ReactNode;
|
|
101
|
+
emptyResultsTitle: ReactNode;
|
|
102
|
+
emptyResultsDescription: ReactNode;
|
|
103
|
+
searchPlaceholder: string;
|
|
104
|
+
searchClearTooltip: ReactNode;
|
|
105
|
+
limitPrefix: ReactNode;
|
|
106
|
+
collectorPlaceholder: string;
|
|
107
|
+
collectorAdd: ReactNode;
|
|
108
|
+
collectorCancel: ReactNode;
|
|
109
|
+
creatorButtonLabel: ReactNode;
|
|
110
|
+
rawButtonLabel: ReactNode;
|
|
111
|
+
clearButtonLabel: ReactNode;
|
|
112
|
+
deleteItemTooltip: ReactNode;
|
|
113
|
+
numericValidationError: ReactNode;
|
|
114
|
+
limitReached: ReactNode;
|
|
115
|
+
limitExceeded: ReactNode;
|
|
116
|
+
copiedTooltip: ReactNode;
|
|
117
|
+
copyTooltip: ReactNode;
|
|
118
|
+
};
|
|
92
119
|
parameter: {
|
|
93
120
|
searchPlaceholder: string;
|
|
94
121
|
noResults: string;
|
|
@@ -107,6 +134,11 @@ export type FactorsTexts = {
|
|
|
107
134
|
};
|
|
108
135
|
};
|
|
109
136
|
export type FactorTypeMapping = Record<DefinedFactorTypes, Partial<SelectedFactorType>>;
|
|
137
|
+
export type ArrayProps = {
|
|
138
|
+
itemType?: ArrayItemType;
|
|
139
|
+
limit?: number;
|
|
140
|
+
collectorSuggestions?: CollectorValue[];
|
|
141
|
+
};
|
|
110
142
|
export type FactorsProps = {
|
|
111
143
|
factorKey?: ReactText;
|
|
112
144
|
error?: boolean;
|
|
@@ -123,6 +155,7 @@ export type FactorsProps = {
|
|
|
123
155
|
onDeactivate?: () => void;
|
|
124
156
|
onChangeValue: (value: FactorValueType) => void;
|
|
125
157
|
value: FactorValueType;
|
|
158
|
+
arrayProps?: ArrayProps;
|
|
126
159
|
textType?: LiteralStringUnion<'autocomplete' | 'expansible' | 'default'>;
|
|
127
160
|
autoResize?: AutoResizeProp;
|
|
128
161
|
relativeDateProps?: {
|
|
@@ -166,11 +199,11 @@ export type FactorTypeSelectorProps = Pick<FactorsProps, 'unavailableFactorTypes
|
|
|
166
199
|
[k in DefinedFactorTypes]: string;
|
|
167
200
|
};
|
|
168
201
|
};
|
|
169
|
-
export type FactorValueProps = Pick<FactorsProps, 'onChangeValue' | 'onParamsClick' | 'value' | 'selectedFactorType' | 'parameters' | 'autocompleteText' | 'withoutTypeSelector' | 'textType' | 'formulaEditor' | 'opened' | 'loading' | 'factorKey' | 'preventAutoloadData' | 'getPopupContainerOverride' | 'onActivate' | 'onDeactivate' | 'error' | 'allowClear' | 'inputProps' | 'autoResize' | 'readOnly' | 'relativeDateProps' | 'getMenuEntryProps'> & {
|
|
202
|
+
export type FactorValueProps = Pick<FactorsProps, 'onChangeValue' | 'onParamsClick' | 'value' | 'selectedFactorType' | 'parameters' | 'autocompleteText' | 'withoutTypeSelector' | 'textType' | 'formulaEditor' | 'opened' | 'loading' | 'factorKey' | 'preventAutoloadData' | 'getPopupContainerOverride' | 'onActivate' | 'onDeactivate' | 'error' | 'allowClear' | 'inputProps' | 'autoResize' | 'readOnly' | 'relativeDateProps' | 'arrayProps' | 'getMenuEntryProps'> & {
|
|
170
203
|
texts: FactorsTexts;
|
|
171
204
|
selectedFactor: SelectedFactorType;
|
|
172
205
|
};
|
|
173
|
-
export type FactorValueComponentProps = Pick<FactorsProps, 'value' | 'parameters' | 'allowClear' | 'autocompleteText' | 'withoutTypeSelector' | 'textType' | 'opened' | 'getPopupContainerOverride' | 'onActivate' | 'onDeactivate' | 'error' | 'inputProps' | 'autoResize' | 'readOnly' | 'getMenuEntryProps'> & {
|
|
206
|
+
export type FactorValueComponentProps = Pick<FactorsProps, 'value' | 'parameters' | 'allowClear' | 'autocompleteText' | 'withoutTypeSelector' | 'textType' | 'opened' | 'getPopupContainerOverride' | 'onActivate' | 'onDeactivate' | 'error' | 'inputProps' | 'autoResize' | 'readOnly' | 'arrayProps' | 'getMenuEntryProps'> & {
|
|
174
207
|
texts: FactorsTexts;
|
|
175
208
|
onChange: (value: FactorValueType) => void;
|
|
176
209
|
factorType: FactorType;
|
package/dist/hooks/useTexts.d.ts
CHANGED
package/dist/hooks/useTexts.js
CHANGED
|
@@ -107,6 +107,92 @@ export var useTexts = function useTexts(defaultTexts) {
|
|
|
107
107
|
defaultMessage: 'Formula'
|
|
108
108
|
})
|
|
109
109
|
},
|
|
110
|
+
array: {
|
|
111
|
+
triggerLabel: intl.formatMessage({
|
|
112
|
+
id: 'DS.FACTORS.ARRAY.TRIGGER_LABEL',
|
|
113
|
+
defaultMessage: 'Define array'
|
|
114
|
+
}),
|
|
115
|
+
modalTitle: intl.formatMessage({
|
|
116
|
+
id: 'DS.FACTORS.ARRAY.MODAL_TITLE',
|
|
117
|
+
defaultMessage: 'Array'
|
|
118
|
+
}),
|
|
119
|
+
clearButtonLabel: intl.formatMessage({
|
|
120
|
+
id: 'DS.FACTORS.ARRAY.CLEAR_BUTTON',
|
|
121
|
+
defaultMessage: 'Clear all'
|
|
122
|
+
}),
|
|
123
|
+
creatorButtonLabel: intl.formatMessage({
|
|
124
|
+
id: 'DS.FACTORS.ARRAY.CREATOR',
|
|
125
|
+
defaultMessage: 'Creator'
|
|
126
|
+
}),
|
|
127
|
+
rawButtonLabel: intl.formatMessage({
|
|
128
|
+
id: 'DS.FACTORS.ARRAY.RAW_BUTTON_LABEL',
|
|
129
|
+
defaultMessage: 'Raw'
|
|
130
|
+
}),
|
|
131
|
+
searchPlaceholder: intl.formatMessage({
|
|
132
|
+
id: 'DS.FACTORS.ARRAY.SEARCH_PLACEHOLDER',
|
|
133
|
+
defaultMessage: 'Search'
|
|
134
|
+
}),
|
|
135
|
+
collectorPlaceholder: intl.formatMessage({
|
|
136
|
+
id: 'DS.FACTORS.ARRAY.COLLECTOR_PLACEHOLDER',
|
|
137
|
+
defaultMessage: 'Type value or paste multiple values separated by `,`'
|
|
138
|
+
}),
|
|
139
|
+
collectorAdd: intl.formatMessage({
|
|
140
|
+
id: 'DS.FACTORS.ARRAY.COLLECTOR_ADD',
|
|
141
|
+
defaultMessage: 'Add'
|
|
142
|
+
}),
|
|
143
|
+
collectorCancel: intl.formatMessage({
|
|
144
|
+
id: 'DS.FACTORS.ARRAY.COLLECTOR_CANCEL',
|
|
145
|
+
defaultMessage: 'Cancel'
|
|
146
|
+
}),
|
|
147
|
+
searchClearTooltip: intl.formatMessage({
|
|
148
|
+
id: 'DS.FACTORS.ARRAY.SEARCH_CLEAR_TOOLTIP',
|
|
149
|
+
defaultMessage: 'Clear'
|
|
150
|
+
}),
|
|
151
|
+
deleteItemTooltip: intl.formatMessage({
|
|
152
|
+
id: 'DS.FACTORS.ARRAY.DELETE_ITEM_TOOLTIP',
|
|
153
|
+
defaultMessage: 'Delete'
|
|
154
|
+
}),
|
|
155
|
+
emptyTitle: intl.formatMessage({
|
|
156
|
+
id: 'DS.FACTORS.ARRAY.EMPTY_TITLE',
|
|
157
|
+
defaultMessage: 'No items defined yet'
|
|
158
|
+
}),
|
|
159
|
+
emptyDescription: intl.formatMessage({
|
|
160
|
+
id: 'DS.FACTORS.ARRAY.EMPTY_DESCRIPTION',
|
|
161
|
+
defaultMessage: 'This is a simple empty state example text. You can easily change it.'
|
|
162
|
+
}),
|
|
163
|
+
emptyResultsTitle: intl.formatMessage({
|
|
164
|
+
id: 'DS.FACTORS.ARRAY.EMPTY_RESULTS_TITLE',
|
|
165
|
+
defaultMessage: 'No items match your query'
|
|
166
|
+
}),
|
|
167
|
+
emptyResultsDescription: intl.formatMessage({
|
|
168
|
+
id: 'DS.FACTORS.ARRAY.EMPTY_RESULTS_DESCRIPTION',
|
|
169
|
+
defaultMessage: 'This is a simple empty state example text. You can easily change it.'
|
|
170
|
+
}),
|
|
171
|
+
limitPrefix: intl.formatMessage({
|
|
172
|
+
id: 'DS.FACTORS.ARRAY.LIMIT_PREFIX',
|
|
173
|
+
defaultMessage: 'Limit'
|
|
174
|
+
}),
|
|
175
|
+
numericValidationError: intl.formatMessage({
|
|
176
|
+
id: 'DS.FACTORS.ARRAY.NUMERIC_VALIDATION_ERROR',
|
|
177
|
+
defaultMessage: 'Some of the values are not a number'
|
|
178
|
+
}),
|
|
179
|
+
limitReached: intl.formatMessage({
|
|
180
|
+
id: 'DS.FACTORS.ARRAY.LIMIT_REACHED',
|
|
181
|
+
defaultMessage: 'Limit has been reached'
|
|
182
|
+
}),
|
|
183
|
+
limitExceeded: intl.formatMessage({
|
|
184
|
+
id: 'DS.FACTORS.ARRAY.LIMIT_EXCEEDED',
|
|
185
|
+
defaultMessage: 'Adding these items will exceed maximum items limit'
|
|
186
|
+
}),
|
|
187
|
+
copiedTooltip: intl.formatMessage({
|
|
188
|
+
id: 'DS.FACTORS.ARRAY.COPIED',
|
|
189
|
+
defaultMessage: 'Copied'
|
|
190
|
+
}),
|
|
191
|
+
copyTooltip: intl.formatMessage({
|
|
192
|
+
id: 'DS.FACTORS.ARRAY.COPY-VALUE',
|
|
193
|
+
defaultMessage: 'Copy value'
|
|
194
|
+
})
|
|
195
|
+
},
|
|
110
196
|
parameter: {
|
|
111
197
|
searchPlaceholder: intl.formatMessage({
|
|
112
198
|
id: 'DS.FACTORS.PARAMETER.SEARCH_PLACEHOLDER',
|