@gravity-ui/dynamic-forms 4.0.0 → 4.1.0
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/build/cjs/lib/core/components/Form/Controller/Controller.js +2 -2
- package/build/cjs/lib/core/components/Form/Controller/utils.js +45 -34
- package/build/cjs/lib/core/components/Form/DynamicField.js +6 -4
- package/build/cjs/lib/core/components/Form/hooks/useCreateContext.js +2 -2
- package/build/cjs/lib/core/components/Form/hooks/useCreateSearchContext.js +2 -2
- package/build/cjs/lib/core/components/Form/hooks/useIntegrationFF.js +6 -4
- package/build/cjs/lib/core/components/Form/hooks/useMutators.js +11 -7
- package/build/cjs/lib/core/components/Form/hooks/useSearchStore.js +4 -3
- package/build/cjs/lib/core/components/Form/hooks/useStore.js +15 -11
- package/build/cjs/lib/core/components/Form/utils/common.js +14 -11
- package/build/cjs/lib/core/components/View/helpers.js +5 -5
- package/build/cjs/lib/core/components/View/hooks/useComponents.js +2 -2
- package/build/cjs/lib/core/components/View/hooks/useCreateContext.js +2 -2
- package/build/cjs/lib/core/components/View/hooks/useRender.js +4 -3
- package/build/cjs/lib/core/helpers.js +5 -4
- package/build/cjs/lib/kit/components/AccordeonCard/AccordeonCard.js +2 -2
- package/build/cjs/lib/kit/components/Card/Card.js +2 -2
- package/build/cjs/lib/kit/components/GenerateRandomValueButton/GenerateRandomValueButton.js +2 -2
- package/build/cjs/lib/kit/components/Inputs/ArrayBase/ArrayBase.js +2 -2
- package/build/cjs/lib/kit/components/Inputs/CardOneOf/CardOneOf.js +2 -2
- package/build/cjs/lib/kit/components/Inputs/MultiOneOf/MultiOneOf.js +4 -3
- package/build/cjs/lib/kit/components/Inputs/ObjectBase/ObjectBase.css +6 -0
- package/build/cjs/lib/kit/components/Inputs/ObjectBase/ObjectBase.js +11 -5
- package/build/cjs/lib/kit/components/Inputs/ObjectValueInput/ObjectValueInput.js +7 -6
- package/build/cjs/lib/kit/components/Inputs/OneOf/OneOf.js +2 -2
- package/build/cjs/lib/kit/components/Inputs/Secret/Secret.js +4 -3
- package/build/cjs/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.js +4 -3
- package/build/cjs/lib/kit/components/Inputs/Text/Text.js +2 -2
- package/build/cjs/lib/kit/components/Inputs/TextContent/TextContent.js +2 -2
- package/build/cjs/lib/kit/components/Inputs/TextLink/TextLink.js +4 -3
- package/build/cjs/lib/kit/components/LazyLoader/LazyLoader.js +2 -2
- package/build/cjs/lib/kit/components/ViewLayouts/ViewAccordeon/ViewAccordeon.js +2 -2
- package/build/cjs/lib/kit/components/ViewLayouts/ViewAccordeonCard/ViewAccordeonCard.js +2 -2
- package/build/cjs/lib/kit/components/ViewLayouts/ViewCardAccordeon.js +2 -2
- package/build/cjs/lib/kit/components/Views/ArrayBaseView/ArrayBaseView.js +2 -2
- package/build/cjs/lib/kit/components/Views/BaseView/BaseView.js +2 -2
- package/build/cjs/lib/kit/components/Views/CardOneOfView.js +2 -2
- package/build/cjs/lib/kit/components/Views/MultiOneOfView/MultiOneOfView.js +2 -2
- package/build/cjs/lib/kit/components/Views/ObjectBaseView/ObjectBaseView.css +6 -0
- package/build/cjs/lib/kit/components/Views/ObjectBaseView/ObjectBaseView.js +16 -9
- package/build/cjs/lib/kit/components/Views/ObjectValueInputView/ObjectValueInputView.js +5 -5
- package/build/cjs/lib/kit/components/Views/OneOfView/OneOfView.js +17 -6
- package/build/cjs/lib/kit/components/Views/TextLinkView/TextLinkView.js +2 -2
- package/build/cjs/lib/kit/constants/common.js +2 -1
- package/build/cjs/lib/kit/hooks/useOneOf/useOneOf.css +5 -0
- package/build/cjs/lib/kit/hooks/useOneOf/useOneOf.js +35 -7
- package/build/cjs/lib/kit/utils/common.js +30 -25
- package/build/cjs/lib/kit/utils/index.js +1 -0
- package/build/cjs/lib/kit/utils/objectKeys.js +7 -0
- package/build/cjs/lib/kit/validators/validators.js +9 -7
- package/build/esm/lib/core/components/Form/Controller/Controller.js +2 -2
- package/build/esm/lib/core/components/Form/Controller/utils.js +45 -34
- package/build/esm/lib/core/components/Form/DynamicField.js +6 -4
- package/build/esm/lib/core/components/Form/hooks/useCreateContext.js +2 -2
- package/build/esm/lib/core/components/Form/hooks/useCreateSearchContext.js +2 -2
- package/build/esm/lib/core/components/Form/hooks/useIntegrationFF.js +6 -4
- package/build/esm/lib/core/components/Form/hooks/useMutators.js +11 -7
- package/build/esm/lib/core/components/Form/hooks/useSearchStore.js +4 -3
- package/build/esm/lib/core/components/Form/hooks/useStore.js +15 -11
- package/build/esm/lib/core/components/Form/utils/common.js +14 -11
- package/build/esm/lib/core/components/View/helpers.js +5 -5
- package/build/esm/lib/core/components/View/hooks/useComponents.js +2 -2
- package/build/esm/lib/core/components/View/hooks/useCreateContext.js +2 -2
- package/build/esm/lib/core/components/View/hooks/useRender.js +4 -3
- package/build/esm/lib/core/helpers.js +5 -4
- package/build/esm/lib/core/types/specs.d.ts +3 -1
- package/build/esm/lib/kit/components/AccordeonCard/AccordeonCard.js +2 -2
- package/build/esm/lib/kit/components/Card/Card.js +2 -2
- package/build/esm/lib/kit/components/GenerateRandomValueButton/GenerateRandomValueButton.js +2 -2
- package/build/esm/lib/kit/components/Inputs/ArrayBase/ArrayBase.js +2 -2
- package/build/esm/lib/kit/components/Inputs/CardOneOf/CardOneOf.js +2 -2
- package/build/esm/lib/kit/components/Inputs/MultiOneOf/MultiOneOf.js +4 -3
- package/build/esm/lib/kit/components/Inputs/ObjectBase/ObjectBase.css +6 -0
- package/build/esm/lib/kit/components/Inputs/ObjectBase/ObjectBase.js +12 -6
- package/build/esm/lib/kit/components/Inputs/ObjectValueInput/ObjectValueInput.js +5 -4
- package/build/esm/lib/kit/components/Inputs/OneOf/OneOf.js +2 -2
- package/build/esm/lib/kit/components/Inputs/Secret/Secret.js +4 -3
- package/build/esm/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.js +4 -3
- package/build/esm/lib/kit/components/Inputs/Text/Text.js +2 -2
- package/build/esm/lib/kit/components/Inputs/TextContent/TextContent.js +2 -2
- package/build/esm/lib/kit/components/Inputs/TextLink/TextLink.js +4 -3
- package/build/esm/lib/kit/components/LazyLoader/LazyLoader.js +2 -2
- package/build/esm/lib/kit/components/ViewLayouts/ViewAccordeon/ViewAccordeon.js +2 -2
- package/build/esm/lib/kit/components/ViewLayouts/ViewAccordeonCard/ViewAccordeonCard.js +2 -2
- package/build/esm/lib/kit/components/ViewLayouts/ViewCardAccordeon.js +2 -2
- package/build/esm/lib/kit/components/Views/ArrayBaseView/ArrayBaseView.js +2 -2
- package/build/esm/lib/kit/components/Views/BaseView/BaseView.js +2 -2
- package/build/esm/lib/kit/components/Views/CardOneOfView.js +2 -2
- package/build/esm/lib/kit/components/Views/MultiOneOfView/MultiOneOfView.js +2 -2
- package/build/esm/lib/kit/components/Views/ObjectBaseView/ObjectBaseView.css +6 -0
- package/build/esm/lib/kit/components/Views/ObjectBaseView/ObjectBaseView.js +16 -9
- package/build/esm/lib/kit/components/Views/ObjectValueInputView/ObjectValueInputView.js +3 -3
- package/build/esm/lib/kit/components/Views/OneOfView/OneOfView.js +18 -7
- package/build/esm/lib/kit/components/Views/TextLinkView/TextLinkView.js +2 -2
- package/build/esm/lib/kit/constants/common.d.ts +1 -0
- package/build/esm/lib/kit/constants/common.js +1 -0
- package/build/esm/lib/kit/hooks/useOneOf/useOneOf.css +5 -0
- package/build/esm/lib/kit/hooks/useOneOf/useOneOf.js +37 -9
- package/build/esm/lib/kit/utils/common.js +30 -25
- package/build/esm/lib/kit/utils/index.d.ts +1 -0
- package/build/esm/lib/kit/utils/index.js +1 -0
- package/build/esm/lib/kit/utils/objectKeys.d.ts +4 -0
- package/build/esm/lib/kit/utils/objectKeys.js +3 -0
- package/build/esm/lib/kit/validators/validators.js +9 -7
- package/package.json +1 -1
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
3
|
+
import get from 'lodash/get';
|
|
4
|
+
import isObjectLike from 'lodash/isObjectLike';
|
|
5
|
+
import keys from 'lodash/keys';
|
|
6
|
+
import set from 'lodash/set';
|
|
3
7
|
export const useMutators = (externalMutators) => {
|
|
4
8
|
const merge = React.useCallback((mutators, store) => {
|
|
5
9
|
const mergeSpec = (a = {}, b) => {
|
|
6
|
-
const result =
|
|
10
|
+
const result = cloneDeep(a);
|
|
7
11
|
const getKeys = (parent) => {
|
|
8
|
-
if (
|
|
9
|
-
return
|
|
12
|
+
if (isObjectLike(parent)) {
|
|
13
|
+
return keys(parent).reduce((acc, parentKey) => {
|
|
10
14
|
const childKeys = getKeys(parent[parentKey]);
|
|
11
15
|
return [
|
|
12
16
|
...acc,
|
|
@@ -18,14 +22,14 @@ export const useMutators = (externalMutators) => {
|
|
|
18
22
|
return [];
|
|
19
23
|
};
|
|
20
24
|
getKeys(b).forEach((key) => {
|
|
21
|
-
|
|
25
|
+
set(result, [key[0], 'value', ...key.slice(1)], get(b, key));
|
|
22
26
|
});
|
|
23
27
|
return result;
|
|
24
28
|
};
|
|
25
29
|
const mergeValuesOrErrors = (a = {}, b) => {
|
|
26
|
-
const result =
|
|
30
|
+
const result = cloneDeep(a);
|
|
27
31
|
Object.keys(b).forEach((key) => {
|
|
28
|
-
|
|
32
|
+
set(result, [key, 'value'], b[key]);
|
|
29
33
|
});
|
|
30
34
|
return result;
|
|
31
35
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import isUndefined from 'lodash/isUndefined';
|
|
3
|
+
import omit from 'lodash/omit';
|
|
3
4
|
import { getParentName } from '../';
|
|
4
5
|
export const useSearchStore = () => {
|
|
5
6
|
const [store, setStore] = React.useState({});
|
|
@@ -20,7 +21,7 @@ export const useSearchStore = () => {
|
|
|
20
21
|
return false;
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
|
-
if (
|
|
24
|
+
if (isUndefined(selfFlag)) {
|
|
24
25
|
return false;
|
|
25
26
|
}
|
|
26
27
|
return true;
|
|
@@ -29,7 +30,7 @@ export const useSearchStore = () => {
|
|
|
29
30
|
store,
|
|
30
31
|
setField: (name, search) => setStore((store) => (Object.assign(Object.assign({}, store), { [name]: search }))),
|
|
31
32
|
removeField: (name) => {
|
|
32
|
-
setStore((store) =>
|
|
33
|
+
setStore((store) => omit(store, name));
|
|
33
34
|
},
|
|
34
35
|
isHiddenField,
|
|
35
36
|
};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import clone from 'lodash/clone';
|
|
3
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
4
|
+
import get from 'lodash/get';
|
|
5
|
+
import omit from 'lodash/omit';
|
|
6
|
+
import set from 'lodash/set';
|
|
3
7
|
import { useFormState } from 'react-final-form';
|
|
4
8
|
import { transformArrIn } from '../utils';
|
|
5
9
|
export const useStore = (name) => {
|
|
@@ -7,37 +11,37 @@ export const useStore = (name) => {
|
|
|
7
11
|
const firstRenderRef = React.useRef(true);
|
|
8
12
|
const [store, setStore] = React.useState(() => {
|
|
9
13
|
const values = transformArrIn({
|
|
10
|
-
[name]:
|
|
14
|
+
[name]: get(formState.values, name),
|
|
11
15
|
});
|
|
12
16
|
const initialValue = transformArrIn({
|
|
13
|
-
[name]:
|
|
17
|
+
[name]: get(formState.initialValues, name),
|
|
14
18
|
});
|
|
15
19
|
return {
|
|
16
20
|
name,
|
|
17
|
-
initialValue:
|
|
18
|
-
values:
|
|
21
|
+
initialValue: cloneDeep(initialValue),
|
|
22
|
+
values: cloneDeep(values),
|
|
19
23
|
errors: {},
|
|
20
24
|
};
|
|
21
25
|
});
|
|
22
26
|
const submitFailed = formState.submitFailed;
|
|
23
27
|
const tools = React.useMemo(() => ({
|
|
24
28
|
initialValue: store.initialValue,
|
|
25
|
-
onChange: (name, value, errors) => setStore((store) => (Object.assign(Object.assign({}, store), { values:
|
|
26
|
-
onUnmount: (name) => setStore((store) => (Object.assign(Object.assign({}, store), { values:
|
|
29
|
+
onChange: (name, value, errors) => setStore((store) => (Object.assign(Object.assign({}, store), { values: set(Object.assign({}, store.values), name, clone(value)), errors: errors || {} }))),
|
|
30
|
+
onUnmount: (name) => setStore((store) => (Object.assign(Object.assign({}, store), { values: omit(store.values, name), errors: omit(store.errors, Object.keys(store.errors).filter((key) => key.startsWith(name))) }))),
|
|
27
31
|
submitFailed,
|
|
28
32
|
}), [store.initialValue, setStore, submitFailed]);
|
|
29
33
|
React.useEffect(() => {
|
|
30
34
|
if (!firstRenderRef.current) {
|
|
31
35
|
const values = transformArrIn({
|
|
32
|
-
[name]:
|
|
36
|
+
[name]: get(formState.values, name),
|
|
33
37
|
});
|
|
34
38
|
const initialValue = transformArrIn({
|
|
35
|
-
[name]:
|
|
39
|
+
[name]: get(formState.initialValues, name),
|
|
36
40
|
});
|
|
37
41
|
setStore({
|
|
38
42
|
name: name,
|
|
39
|
-
initialValue:
|
|
40
|
-
values:
|
|
43
|
+
initialValue: cloneDeep(initialValue),
|
|
44
|
+
values: cloneDeep(values),
|
|
41
45
|
errors: {},
|
|
42
46
|
});
|
|
43
47
|
}
|
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
import
|
|
1
|
+
import forEach from 'lodash/forEach';
|
|
2
|
+
import isArray from 'lodash/isArray';
|
|
3
|
+
import isObject from 'lodash/isObject';
|
|
4
|
+
import isObjectLike from 'lodash/isObjectLike';
|
|
2
5
|
import { SpecTypes } from '../../../constants';
|
|
3
6
|
import { isStringSpec } from '../../../helpers';
|
|
4
7
|
import { OBJECT_ARRAY_CNT, OBJECT_ARRAY_FLAG, SPEC_TYPE_FOR_GENERATE_BUTTON } from '../constants';
|
|
5
|
-
export const isCorrectConfig = (candidate) => Object.values(SpecTypes).every((type) =>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
export const isCorrectConfig = (candidate) => Object.values(SpecTypes).every((type) => isObjectLike(candidate) &&
|
|
9
|
+
isObjectLike(candidate[type]) &&
|
|
10
|
+
isObjectLike(candidate[type].inputs) &&
|
|
11
|
+
isObjectLike(candidate[type].layouts) &&
|
|
12
|
+
isObjectLike(candidate[type].validators));
|
|
10
13
|
export const transformArrIn = (value) => {
|
|
11
|
-
if (
|
|
14
|
+
if (isArray(value)) {
|
|
12
15
|
return value.reduce((arrObj, item, idx) => {
|
|
13
16
|
arrObj[`<${idx}>`] = transformArrIn(item);
|
|
14
17
|
return arrObj;
|
|
15
18
|
}, { [OBJECT_ARRAY_FLAG]: true, [OBJECT_ARRAY_CNT]: value.length });
|
|
16
19
|
}
|
|
17
|
-
if (
|
|
20
|
+
if (isObject(value)) {
|
|
18
21
|
const _value = Object.assign({}, value);
|
|
19
|
-
|
|
22
|
+
forEach(_value, (item, key) => {
|
|
20
23
|
_value[key] = transformArrIn(item);
|
|
21
24
|
});
|
|
22
25
|
return _value;
|
|
@@ -24,7 +27,7 @@ export const transformArrIn = (value) => {
|
|
|
24
27
|
return value;
|
|
25
28
|
};
|
|
26
29
|
export const transformArrOut = (value) => {
|
|
27
|
-
if (
|
|
30
|
+
if (isObject(value) && !isArray(value)) {
|
|
28
31
|
if (value[OBJECT_ARRAY_FLAG]) {
|
|
29
32
|
const _value = Object.keys(value)
|
|
30
33
|
.filter((key) => key !== OBJECT_ARRAY_FLAG && key !== OBJECT_ARRAY_CNT)
|
|
@@ -34,7 +37,7 @@ export const transformArrOut = (value) => {
|
|
|
34
37
|
return _value;
|
|
35
38
|
}
|
|
36
39
|
const _value = Object.assign({}, value);
|
|
37
|
-
|
|
40
|
+
forEach(_value, (item, key) => {
|
|
38
41
|
_value[key] = transformArrOut(item);
|
|
39
42
|
});
|
|
40
43
|
return _value;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import isObjectLike from 'lodash/isObjectLike';
|
|
2
2
|
import { SpecTypes } from '../../constants';
|
|
3
|
-
export const isCorrectViewConfig = (candidate) => Object.values(SpecTypes).every((type) =>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
export const isCorrectViewConfig = (candidate) => Object.values(SpecTypes).every((type) => isObjectLike(candidate) &&
|
|
4
|
+
isObjectLike(candidate[type]) &&
|
|
5
|
+
isObjectLike(candidate[type].views) &&
|
|
6
|
+
isObjectLike(candidate[type].layouts));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import isString from 'lodash/isString';
|
|
3
3
|
import { isValidElementType } from 'react-is';
|
|
4
4
|
import { isCorrectSpec } from '../../../helpers';
|
|
5
5
|
import { isCorrectViewConfig } from '../helpers';
|
|
@@ -21,7 +21,7 @@ export const useComponents = (spec, config) => {
|
|
|
21
21
|
return;
|
|
22
22
|
}, [views, (_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.type]);
|
|
23
23
|
const Layout = React.useMemo(() => {
|
|
24
|
-
if (layouts &&
|
|
24
|
+
if (layouts && isString(spec.viewSpec.layout)) {
|
|
25
25
|
const Component = layouts[spec.viewSpec.layout];
|
|
26
26
|
if (isValidElementType(Component)) {
|
|
27
27
|
return Component;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import get from 'lodash/get';
|
|
3
|
+
import isString from 'lodash/isString';
|
|
3
4
|
import { isValidElementType } from 'react-is';
|
|
4
5
|
import { isCorrectSpec } from '../../../helpers';
|
|
5
6
|
export const useRender = ({ value, name, spec, viewEntity, Layout, Link, }) => {
|
|
6
7
|
const render = React.useMemo(() => {
|
|
7
8
|
var _a;
|
|
8
|
-
if (viewEntity && isCorrectSpec(spec) &&
|
|
9
|
+
if (viewEntity && isCorrectSpec(spec) && isString(name)) {
|
|
9
10
|
if (!spec.viewSpec.hidden) {
|
|
10
|
-
const currentValue = name ?
|
|
11
|
+
const currentValue = name ? get(value, name) : value;
|
|
11
12
|
const linkValue = isValidElementType(Link) && ((_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.link) ? (React.createElement(Link, { value: currentValue, link: spec.viewSpec.link })) : undefined;
|
|
12
13
|
if (viewEntity.independent) {
|
|
13
14
|
const InputComponent = viewEntity.Component;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import isObjectLike from 'lodash/isObjectLike';
|
|
2
|
+
import isString from 'lodash/isString';
|
|
2
3
|
import { SpecTypes } from './constants';
|
|
3
|
-
export const isCorrectSpec = (candidate) =>
|
|
4
|
+
export const isCorrectSpec = (candidate) => isObjectLike(candidate) &&
|
|
4
5
|
(candidate.type === SpecTypes.Array ||
|
|
5
6
|
candidate.type === SpecTypes.Boolean ||
|
|
6
7
|
candidate.type === SpecTypes.Number ||
|
|
7
8
|
candidate.type === SpecTypes.Object ||
|
|
8
9
|
candidate.type === SpecTypes.String) &&
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
isObjectLike(candidate.viewSpec) &&
|
|
11
|
+
isString(candidate.viewSpec.type);
|
|
11
12
|
export const isArraySpec = (candidate) => (candidate === null || candidate === void 0 ? void 0 : candidate.type) === SpecTypes.Array;
|
|
12
13
|
export const isBooleanSpec = (candidate) => (candidate === null || candidate === void 0 ? void 0 : candidate.type) === SpecTypes.Boolean;
|
|
13
14
|
export const isNumberSpec = (candidate) => (candidate === null || candidate === void 0 ? void 0 : candidate.type) === SpecTypes.Number;
|
|
@@ -95,12 +95,14 @@ export interface ObjectSpec<LinkType = any, InputComponentProps extends Record<s
|
|
|
95
95
|
order?: string[];
|
|
96
96
|
link?: LinkType;
|
|
97
97
|
oneOfParams?: {
|
|
98
|
-
toggler?: 'select' | 'radio' | 'card';
|
|
98
|
+
toggler?: 'select' | 'radio' | 'card' | 'checkbox';
|
|
99
|
+
booleanMap?: Record<'true' | 'false', string>;
|
|
99
100
|
};
|
|
100
101
|
placeholder?: string;
|
|
101
102
|
hidden?: boolean;
|
|
102
103
|
inputProps?: InputComponentProps;
|
|
103
104
|
layoutProps?: LayoutComponentProps;
|
|
105
|
+
delimiter?: Record<string, string>;
|
|
104
106
|
};
|
|
105
107
|
}
|
|
106
108
|
export interface StringSpec<LinkType = any, InputComponentProps extends Record<string, any> | undefined = undefined, LayoutComponentProps extends Record<string, any> | undefined = undefined> {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ChevronDown } from '@gravity-ui/icons';
|
|
3
3
|
import { Button, Icon, Text } from '@gravity-ui/uikit';
|
|
4
|
-
import
|
|
4
|
+
import isString from 'lodash/isString';
|
|
5
5
|
import { block } from '../../utils';
|
|
6
6
|
import './AccordeonCard.css';
|
|
7
7
|
const b = block('accordeon-card');
|
|
@@ -29,7 +29,7 @@ export const AccordeonCard = ({ className, name, header, description, open: prop
|
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
const currentHeaderVariant = React.useMemo(() => {
|
|
32
|
-
if (!
|
|
32
|
+
if (!isString(header)) {
|
|
33
33
|
return 'body-1';
|
|
34
34
|
}
|
|
35
35
|
if (titleSize === 'm') {
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { HelpPopover } from '@gravity-ui/components';
|
|
3
3
|
import { ChevronDown } from '@gravity-ui/icons';
|
|
4
4
|
import { Button, Card as CardBase, Icon, Popover, Text } from '@gravity-ui/uikit';
|
|
5
|
-
import
|
|
5
|
+
import isString from 'lodash/isString';
|
|
6
6
|
import { COMMON_POPOVER_PLACEMENT, COMMON_TITLE_MAX_WIDTH } from '../../constants/common';
|
|
7
7
|
import { block } from '../../utils';
|
|
8
8
|
import './Card.css';
|
|
@@ -32,7 +32,7 @@ export const Card = ({ name, title: propsTitle, description, actions, open: prop
|
|
|
32
32
|
const preventEvent = React.useCallback((e) => e.stopPropagation(), []);
|
|
33
33
|
const titlePopoverDisabled = (((_a = titleRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0) <= COMMON_TITLE_MAX_WIDTH;
|
|
34
34
|
const title = React.useMemo(() => {
|
|
35
|
-
if (
|
|
35
|
+
if (isString(propsTitle)) {
|
|
36
36
|
return (React.createElement(React.Fragment, null,
|
|
37
37
|
React.createElement(Popover, { content: propsTitle, disabled: titlePopoverDisabled, placement: COMMON_POPOVER_PLACEMENT },
|
|
38
38
|
React.createElement(Text, { className: b('title'), ellipsis: true, ref: titleRef, variant: "subheader-2" }, propsTitle)),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Button } from '@gravity-ui/uikit';
|
|
3
|
-
import
|
|
3
|
+
import isFunction from 'lodash/isFunction';
|
|
4
4
|
import { useGenerateRandomValue } from '../../../core/components/Form/hooks';
|
|
5
5
|
import i18n from '../../i18n';
|
|
6
6
|
import { block } from '../../utils';
|
|
@@ -8,7 +8,7 @@ import './GenerateRandomValueButton.css';
|
|
|
8
8
|
const b = block('generate-random-value-button');
|
|
9
9
|
export const GenerateRandomValueButton = ({ spec, onChange, }) => {
|
|
10
10
|
const generateRandomValue = useGenerateRandomValue();
|
|
11
|
-
if (
|
|
11
|
+
if (isFunction(generateRandomValue) && spec.viewSpec.generateRandomValueButton) {
|
|
12
12
|
return (React.createElement(Button, { onClick: () => onChange(generateRandomValue(spec)), className: b() }, i18n('button-generate')));
|
|
13
13
|
}
|
|
14
14
|
return null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Plus } from '@gravity-ui/icons';
|
|
3
3
|
import { Button, Icon, Label } from '@gravity-ui/uikit';
|
|
4
|
-
import
|
|
4
|
+
import set from 'lodash/set';
|
|
5
5
|
import { Controller, OBJECT_ARRAY_CNT, OBJECT_ARRAY_FLAG, isBooleanSpec, isCorrectSpec, isNumberSpec, isStringSpec, transformArrIn, } from '../../../../core';
|
|
6
6
|
import { block } from '../../../utils';
|
|
7
7
|
import './ArrayBase.css';
|
|
@@ -25,7 +25,7 @@ export const ArrayBase = ({ spec, name, arrayInput, input }) => {
|
|
|
25
25
|
: `${idx + 1}` });
|
|
26
26
|
return itemSpec;
|
|
27
27
|
}, [spec.items, itemSpecCorrect]);
|
|
28
|
-
const parentOnChange = React.useCallback((childName, childValue, childErrors) => input.onChange((currentValue) =>
|
|
28
|
+
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]);
|
|
29
29
|
const AddButton = React.useCallback(() => {
|
|
30
30
|
let onClick = () => arrayInput.onItemAdd(undefined);
|
|
31
31
|
let qa = `${name}-add-item`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import set from 'lodash/set';
|
|
3
3
|
import { Card } from '../../';
|
|
4
4
|
import { Controller, isArrayItem, } from '../../../../core';
|
|
5
5
|
import { useErrorChecker, useOneOf } from '../../../hooks';
|
|
@@ -23,7 +23,7 @@ export const CardOneOf = (props) => {
|
|
|
23
23
|
return;
|
|
24
24
|
}, [name, input.onDrop]);
|
|
25
25
|
const parentOnChange = React.useCallback((childName, childValue, childErrors) => {
|
|
26
|
-
const value =
|
|
26
|
+
const value = set({}, childName.split(`${input.name}.`).join(''), childValue);
|
|
27
27
|
input.onChange(value, childErrors);
|
|
28
28
|
}, [input.onChange, input.name]);
|
|
29
29
|
useErrorChecker({ name, meta, open, setOpen });
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Select } from '@gravity-ui/uikit';
|
|
3
|
-
import
|
|
3
|
+
import isObjectLike from 'lodash/isObjectLike';
|
|
4
|
+
import set from 'lodash/set';
|
|
4
5
|
import { Controller, } from '../../../../core';
|
|
5
6
|
import { block } from '../../../utils';
|
|
6
7
|
import { GroupIndent } from '../../GroupIndent';
|
|
@@ -19,9 +20,9 @@ export const MultiOneOf = (props) => {
|
|
|
19
20
|
}
|
|
20
21
|
}, [onFocus, onBlur]);
|
|
21
22
|
const parentOnChange = React.useCallback((childName, childValue, childErrors) => {
|
|
22
|
-
onChange((currentValue) =>
|
|
23
|
+
onChange((currentValue) => set(Object.assign({}, currentValue), childName.split(`${name}.`).join(''), childValue), childErrors);
|
|
23
24
|
}, [name, onChange]);
|
|
24
|
-
const specProperties = React.useMemo(() => (
|
|
25
|
+
const specProperties = React.useMemo(() => (isObjectLike(spec.properties) ? spec.properties : {}), [spec.properties]);
|
|
25
26
|
const options = React.useMemo(() => (spec.viewSpec.order || Object.keys(specProperties)).map((value) => {
|
|
26
27
|
var _a, _b;
|
|
27
28
|
const title = ((_a = spec.description) === null || _a === void 0 ? void 0 : _a[value]) ||
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { Plus } from '@gravity-ui/icons';
|
|
4
|
-
import { Button, Icon } from '@gravity-ui/uikit';
|
|
5
|
-
import
|
|
4
|
+
import { Button, Icon, Text } from '@gravity-ui/uikit';
|
|
5
|
+
import isObjectLike from 'lodash/isObjectLike';
|
|
6
|
+
import set from 'lodash/set';
|
|
6
7
|
import { Controller, transformArrIn, } from '../../../../core';
|
|
7
8
|
import { block, filterPropertiesForObjectInline } from '../../../utils';
|
|
8
9
|
import './ObjectBase.css';
|
|
@@ -15,10 +16,10 @@ export const ObjectBase = (_a) => {
|
|
|
15
16
|
React.createElement(Icon, { data: Plus, size: 14 }),
|
|
16
17
|
spec.viewSpec.layoutTitle || null));
|
|
17
18
|
}, [spec.defaultValue, spec.viewSpec.layoutTitle, restProps.input.onChange]);
|
|
18
|
-
const parentOnChange = React.useCallback((childName, childValue, childErrors) => restProps.input.onChange((currentValue) =>
|
|
19
|
+
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]);
|
|
19
20
|
const content = React.useMemo(() => {
|
|
20
21
|
if (!spec.properties ||
|
|
21
|
-
!
|
|
22
|
+
!isObjectLike(spec.properties) ||
|
|
22
23
|
!Object.keys(spec.properties || {}).length) {
|
|
23
24
|
return null;
|
|
24
25
|
}
|
|
@@ -28,12 +29,17 @@ export const ObjectBase = (_a) => {
|
|
|
28
29
|
const specProperties = inline
|
|
29
30
|
? filterPropertiesForObjectInline(spec.properties)
|
|
30
31
|
: spec.properties;
|
|
31
|
-
|
|
32
|
+
const delimiter = spec.viewSpec.delimiter;
|
|
33
|
+
const orderProperties = spec.viewSpec.order || Object.keys(specProperties);
|
|
34
|
+
return (React.createElement("div", { className: b('content', { inline }) }, orderProperties.map((property) => {
|
|
32
35
|
var _a;
|
|
33
|
-
return specProperties[property] ? (React.createElement(
|
|
36
|
+
return specProperties[property] ? (React.createElement(React.Fragment, { key: `${name ? name + '.' : ''}${property}` },
|
|
37
|
+
React.createElement(Controller, { value: (_a = restProps.input.value) === null || _a === void 0 ? void 0 : _a[property], spec: specProperties[property], name: `${name ? name + '.' : ''}${property}`, parentOnChange: parentOnChange, parentOnUnmount: restProps.input.parentOnUnmount }),
|
|
38
|
+
delimiter && delimiter[property] ? (React.createElement(Text, { className: b('delimiter') }, delimiter[property])) : null)) : null;
|
|
34
39
|
})));
|
|
35
40
|
}, [
|
|
36
41
|
spec.properties,
|
|
42
|
+
spec.viewSpec.delimiter,
|
|
37
43
|
spec.viewSpec.order,
|
|
38
44
|
restProps.input.value,
|
|
39
45
|
restProps.input.parentOnUnmount,
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
3
|
+
import set from 'lodash/set';
|
|
3
4
|
import { Controller } from '../../../../core';
|
|
4
|
-
|
|
5
|
+
import { OBJECT_VALUE_PROPERTY_NAME } from '../../../constants/common';
|
|
5
6
|
export const ObjectValueInput = (props) => {
|
|
6
7
|
var _a;
|
|
7
8
|
const { spec, input, name, Layout } = props;
|
|
8
|
-
const parentOnChange = React.useCallback((childName, childValue, childErrors) => input.onChange((currentValue) =>
|
|
9
|
+
const parentOnChange = React.useCallback((childName, childValue, childErrors) => input.onChange((currentValue) => set(Object.assign({}, currentValue), childName.split(`${name}.`).join(''), childValue), childErrors), [input.onChange, input.name]);
|
|
9
10
|
const childSpec = React.useMemo(() => {
|
|
10
11
|
var _a;
|
|
11
12
|
if ((_a = spec.properties) === null || _a === void 0 ? void 0 : _a[OBJECT_VALUE_PROPERTY_NAME]) {
|
|
12
|
-
const childSpec =
|
|
13
|
+
const childSpec = cloneDeep(spec.properties[OBJECT_VALUE_PROPERTY_NAME]);
|
|
13
14
|
childSpec.viewSpec.layout = 'transparent';
|
|
14
15
|
return childSpec;
|
|
15
16
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import set from 'lodash/set';
|
|
3
3
|
import { GroupIndent } from '../../';
|
|
4
4
|
import { Controller, } from '../../../../core';
|
|
5
5
|
import { useOneOf } from '../../../hooks';
|
|
@@ -10,7 +10,7 @@ const OneOfComponent = (props) => {
|
|
|
10
10
|
var _a;
|
|
11
11
|
const { oneOfValue, specProperties, toggler } = useOneOf({ props });
|
|
12
12
|
const parentOnChange = React.useCallback((childName, childValue, childErrors) => {
|
|
13
|
-
const value =
|
|
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
16
|
return (React.createElement("div", { className: b({
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
3
|
+
import set from 'lodash/set';
|
|
3
4
|
import { Controller } from '../../../../core';
|
|
4
5
|
const SECRET_PROPERTY_NAME = 'raw';
|
|
5
6
|
export const Secret = (props) => {
|
|
@@ -8,13 +9,13 @@ export const Secret = (props) => {
|
|
|
8
9
|
const childSpec = React.useMemo(() => {
|
|
9
10
|
var _a, _b;
|
|
10
11
|
if ((_a = spec.properties) === null || _a === void 0 ? void 0 : _a[SECRET_PROPERTY_NAME]) {
|
|
11
|
-
const childSpec =
|
|
12
|
+
const childSpec = cloneDeep((_b = spec.properties) === null || _b === void 0 ? void 0 : _b[SECRET_PROPERTY_NAME]);
|
|
12
13
|
childSpec.viewSpec.layout = 'transparent';
|
|
13
14
|
return childSpec;
|
|
14
15
|
}
|
|
15
16
|
return undefined;
|
|
16
17
|
}, [spec.properties]);
|
|
17
|
-
const parentOnChange = React.useCallback((childName, childValue, childErrors) => input.onChange((currentValue) =>
|
|
18
|
+
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]);
|
|
18
19
|
if (!childSpec) {
|
|
19
20
|
return null;
|
|
20
21
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Plus, TrashBin } from '@gravity-ui/icons';
|
|
3
3
|
import { Button, Icon, Table } from '@gravity-ui/uikit';
|
|
4
|
-
import
|
|
4
|
+
import noop from 'lodash/noop';
|
|
5
|
+
import set from 'lodash/set';
|
|
5
6
|
import { Controller, OBJECT_ARRAY_CNT, OBJECT_ARRAY_FLAG, isArraySpec, isBooleanSpec, isObjectSpec, transformArrIn, } from '../../../../core';
|
|
6
7
|
import { useSearchContext } from '../../../../core/components/Form/hooks';
|
|
7
8
|
import { block } from '../../../utils';
|
|
@@ -22,7 +23,7 @@ export const TableArrayInput = ({ spec, name, arrayInput, input }) => {
|
|
|
22
23
|
const onItemRemove = React.useCallback((key) => {
|
|
23
24
|
arrayInput.onItemRemove(key);
|
|
24
25
|
}, [arrayInput.onItemRemove]);
|
|
25
|
-
const parentOnChange = React.useCallback((childName, childValue, childErrors) => input.onChange((currentValue) =>
|
|
26
|
+
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]);
|
|
26
27
|
const columns = React.useMemo(() => {
|
|
27
28
|
const { items, viewSpec: { table }, } = spec;
|
|
28
29
|
if (!(table === null || table === void 0 ? void 0 : table.length) || !isObjectSpec(items)) {
|
|
@@ -56,7 +57,7 @@ export const TableArrayInput = ({ spec, name, arrayInput, input }) => {
|
|
|
56
57
|
arr: isArraySpec(preparedEntitySpec),
|
|
57
58
|
obj: isObjectSpec(preparedEntitySpec),
|
|
58
59
|
}), key: `${name}.<${key}>.${property}` },
|
|
59
|
-
React.createElement(Controller, { value: (_c = (_b = input.value) === null || _b === void 0 ? void 0 : _b[`<${key}>`]) === null || _c === void 0 ? void 0 : _c[property], spec: preparedEntitySpec, name: `${name}.<${key}>.${property}`, parentOnChange: parentOnChange, parentOnUnmount:
|
|
60
|
+
React.createElement(Controller, { value: (_c = (_b = input.value) === null || _b === void 0 ? void 0 : _b[`<${key}>`]) === null || _c === void 0 ? void 0 : _c[property], spec: preparedEntitySpec, name: `${name}.<${key}>.${property}`, parentOnChange: parentOnChange, parentOnUnmount: noop })));
|
|
60
61
|
},
|
|
61
62
|
}));
|
|
62
63
|
return [idxColumn, ...columns, removeColumn];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { PasswordInput } from '@gravity-ui/components';
|
|
3
3
|
import { TextInput } from '@gravity-ui/uikit';
|
|
4
|
-
import
|
|
4
|
+
import isNil from 'lodash/isNil';
|
|
5
5
|
export const Text = ({ name, input: { value, onBlur, onChange, onFocus }, spec, inputProps, }) => {
|
|
6
|
-
const props = Object.assign(Object.assign({ hasClear: true }, inputProps), { value:
|
|
6
|
+
const props = Object.assign(Object.assign({ hasClear: true }, inputProps), { value: isNil(value) ? '' : `${value}`, onBlur: onBlur, onFocus: onFocus, onUpdate: onChange, disabled: spec.viewSpec.disabled, placeholder: spec.viewSpec.placeholder, qa: name });
|
|
7
7
|
if (spec.viewSpec.type === 'password') {
|
|
8
8
|
return (React.createElement(PasswordInput, Object.assign({}, props, { autoComplete: "new-password", showCopyButton: true, showRevealButton: true })));
|
|
9
9
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { Label, Text } from '@gravity-ui/uikit';
|
|
4
|
-
import
|
|
4
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
5
5
|
import { block } from '../../../utils';
|
|
6
6
|
import { LazyLoader } from '../../LazyLoader';
|
|
7
7
|
import { loadIcon } from './utils';
|
|
@@ -29,7 +29,7 @@ export const TextContent = (_a) => {
|
|
|
29
29
|
React.createElement(Text, { color: "secondary" }, input.value))) : null));
|
|
30
30
|
}
|
|
31
31
|
if (Layout) {
|
|
32
|
-
const _spec =
|
|
32
|
+
const _spec = cloneDeep(spec);
|
|
33
33
|
if (!(textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.text)) {
|
|
34
34
|
_spec.viewSpec.layoutDescription = undefined;
|
|
35
35
|
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
3
|
+
import set from 'lodash/set';
|
|
3
4
|
import { Controller, isStringSpec, } from '../../../../core';
|
|
4
5
|
const TEXT_LINK_PROPERTY_NAME = 'text';
|
|
5
6
|
export const TextLink = (props) => {
|
|
6
7
|
var _a;
|
|
7
8
|
const { spec, input, name, Layout } = props;
|
|
8
|
-
const parentOnChange = React.useCallback((childName, childValue, childErrors) => input.onChange((currentValue) =>
|
|
9
|
+
const parentOnChange = React.useCallback((childName, childValue, childErrors) => input.onChange((currentValue) => set(Object.assign({}, currentValue), childName.split(`${name}.`).join(''), childValue), childErrors), [input.onChange, input.name]);
|
|
9
10
|
const childSpec = React.useMemo(() => {
|
|
10
11
|
var _a;
|
|
11
12
|
if (((_a = spec.properties) === null || _a === void 0 ? void 0 : _a[TEXT_LINK_PROPERTY_NAME]) &&
|
|
12
13
|
isStringSpec(spec.properties[TEXT_LINK_PROPERTY_NAME])) {
|
|
13
|
-
const childSpec =
|
|
14
|
+
const childSpec = cloneDeep(spec.properties[TEXT_LINK_PROPERTY_NAME]);
|
|
14
15
|
childSpec.viewSpec.layout = 'transparent';
|
|
15
16
|
return childSpec;
|
|
16
17
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import isUndefined from 'lodash/isUndefined';
|
|
3
3
|
export const LazyLoader = ({ component, initialFallback = React.createElement(React.Fragment, null), }) => {
|
|
4
4
|
const fallback = React.useRef(() => initialFallback);
|
|
5
5
|
const Component = component;
|
|
6
6
|
const updateFallback = async () => {
|
|
7
7
|
const result = await component._result;
|
|
8
|
-
if (!
|
|
8
|
+
if (!isUndefined(result)) {
|
|
9
9
|
fallback.current = result.default;
|
|
10
10
|
}
|
|
11
11
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import isBoolean from 'lodash/isBoolean';
|
|
3
3
|
import { isNotEmptyValue } from '../../../utils';
|
|
4
4
|
import { SimpleVerticalAccordeon } from '../../SimpleVerticalAccordeon';
|
|
5
5
|
export const ViewAccordeon = ({ name, value, spec, children, }) => {
|
|
6
|
-
const [open, setOpen] = React.useState(
|
|
6
|
+
const [open, setOpen] = React.useState(isBoolean(spec.viewSpec.layoutOpen) ? spec.viewSpec.layoutOpen : true);
|
|
7
7
|
if (!isNotEmptyValue(value, spec)) {
|
|
8
8
|
return null;
|
|
9
9
|
}
|