@gravity-ui/dynamic-forms 1.0.2 → 1.1.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/build/cjs/lib/core/components/Form/Controller.js +10 -2
- package/build/cjs/lib/core/components/Form/DynamicField.js +1 -1
- package/build/cjs/lib/core/components/Form/hooks/useField.js +11 -3
- package/build/cjs/lib/core/components/Form/hooks/useStore.js +2 -8
- package/build/cjs/lib/kit/components/Inputs/ArrayBase/ArrayBase.js +4 -3
- package/build/cjs/lib/kit/components/Inputs/CardOneOf/CardOneOf.js +2 -1
- package/build/cjs/lib/kit/components/Inputs/ObjectBase/ObjectBase.js +11 -2
- package/build/cjs/lib/kit/components/Inputs/OneOf/OneOf.js +2 -1
- package/build/cjs/lib/kit/components/Inputs/OneOfCard/OneOfCard.js +2 -1
- package/build/cjs/lib/kit/components/Inputs/Secret/Secret.js +2 -1
- package/build/cjs/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.js +3 -2
- package/build/cjs/lib/kit/components/Layouts/Row/Row.css +9 -0
- package/build/cjs/lib/kit/components/Layouts/Row/Row.js +11 -6
- package/build/cjs/lib/kit/constants/config.js +5 -0
- package/build/esm/lib/core/components/Form/Controller.d.ts +2 -1
- package/build/esm/lib/core/components/Form/Controller.js +10 -2
- package/build/esm/lib/core/components/Form/DynamicField.js +1 -1
- package/build/esm/lib/core/components/Form/hooks/useField.d.ts +2 -1
- package/build/esm/lib/core/components/Form/hooks/useField.js +11 -3
- package/build/esm/lib/core/components/Form/hooks/useStore.js +2 -8
- package/build/esm/lib/kit/components/Inputs/ArrayBase/ArrayBase.js +4 -3
- package/build/esm/lib/kit/components/Inputs/CardOneOf/CardOneOf.js +2 -1
- package/build/esm/lib/kit/components/Inputs/ObjectBase/ObjectBase.js +11 -2
- package/build/esm/lib/kit/components/Inputs/OneOf/OneOf.js +2 -1
- package/build/esm/lib/kit/components/Inputs/OneOfCard/OneOfCard.js +2 -1
- package/build/esm/lib/kit/components/Inputs/Secret/Secret.js +2 -1
- package/build/esm/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.js +3 -2
- package/build/esm/lib/kit/components/Layouts/Row/Row.css +9 -0
- package/build/esm/lib/kit/components/Layouts/Row/Row.d.ts +2 -1
- package/build/esm/lib/kit/components/Layouts/Row/Row.js +9 -5
- package/build/esm/lib/kit/constants/config.js +6 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.1.1](https://github.com/gravity-ui/dynamic-forms/compare/v1.1.0...v1.1.1) (2023-03-21)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* fix incorrect unmount ([#12](https://github.com/gravity-ui/dynamic-forms/issues/12)) ([592652b](https://github.com/gravity-ui/dynamic-forms/commit/592652b2814567b2188ec43779eb591b7dec6ade))
|
|
9
|
+
|
|
10
|
+
## [1.1.0](https://github.com/gravity-ui/dynamic-forms/compare/v1.0.2...v1.1.0) (2023-03-19)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* add `row_verbose` layout ([#7](https://github.com/gravity-ui/dynamic-forms/issues/7)) ([a3030e1](https://github.com/gravity-ui/dynamic-forms/commit/a3030e105708c41211339d8ddd0b21e0b16cebfa))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* fix store errors ([#11](https://github.com/gravity-ui/dynamic-forms/issues/11)) ([3ed0d8e](https://github.com/gravity-ui/dynamic-forms/commit/3ed0d8e7cb4faefad351c5551b48461e7f6fd529))
|
|
21
|
+
|
|
3
22
|
## [1.0.2](https://github.com/gravity-ui/dynamic-forms/compare/v1.0.1...v1.0.2) (2023-03-15)
|
|
4
23
|
|
|
5
24
|
|
|
@@ -5,12 +5,20 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
6
6
|
const helpers_1 = require("../../helpers");
|
|
7
7
|
const hooks_1 = require("./hooks");
|
|
8
|
-
const Controller = ({ spec, name, initialValue, parentOnChange, }) => {
|
|
8
|
+
const Controller = ({ spec, name, initialValue, parentOnChange, parentOnUnmount, }) => {
|
|
9
9
|
const { tools } = (0, hooks_1.useDynamicFormsCtx)();
|
|
10
10
|
const { inputEntity, Layout } = (0, hooks_1.useComponents)(spec);
|
|
11
11
|
const render = (0, hooks_1.useRender)({ name, spec, inputEntity, Layout });
|
|
12
12
|
const validate = (0, hooks_1.useValidate)(spec);
|
|
13
|
-
const renderProps = (0, hooks_1.useField)({
|
|
13
|
+
const renderProps = (0, hooks_1.useField)({
|
|
14
|
+
name,
|
|
15
|
+
initialValue,
|
|
16
|
+
spec,
|
|
17
|
+
validate,
|
|
18
|
+
tools,
|
|
19
|
+
parentOnChange,
|
|
20
|
+
parentOnUnmount,
|
|
21
|
+
});
|
|
14
22
|
if (lodash_1.default.isString(name) && (0, helpers_1.isCorrectSpec)(spec)) {
|
|
15
23
|
return render(renderProps);
|
|
16
24
|
}
|
|
@@ -20,7 +20,7 @@ const DynamicField = ({ name, spec, config, Monaco }) => {
|
|
|
20
20
|
const correctParams = react_1.default.useMemo(() => lodash_1.default.isString(name) && (0, helpers_1.isCorrectSpec)(spec) && (0, helpers_2.isCorrectConfig)(config), [name, spec, config]);
|
|
21
21
|
if (correctParams) {
|
|
22
22
|
return (react_1.default.createElement(DynamicFormsCtx.Provider, { value: context },
|
|
23
|
-
react_1.default.createElement(Controller_1.Controller, { spec: spec, name: name, parentOnChange: null, initialValue: lodash_1.default.get(tools.initialValue, name) }),
|
|
23
|
+
react_1.default.createElement(Controller_1.Controller, { spec: spec, name: name, parentOnChange: null, parentOnUnmount: null, initialValue: lodash_1.default.get(tools.initialValue, name) }),
|
|
24
24
|
watcher));
|
|
25
25
|
}
|
|
26
26
|
return null;
|
|
@@ -7,7 +7,7 @@ const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
|
7
7
|
const helpers_1 = require("../../../helpers");
|
|
8
8
|
const constants_1 = require("../constants");
|
|
9
9
|
const helpers_2 = require("../helpers");
|
|
10
|
-
const useField = ({ name, spec, initialValue, validate: propsValidate, tools, parentOnChange, }) => {
|
|
10
|
+
const useField = ({ name, spec, initialValue, validate: propsValidate, tools, parentOnChange, parentOnUnmount, }) => {
|
|
11
11
|
const firstRenderRef = react_1.default.useRef(true);
|
|
12
12
|
const validate = react_1.default.useCallback((value) => {
|
|
13
13
|
if (value === constants_1.REMOVED_ITEM) {
|
|
@@ -53,7 +53,15 @@ const useField = ({ name, spec, initialValue, validate: propsValidate, tools, pa
|
|
|
53
53
|
const _value = lodash_1.default.isFunction(valOrSetter) ? valOrSetter(state.value) : valOrSetter;
|
|
54
54
|
const error = validate === null || validate === void 0 ? void 0 : validate(_value);
|
|
55
55
|
const value = (0, helpers_2.transformArrIn)(_value);
|
|
56
|
-
|
|
56
|
+
let newChildErrors = Object.assign({}, state.childErrors);
|
|
57
|
+
if (childErrors) {
|
|
58
|
+
const nearestChildName = lodash_1.default.keys(childErrors).sort((a, b) => a.length - b.length)[0];
|
|
59
|
+
if (nearestChildName) {
|
|
60
|
+
const existingСhildNames = lodash_1.default.keys(newChildErrors).filter((childName) => childName.startsWith(nearestChildName));
|
|
61
|
+
newChildErrors = Object.assign(Object.assign({}, lodash_1.default.omit(newChildErrors, existingСhildNames)), childErrors);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return Object.assign(Object.assign({}, state), { dirty: !lodash_1.default.isEqual(value, initialValue), error, invalid: Boolean(error), modified: true, pristine: value === initialValue, touched: true, valid: !error, value, visited: true, childErrors: newChildErrors });
|
|
57
65
|
});
|
|
58
66
|
};
|
|
59
67
|
const onDrop = () => {
|
|
@@ -125,7 +133,7 @@ const useField = ({ name, spec, initialValue, validate: propsValidate, tools, pa
|
|
|
125
133
|
react_1.default.useEffect(() => {
|
|
126
134
|
firstRenderRef.current = false;
|
|
127
135
|
return () => {
|
|
128
|
-
tools.onUnmount(name);
|
|
136
|
+
(parentOnUnmount ? parentOnUnmount : tools.onUnmount)(name);
|
|
129
137
|
};
|
|
130
138
|
}, []);
|
|
131
139
|
return renderProps;
|
|
@@ -5,7 +5,6 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
6
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
7
7
|
const react_final_form_1 = require("react-final-form");
|
|
8
|
-
const constants_1 = require("../constants");
|
|
9
8
|
const helpers_1 = require("../helpers");
|
|
10
9
|
const useStore = (name) => {
|
|
11
10
|
const form = (0, react_final_form_1.useForm)();
|
|
@@ -50,13 +49,8 @@ const useStore = (name) => {
|
|
|
50
49
|
}, [store.name, store.errors]);
|
|
51
50
|
const tools = react_1.default.useMemo(() => ({
|
|
52
51
|
initialValue: store.initialValue,
|
|
53
|
-
onChange: (name, value, errors) => setStore((store) => (Object.assign(Object.assign({}, store), { values: lodash_1.default.set(Object.assign({}, store.values), name, value), errors:
|
|
54
|
-
onUnmount: (name) => setStore((store) => {
|
|
55
|
-
const value = lodash_1.default.get(store.values, name);
|
|
56
|
-
const values = value && value !== constants_1.REMOVED_ITEM
|
|
57
|
-
? Object.assign({}, lodash_1.default.set(store.values, name, undefined)) : store.values;
|
|
58
|
-
return Object.assign(Object.assign({}, store), { values, errors: Object.assign({}, lodash_1.default.omit(store.errors, Object.keys(store.errors).filter((key) => key.startsWith(name)))) });
|
|
59
|
-
}),
|
|
52
|
+
onChange: (name, value, errors) => setStore((store) => (Object.assign(Object.assign({}, store), { values: lodash_1.default.set(Object.assign({}, store.values), name, value), errors: errors || {} }))),
|
|
53
|
+
onUnmount: (name) => setStore((store) => (Object.assign(Object.assign({}, store), { errors: lodash_1.default.omit(store.errors, Object.keys(store.errors).filter((key) => key.startsWith(name))) }))),
|
|
60
54
|
submitFailed,
|
|
61
55
|
}), [store.initialValue, setStore, submitFailed]);
|
|
62
56
|
const change = react_1.default.useCallback(lodash_1.default.debounce((value) => {
|
|
@@ -20,7 +20,7 @@ const ArrayBase = ({ spec, name, arrayInput, input }) => {
|
|
|
20
20
|
let item;
|
|
21
21
|
if (!((_a = spec.items) === null || _a === void 0 ? void 0 : _a.required)) {
|
|
22
22
|
if ((0, core_1.isArraySpec)(spec.items)) {
|
|
23
|
-
item = { OBJECT_ARRAY_FLAG: true, OBJECT_ARRAY_CNT: 0 };
|
|
23
|
+
item = { [core_1.OBJECT_ARRAY_FLAG]: true, [core_1.OBJECT_ARRAY_CNT]: 0 };
|
|
24
24
|
}
|
|
25
25
|
else if ((0, core_1.isObjectSpec)(spec.items)) {
|
|
26
26
|
item = {};
|
|
@@ -39,14 +39,15 @@ const ArrayBase = ({ spec, name, arrayInput, input }) => {
|
|
|
39
39
|
return itemSpec;
|
|
40
40
|
}, [spec.items, itemSpecCorrect]);
|
|
41
41
|
const parentOnChange = react_1.default.useCallback((childName, childValue, childErrors) => input.onChange((currentValue) => lodash_1.default.set(Object.assign({}, currentValue), childName.split(`${input.name}.`).join(''), childValue), childErrors), [input.onChange, input.name]);
|
|
42
|
+
const parentOnUnmount = react_1.default.useCallback((childName) => input.onChange((currentValue) => currentValue, { [childName]: false }), [input.onChange]);
|
|
42
43
|
const items = react_1.default.useMemo(() => keys.map((key, idx) => {
|
|
43
44
|
var _a;
|
|
44
45
|
const itemSpec = getItemSpec(idx);
|
|
45
46
|
if (!itemSpec) {
|
|
46
47
|
return null;
|
|
47
48
|
}
|
|
48
|
-
return (react_1.default.createElement(core_1.Controller, { initialValue: (_a = input.value) === null || _a === void 0 ? void 0 : _a[`<${key}>`], parentOnChange: parentOnChange, spec: itemSpec, name: `${name}.<${key}>`, key: `${name}.<${key}>` }));
|
|
49
|
-
}), [keys.join(''), name, getItemSpec, parentOnChange, input.value]);
|
|
49
|
+
return (react_1.default.createElement(core_1.Controller, { initialValue: (_a = input.value) === null || _a === void 0 ? void 0 : _a[`<${key}>`], parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount, spec: itemSpec, name: `${name}.<${key}>`, key: `${name}.<${key}>` }));
|
|
50
|
+
}), [keys.join(''), name, getItemSpec, parentOnChange, parentOnUnmount, input.value]);
|
|
50
51
|
if (!itemSpecCorrect) {
|
|
51
52
|
return null;
|
|
52
53
|
}
|
|
@@ -30,7 +30,8 @@ const CardOneOf = (props) => {
|
|
|
30
30
|
const value = lodash_1.default.set({}, childName.split(`${input.name}.`).join(''), childValue);
|
|
31
31
|
input.onChange(value, childErrors);
|
|
32
32
|
}, [input.onChange, input.name]);
|
|
33
|
+
const parentOnUnmount = react_1.default.useCallback((childName) => input.onChange((currentValue) => currentValue, { [childName]: false }), [input.onChange]);
|
|
33
34
|
(0, hooks_1.useErrorChecker)({ name, meta, open, setOpen });
|
|
34
|
-
return (react_1.default.createElement(__1.Card, { title: toggler, description: spec.viewSpec.layoutDescription, actions: actions, open: open, onToggle: onToggle, disableHeaderToggle: true }, specProperties[oneOfValue] ? (react_1.default.createElement(core_1.Controller, { initialValue: (_a = input.value) === null || _a === void 0 ? void 0 : _a[oneOfValue], spec: specProperties[oneOfValue], name: `${name}.${oneOfValue}`, parentOnChange: parentOnChange, key: `${name}.${oneOfValue}` })) : null));
|
|
35
|
+
return (react_1.default.createElement(__1.Card, { title: toggler, description: spec.viewSpec.layoutDescription, actions: actions, open: open, onToggle: onToggle, disableHeaderToggle: true }, specProperties[oneOfValue] ? (react_1.default.createElement(core_1.Controller, { initialValue: (_a = input.value) === null || _a === void 0 ? void 0 : _a[oneOfValue], spec: specProperties[oneOfValue], name: `${name}.${oneOfValue}`, parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount, key: `${name}.${oneOfValue}` })) : null));
|
|
35
36
|
};
|
|
36
37
|
exports.CardOneOf = CardOneOf;
|
|
@@ -16,6 +16,7 @@ const ObjectBase = (_a) => {
|
|
|
16
16
|
spec.viewSpec.layoutTitle || null));
|
|
17
17
|
}, [spec.defaultValue, spec.viewSpec.layoutTitle, restProps.input.onChange]);
|
|
18
18
|
const parentOnChange = react_1.default.useCallback((childName, childValue, childErrors) => restProps.input.onChange((currentValue) => lodash_1.default.set(Object.assign({}, currentValue), childName.split(`${restProps.input.name}.`).join(''), childValue), childErrors), [restProps.input.onChange, restProps.input.name]);
|
|
19
|
+
const parentOnUnmount = react_1.default.useCallback((childName) => restProps.input.onChange((currentValue) => currentValue, { [childName]: false }), [restProps.input.onChange]);
|
|
19
20
|
const content = react_1.default.useMemo(() => {
|
|
20
21
|
if (!lodash_1.default.isObjectLike(spec.properties) || !Object.keys(spec.properties || {}).length) {
|
|
21
22
|
return null;
|
|
@@ -26,9 +27,17 @@ const ObjectBase = (_a) => {
|
|
|
26
27
|
const specProperties = Object.assign({}, spec.properties);
|
|
27
28
|
return (react_1.default.createElement(react_1.default.Fragment, null, (spec.viewSpec.order || Object.keys(specProperties)).map((property) => {
|
|
28
29
|
var _a;
|
|
29
|
-
return specProperties[property] ? (react_1.default.createElement(core_1.Controller, { initialValue: (_a = restProps.input.value) === null || _a === void 0 ? void 0 : _a[property], spec: specProperties[property], name: `${name ? name + '.' : ''}${property}`, parentOnChange: parentOnChange, key: `${name ? name + '.' : ''}${property}` })) : null;
|
|
30
|
+
return specProperties[property] ? (react_1.default.createElement(core_1.Controller, { initialValue: (_a = restProps.input.value) === null || _a === void 0 ? void 0 : _a[property], spec: specProperties[property], name: `${name ? name + '.' : ''}${property}`, parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount, key: `${name ? name + '.' : ''}${property}` })) : null;
|
|
30
31
|
})));
|
|
31
|
-
}, [
|
|
32
|
+
}, [
|
|
33
|
+
spec.properties,
|
|
34
|
+
spec.viewSpec.order,
|
|
35
|
+
name,
|
|
36
|
+
restProps.input.value,
|
|
37
|
+
addBtn,
|
|
38
|
+
parentOnChange,
|
|
39
|
+
parentOnUnmount,
|
|
40
|
+
]);
|
|
32
41
|
if (!Layout || !content) {
|
|
33
42
|
return content;
|
|
34
43
|
}
|
|
@@ -16,9 +16,10 @@ const OneOf = (props) => {
|
|
|
16
16
|
const value = lodash_1.default.set({}, childName.split(`${props.input.name}.`).join(''), childValue);
|
|
17
17
|
props.input.onChange(value, childErrors);
|
|
18
18
|
}, [props.input.onChange, props.input.name]);
|
|
19
|
+
const parentOnUnmount = react_1.default.useCallback((childName) => props.input.onChange((currentValue) => currentValue, { [childName]: false }), [props.input.onChange]);
|
|
19
20
|
return (react_1.default.createElement("div", { className: b() },
|
|
20
21
|
specProperties[oneOfValue] ? (react_1.default.createElement(__1.GroupIndent, null,
|
|
21
|
-
react_1.default.createElement(core_1.Controller, { initialValue: (_a = props.input.value) === null || _a === void 0 ? void 0 : _a[oneOfValue], spec: specProperties[oneOfValue], name: `${props.name}.${oneOfValue}`, parentOnChange: parentOnChange, key: `${props.name}.${oneOfValue}` }))) : null,
|
|
22
|
+
react_1.default.createElement(core_1.Controller, { initialValue: (_a = props.input.value) === null || _a === void 0 ? void 0 : _a[oneOfValue], spec: specProperties[oneOfValue], name: `${props.name}.${oneOfValue}`, parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount, key: `${props.name}.${oneOfValue}` }))) : null,
|
|
22
23
|
react_1.default.createElement("div", { className: b('toggler') }, toggler)));
|
|
23
24
|
};
|
|
24
25
|
exports.OneOf = OneOf;
|
|
@@ -37,7 +37,8 @@ const OneOfCard = (props) => {
|
|
|
37
37
|
const value = lodash_1.default.set({}, childName.split(`${input.name}.`).join(''), childValue);
|
|
38
38
|
input.onChange(value, childErrors);
|
|
39
39
|
}, [input.onChange, input.name]);
|
|
40
|
+
const parentOnUnmount = react_1.default.useCallback((childName) => input.onChange((currentValue) => currentValue, { [childName]: false }), [input.onChange]);
|
|
40
41
|
(0, hooks_1.useErrorChecker)({ name, meta, open, setOpen });
|
|
41
|
-
return (react_1.default.createElement(__1.AccordeonCard, { className: b(), header: toggler, description: spec.viewSpec.layoutDescription || '', open: open, onToggle: onToggle, ignoreHeaderToggle: true, headerActionsTemplate: headerActionsTemplate }, specProperties[oneOfValue] ? (react_1.default.createElement(core_1.Controller, { initialValue: (_a = props.input.value) === null || _a === void 0 ? void 0 : _a[oneOfValue], spec: specProperties[oneOfValue], name: `${name}.${oneOfValue}`, parentOnChange: parentOnChange, key: `${name}.${oneOfValue}` })) : null));
|
|
42
|
+
return (react_1.default.createElement(__1.AccordeonCard, { className: b(), header: toggler, description: spec.viewSpec.layoutDescription || '', open: open, onToggle: onToggle, ignoreHeaderToggle: true, headerActionsTemplate: headerActionsTemplate }, specProperties[oneOfValue] ? (react_1.default.createElement(core_1.Controller, { initialValue: (_a = props.input.value) === null || _a === void 0 ? void 0 : _a[oneOfValue], spec: specProperties[oneOfValue], name: `${name}.${oneOfValue}`, parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount, key: `${name}.${oneOfValue}` })) : null));
|
|
42
43
|
};
|
|
43
44
|
exports.OneOfCard = OneOfCard;
|
|
@@ -9,6 +9,7 @@ const SECRET_PROPERTY_NAME = 'raw';
|
|
|
9
9
|
const Secret = ({ spec, name, input }) => {
|
|
10
10
|
var _a;
|
|
11
11
|
const parentOnChange = react_1.default.useCallback((childName, childValue, childErrors) => input.onChange((currentValue) => lodash_1.default.set(Object.assign({}, currentValue), childName.split(`${input.name}.`).join(''), childValue), childErrors), [input.onChange, input.name]);
|
|
12
|
+
const parentOnUnmount = react_1.default.useCallback((childName) => input.onChange((currentValue) => currentValue, { [childName]: false }), [input.onChange]);
|
|
12
13
|
if (!lodash_1.default.isObjectLike(spec.properties)) {
|
|
13
14
|
return null;
|
|
14
15
|
}
|
|
@@ -16,6 +17,6 @@ const Secret = ({ spec, name, input }) => {
|
|
|
16
17
|
if (!specProperties[SECRET_PROPERTY_NAME]) {
|
|
17
18
|
return null;
|
|
18
19
|
}
|
|
19
|
-
return (react_1.default.createElement(core_1.Controller, { initialValue: (_a = input.value) === null || _a === void 0 ? void 0 : _a[SECRET_PROPERTY_NAME], spec: specProperties[SECRET_PROPERTY_NAME], name: `${name}.${SECRET_PROPERTY_NAME}`, parentOnChange: parentOnChange, key: `${name}.${SECRET_PROPERTY_NAME}` }));
|
|
20
|
+
return (react_1.default.createElement(core_1.Controller, { initialValue: (_a = input.value) === null || _a === void 0 ? void 0 : _a[SECRET_PROPERTY_NAME], spec: specProperties[SECRET_PROPERTY_NAME], name: `${name}.${SECRET_PROPERTY_NAME}`, parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount, key: `${name}.${SECRET_PROPERTY_NAME}` }));
|
|
20
21
|
};
|
|
21
22
|
exports.Secret = Secret;
|
|
@@ -23,6 +23,7 @@ const TableArrayInput = ({ spec, name, arrayInput, input }) => {
|
|
|
23
23
|
arrayInput.onItemRemove(key);
|
|
24
24
|
}, [arrayInput.onItemRemove]);
|
|
25
25
|
const parentOnChange = react_1.default.useCallback((childName, childValue, childErrors) => input.onChange((currentValue) => lodash_1.default.set(Object.assign({}, currentValue), childName.split(`${input.name}.`).join(''), childValue), childErrors), [input.onChange, input.name]);
|
|
26
|
+
const parentOnUnmount = react_1.default.useCallback((childName) => input.onChange((currentValue) => currentValue, { [childName]: false }), [input.onChange]);
|
|
26
27
|
const columns = react_1.default.useMemo(() => {
|
|
27
28
|
const { items, viewSpec: { table }, } = spec;
|
|
28
29
|
if (!(table === null || table === void 0 ? void 0 : table.length) || !(0, core_1.isObjectSpec)(items)) {
|
|
@@ -55,11 +56,11 @@ const TableArrayInput = ({ spec, name, arrayInput, input }) => {
|
|
|
55
56
|
arr: (0, core_1.isArraySpec)(entitySpec),
|
|
56
57
|
obj: (0, core_1.isObjectSpec)(entitySpec),
|
|
57
58
|
}), key: `${name}.<${key}>.${property}` },
|
|
58
|
-
react_1.default.createElement(core_1.Controller, { initialValue: (_c = (_b = input.value) === null || _b === void 0 ? void 0 : _b[`<${key}>`]) === null || _c === void 0 ? void 0 : _c[property], spec: entitySpec, name: `${name}.<${key}>.${property}`, parentOnChange: parentOnChange })));
|
|
59
|
+
react_1.default.createElement(core_1.Controller, { initialValue: (_c = (_b = input.value) === null || _b === void 0 ? void 0 : _b[`<${key}>`]) === null || _c === void 0 ? void 0 : _c[property], spec: entitySpec, name: `${name}.<${key}>.${property}`, parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount })));
|
|
59
60
|
},
|
|
60
61
|
}));
|
|
61
62
|
return [idxColumn, ...columns, removeColumn];
|
|
62
|
-
}, [name, spec, onItemRemove, parentOnChange, input.value]);
|
|
63
|
+
}, [name, spec, onItemRemove, parentOnChange, parentOnUnmount, input.value]);
|
|
63
64
|
if (!columns) {
|
|
64
65
|
return null;
|
|
65
66
|
}
|
|
@@ -43,9 +43,18 @@
|
|
|
43
43
|
}
|
|
44
44
|
.df-row__right {
|
|
45
45
|
display: flex;
|
|
46
|
+
flex-direction: column;
|
|
46
47
|
flex-grow: 1;
|
|
47
48
|
margin-left: 15px;
|
|
48
49
|
}
|
|
50
|
+
.df-row__right-inner {
|
|
51
|
+
display: flex;
|
|
52
|
+
}
|
|
53
|
+
.df-row__description {
|
|
54
|
+
margin-top: 10px;
|
|
55
|
+
color: var(--yc-color-text-secondary);
|
|
56
|
+
word-break: break-word;
|
|
57
|
+
}
|
|
49
58
|
.df-row__remove-button {
|
|
50
59
|
margin-left: 5px;
|
|
51
60
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Row = void 0;
|
|
3
|
+
exports.RowVerbose = exports.Row = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
6
|
const icons_1 = require("@gravity-ui/icons");
|
|
@@ -9,7 +9,7 @@ const core_1 = require("../../../../core");
|
|
|
9
9
|
const components_1 = require("../../../components");
|
|
10
10
|
const utils_1 = require("../../../utils");
|
|
11
11
|
const b = (0, utils_1.block)('row');
|
|
12
|
-
const
|
|
12
|
+
const RowBase = ({ name, spec, input, meta, verboseDescription, children, }) => {
|
|
13
13
|
const arrayItem = react_1.default.useMemo(() => (0, core_1.isArrayItem)(name), [name]);
|
|
14
14
|
return (react_1.default.createElement("div", { className: b({ 'extra-width': (0, core_1.isArraySpec)(spec) || arrayItem }) },
|
|
15
15
|
react_1.default.createElement("div", { className: b('left') },
|
|
@@ -17,11 +17,16 @@ const Row = ({ name, spec, input, meta, children, }) => {
|
|
|
17
17
|
react_1.default.createElement("div", { className: b('title') },
|
|
18
18
|
spec.viewSpec.layoutTitle,
|
|
19
19
|
spec.required && react_1.default.createElement("span", { className: b('required-mark') }, "*")),
|
|
20
|
-
spec.viewSpec.layoutDescription ? (react_1.default.createElement("div", { className: b('note') },
|
|
20
|
+
!verboseDescription && spec.viewSpec.layoutDescription ? (react_1.default.createElement("div", { className: b('note') },
|
|
21
21
|
react_1.default.createElement(uikit_1.HelpPopover, { htmlContent: spec.viewSpec.layoutDescription, placement: ['bottom', 'top'] }))) : null)),
|
|
22
22
|
react_1.default.createElement("div", { className: b('right') },
|
|
23
|
-
react_1.default.createElement(
|
|
24
|
-
|
|
25
|
-
react_1.default.createElement(uikit_1.
|
|
23
|
+
react_1.default.createElement("div", { className: b('right-inner') },
|
|
24
|
+
react_1.default.createElement(components_1.ErrorWrapper, { name: name, meta: meta, withoutChildErrorStyles: (0, core_1.isArraySpec)(spec) || (0, core_1.isObjectSpec)(spec) }, children),
|
|
25
|
+
arrayItem ? (react_1.default.createElement(uikit_1.Button, { view: "flat", className: b('remove-button'), onClick: input.onDrop },
|
|
26
|
+
react_1.default.createElement(uikit_1.Icon, { data: icons_1.Xmark, size: 16 }))) : null),
|
|
27
|
+
verboseDescription && spec.viewSpec.layoutDescription ? (react_1.default.createElement("div", { className: b('description'), dangerouslySetInnerHTML: { __html: spec.viewSpec.layoutDescription } })) : null)));
|
|
26
28
|
};
|
|
29
|
+
const Row = (props) => (react_1.default.createElement(RowBase, Object.assign({}, props)));
|
|
27
30
|
exports.Row = Row;
|
|
31
|
+
const RowVerbose = (props) => (react_1.default.createElement(RowBase, Object.assign({ verboseDescription: true }, props)));
|
|
32
|
+
exports.RowVerbose = RowVerbose;
|
|
@@ -12,6 +12,7 @@ exports.dynamicConfig = {
|
|
|
12
12
|
},
|
|
13
13
|
layouts: {
|
|
14
14
|
row: components_1.Row,
|
|
15
|
+
row_verbose: components_1.RowVerbose,
|
|
15
16
|
accordeon: components_1.Accordeon,
|
|
16
17
|
section: components_1.Section,
|
|
17
18
|
section2: components_1.Section2,
|
|
@@ -32,6 +33,7 @@ exports.dynamicConfig = {
|
|
|
32
33
|
},
|
|
33
34
|
layouts: {
|
|
34
35
|
row: components_1.Row,
|
|
36
|
+
row_verbose: components_1.RowVerbose,
|
|
35
37
|
table_item: components_1.TableCell,
|
|
36
38
|
},
|
|
37
39
|
validators: {
|
|
@@ -44,6 +46,7 @@ exports.dynamicConfig = {
|
|
|
44
46
|
},
|
|
45
47
|
layouts: {
|
|
46
48
|
row: components_1.Row,
|
|
49
|
+
row_verbose: components_1.RowVerbose,
|
|
47
50
|
table_item: components_1.TableCell,
|
|
48
51
|
transparent: components_1.Transparent,
|
|
49
52
|
},
|
|
@@ -60,6 +63,7 @@ exports.dynamicConfig = {
|
|
|
60
63
|
},
|
|
61
64
|
layouts: {
|
|
62
65
|
row: components_1.Row,
|
|
66
|
+
row_verbose: components_1.RowVerbose,
|
|
63
67
|
accordeon: components_1.Accordeon,
|
|
64
68
|
section: components_1.Section,
|
|
65
69
|
section2: components_1.Section2,
|
|
@@ -85,6 +89,7 @@ exports.dynamicConfig = {
|
|
|
85
89
|
},
|
|
86
90
|
layouts: {
|
|
87
91
|
row: components_1.Row,
|
|
92
|
+
row_verbose: components_1.RowVerbose,
|
|
88
93
|
table_item: components_1.TableCell,
|
|
89
94
|
transparent: components_1.Transparent,
|
|
90
95
|
section: components_1.Section,
|
|
@@ -5,5 +5,6 @@ export interface ControllerProps<Value extends FieldValue, SpecType extends Spec
|
|
|
5
5
|
name: string;
|
|
6
6
|
initialValue: Value;
|
|
7
7
|
parentOnChange: ((childName: string, childValue: FieldValue, childErrors: Record<string, ValidateError>) => void) | null;
|
|
8
|
+
parentOnUnmount: ((childName: string) => void) | null;
|
|
8
9
|
}
|
|
9
|
-
export declare const Controller: <Value extends FieldValue, SpecType extends Spec>({ spec, name, initialValue, parentOnChange, }: ControllerProps<Value, SpecType>) => JSX.Element | null;
|
|
10
|
+
export declare const Controller: <Value extends FieldValue, SpecType extends Spec>({ spec, name, initialValue, parentOnChange, parentOnUnmount, }: ControllerProps<Value, SpecType>) => JSX.Element | null;
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
import { isCorrectSpec } from '../../helpers';
|
|
3
3
|
import { useComponents, useDynamicFormsCtx, useField, useRender, useValidate } from './hooks';
|
|
4
|
-
export const Controller = ({ spec, name, initialValue, parentOnChange, }) => {
|
|
4
|
+
export const Controller = ({ spec, name, initialValue, parentOnChange, parentOnUnmount, }) => {
|
|
5
5
|
const { tools } = useDynamicFormsCtx();
|
|
6
6
|
const { inputEntity, Layout } = useComponents(spec);
|
|
7
7
|
const render = useRender({ name, spec, inputEntity, Layout });
|
|
8
8
|
const validate = useValidate(spec);
|
|
9
|
-
const renderProps = useField({
|
|
9
|
+
const renderProps = useField({
|
|
10
|
+
name,
|
|
11
|
+
initialValue,
|
|
12
|
+
spec,
|
|
13
|
+
validate,
|
|
14
|
+
tools,
|
|
15
|
+
parentOnChange,
|
|
16
|
+
parentOnUnmount,
|
|
17
|
+
});
|
|
10
18
|
if (_.isString(name) && isCorrectSpec(spec)) {
|
|
11
19
|
return render(renderProps);
|
|
12
20
|
}
|
|
@@ -16,7 +16,7 @@ export const DynamicField = ({ name, spec, config, Monaco }) => {
|
|
|
16
16
|
const correctParams = React.useMemo(() => _.isString(name) && isCorrectSpec(spec) && isCorrectConfig(config), [name, spec, config]);
|
|
17
17
|
if (correctParams) {
|
|
18
18
|
return (React.createElement(DynamicFormsCtx.Provider, { value: context },
|
|
19
|
-
React.createElement(Controller, { spec: spec, name: name, parentOnChange: null, initialValue: _.get(tools.initialValue, name) }),
|
|
19
|
+
React.createElement(Controller, { spec: spec, name: name, parentOnChange: null, parentOnUnmount: null, initialValue: _.get(tools.initialValue, name) }),
|
|
20
20
|
watcher));
|
|
21
21
|
}
|
|
22
22
|
return null;
|
|
@@ -7,5 +7,6 @@ export interface FieldProps<Value extends FieldValue, SpecType extends Spec> {
|
|
|
7
7
|
validate?: (value?: Value) => ValidateError;
|
|
8
8
|
tools: DynamicFormsContext['tools'];
|
|
9
9
|
parentOnChange: ((childName: string, childValue: FieldValue, childErrors: Record<string, ValidateError>) => void) | null;
|
|
10
|
+
parentOnUnmount: ((childName: string) => void) | null;
|
|
10
11
|
}
|
|
11
|
-
export declare const useField: <Value extends FieldValue, SpecType extends Spec>({ name, spec, initialValue, validate: propsValidate, tools, parentOnChange, }: FieldProps<Value, SpecType>) => FieldRenderProps<Value>;
|
|
12
|
+
export declare const useField: <Value extends FieldValue, SpecType extends Spec>({ name, spec, initialValue, validate: propsValidate, tools, parentOnChange, parentOnUnmount, }: FieldProps<Value, SpecType>) => FieldRenderProps<Value>;
|
|
@@ -3,7 +3,7 @@ import _ from 'lodash';
|
|
|
3
3
|
import { isArraySpec, isObjectSpec } from '../../../helpers';
|
|
4
4
|
import { OBJECT_ARRAY_CNT, OBJECT_ARRAY_FLAG, REMOVED_ITEM } from '../constants';
|
|
5
5
|
import { isArrayItem, transformArrIn, transformArrOut } from '../helpers';
|
|
6
|
-
export const useField = ({ name, spec, initialValue, validate: propsValidate, tools, parentOnChange, }) => {
|
|
6
|
+
export const useField = ({ name, spec, initialValue, validate: propsValidate, tools, parentOnChange, parentOnUnmount, }) => {
|
|
7
7
|
const firstRenderRef = React.useRef(true);
|
|
8
8
|
const validate = React.useCallback((value) => {
|
|
9
9
|
if (value === REMOVED_ITEM) {
|
|
@@ -49,7 +49,15 @@ export const useField = ({ name, spec, initialValue, validate: propsValidate, to
|
|
|
49
49
|
const _value = _.isFunction(valOrSetter) ? valOrSetter(state.value) : valOrSetter;
|
|
50
50
|
const error = validate === null || validate === void 0 ? void 0 : validate(_value);
|
|
51
51
|
const value = transformArrIn(_value);
|
|
52
|
-
|
|
52
|
+
let newChildErrors = Object.assign({}, state.childErrors);
|
|
53
|
+
if (childErrors) {
|
|
54
|
+
const nearestChildName = _.keys(childErrors).sort((a, b) => a.length - b.length)[0];
|
|
55
|
+
if (nearestChildName) {
|
|
56
|
+
const existingСhildNames = _.keys(newChildErrors).filter((childName) => childName.startsWith(nearestChildName));
|
|
57
|
+
newChildErrors = Object.assign(Object.assign({}, _.omit(newChildErrors, existingСhildNames)), childErrors);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return Object.assign(Object.assign({}, state), { dirty: !_.isEqual(value, initialValue), error, invalid: Boolean(error), modified: true, pristine: value === initialValue, touched: true, valid: !error, value, visited: true, childErrors: newChildErrors });
|
|
53
61
|
});
|
|
54
62
|
};
|
|
55
63
|
const onDrop = () => {
|
|
@@ -121,7 +129,7 @@ export const useField = ({ name, spec, initialValue, validate: propsValidate, to
|
|
|
121
129
|
React.useEffect(() => {
|
|
122
130
|
firstRenderRef.current = false;
|
|
123
131
|
return () => {
|
|
124
|
-
tools.onUnmount(name);
|
|
132
|
+
(parentOnUnmount ? parentOnUnmount : tools.onUnmount)(name);
|
|
125
133
|
};
|
|
126
134
|
}, []);
|
|
127
135
|
return renderProps;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import _ from 'lodash';
|
|
3
3
|
import { Field as FinalFormField, useForm } from 'react-final-form';
|
|
4
|
-
import { REMOVED_ITEM } from '../constants';
|
|
5
4
|
import { transformArrIn, transformArrOut } from '../helpers';
|
|
6
5
|
export const useStore = (name) => {
|
|
7
6
|
const form = useForm();
|
|
@@ -46,13 +45,8 @@ export const useStore = (name) => {
|
|
|
46
45
|
}, [store.name, store.errors]);
|
|
47
46
|
const tools = React.useMemo(() => ({
|
|
48
47
|
initialValue: store.initialValue,
|
|
49
|
-
onChange: (name, value, errors) => setStore((store) => (Object.assign(Object.assign({}, store), { values: _.set(Object.assign({}, store.values), name, value), errors:
|
|
50
|
-
onUnmount: (name) => setStore((store) => {
|
|
51
|
-
const value = _.get(store.values, name);
|
|
52
|
-
const values = value && value !== REMOVED_ITEM
|
|
53
|
-
? Object.assign({}, _.set(store.values, name, undefined)) : store.values;
|
|
54
|
-
return Object.assign(Object.assign({}, store), { values, errors: Object.assign({}, _.omit(store.errors, Object.keys(store.errors).filter((key) => key.startsWith(name)))) });
|
|
55
|
-
}),
|
|
48
|
+
onChange: (name, value, errors) => setStore((store) => (Object.assign(Object.assign({}, store), { values: _.set(Object.assign({}, store.values), name, value), errors: errors || {} }))),
|
|
49
|
+
onUnmount: (name) => setStore((store) => (Object.assign(Object.assign({}, store), { errors: _.omit(store.errors, Object.keys(store.errors).filter((key) => key.startsWith(name))) }))),
|
|
56
50
|
submitFailed,
|
|
57
51
|
}), [store.initialValue, setStore, submitFailed]);
|
|
58
52
|
const change = React.useCallback(_.debounce((value) => {
|
|
@@ -16,7 +16,7 @@ export const ArrayBase = ({ spec, name, arrayInput, input }) => {
|
|
|
16
16
|
let item;
|
|
17
17
|
if (!((_a = spec.items) === null || _a === void 0 ? void 0 : _a.required)) {
|
|
18
18
|
if (isArraySpec(spec.items)) {
|
|
19
|
-
item = { OBJECT_ARRAY_FLAG: true, OBJECT_ARRAY_CNT: 0 };
|
|
19
|
+
item = { [OBJECT_ARRAY_FLAG]: true, [OBJECT_ARRAY_CNT]: 0 };
|
|
20
20
|
}
|
|
21
21
|
else if (isObjectSpec(spec.items)) {
|
|
22
22
|
item = {};
|
|
@@ -35,14 +35,15 @@ export const ArrayBase = ({ spec, name, arrayInput, input }) => {
|
|
|
35
35
|
return itemSpec;
|
|
36
36
|
}, [spec.items, itemSpecCorrect]);
|
|
37
37
|
const parentOnChange = React.useCallback((childName, childValue, childErrors) => input.onChange((currentValue) => _.set(Object.assign({}, currentValue), childName.split(`${input.name}.`).join(''), childValue), childErrors), [input.onChange, input.name]);
|
|
38
|
+
const parentOnUnmount = React.useCallback((childName) => input.onChange((currentValue) => currentValue, { [childName]: false }), [input.onChange]);
|
|
38
39
|
const items = React.useMemo(() => keys.map((key, idx) => {
|
|
39
40
|
var _a;
|
|
40
41
|
const itemSpec = getItemSpec(idx);
|
|
41
42
|
if (!itemSpec) {
|
|
42
43
|
return null;
|
|
43
44
|
}
|
|
44
|
-
return (React.createElement(Controller, { initialValue: (_a = input.value) === null || _a === void 0 ? void 0 : _a[`<${key}>`], parentOnChange: parentOnChange, spec: itemSpec, name: `${name}.<${key}>`, key: `${name}.<${key}>` }));
|
|
45
|
-
}), [keys.join(''), name, getItemSpec, parentOnChange, input.value]);
|
|
45
|
+
return (React.createElement(Controller, { initialValue: (_a = input.value) === null || _a === void 0 ? void 0 : _a[`<${key}>`], parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount, spec: itemSpec, name: `${name}.<${key}>`, key: `${name}.<${key}>` }));
|
|
46
|
+
}), [keys.join(''), name, getItemSpec, parentOnChange, parentOnUnmount, input.value]);
|
|
46
47
|
if (!itemSpecCorrect) {
|
|
47
48
|
return null;
|
|
48
49
|
}
|
|
@@ -26,6 +26,7 @@ export const CardOneOf = (props) => {
|
|
|
26
26
|
const value = _.set({}, childName.split(`${input.name}.`).join(''), childValue);
|
|
27
27
|
input.onChange(value, childErrors);
|
|
28
28
|
}, [input.onChange, input.name]);
|
|
29
|
+
const parentOnUnmount = React.useCallback((childName) => input.onChange((currentValue) => currentValue, { [childName]: false }), [input.onChange]);
|
|
29
30
|
useErrorChecker({ name, meta, open, setOpen });
|
|
30
|
-
return (React.createElement(Card, { title: toggler, description: spec.viewSpec.layoutDescription, actions: actions, open: open, onToggle: onToggle, disableHeaderToggle: true }, specProperties[oneOfValue] ? (React.createElement(Controller, { initialValue: (_a = input.value) === null || _a === void 0 ? void 0 : _a[oneOfValue], spec: specProperties[oneOfValue], name: `${name}.${oneOfValue}`, parentOnChange: parentOnChange, key: `${name}.${oneOfValue}` })) : null));
|
|
31
|
+
return (React.createElement(Card, { title: toggler, description: spec.viewSpec.layoutDescription, actions: actions, open: open, onToggle: onToggle, disableHeaderToggle: true }, specProperties[oneOfValue] ? (React.createElement(Controller, { initialValue: (_a = input.value) === null || _a === void 0 ? void 0 : _a[oneOfValue], spec: specProperties[oneOfValue], name: `${name}.${oneOfValue}`, parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount, key: `${name}.${oneOfValue}` })) : null));
|
|
31
32
|
};
|
|
@@ -13,6 +13,7 @@ export const ObjectBase = (_a) => {
|
|
|
13
13
|
spec.viewSpec.layoutTitle || null));
|
|
14
14
|
}, [spec.defaultValue, spec.viewSpec.layoutTitle, restProps.input.onChange]);
|
|
15
15
|
const parentOnChange = React.useCallback((childName, childValue, childErrors) => restProps.input.onChange((currentValue) => _.set(Object.assign({}, currentValue), childName.split(`${restProps.input.name}.`).join(''), childValue), childErrors), [restProps.input.onChange, restProps.input.name]);
|
|
16
|
+
const parentOnUnmount = React.useCallback((childName) => restProps.input.onChange((currentValue) => currentValue, { [childName]: false }), [restProps.input.onChange]);
|
|
16
17
|
const content = React.useMemo(() => {
|
|
17
18
|
if (!_.isObjectLike(spec.properties) || !Object.keys(spec.properties || {}).length) {
|
|
18
19
|
return null;
|
|
@@ -23,9 +24,17 @@ export const ObjectBase = (_a) => {
|
|
|
23
24
|
const specProperties = Object.assign({}, spec.properties);
|
|
24
25
|
return (React.createElement(React.Fragment, null, (spec.viewSpec.order || Object.keys(specProperties)).map((property) => {
|
|
25
26
|
var _a;
|
|
26
|
-
return specProperties[property] ? (React.createElement(Controller, { initialValue: (_a = restProps.input.value) === null || _a === void 0 ? void 0 : _a[property], spec: specProperties[property], name: `${name ? name + '.' : ''}${property}`, parentOnChange: parentOnChange, key: `${name ? name + '.' : ''}${property}` })) : null;
|
|
27
|
+
return specProperties[property] ? (React.createElement(Controller, { initialValue: (_a = restProps.input.value) === null || _a === void 0 ? void 0 : _a[property], spec: specProperties[property], name: `${name ? name + '.' : ''}${property}`, parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount, key: `${name ? name + '.' : ''}${property}` })) : null;
|
|
27
28
|
})));
|
|
28
|
-
}, [
|
|
29
|
+
}, [
|
|
30
|
+
spec.properties,
|
|
31
|
+
spec.viewSpec.order,
|
|
32
|
+
name,
|
|
33
|
+
restProps.input.value,
|
|
34
|
+
addBtn,
|
|
35
|
+
parentOnChange,
|
|
36
|
+
parentOnUnmount,
|
|
37
|
+
]);
|
|
29
38
|
if (!Layout || !content) {
|
|
30
39
|
return content;
|
|
31
40
|
}
|
|
@@ -13,8 +13,9 @@ export const OneOf = (props) => {
|
|
|
13
13
|
const value = _.set({}, childName.split(`${props.input.name}.`).join(''), childValue);
|
|
14
14
|
props.input.onChange(value, childErrors);
|
|
15
15
|
}, [props.input.onChange, props.input.name]);
|
|
16
|
+
const parentOnUnmount = React.useCallback((childName) => props.input.onChange((currentValue) => currentValue, { [childName]: false }), [props.input.onChange]);
|
|
16
17
|
return (React.createElement("div", { className: b() },
|
|
17
18
|
specProperties[oneOfValue] ? (React.createElement(GroupIndent, null,
|
|
18
|
-
React.createElement(Controller, { initialValue: (_a = props.input.value) === null || _a === void 0 ? void 0 : _a[oneOfValue], spec: specProperties[oneOfValue], name: `${props.name}.${oneOfValue}`, parentOnChange: parentOnChange, key: `${props.name}.${oneOfValue}` }))) : null,
|
|
19
|
+
React.createElement(Controller, { initialValue: (_a = props.input.value) === null || _a === void 0 ? void 0 : _a[oneOfValue], spec: specProperties[oneOfValue], name: `${props.name}.${oneOfValue}`, parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount, key: `${props.name}.${oneOfValue}` }))) : null,
|
|
19
20
|
React.createElement("div", { className: b('toggler') }, toggler)));
|
|
20
21
|
};
|
|
@@ -34,6 +34,7 @@ export const OneOfCard = (props) => {
|
|
|
34
34
|
const value = _.set({}, childName.split(`${input.name}.`).join(''), childValue);
|
|
35
35
|
input.onChange(value, childErrors);
|
|
36
36
|
}, [input.onChange, input.name]);
|
|
37
|
+
const parentOnUnmount = React.useCallback((childName) => input.onChange((currentValue) => currentValue, { [childName]: false }), [input.onChange]);
|
|
37
38
|
useErrorChecker({ name, meta, open, setOpen });
|
|
38
|
-
return (React.createElement(AccordeonCard, { className: b(), header: toggler, description: spec.viewSpec.layoutDescription || '', open: open, onToggle: onToggle, ignoreHeaderToggle: true, headerActionsTemplate: headerActionsTemplate }, specProperties[oneOfValue] ? (React.createElement(Controller, { initialValue: (_a = props.input.value) === null || _a === void 0 ? void 0 : _a[oneOfValue], spec: specProperties[oneOfValue], name: `${name}.${oneOfValue}`, parentOnChange: parentOnChange, key: `${name}.${oneOfValue}` })) : null));
|
|
39
|
+
return (React.createElement(AccordeonCard, { className: b(), header: toggler, description: spec.viewSpec.layoutDescription || '', open: open, onToggle: onToggle, ignoreHeaderToggle: true, headerActionsTemplate: headerActionsTemplate }, specProperties[oneOfValue] ? (React.createElement(Controller, { initialValue: (_a = props.input.value) === null || _a === void 0 ? void 0 : _a[oneOfValue], spec: specProperties[oneOfValue], name: `${name}.${oneOfValue}`, parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount, key: `${name}.${oneOfValue}` })) : null));
|
|
39
40
|
};
|
|
@@ -5,6 +5,7 @@ const SECRET_PROPERTY_NAME = 'raw';
|
|
|
5
5
|
export const Secret = ({ spec, name, input }) => {
|
|
6
6
|
var _a;
|
|
7
7
|
const parentOnChange = React.useCallback((childName, childValue, childErrors) => input.onChange((currentValue) => _.set(Object.assign({}, currentValue), childName.split(`${input.name}.`).join(''), childValue), childErrors), [input.onChange, input.name]);
|
|
8
|
+
const parentOnUnmount = React.useCallback((childName) => input.onChange((currentValue) => currentValue, { [childName]: false }), [input.onChange]);
|
|
8
9
|
if (!_.isObjectLike(spec.properties)) {
|
|
9
10
|
return null;
|
|
10
11
|
}
|
|
@@ -12,5 +13,5 @@ export const Secret = ({ spec, name, input }) => {
|
|
|
12
13
|
if (!specProperties[SECRET_PROPERTY_NAME]) {
|
|
13
14
|
return null;
|
|
14
15
|
}
|
|
15
|
-
return (React.createElement(Controller, { initialValue: (_a = input.value) === null || _a === void 0 ? void 0 : _a[SECRET_PROPERTY_NAME], spec: specProperties[SECRET_PROPERTY_NAME], name: `${name}.${SECRET_PROPERTY_NAME}`, parentOnChange: parentOnChange, key: `${name}.${SECRET_PROPERTY_NAME}` }));
|
|
16
|
+
return (React.createElement(Controller, { initialValue: (_a = input.value) === null || _a === void 0 ? void 0 : _a[SECRET_PROPERTY_NAME], spec: specProperties[SECRET_PROPERTY_NAME], name: `${name}.${SECRET_PROPERTY_NAME}`, parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount, key: `${name}.${SECRET_PROPERTY_NAME}` }));
|
|
16
17
|
};
|
|
@@ -20,6 +20,7 @@ export const TableArrayInput = ({ spec, name, arrayInput, input }) => {
|
|
|
20
20
|
arrayInput.onItemRemove(key);
|
|
21
21
|
}, [arrayInput.onItemRemove]);
|
|
22
22
|
const parentOnChange = React.useCallback((childName, childValue, childErrors) => input.onChange((currentValue) => _.set(Object.assign({}, currentValue), childName.split(`${input.name}.`).join(''), childValue), childErrors), [input.onChange, input.name]);
|
|
23
|
+
const parentOnUnmount = React.useCallback((childName) => input.onChange((currentValue) => currentValue, { [childName]: false }), [input.onChange]);
|
|
23
24
|
const columns = React.useMemo(() => {
|
|
24
25
|
const { items, viewSpec: { table }, } = spec;
|
|
25
26
|
if (!(table === null || table === void 0 ? void 0 : table.length) || !isObjectSpec(items)) {
|
|
@@ -52,11 +53,11 @@ export const TableArrayInput = ({ spec, name, arrayInput, input }) => {
|
|
|
52
53
|
arr: isArraySpec(entitySpec),
|
|
53
54
|
obj: isObjectSpec(entitySpec),
|
|
54
55
|
}), key: `${name}.<${key}>.${property}` },
|
|
55
|
-
React.createElement(Controller, { initialValue: (_c = (_b = input.value) === null || _b === void 0 ? void 0 : _b[`<${key}>`]) === null || _c === void 0 ? void 0 : _c[property], spec: entitySpec, name: `${name}.<${key}>.${property}`, parentOnChange: parentOnChange })));
|
|
56
|
+
React.createElement(Controller, { initialValue: (_c = (_b = input.value) === null || _b === void 0 ? void 0 : _b[`<${key}>`]) === null || _c === void 0 ? void 0 : _c[property], spec: entitySpec, name: `${name}.<${key}>.${property}`, parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount })));
|
|
56
57
|
},
|
|
57
58
|
}));
|
|
58
59
|
return [idxColumn, ...columns, removeColumn];
|
|
59
|
-
}, [name, spec, onItemRemove, parentOnChange, input.value]);
|
|
60
|
+
}, [name, spec, onItemRemove, parentOnChange, parentOnUnmount, input.value]);
|
|
60
61
|
if (!columns) {
|
|
61
62
|
return null;
|
|
62
63
|
}
|
|
@@ -43,9 +43,18 @@
|
|
|
43
43
|
}
|
|
44
44
|
.df-row__right {
|
|
45
45
|
display: flex;
|
|
46
|
+
flex-direction: column;
|
|
46
47
|
flex-grow: 1;
|
|
47
48
|
margin-left: 15px;
|
|
48
49
|
}
|
|
50
|
+
.df-row__right-inner {
|
|
51
|
+
display: flex;
|
|
52
|
+
}
|
|
53
|
+
.df-row__description {
|
|
54
|
+
margin-top: 10px;
|
|
55
|
+
color: var(--yc-color-text-secondary);
|
|
56
|
+
word-break: break-word;
|
|
57
|
+
}
|
|
49
58
|
.df-row__remove-button {
|
|
50
59
|
margin-left: 5px;
|
|
51
60
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { FieldValue, LayoutProps, Spec } from '../../../../core';
|
|
2
2
|
import './Row.css';
|
|
3
|
-
export declare const Row: <T extends FieldValue, S extends Spec>(
|
|
3
|
+
export declare const Row: <T extends FieldValue, S extends Spec>(props: LayoutProps<T, S>) => JSX.Element;
|
|
4
|
+
export declare const RowVerbose: <T extends FieldValue, S extends Spec>(props: LayoutProps<T, S>) => JSX.Element;
|
|
@@ -6,7 +6,7 @@ import { ErrorWrapper } from '../../../components';
|
|
|
6
6
|
import { block } from '../../../utils';
|
|
7
7
|
import './Row.css';
|
|
8
8
|
const b = block('row');
|
|
9
|
-
|
|
9
|
+
const RowBase = ({ name, spec, input, meta, verboseDescription, children, }) => {
|
|
10
10
|
const arrayItem = React.useMemo(() => isArrayItem(name), [name]);
|
|
11
11
|
return (React.createElement("div", { className: b({ 'extra-width': isArraySpec(spec) || arrayItem }) },
|
|
12
12
|
React.createElement("div", { className: b('left') },
|
|
@@ -14,10 +14,14 @@ export const Row = ({ name, spec, input, meta, children, }) => {
|
|
|
14
14
|
React.createElement("div", { className: b('title') },
|
|
15
15
|
spec.viewSpec.layoutTitle,
|
|
16
16
|
spec.required && React.createElement("span", { className: b('required-mark') }, "*")),
|
|
17
|
-
spec.viewSpec.layoutDescription ? (React.createElement("div", { className: b('note') },
|
|
17
|
+
!verboseDescription && spec.viewSpec.layoutDescription ? (React.createElement("div", { className: b('note') },
|
|
18
18
|
React.createElement(HelpPopover, { htmlContent: spec.viewSpec.layoutDescription, placement: ['bottom', 'top'] }))) : null)),
|
|
19
19
|
React.createElement("div", { className: b('right') },
|
|
20
|
-
React.createElement(
|
|
21
|
-
|
|
22
|
-
React.createElement(
|
|
20
|
+
React.createElement("div", { className: b('right-inner') },
|
|
21
|
+
React.createElement(ErrorWrapper, { name: name, meta: meta, withoutChildErrorStyles: isArraySpec(spec) || isObjectSpec(spec) }, children),
|
|
22
|
+
arrayItem ? (React.createElement(Button, { view: "flat", className: b('remove-button'), onClick: input.onDrop },
|
|
23
|
+
React.createElement(Icon, { data: Xmark, size: 16 }))) : null),
|
|
24
|
+
verboseDescription && spec.viewSpec.layoutDescription ? (React.createElement("div", { className: b('description'), dangerouslySetInnerHTML: { __html: spec.viewSpec.layoutDescription } })) : null)));
|
|
23
25
|
};
|
|
26
|
+
export const Row = (props) => (React.createElement(RowBase, Object.assign({}, props)));
|
|
27
|
+
export const RowVerbose = (props) => (React.createElement(RowBase, Object.assign({ verboseDescription: true }, props)));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Accordeon, AccordeonCardLayout, ArrayBase, ArrayBaseView, BaseView, CardAccordeon, CardOneOf, CardOneOfView, CardSection, Checkbox, Group, Group2, MonacoInput, MonacoInputCard, MonacoView, MonacoViewCard, MultiSelect, MultiSelectView, NumberWithScale, NumberWithScaleView, ObjectBase, ObjectBaseView, OneOf, OneOfCard, OneOfCardView, OneOfView, Row, Row2, Secret, Section, Section2, SectionCard, SectionCard2, SectionWithSubtitle, SectionWithSubtitle2, Select, TableArrayInput, TableArrayView, TableCell, Text, TextArea, TextAreaView, TextContent, Transparent, ViewAccordeon, ViewAccordeonCard, ViewCardAccordeon, ViewCardSection, ViewGroup, ViewGroup2, ViewRow, ViewRow2, ViewSection, ViewSection2, ViewSectionCard, ViewSectionCard2, ViewTableCell, ViewTransparent, } from '../components';
|
|
1
|
+
import { Accordeon, AccordeonCardLayout, ArrayBase, ArrayBaseView, BaseView, CardAccordeon, CardOneOf, CardOneOfView, CardSection, Checkbox, Group, Group2, MonacoInput, MonacoInputCard, MonacoView, MonacoViewCard, MultiSelect, MultiSelectView, NumberWithScale, NumberWithScaleView, ObjectBase, ObjectBaseView, OneOf, OneOfCard, OneOfCardView, OneOfView, Row, Row2, RowVerbose, Secret, Section, Section2, SectionCard, SectionCard2, SectionWithSubtitle, SectionWithSubtitle2, Select, TableArrayInput, TableArrayView, TableCell, Text, TextArea, TextAreaView, TextContent, Transparent, ViewAccordeon, ViewAccordeonCard, ViewCardAccordeon, ViewCardSection, ViewGroup, ViewGroup2, ViewRow, ViewRow2, ViewSection, ViewSection2, ViewSectionCard, ViewSectionCard2, ViewTableCell, ViewTransparent, } from '../components';
|
|
2
2
|
import { getArrayValidator, getBooleanValidator, getNumberValidator, getObjectValidator, getStringValidator, } from '../validators';
|
|
3
3
|
export const dynamicConfig = {
|
|
4
4
|
array: {
|
|
@@ -9,6 +9,7 @@ export const dynamicConfig = {
|
|
|
9
9
|
},
|
|
10
10
|
layouts: {
|
|
11
11
|
row: Row,
|
|
12
|
+
row_verbose: RowVerbose,
|
|
12
13
|
accordeon: Accordeon,
|
|
13
14
|
section: Section,
|
|
14
15
|
section2: Section2,
|
|
@@ -29,6 +30,7 @@ export const dynamicConfig = {
|
|
|
29
30
|
},
|
|
30
31
|
layouts: {
|
|
31
32
|
row: Row,
|
|
33
|
+
row_verbose: RowVerbose,
|
|
32
34
|
table_item: TableCell,
|
|
33
35
|
},
|
|
34
36
|
validators: {
|
|
@@ -41,6 +43,7 @@ export const dynamicConfig = {
|
|
|
41
43
|
},
|
|
42
44
|
layouts: {
|
|
43
45
|
row: Row,
|
|
46
|
+
row_verbose: RowVerbose,
|
|
44
47
|
table_item: TableCell,
|
|
45
48
|
transparent: Transparent,
|
|
46
49
|
},
|
|
@@ -57,6 +60,7 @@ export const dynamicConfig = {
|
|
|
57
60
|
},
|
|
58
61
|
layouts: {
|
|
59
62
|
row: Row,
|
|
63
|
+
row_verbose: RowVerbose,
|
|
60
64
|
accordeon: Accordeon,
|
|
61
65
|
section: Section,
|
|
62
66
|
section2: Section2,
|
|
@@ -82,6 +86,7 @@ export const dynamicConfig = {
|
|
|
82
86
|
},
|
|
83
87
|
layouts: {
|
|
84
88
|
row: Row,
|
|
89
|
+
row_verbose: RowVerbose,
|
|
85
90
|
table_item: TableCell,
|
|
86
91
|
transparent: Transparent,
|
|
87
92
|
section: Section,
|