@gravity-ui/dynamic-forms 4.0.0 → 4.0.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/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.js +4 -3
- package/build/cjs/lib/kit/components/Inputs/ObjectValueInput/ObjectValueInput.js +4 -3
- 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.js +2 -2
- package/build/cjs/lib/kit/components/Views/ObjectValueInputView/ObjectValueInputView.js +2 -2
- package/build/cjs/lib/kit/components/Views/OneOfView/OneOfView.js +2 -2
- package/build/cjs/lib/kit/components/Views/TextLinkView/TextLinkView.js +2 -2
- package/build/cjs/lib/kit/hooks/useOneOf/useOneOf.js +5 -4
- package/build/cjs/lib/kit/utils/common.js +30 -25
- 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/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.js +4 -3
- package/build/esm/lib/kit/components/Inputs/ObjectValueInput/ObjectValueInput.js +4 -3
- 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.js +2 -2
- package/build/esm/lib/kit/components/Views/ObjectValueInputView/ObjectValueInputView.js +2 -2
- package/build/esm/lib/kit/components/Views/OneOfView/OneOfView.js +2 -2
- package/build/esm/lib/kit/components/Views/TextLinkView/TextLinkView.js +2 -2
- package/build/esm/lib/kit/hooks/useOneOf/useOneOf.js +5 -4
- package/build/esm/lib/kit/utils/common.js +30 -25
- package/build/esm/lib/kit/validators/validators.js +9 -7
- package/package.json +1 -1
|
@@ -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;
|
|
@@ -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]) ||
|
|
@@ -2,7 +2,8 @@ import { __rest } from "tslib";
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { Plus } from '@gravity-ui/icons';
|
|
4
4
|
import { Button, Icon } from '@gravity-ui/uikit';
|
|
5
|
-
import
|
|
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
|
}
|
|
@@ -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
|
const OBJECT_VALUE_PROPERTY_NAME = 'value';
|
|
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
|
}
|
|
@@ -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 { AccordeonCard } from '../../AccordeonCard';
|
|
5
5
|
export const ViewAccordeonCard = ({ value, name, 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
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import isBoolean from 'lodash/isBoolean';
|
|
3
3
|
import { Card } from '../';
|
|
4
4
|
import { isNotEmptyValue } from '../../utils';
|
|
5
5
|
export const ViewCardAccordeon = ({ 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
|
const onToggle = React.useCallback(() => setOpen((f) => !f), [setOpen]);
|
|
8
8
|
if (!isNotEmptyValue(value, spec)) {
|
|
9
9
|
return null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Label } from '@gravity-ui/uikit';
|
|
3
|
-
import
|
|
3
|
+
import map from 'lodash/map';
|
|
4
4
|
import { ViewController, isCorrectSpec } from '../../../../core';
|
|
5
5
|
import { block } from '../../../utils';
|
|
6
6
|
import './ArrayBaseView.css';
|
|
@@ -17,7 +17,7 @@ export const ArrayBaseView = ({ spec, name, value = [] }) => {
|
|
|
17
17
|
: `${idx + 1}` });
|
|
18
18
|
return itemSpec;
|
|
19
19
|
}, [spec.items, itemSpecCorrect]);
|
|
20
|
-
const items = React.useMemo(() =>
|
|
20
|
+
const items = React.useMemo(() => map(value, (__, idx) => {
|
|
21
21
|
const itemSpec = getItemSpec(idx);
|
|
22
22
|
if (!itemSpec) {
|
|
23
23
|
return null;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import isString from 'lodash/isString';
|
|
3
3
|
import { LongValue } from '../../../components';
|
|
4
4
|
export const BaseView = ({ value, spec, linkValue, }) => {
|
|
5
5
|
var _a;
|
|
6
|
-
if (
|
|
6
|
+
if (isString(value) && linkValue) {
|
|
7
7
|
return React.createElement(React.Fragment, null, linkValue);
|
|
8
8
|
}
|
|
9
9
|
return (React.createElement(LongValue, { value: ((_a = spec === null || spec === void 0 ? void 0 : spec.description) === null || _a === void 0 ? void 0 : _a[String(value)]) || String(value) }));
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import isObjectLike from 'lodash/isObjectLike';
|
|
3
3
|
import { Card, ViewRow } from '../';
|
|
4
4
|
import { ViewController } from '../../../core';
|
|
5
5
|
export const CardOneOfView = (props) => {
|
|
6
6
|
const { value = {}, spec, name } = props;
|
|
7
7
|
const [open, setOpen] = React.useState(true);
|
|
8
8
|
const onToggle = React.useCallback(() => setOpen((f) => !f), [setOpen]);
|
|
9
|
-
const specProperties = React.useMemo(() => (
|
|
9
|
+
const specProperties = React.useMemo(() => (isObjectLike(spec.properties) ? spec.properties : {}), [spec.properties]);
|
|
10
10
|
const valueKey = React.useMemo(() => Object.keys(value)[0], [value]);
|
|
11
11
|
const valueName = React.useMemo(() => {
|
|
12
12
|
var _a, _b;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Popover } from '@gravity-ui/uikit';
|
|
3
|
-
import
|
|
3
|
+
import isObjectLike from 'lodash/isObjectLike';
|
|
4
4
|
import { ViewController } from '../../../../core';
|
|
5
5
|
import { block } from '../../../utils';
|
|
6
6
|
import { GroupIndent } from '../../GroupIndent';
|
|
@@ -8,7 +8,7 @@ import './MultiOneOfView.css';
|
|
|
8
8
|
const b = block('multi-oneof-view');
|
|
9
9
|
export const MultiOneOfView = (props) => {
|
|
10
10
|
const { name, value, Layout, spec, withoutIndent } = props;
|
|
11
|
-
const specProperties = React.useMemo(() => (
|
|
11
|
+
const specProperties = React.useMemo(() => (isObjectLike(spec.properties) ? spec.properties : {}), [spec.properties]);
|
|
12
12
|
const values = React.useMemo(() => Object.keys(value || []), [value]);
|
|
13
13
|
const items = React.useMemo(() => values.map((value) => {
|
|
14
14
|
var _a, _b;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import
|
|
3
|
+
import isObjectLike from 'lodash/isObjectLike';
|
|
4
4
|
import { ViewController } from '../../../../core';
|
|
5
5
|
import { block, filterPropertiesForObjectInline } from '../../../utils';
|
|
6
6
|
import './ObjectBaseView.css';
|
|
7
7
|
const b = block('object-base-view');
|
|
8
8
|
export const ObjectBaseView = (_a) => {
|
|
9
9
|
var { inline, spec, name, Layout } = _a, restProps = __rest(_a, ["inline", "spec", "name", "Layout"]);
|
|
10
|
-
if (!spec.properties || !
|
|
10
|
+
if (!spec.properties || !isObjectLike(spec.properties)) {
|
|
11
11
|
return null;
|
|
12
12
|
}
|
|
13
13
|
const specProperties = inline
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import
|
|
3
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
4
4
|
import { ViewController } from '../../../../core';
|
|
5
5
|
const OBJECT_VALUE_PROPERTY_NAME = 'value';
|
|
6
6
|
export const ObjectValueInputView = (_a) => {
|
|
@@ -8,7 +8,7 @@ export const ObjectValueInputView = (_a) => {
|
|
|
8
8
|
const childSpec = React.useMemo(() => {
|
|
9
9
|
var _a;
|
|
10
10
|
if ((_a = spec.properties) === null || _a === void 0 ? void 0 : _a[OBJECT_VALUE_PROPERTY_NAME]) {
|
|
11
|
-
const childSpec =
|
|
11
|
+
const childSpec = cloneDeep(spec.properties[OBJECT_VALUE_PROPERTY_NAME]);
|
|
12
12
|
childSpec.viewSpec.layout = '';
|
|
13
13
|
return childSpec;
|
|
14
14
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import isObjectLike from 'lodash/isObjectLike';
|
|
3
3
|
import { GroupIndent } from '../../';
|
|
4
4
|
import { ViewController } from '../../../../core';
|
|
5
5
|
import { block } from '../../../utils';
|
|
@@ -7,7 +7,7 @@ import './OneOfView.css';
|
|
|
7
7
|
const b = block('oneof-view');
|
|
8
8
|
const OneOfViewComponent = (props) => {
|
|
9
9
|
const { value = {}, spec, Layout, name } = props;
|
|
10
|
-
const specProperties = React.useMemo(() => (
|
|
10
|
+
const specProperties = React.useMemo(() => (isObjectLike(spec.properties) ? spec.properties : {}), [spec.properties]);
|
|
11
11
|
const valueKey = React.useMemo(() => Object.keys(value)[0], [value]);
|
|
12
12
|
const valueName = React.useMemo(() => {
|
|
13
13
|
var _a, _b;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import
|
|
3
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
4
4
|
import { ViewController, isStringSpec } from '../../../../core';
|
|
5
5
|
const TEXT_LINK_PROPERTY_NAME = 'text';
|
|
6
6
|
export const TextLinkView = (_a) => {
|
|
@@ -9,7 +9,7 @@ export const TextLinkView = (_a) => {
|
|
|
9
9
|
var _a;
|
|
10
10
|
if (((_a = spec.properties) === null || _a === void 0 ? void 0 : _a[TEXT_LINK_PROPERTY_NAME]) &&
|
|
11
11
|
isStringSpec(spec.properties[TEXT_LINK_PROPERTY_NAME])) {
|
|
12
|
-
const childSpec =
|
|
12
|
+
const childSpec = cloneDeep(spec.properties[TEXT_LINK_PROPERTY_NAME]);
|
|
13
13
|
childSpec.viewSpec.layout = '';
|
|
14
14
|
childSpec.viewSpec.link = value === null || value === void 0 ? void 0 : value.link;
|
|
15
15
|
return childSpec;
|