@antscorp/antsomi-ui 1.3.5-beta.988 → 1.3.5-beta.990
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/es/components/molecules/CodeStructure/CodeStructure.js +33 -28
- package/es/components/molecules/CodeStructure/index.d.ts +2 -0
- package/es/components/molecules/CodeStructure/index.js +1 -0
- package/es/components/molecules/CodeStructure/type.d.ts +10 -10
- package/es/components/molecules/CodeStructure/type.js +8 -8
- package/es/components/molecules/index.d.ts +1 -0
- package/es/components/molecules/index.js +1 -0
- package/es/hooks/index.d.ts +1 -0
- package/es/hooks/index.js +1 -0
- package/es/hooks/useDebouncedCallbackV2.d.ts +3 -0
- package/es/hooks/useDebouncedCallbackV2.js +9 -0
- package/package.json +1 -1
|
@@ -11,13 +11,14 @@ import { RefillUnitType } from './type';
|
|
|
11
11
|
// Constants
|
|
12
12
|
import { CAPITALIZATION_OPTIONS, CHARACTER_ORDER_OPTIONS, CHARACTER_TYPE_OPTIONS, REFILL_UNIT_OPTIONS, SEPARATOR_OPTIONS, } from './constants';
|
|
13
13
|
import { CodeStructureWrapper } from './styled';
|
|
14
|
+
import { useDebouncedCallbackV2 } from '@antscorp/antsomi-ui/es/hooks';
|
|
14
15
|
const { Title } = Typography;
|
|
15
16
|
export const CodeStructure = ({ initialData, onChange }) => {
|
|
16
17
|
const [form] = Form.useForm();
|
|
17
18
|
const [state, setState] = useImmer({
|
|
18
19
|
codeSample: '',
|
|
19
20
|
maxCodes: 0,
|
|
20
|
-
refillThreshold:
|
|
21
|
+
refillThreshold: 0,
|
|
21
22
|
refillInterval: 'auto',
|
|
22
23
|
refillUnit: 'codes',
|
|
23
24
|
codeWithPrefixAndSuffix: '',
|
|
@@ -33,12 +34,10 @@ export const CodeStructure = ({ initialData, onChange }) => {
|
|
|
33
34
|
draft.maxCodes = value;
|
|
34
35
|
});
|
|
35
36
|
};
|
|
36
|
-
/** *********** ✨ Codeium Command ⭐ ************ */
|
|
37
37
|
/**
|
|
38
38
|
* Update the code sample with prefix and suffix
|
|
39
39
|
* @param {string} value The new value of code sample with prefix and suffix
|
|
40
40
|
*/
|
|
41
|
-
/** **** 99b15217-c7a7-4093-8b8f-ea4b4271af48 ****** */
|
|
42
41
|
const setCodeWithPrefixAndSuffix = (value) => {
|
|
43
42
|
setState(draft => {
|
|
44
43
|
draft.codeWithPrefixAndSuffix = value;
|
|
@@ -50,54 +49,56 @@ export const CodeStructure = ({ initialData, onChange }) => {
|
|
|
50
49
|
});
|
|
51
50
|
}, [setState]);
|
|
52
51
|
const setRefillUnit = useCallback((value) => {
|
|
52
|
+
if (value === RefillUnitType.PERCENT) {
|
|
53
|
+
setRefillThreshold(1);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
setRefillThreshold(0);
|
|
57
|
+
}
|
|
53
58
|
setState(draft => {
|
|
54
59
|
draft.refillUnit = value;
|
|
55
60
|
});
|
|
56
|
-
}, [setState]);
|
|
61
|
+
}, [setState, setRefillThreshold]);
|
|
62
|
+
const debouncedOnChange = useDebouncedCallbackV2(onChange, 350);
|
|
57
63
|
const updateFormValues = (data) => {
|
|
58
64
|
const allValues = form.getFieldsValue();
|
|
65
|
+
const numLetters = form.getFieldValue('alphabetLetters');
|
|
66
|
+
const numDigits = form.getFieldValue('digitalNumbers');
|
|
67
|
+
const type = form.getFieldValue('characterType');
|
|
59
68
|
form.setFieldsValue(allValues);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
...(allValues.refillInterval === 'auto' ? { refillThreshold, refillUnit } : {}),
|
|
63
|
-
};
|
|
64
|
-
onChange(dataOnChange);
|
|
69
|
+
let totalPredicted = maxCodes;
|
|
70
|
+
const isRelevantChangeMaxCode = Object.keys(data).some(key => key === 'alphabetLetters' || key === 'digitalNumbers' || key === 'characterType');
|
|
65
71
|
const isRelevantChangeCodeKey = Object.keys(data).some(key => key !== 'quantity' &&
|
|
66
72
|
key !== 'suffix' &&
|
|
67
73
|
key !== 'prefix' &&
|
|
68
74
|
key !== 'refillInterval' &&
|
|
69
75
|
key !== 'separator');
|
|
70
76
|
const isChangePrefix = Object.keys(data).some(key => key === 'suffix' || key === 'prefix' || key === 'separator');
|
|
77
|
+
if (isRelevantChangeMaxCode) {
|
|
78
|
+
const total = calculateTotalCodes(numLetters, numDigits, type);
|
|
79
|
+
totalPredicted = total;
|
|
80
|
+
setMaxCodes(total);
|
|
81
|
+
}
|
|
71
82
|
if (isRelevantChangeCodeKey) {
|
|
72
83
|
setCodeSample(generateRandomCodeWithConfig(form.getFieldsValue()));
|
|
73
84
|
}
|
|
74
85
|
if (isChangePrefix) {
|
|
75
86
|
setCodeWithPrefixAndSuffix(generateCodeWithPrefixAndSuffix(codeSample, form.getFieldValue('prefix'), form.getFieldValue('suffix'), form.getFieldValue('separator')));
|
|
76
87
|
}
|
|
88
|
+
const dataOnChange = {
|
|
89
|
+
...allValues,
|
|
90
|
+
totalPredicted,
|
|
91
|
+
...(allValues.refillInterval === 'auto' ? { refillThreshold, refillUnit } : {}),
|
|
92
|
+
};
|
|
93
|
+
debouncedOnChange(dataOnChange);
|
|
77
94
|
};
|
|
78
|
-
const computeTotalCodes = useCallback(() => {
|
|
79
|
-
const numLetters = form.getFieldValue('alphabetLetters');
|
|
80
|
-
const numDigits = form.getFieldValue('digitalNumbers');
|
|
81
|
-
const type = form.getFieldValue('characterType');
|
|
82
|
-
if (numLetters && numDigits && type) {
|
|
83
|
-
const total = calculateTotalCodes(numLetters, numDigits, type);
|
|
84
|
-
setMaxCodes(total);
|
|
85
|
-
}
|
|
86
|
-
}, [form]);
|
|
87
95
|
// Effects
|
|
88
96
|
useEffect(() => {
|
|
89
|
-
setRefillThreshold(initialData.refillThreshold ||
|
|
97
|
+
setRefillThreshold(initialData.refillThreshold || 0);
|
|
90
98
|
}, [initialData.refillThreshold, setRefillThreshold]);
|
|
91
99
|
useEffect(() => {
|
|
92
100
|
setRefillUnit(initialData.refillUnit || RefillUnitType.CODES);
|
|
93
101
|
}, [initialData.refillUnit, setRefillUnit]);
|
|
94
|
-
useEffect(() => {
|
|
95
|
-
computeTotalCodes();
|
|
96
|
-
}, [
|
|
97
|
-
form.getFieldValue('alphabetLetters'),
|
|
98
|
-
form.getFieldValue('digitalNumbers'),
|
|
99
|
-
form.getFieldValue('characterType'),
|
|
100
|
-
]);
|
|
101
102
|
useEffect(() => {
|
|
102
103
|
setCodeSample(generateRandomCodeWithConfig(form.getFieldsValue()));
|
|
103
104
|
setMaxCodes(calculateTotalCodes(form.getFieldValue('alphabetLetters'), form.getFieldValue('digitalNumbers'), form.getFieldValue('characterType')));
|
|
@@ -105,7 +106,11 @@ export const CodeStructure = ({ initialData, onChange }) => {
|
|
|
105
106
|
useEffect(() => {
|
|
106
107
|
form.setFieldsValue(initialData);
|
|
107
108
|
}, [initialData, form]);
|
|
108
|
-
return (_jsx(CodeStructureWrapper, { children: _jsxs(Form, { form: form, layout: "horizontal", labelCol: { span:
|
|
109
|
+
return (_jsx(CodeStructureWrapper, { children: _jsxs(Form, { form: form, layout: "horizontal", labelCol: { span: 6 }, colon: false, wrapperCol: { span: 24 }, labelAlign: "left", initialValues: initialData, onValuesChange: updateFormValues, children: [_jsx(Title, { level: 5, children: translate(translations._POOL_RULE_SETTING_CODE_STRUCTURE, 'Code Structure') }), _jsx(Form.Item, { label: translate(translations._POOL_RULE_SETTING_CODE_STRUCTURE_PREFIX, 'Prefix'), name: "prefix", children: _jsx(Input, { placeholder: "", style: {
|
|
110
|
+
maxWidth: 465,
|
|
111
|
+
} }) }), _jsxs(Row, { children: [_jsx(Col, { span: 6, offset: 0, children: translate(translations._POOL_RULE_SETTING_CODE_STRUCTURE_INFIX, 'Infix') }), _jsx(Col, { span: 16, offset: 0, children: _jsxs(Flex, { vertical: true, gap: 10, children: [_jsx(Row, { children: _jsx(Col, { offset: 0, children: translate(translations._POOL_RULE_SETTING_CODE_STRUCTURE_CHAC_TYPE, 'Character Type') }) }), _jsx(Form.Item, { name: "characterType", children: _jsx(Radio.Group, { options: CHARACTER_TYPE_OPTIONS }) })] }) })] }), _jsx(Row, { children: _jsx(Col, { offset: 6, children: _jsxs(Flex, { gap: 10, align: "center", children: [_jsx(Form.Item, { name: "digitalNumbers", children: _jsx(InputNumber, { min: 1, max: 50, style: { width: '40px' } }) }), _jsx("div", { style: { marginBottom: '15px' }, children: translate(translations._POOL_RULE_SETTING_CODE_STRUCTURE_CHAC_TYPE_DIG_NO, 'digital numbers') })] }) }) }), _jsx(Row, { children: _jsx(Col, { offset: 6, children: _jsxs(Flex, { gap: 10, align: "center", children: [_jsx(Form.Item, { name: "alphabetLetters", children: _jsx(InputNumber, { min: 1, max: 50, style: { width: '40px' } }) }), _jsx("div", { style: { marginBottom: '15px' }, children: translate(translations._POOL_RULE_SETTING_CODE_STRUCTURE_CHAC_TYPE_LET_NO, 'alphabet letters') })] }) }) }), _jsxs(Flex, { vertical: true, gap: 10, children: [_jsx(Row, { children: _jsx(Col, { offset: 6, children: translate(translations._POOL_RULE_SETTING_CODE_STRUCTURE_CAP, 'Letters Capitalization') }) }), _jsx(Form.Item, { label: _jsx("span", { children: "\u00A0" }), name: "capitalization", children: _jsx(Radio.Group, { options: CAPITALIZATION_OPTIONS }) })] }), _jsxs(Flex, { vertical: true, gap: 10, children: [_jsx(Row, { children: _jsx(Col, { offset: 6, children: translate(translations._POOL_RULE_SETTING_CODE_STRUCTURE_CHAC_ORDER, 'Character Order') }) }), _jsx(Form.Item, { label: _jsx("span", { children: "\u00A0" }), name: "characterOrder", children: _jsx(Radio.Group, { options: CHARACTER_ORDER_OPTIONS }) })] }), _jsx(Form.Item, { label: translate(translations._POOL_RULE_SETTING_CODE_STRUCTURE_SUFFIX, 'Suffix'), name: "suffix", children: _jsx(Input, { placeholder: "", style: {
|
|
112
|
+
maxWidth: 465,
|
|
113
|
+
} }) }), _jsx(Form.Item, { label: translate(translations._POOL_RULE_SETTING_CODE_STRUCTURE_SEPARATOR, 'Separator'), name: "separator", children: _jsx(Select, { options: SEPARATOR_OPTIONS, style: { width: '180px' } }) }), _jsxs(Row, { children: [_jsx(Col, { span: 6, children: _jsxs(Flex, { justify: "start", align: "center", gap: 5, children: [translate(translations._POOL_RULE_SETTING_CODE_STRUCTURE_QUANTITY, 'Quantity'), ' ', _jsx("span", { style: { color: 'red' }, children: "*" })] }) }), _jsx(Col, { children: _jsxs(Flex, { gap: 10, align: "center", children: [_jsx(Form.Item, { name: "quantity", children: _jsx(InputNumber, { min: 1, max: 10000 }) }), _jsx("div", { style: { marginBottom: '15px' }, children: "code(s) per time" })] }) })] }), _jsxs(Form.Item, { label: translate(translations._ACT_PREVIEW, 'Preview'), children: ["Maximum of ", _jsx("b", { children: maxCodes.toLocaleString() }), " codes (sample", ' ', generateCodeWithPrefixAndSuffix(codeSample, form.getFieldValue('prefix'), form.getFieldValue('suffix'), form.getFieldValue('separator')), ") to be generated"] }), _jsx(Title, { level: 5, children: "Code Refill" }), _jsx(Form.Item, { label: "Refill Interval", name: "refillInterval", children: _jsxs(Radio.Group, { style: { display: 'flex', flexDirection: 'column', gap: '10px' }, onChange: e => {
|
|
109
114
|
e.preventDefault();
|
|
110
|
-
}, children: [_jsx(Radio, { value: "manual", children: "Manual refill only" }), _jsx(Radio, { value: "auto", children: _jsxs(Flex, { gap: 10, align: "center", children: [_jsx(Typography.Text, { style: { whiteSpace: 'nowrap' }, children: "Add codes when less than" }), _jsx(InputNumber, { min: 1, max:
|
|
115
|
+
}, children: [_jsx(Radio, { value: "manual", children: "Manual refill only" }), _jsx(Radio, { value: "auto", children: _jsxs(Flex, { gap: 10, align: "center", children: [_jsx(Typography.Text, { style: { whiteSpace: 'nowrap' }, children: "Add codes when less than" }), _jsx(InputNumber, { min: refillUnit === RefillUnitType.CODES ? 0 : 1, max: refillUnit === RefillUnitType.PERCENT ? 100 : undefined, style: { width: '63px' }, value: refillThreshold, onChange: value => setRefillThreshold(value || 1) }), _jsx(Select, { onClick: e => e.preventDefault(), value: refillUnit, onChange: setRefillUnit, options: REFILL_UNIT_OPTIONS, style: { width: '63px' } }), "remaining"] }) })] }) })] }) }));
|
|
111
116
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CodeStructure } from './CodeStructure';
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
export declare enum CharacterType {
|
|
2
|
-
DIGITS = "
|
|
2
|
+
DIGITS = "numbers",
|
|
3
3
|
LETTERS = "letters",
|
|
4
|
-
DIGIT_AND_LETTERS = "
|
|
4
|
+
DIGIT_AND_LETTERS = "both"
|
|
5
5
|
}
|
|
6
6
|
export declare enum CharacterOrderType {
|
|
7
7
|
RANDOM = "random",
|
|
8
|
-
LETTER_FIRST = "
|
|
9
|
-
NUMBER_FIRST = "
|
|
8
|
+
LETTER_FIRST = "letters_first",
|
|
9
|
+
NUMBER_FIRST = "numbers_first"
|
|
10
10
|
}
|
|
11
11
|
export declare enum CapitalizationType {
|
|
12
|
-
UPPERCASE = "
|
|
13
|
-
LOWERCASE = "
|
|
14
|
-
TITLE_CASE = "
|
|
12
|
+
UPPERCASE = "upper",
|
|
13
|
+
LOWERCASE = "lower",
|
|
14
|
+
TITLE_CASE = "title"
|
|
15
15
|
}
|
|
16
16
|
export declare enum SeparatorType {
|
|
17
17
|
HYPHEN = "hyphen",
|
|
18
|
-
UNDERSCORE = "
|
|
18
|
+
UNDERSCORE = "under_score",
|
|
19
19
|
DOT = "dot",
|
|
20
20
|
NONE = "none"
|
|
21
21
|
}
|
|
@@ -35,9 +35,9 @@ export interface CodeStructureData {
|
|
|
35
35
|
characterOrder: CharacterOrderType;
|
|
36
36
|
separator: SeparatorType;
|
|
37
37
|
quantity: number;
|
|
38
|
-
suffix
|
|
38
|
+
suffix?: string;
|
|
39
39
|
refillInterval: RefillType;
|
|
40
|
-
prefix
|
|
40
|
+
prefix?: string;
|
|
41
41
|
refillThreshold?: number;
|
|
42
42
|
refillUnit?: RefillUnitType;
|
|
43
43
|
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
export var CharacterType;
|
|
2
2
|
(function (CharacterType) {
|
|
3
|
-
CharacterType["DIGITS"] = "
|
|
3
|
+
CharacterType["DIGITS"] = "numbers";
|
|
4
4
|
CharacterType["LETTERS"] = "letters";
|
|
5
|
-
CharacterType["DIGIT_AND_LETTERS"] = "
|
|
5
|
+
CharacterType["DIGIT_AND_LETTERS"] = "both";
|
|
6
6
|
})(CharacterType || (CharacterType = {}));
|
|
7
7
|
export var CharacterOrderType;
|
|
8
8
|
(function (CharacterOrderType) {
|
|
9
9
|
CharacterOrderType["RANDOM"] = "random";
|
|
10
|
-
CharacterOrderType["LETTER_FIRST"] = "
|
|
11
|
-
CharacterOrderType["NUMBER_FIRST"] = "
|
|
10
|
+
CharacterOrderType["LETTER_FIRST"] = "letters_first";
|
|
11
|
+
CharacterOrderType["NUMBER_FIRST"] = "numbers_first";
|
|
12
12
|
})(CharacterOrderType || (CharacterOrderType = {}));
|
|
13
13
|
export var CapitalizationType;
|
|
14
14
|
(function (CapitalizationType) {
|
|
15
|
-
CapitalizationType["UPPERCASE"] = "
|
|
16
|
-
CapitalizationType["LOWERCASE"] = "
|
|
17
|
-
CapitalizationType["TITLE_CASE"] = "
|
|
15
|
+
CapitalizationType["UPPERCASE"] = "upper";
|
|
16
|
+
CapitalizationType["LOWERCASE"] = "lower";
|
|
17
|
+
CapitalizationType["TITLE_CASE"] = "title";
|
|
18
18
|
})(CapitalizationType || (CapitalizationType = {}));
|
|
19
19
|
export var SeparatorType;
|
|
20
20
|
(function (SeparatorType) {
|
|
21
21
|
SeparatorType["HYPHEN"] = "hyphen";
|
|
22
|
-
SeparatorType["UNDERSCORE"] = "
|
|
22
|
+
SeparatorType["UNDERSCORE"] = "under_score";
|
|
23
23
|
SeparatorType["DOT"] = "dot";
|
|
24
24
|
SeparatorType["NONE"] = "none";
|
|
25
25
|
})(SeparatorType || (SeparatorType = {}));
|
|
@@ -66,6 +66,7 @@ export * from './EmojiCollections';
|
|
|
66
66
|
export * from './EmojiPopover';
|
|
67
67
|
export * from './DisplayFormat';
|
|
68
68
|
export { default as InputSelectAttribute } from './InputSelectAttribute';
|
|
69
|
+
export * from './CodeStructure';
|
|
69
70
|
export { EditorScript } from './EditorScript';
|
|
70
71
|
export { EditorTab } from './EditorTab';
|
|
71
72
|
export { SelectAccount } from './SelectAccount';
|
|
@@ -66,6 +66,7 @@ export * from './EmojiCollections';
|
|
|
66
66
|
export * from './EmojiPopover';
|
|
67
67
|
export * from './DisplayFormat';
|
|
68
68
|
export { default as InputSelectAttribute } from './InputSelectAttribute';
|
|
69
|
+
export * from './CodeStructure';
|
|
69
70
|
export { EditorScript } from './EditorScript';
|
|
70
71
|
export { EditorTab } from './EditorTab';
|
|
71
72
|
export { SelectAccount } from './SelectAccount';
|
package/es/hooks/index.d.ts
CHANGED
package/es/hooks/index.js
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useCallback, useRef } from 'react';
|
|
2
|
+
export const useDebouncedCallbackV2 = (func, wait) => {
|
|
3
|
+
const timeout = useRef();
|
|
4
|
+
const debouncedFunc = (arg) => {
|
|
5
|
+
clearTimeout(timeout.current);
|
|
6
|
+
timeout.current = setTimeout(() => func(arg), wait);
|
|
7
|
+
};
|
|
8
|
+
return useCallback(debouncedFunc, [func, wait]);
|
|
9
|
+
};
|