@gravity-ui/dynamic-forms 1.1.1 → 1.2.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.
Files changed (57) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/build/cjs/lib/core/components/Form/Controller.js +3 -1
  3. package/build/cjs/lib/core/components/Form/DynamicField.js +14 -5
  4. package/build/cjs/lib/core/components/Form/hooks/index.js +4 -0
  5. package/build/cjs/lib/core/components/Form/hooks/useComponents.js +2 -2
  6. package/build/cjs/lib/core/components/Form/hooks/useCreateSearchContext.js +9 -0
  7. package/build/cjs/lib/core/components/Form/hooks/useField.js +6 -6
  8. package/build/cjs/lib/core/components/Form/hooks/useSearch/index.js +4 -0
  9. package/build/cjs/lib/core/components/Form/hooks/useSearch/useSearch.css +9 -0
  10. package/build/cjs/lib/core/components/Form/hooks/useSearch/useSearch.js +22 -0
  11. package/build/cjs/lib/core/components/Form/hooks/useSearchContext.js +12 -0
  12. package/build/cjs/lib/core/components/Form/hooks/useSearchStore.js +38 -0
  13. package/build/cjs/lib/core/components/Form/hooks/useStore.js +4 -4
  14. package/build/cjs/lib/core/components/Form/hooks/useValidate.js +2 -2
  15. package/build/cjs/lib/core/components/Form/index.js +1 -1
  16. package/build/cjs/lib/core/components/Form/types/index.js +1 -0
  17. package/build/cjs/lib/core/components/Form/types/search.js +2 -0
  18. package/build/cjs/lib/core/components/Form/{helpers.js → utils/common.js} +2 -2
  19. package/build/cjs/lib/core/components/Form/utils/index.js +5 -0
  20. package/build/cjs/lib/core/components/Form/utils/search.js +19 -0
  21. package/build/cjs/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.css +10 -0
  22. package/build/cjs/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.js +19 -9
  23. package/build/esm/lib/core/components/Form/Controller.js +3 -1
  24. package/build/esm/lib/core/components/Form/DynamicField.d.ts +2 -1
  25. package/build/esm/lib/core/components/Form/DynamicField.js +14 -5
  26. package/build/esm/lib/core/components/Form/hooks/index.d.ts +4 -0
  27. package/build/esm/lib/core/components/Form/hooks/index.js +4 -0
  28. package/build/esm/lib/core/components/Form/hooks/useComponents.js +1 -1
  29. package/build/esm/lib/core/components/Form/hooks/useCreateSearchContext.d.ts +3 -0
  30. package/build/esm/lib/core/components/Form/hooks/useCreateSearchContext.js +4 -0
  31. package/build/esm/lib/core/components/Form/hooks/useField.js +1 -1
  32. package/build/esm/lib/core/components/Form/hooks/useSearch/index.d.ts +1 -0
  33. package/build/esm/lib/core/components/Form/hooks/useSearch/index.js +1 -0
  34. package/build/esm/lib/core/components/Form/hooks/useSearch/useSearch.css +9 -0
  35. package/build/esm/lib/core/components/Form/hooks/useSearch/useSearch.d.ts +4 -0
  36. package/build/esm/lib/core/components/Form/hooks/useSearch/useSearch.js +18 -0
  37. package/build/esm/lib/core/components/Form/hooks/useSearchContext.d.ts +1 -0
  38. package/build/esm/lib/core/components/Form/hooks/useSearchContext.js +7 -0
  39. package/build/esm/lib/core/components/Form/hooks/useSearchStore.d.ts +8 -0
  40. package/build/esm/lib/core/components/Form/hooks/useSearchStore.js +33 -0
  41. package/build/esm/lib/core/components/Form/hooks/useStore.js +1 -1
  42. package/build/esm/lib/core/components/Form/hooks/useValidate.js +1 -1
  43. package/build/esm/lib/core/components/Form/index.d.ts +1 -1
  44. package/build/esm/lib/core/components/Form/index.js +1 -1
  45. package/build/esm/lib/core/components/Form/types/index.d.ts +1 -0
  46. package/build/esm/lib/core/components/Form/types/index.js +1 -0
  47. package/build/esm/lib/core/components/Form/types/search.d.ts +8 -0
  48. package/build/esm/lib/core/components/Form/types/search.js +1 -0
  49. package/build/esm/lib/core/components/Form/{helpers.d.ts → utils/common.d.ts} +1 -1
  50. package/build/esm/lib/core/components/Form/{helpers.js → utils/common.js} +2 -2
  51. package/build/esm/lib/core/components/Form/utils/index.d.ts +2 -0
  52. package/build/esm/lib/core/components/Form/utils/index.js +2 -0
  53. package/build/esm/lib/core/components/Form/utils/search.d.ts +3 -0
  54. package/build/esm/lib/core/components/Form/utils/search.js +14 -0
  55. package/build/esm/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.css +10 -0
  56. package/build/esm/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.js +19 -9
  57. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.2.0](https://github.com/gravity-ui/dynamic-forms/compare/v1.1.1...v1.2.0) (2023-03-23)
4
+
5
+
6
+ ### Features
7
+
8
+ * search ([#10](https://github.com/gravity-ui/dynamic-forms/issues/10)) ([4ed7d5c](https://github.com/gravity-ui/dynamic-forms/commit/4ed7d5c85dbb890f4c8148d4de43a626917cec0f))
9
+
3
10
  ## [1.1.1](https://github.com/gravity-ui/dynamic-forms/compare/v1.1.0...v1.1.1) (2023-03-21)
4
11
 
5
12
 
@@ -5,6 +5,7 @@ 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 useSearch_1 = require("./hooks/useSearch");
8
9
  const Controller = ({ spec, name, initialValue, parentOnChange, parentOnUnmount, }) => {
9
10
  const { tools } = (0, hooks_1.useDynamicFormsCtx)();
10
11
  const { inputEntity, Layout } = (0, hooks_1.useComponents)(spec);
@@ -19,8 +20,9 @@ const Controller = ({ spec, name, initialValue, parentOnChange, parentOnUnmount,
19
20
  parentOnChange,
20
21
  parentOnUnmount,
21
22
  });
23
+ const withSearch = (0, useSearch_1.useSearch)(spec, renderProps.input.value, name);
22
24
  if (lodash_1.default.isString(name) && (0, helpers_1.isCorrectSpec)(spec)) {
23
- return render(renderProps);
25
+ return withSearch(render(renderProps));
24
26
  }
25
27
  return null;
26
28
  };
@@ -7,21 +7,30 @@ const lodash_1 = tslib_1.__importDefault(require("lodash"));
7
7
  const react_is_1 = require("react-is");
8
8
  const helpers_1 = require("../../helpers");
9
9
  const Controller_1 = require("./Controller");
10
- const helpers_2 = require("./helpers");
11
10
  const hooks_1 = require("./hooks");
12
- const DynamicField = ({ name, spec, config, Monaco }) => {
11
+ const utils_1 = require("./utils");
12
+ const DynamicField = ({ name, spec, config, Monaco, search }) => {
13
13
  const DynamicFormsCtx = (0, hooks_1.useCreateContext)();
14
+ const SearchContext = (0, hooks_1.useCreateSearchContext)();
14
15
  const { tools, watcher } = (0, hooks_1.useStore)(name);
16
+ const { setField, removeField, isHiddenField } = (0, hooks_1.useSearchStore)(name);
15
17
  const context = react_1.default.useMemo(() => ({
16
18
  config,
17
19
  Monaco: (0, react_is_1.isValidElementType)(Monaco) ? Monaco : undefined,
18
20
  tools,
19
21
  }), [tools, config, Monaco]);
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]);
22
+ const searchContext = react_1.default.useMemo(() => ({
23
+ setField,
24
+ removeField,
25
+ isHiddenField,
26
+ searchFunction: lodash_1.default.isFunction(search) ? search : (0, utils_1.getDefaultSearchFunction)(search),
27
+ }), [isHiddenField, removeField, search, setField]);
28
+ const correctParams = react_1.default.useMemo(() => lodash_1.default.isString(name) && (0, helpers_1.isCorrectSpec)(spec) && (0, utils_1.isCorrectConfig)(config), [name, spec, config]);
21
29
  if (correctParams) {
22
30
  return (react_1.default.createElement(DynamicFormsCtx.Provider, { value: context },
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
- watcher));
31
+ react_1.default.createElement(SearchContext.Provider, { value: searchContext },
32
+ react_1.default.createElement(Controller_1.Controller, { spec: spec, name: name, parentOnChange: null, parentOnUnmount: null, initialValue: lodash_1.default.get(tools.initialValue, name) }),
33
+ watcher)));
25
34
  }
26
35
  return null;
27
36
  };
@@ -9,3 +9,7 @@ tslib_1.__exportStar(require("./useRender"), exports);
9
9
  tslib_1.__exportStar(require("./useStore"), exports);
10
10
  tslib_1.__exportStar(require("./useValidate"), exports);
11
11
  tslib_1.__exportStar(require("./useMonaco"), exports);
12
+ tslib_1.__exportStar(require("./useSearchStore"), exports);
13
+ tslib_1.__exportStar(require("./useSearchContext"), exports);
14
+ tslib_1.__exportStar(require("./useSearch"), exports);
15
+ tslib_1.__exportStar(require("./useCreateSearchContext"), exports);
@@ -6,13 +6,13 @@ const react_1 = tslib_1.__importDefault(require("react"));
6
6
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
7
7
  const react_is_1 = require("react-is");
8
8
  const helpers_1 = require("../../../helpers");
9
- const helpers_2 = require("../helpers");
9
+ const utils_1 = require("../utils");
10
10
  const _1 = require("./");
11
11
  const useComponents = (spec) => {
12
12
  var _a, _b;
13
13
  const { config } = (0, _1.useDynamicFormsCtx)();
14
14
  const { inputs, layouts } = react_1.default.useMemo(() => {
15
- if ((0, helpers_2.isCorrectConfig)(config) && (0, helpers_1.isCorrectSpec)(spec)) {
15
+ if ((0, utils_1.isCorrectConfig)(config) && (0, helpers_1.isCorrectSpec)(spec)) {
16
16
  return config[spec.type];
17
17
  }
18
18
  return {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useCreateSearchContext = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
7
+ const createContext = lodash_1.default.once(() => react_1.default.createContext({}));
8
+ const useCreateSearchContext = () => createContext();
9
+ exports.useCreateSearchContext = useCreateSearchContext;
@@ -6,20 +6,20 @@ const react_1 = tslib_1.__importDefault(require("react"));
6
6
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
7
7
  const helpers_1 = require("../../../helpers");
8
8
  const constants_1 = require("../constants");
9
- const helpers_2 = require("../helpers");
9
+ const utils_1 = require("../utils");
10
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) {
14
14
  return;
15
15
  }
16
- return propsValidate === null || propsValidate === void 0 ? void 0 : propsValidate((0, helpers_2.transformArrOut)(value));
16
+ return propsValidate === null || propsValidate === void 0 ? void 0 : propsValidate((0, utils_1.transformArrOut)(value));
17
17
  }, [propsValidate]);
18
18
  const [state, setState] = react_1.default.useState(() => {
19
19
  let value = lodash_1.default.cloneDeep(initialValue);
20
20
  if (lodash_1.default.isNil(value)) {
21
21
  if (spec.defaultValue) {
22
- value = (0, helpers_2.transformArrIn)(spec.defaultValue);
22
+ value = (0, utils_1.transformArrIn)(spec.defaultValue);
23
23
  }
24
24
  // if the spec with type array or object, and this spec has "required === true",
25
25
  // we immediately exclude empty value
@@ -52,7 +52,7 @@ const useField = ({ name, spec, initialValue, validate: propsValidate, tools, pa
52
52
  setState((state) => {
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
- const value = (0, helpers_2.transformArrIn)(_value);
55
+ const value = (0, utils_1.transformArrIn)(_value);
56
56
  let newChildErrors = Object.assign({}, state.childErrors);
57
57
  if (childErrors) {
58
58
  const nearestChildName = lodash_1.default.keys(childErrors).sort((a, b) => a.length - b.length)[0];
@@ -65,7 +65,7 @@ const useField = ({ name, spec, initialValue, validate: propsValidate, tools, pa
65
65
  });
66
66
  };
67
67
  const onDrop = () => {
68
- if ((0, helpers_2.isArrayItem)(name)) {
68
+ if ((0, utils_1.isArrayItem)(name)) {
69
69
  onChange(constants_1.REMOVED_ITEM);
70
70
  }
71
71
  else {
@@ -86,7 +86,7 @@ const useField = ({ name, spec, initialValue, validate: propsValidate, tools, pa
86
86
  [constants_1.OBJECT_ARRAY_FLAG]: true,
87
87
  [constants_1.OBJECT_ARRAY_CNT]: 0,
88
88
  });
89
- const value = Object.assign(Object.assign({}, stateValue), { [`<${stateValue[constants_1.OBJECT_ARRAY_CNT]}>`]: (0, helpers_2.transformArrIn)(_value), [constants_1.OBJECT_ARRAY_CNT]: stateValue[constants_1.OBJECT_ARRAY_CNT] + 1 });
89
+ const value = Object.assign(Object.assign({}, stateValue), { [`<${stateValue[constants_1.OBJECT_ARRAY_CNT]}>`]: (0, utils_1.transformArrIn)(_value), [constants_1.OBJECT_ARRAY_CNT]: stateValue[constants_1.OBJECT_ARRAY_CNT] + 1 });
90
90
  const error = validate === null || validate === void 0 ? void 0 : validate(value);
91
91
  setState((state) => (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 })));
92
92
  };
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./useSearch"), exports);
@@ -0,0 +1,9 @@
1
+ .df-use-search {
2
+ margin-bottom: 15px;
3
+ }
4
+ .df-use-search_hidden {
5
+ display: none;
6
+ }
7
+ .df-use-search:last-child {
8
+ margin-bottom: 0;
9
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSearch = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const utils_1 = require("../../../../../kit/utils");
7
+ const useSearchContext_1 = require("../useSearchContext");
8
+ const b = (0, utils_1.block)('use-search');
9
+ const useSearch = (spec, value, name) => {
10
+ const { setField, removeField, isHiddenField, searchFunction } = (0, useSearchContext_1.useSearchContext)();
11
+ const searchResult = react_1.default.useMemo(() => !searchFunction(spec, value, name), [name, searchFunction, spec, value]);
12
+ const hidden = react_1.default.useMemo(() => isHiddenField(name), [isHiddenField, name]);
13
+ const withSearch = react_1.default.useCallback((children) => react_1.default.createElement("div", { className: b({ hidden: hidden }) }, children), [hidden]);
14
+ react_1.default.useEffect(() => {
15
+ setField(name, searchResult);
16
+ }, [searchResult]);
17
+ react_1.default.useEffect(() => {
18
+ return () => removeField(name);
19
+ }, []);
20
+ return withSearch;
21
+ };
22
+ exports.useSearch = useSearch;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSearchContext = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const index_1 = require("./index");
7
+ const useSearchContext = () => {
8
+ const SearchContext = (0, index_1.useCreateSearchContext)();
9
+ const context = react_1.default.useContext(SearchContext);
10
+ return context;
11
+ };
12
+ exports.useSearchContext = useSearchContext;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSearchStore = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
7
+ const __1 = require("../");
8
+ const useSearchStore = (name) => {
9
+ const [store, setStore] = react_1.default.useState({ [name]: false });
10
+ const isHiddenField = react_1.default.useCallback((name) => {
11
+ const selfFlag = store[name];
12
+ if (selfFlag === false) {
13
+ return false;
14
+ }
15
+ let parentName = (0, __1.getParentName)(name);
16
+ while (parentName) {
17
+ if (store[parentName] === false) {
18
+ return false;
19
+ }
20
+ parentName = (0, __1.getParentName)(parentName);
21
+ }
22
+ for (const key of Object.keys(store)) {
23
+ if (key.includes(name + '.') && !store[key]) {
24
+ return false;
25
+ }
26
+ }
27
+ return true;
28
+ }, [store]);
29
+ return {
30
+ store,
31
+ setField: (name, search) => setStore((store) => (Object.assign(Object.assign({}, store), { [name]: search }))),
32
+ removeField: (name) => {
33
+ setStore((store) => lodash_1.default.omit(store, name));
34
+ },
35
+ isHiddenField,
36
+ };
37
+ };
38
+ exports.useSearchStore = useSearchStore;
@@ -5,12 +5,12 @@ 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 helpers_1 = require("../helpers");
8
+ const utils_1 = require("../utils");
9
9
  const useStore = (name) => {
10
10
  const form = (0, react_final_form_1.useForm)();
11
11
  const firstRenderRef = react_1.default.useRef(true);
12
12
  const [store, setStore] = react_1.default.useState(() => {
13
- const initialValue = (0, helpers_1.transformArrIn)({
13
+ const initialValue = (0, utils_1.transformArrIn)({
14
14
  [name]: lodash_1.default.get(form.getState().values, name),
15
15
  });
16
16
  return {
@@ -54,14 +54,14 @@ const useStore = (name) => {
54
54
  submitFailed,
55
55
  }), [store.initialValue, setStore, submitFailed]);
56
56
  const change = react_1.default.useCallback(lodash_1.default.debounce((value) => {
57
- form.change(store.name, lodash_1.default.get((0, helpers_1.transformArrOut)(value), store.name));
57
+ form.change(store.name, lodash_1.default.get((0, utils_1.transformArrOut)(value), store.name));
58
58
  }, 100), [form.change, store.name]);
59
59
  react_1.default.useEffect(() => {
60
60
  change(store.values);
61
61
  }, [store.values]);
62
62
  react_1.default.useEffect(() => {
63
63
  if (!firstRenderRef.current) {
64
- const initialValue = (0, helpers_1.transformArrIn)({
64
+ const initialValue = (0, utils_1.transformArrIn)({
65
65
  [name]: lodash_1.default.get(form.getState().values, name),
66
66
  });
67
67
  setStore({
@@ -5,12 +5,12 @@ 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 helpers_1 = require("../../../helpers");
8
- const helpers_2 = require("../helpers");
8
+ const utils_1 = require("../utils");
9
9
  const _1 = require("./");
10
10
  const useValidate = (spec) => {
11
11
  const { config } = (0, _1.useDynamicFormsCtx)();
12
12
  const { validators } = react_1.default.useMemo(() => {
13
- if ((0, helpers_2.isCorrectConfig)(config) && (0, helpers_1.isCorrectSpec)(spec)) {
13
+ if ((0, utils_1.isCorrectConfig)(config) && (0, helpers_1.isCorrectSpec)(spec)) {
14
14
  return config[spec.type];
15
15
  }
16
16
  return {};
@@ -4,5 +4,5 @@ const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./constants"), exports);
5
5
  tslib_1.__exportStar(require("./Controller"), exports);
6
6
  tslib_1.__exportStar(require("./DynamicField"), exports);
7
- tslib_1.__exportStar(require("./helpers"), exports);
8
7
  tslib_1.__exportStar(require("./types"), exports);
8
+ tslib_1.__exportStar(require("./utils"), exports);
@@ -13,3 +13,4 @@ tslib_1.__exportStar(require("./object"), exports);
13
13
  tslib_1.__exportStar(require("./string"), exports);
14
14
  tslib_1.__exportStar(require("./validators"), exports);
15
15
  tslib_1.__exportStar(require("./value"), exports);
16
+ tslib_1.__exportStar(require("./search"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isArrayItem = exports.transformArrOut = exports.transformArrIn = exports.isCorrectConfig = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
6
- const constants_1 = require("../../constants");
7
- const constants_2 = require("./constants");
6
+ const constants_1 = require("../../../constants");
7
+ const constants_2 = require("../constants");
8
8
  const isCorrectConfig = (candidate) => Object.values(constants_1.SpecTypes).every((type) => lodash_1.default.isObjectLike(candidate) &&
9
9
  lodash_1.default.isObjectLike(candidate[type]) &&
10
10
  lodash_1.default.isObjectLike(candidate[type].inputs) &&
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./common"), exports);
5
+ tslib_1.__exportStar(require("./search"), exports);
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDefaultSearchFunction = exports.getParentName = void 0;
4
+ const getParentName = (name) => {
5
+ const index = name.lastIndexOf('.');
6
+ if (index !== -1) {
7
+ return name.substring(0, index);
8
+ }
9
+ return undefined;
10
+ };
11
+ exports.getParentName = getParentName;
12
+ const getDefaultSearchFunction = (search) => (spec) => {
13
+ var _a;
14
+ if (search) {
15
+ return Boolean((_a = spec.viewSpec.layoutTitle) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(search.trim().toLowerCase()));
16
+ }
17
+ return true;
18
+ };
19
+ exports.getDefaultSearchFunction = getDefaultSearchFunction;
@@ -1,6 +1,16 @@
1
1
  .df-table-array__table {
2
2
  margin-bottom: 10px;
3
3
  }
4
+ .df-table-array__table .yc-table__cell {
5
+ border-bottom: 0px transparent;
6
+ }
7
+ .df-table-array__row .yc-table__cell {
8
+ border-bottom: 0px transparent;
9
+ border-top: 1px solid var(--yc-color-line-generic);
10
+ }
11
+ .df-table-array__row_hidden {
12
+ display: none;
13
+ }
4
14
  .df-table-array__cell .yc-text-input,
5
15
  .df-table-array__cell .yc-select-control,
6
16
  .df-table-array__cell .yc-select,
@@ -7,15 +7,20 @@ const icons_1 = require("@gravity-ui/icons");
7
7
  const uikit_1 = require("@gravity-ui/uikit");
8
8
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
9
9
  const core_1 = require("../../../../core");
10
+ const hooks_1 = require("../../../../core/components/Form/hooks");
10
11
  const utils_1 = require("../../../utils");
11
12
  const b = (0, utils_1.block)('table-array');
12
13
  const TableArrayInput = ({ spec, name, arrayInput, input }) => {
14
+ const { isHiddenField } = (0, hooks_1.useSearchContext)();
13
15
  const keys = react_1.default.useMemo(() => Object.keys(arrayInput.value || {})
14
16
  .filter((k) => k !== core_1.OBJECT_ARRAY_FLAG &&
15
17
  k !== core_1.OBJECT_ARRAY_CNT &&
16
18
  arrayInput.value[k] !== core_1.REMOVED_ITEM)
17
19
  .map((k) => k.split('<').join('').split('>').join(''))
18
- .sort((a, b) => Number(a) - Number(b)), [arrayInput.value]);
20
+ .sort((a, b) => Number(a) - Number(b))
21
+ .map((key) => ({
22
+ key,
23
+ })), [arrayInput.value]);
19
24
  const onItemAdd = react_1.default.useCallback(() => {
20
25
  arrayInput.onItemAdd({});
21
26
  }, [arrayInput.onItemAdd]);
@@ -33,39 +38,44 @@ const TableArrayInput = ({ spec, name, arrayInput, input }) => {
33
38
  id: 'idx',
34
39
  name: '',
35
40
  sticky: 'left',
36
- template: (key, idx) => (react_1.default.createElement("div", { className: b('idx'), key: `idx-${key}` }, idx + 1)),
41
+ template: ({ key }, idx) => (react_1.default.createElement("div", { className: b('idx'), key: `idx-${key}` }, idx + 1)),
37
42
  };
38
43
  const removeColumn = {
39
44
  id: 'remove',
40
45
  name: '',
41
46
  sticky: 'right',
42
- template: (key) => (react_1.default.createElement(uikit_1.Button, { view: "flat", onClick: () => onItemRemove(key), key: `remove-${key}` },
47
+ template: ({ key }) => (react_1.default.createElement(uikit_1.Button, { view: "flat", onClick: () => onItemRemove(key), key: `remove-${key}` },
43
48
  react_1.default.createElement(uikit_1.Icon, { data: icons_1.Xmark, size: 16 }))),
44
49
  };
45
50
  const columns = table.map(({ property, label }) => ({
46
51
  id: property,
47
52
  name: label,
48
- template: (key) => {
53
+ template: ({ key, }, idx) => {
49
54
  var _a, _b, _c;
50
55
  const entitySpec = (_a = items === null || items === void 0 ? void 0 : items.properties) === null || _a === void 0 ? void 0 : _a[property];
51
56
  if (!entitySpec) {
52
57
  return null;
53
58
  }
59
+ const preparedEntitySpec = Object.assign(Object.assign({}, entitySpec), { viewSpec: Object.assign(Object.assign({}, entitySpec.viewSpec), { layoutTitle: table.map(({ label }) => label).join(` ${idx + 1} `) + ` ${idx + 1}` }) });
54
60
  return (react_1.default.createElement("div", { className: b('cell', {
55
- bool: (0, core_1.isBooleanSpec)(entitySpec),
56
- arr: (0, core_1.isArraySpec)(entitySpec),
57
- obj: (0, core_1.isObjectSpec)(entitySpec),
61
+ bool: (0, core_1.isBooleanSpec)(preparedEntitySpec),
62
+ arr: (0, core_1.isArraySpec)(preparedEntitySpec),
63
+ obj: (0, core_1.isObjectSpec)(preparedEntitySpec),
58
64
  }), key: `${name}.<${key}>.${property}` },
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 })));
65
+ 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: preparedEntitySpec, name: `${name}.<${key}>.${property}`, parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount })));
60
66
  },
61
67
  }));
62
68
  return [idxColumn, ...columns, removeColumn];
63
69
  }, [name, spec, onItemRemove, parentOnChange, parentOnUnmount, input.value]);
70
+ const getRowClassNames = react_1.default.useCallback(({ key }) => {
71
+ const searchResult = isHiddenField(`${name}.<${key}>`);
72
+ return [b('row', { hidden: searchResult })];
73
+ }, [isHiddenField, name]);
64
74
  if (!columns) {
65
75
  return null;
66
76
  }
67
77
  return (react_1.default.createElement("div", { className: b() },
68
- keys.length ? (react_1.default.createElement(uikit_1.Table, { className: b('table'), data: keys, columns: columns, getRowId: (_, idx) => `${name}-${idx}`, verticalAlign: "top" })) : null,
78
+ keys.length ? (react_1.default.createElement(uikit_1.Table, { className: b('table'), data: keys, columns: columns, getRowId: (_, idx) => `${name}-${idx}`, verticalAlign: "top", getRowClassNames: getRowClassNames })) : null,
69
79
  !arrayInput.value && spec.defaultValue ? (react_1.default.createElement(uikit_1.Button, { onClick: () => input.onChange((0, core_1.transformArrIn)(spec.defaultValue)), disabled: spec.viewSpec.disabled },
70
80
  react_1.default.createElement(uikit_1.Icon, { data: icons_1.Plus, size: 14 }),
71
81
  spec.viewSpec.layoutTitle || null)) : (react_1.default.createElement(uikit_1.Button, { onClick: onItemAdd, disabled: spec.viewSpec.disabled },
@@ -1,6 +1,7 @@
1
1
  import _ from 'lodash';
2
2
  import { isCorrectSpec } from '../../helpers';
3
3
  import { useComponents, useDynamicFormsCtx, useField, useRender, useValidate } from './hooks';
4
+ import { useSearch } from './hooks/useSearch';
4
5
  export const Controller = ({ spec, name, initialValue, parentOnChange, parentOnUnmount, }) => {
5
6
  const { tools } = useDynamicFormsCtx();
6
7
  const { inputEntity, Layout } = useComponents(spec);
@@ -15,8 +16,9 @@ export const Controller = ({ spec, name, initialValue, parentOnChange, parentOnU
15
16
  parentOnChange,
16
17
  parentOnUnmount,
17
18
  });
19
+ const withSearch = useSearch(spec, renderProps.input.value, name);
18
20
  if (_.isString(name) && isCorrectSpec(spec)) {
19
- return render(renderProps);
21
+ return withSearch(render(renderProps));
20
22
  }
21
23
  return null;
22
24
  };
@@ -1,11 +1,12 @@
1
1
  import React from 'react';
2
2
  import type { MonacoEditorProps } from 'react-monaco-editor/lib/types';
3
3
  import { Spec } from '../../types';
4
- import { DynamicFormConfig } from './types';
4
+ import { DynamicFormConfig, FieldValue } from './types';
5
5
  export interface DynamicFieldProps {
6
6
  name: string;
7
7
  spec: Spec;
8
8
  config: DynamicFormConfig;
9
9
  Monaco?: React.ComponentType<MonacoEditorProps>;
10
+ search?: string | ((spec: Spec, input: FieldValue, name: string) => boolean);
10
11
  }
11
12
  export declare const DynamicField: React.FC<DynamicFieldProps>;
@@ -3,21 +3,30 @@ import _ from 'lodash';
3
3
  import { isValidElementType } from 'react-is';
4
4
  import { isCorrectSpec } from '../../helpers';
5
5
  import { Controller } from './Controller';
6
- import { isCorrectConfig } from './helpers';
7
- import { useCreateContext, useStore } from './hooks';
8
- export const DynamicField = ({ name, spec, config, Monaco }) => {
6
+ import { useCreateContext, useCreateSearchContext, useSearchStore, useStore } from './hooks';
7
+ import { getDefaultSearchFunction, isCorrectConfig } from './utils';
8
+ export const DynamicField = ({ name, spec, config, Monaco, search }) => {
9
9
  const DynamicFormsCtx = useCreateContext();
10
+ const SearchContext = useCreateSearchContext();
10
11
  const { tools, watcher } = useStore(name);
12
+ const { setField, removeField, isHiddenField } = useSearchStore(name);
11
13
  const context = React.useMemo(() => ({
12
14
  config,
13
15
  Monaco: isValidElementType(Monaco) ? Monaco : undefined,
14
16
  tools,
15
17
  }), [tools, config, Monaco]);
18
+ const searchContext = React.useMemo(() => ({
19
+ setField,
20
+ removeField,
21
+ isHiddenField,
22
+ searchFunction: _.isFunction(search) ? search : getDefaultSearchFunction(search),
23
+ }), [isHiddenField, removeField, search, setField]);
16
24
  const correctParams = React.useMemo(() => _.isString(name) && isCorrectSpec(spec) && isCorrectConfig(config), [name, spec, config]);
17
25
  if (correctParams) {
18
26
  return (React.createElement(DynamicFormsCtx.Provider, { value: context },
19
- React.createElement(Controller, { spec: spec, name: name, parentOnChange: null, parentOnUnmount: null, initialValue: _.get(tools.initialValue, name) }),
20
- watcher));
27
+ React.createElement(SearchContext.Provider, { value: searchContext },
28
+ React.createElement(Controller, { spec: spec, name: name, parentOnChange: null, parentOnUnmount: null, initialValue: _.get(tools.initialValue, name) }),
29
+ watcher)));
21
30
  }
22
31
  return null;
23
32
  };
@@ -6,3 +6,7 @@ export * from './useRender';
6
6
  export * from './useStore';
7
7
  export * from './useValidate';
8
8
  export * from './useMonaco';
9
+ export * from './useSearchStore';
10
+ export * from './useSearchContext';
11
+ export * from './useSearch';
12
+ export * from './useCreateSearchContext';
@@ -6,3 +6,7 @@ export * from './useRender';
6
6
  export * from './useStore';
7
7
  export * from './useValidate';
8
8
  export * from './useMonaco';
9
+ export * from './useSearchStore';
10
+ export * from './useSearchContext';
11
+ export * from './useSearch';
12
+ export * from './useCreateSearchContext';
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import _ from 'lodash';
3
3
  import { isValidElementType } from 'react-is';
4
4
  import { isCorrectSpec } from '../../../helpers';
5
- import { isCorrectConfig } from '../helpers';
5
+ import { isCorrectConfig } from '../utils';
6
6
  import { useDynamicFormsCtx } from './';
7
7
  export const useComponents = (spec) => {
8
8
  var _a, _b;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import { SearchContext } from '../types';
3
+ export declare const useCreateSearchContext: () => React.Context<SearchContext>;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import _ from 'lodash';
3
+ const createContext = _.once(() => React.createContext({}));
4
+ export const useCreateSearchContext = () => createContext();
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import _ from 'lodash';
3
3
  import { isArraySpec, isObjectSpec } from '../../../helpers';
4
4
  import { OBJECT_ARRAY_CNT, OBJECT_ARRAY_FLAG, REMOVED_ITEM } from '../constants';
5
- import { isArrayItem, transformArrIn, transformArrOut } from '../helpers';
5
+ import { isArrayItem, transformArrIn, transformArrOut } from '../utils';
6
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) => {
@@ -0,0 +1 @@
1
+ export * from './useSearch';
@@ -0,0 +1 @@
1
+ export * from './useSearch';
@@ -0,0 +1,9 @@
1
+ .df-use-search {
2
+ margin-bottom: 15px;
3
+ }
4
+ .df-use-search_hidden {
5
+ display: none;
6
+ }
7
+ .df-use-search:last-child {
8
+ margin-bottom: 0;
9
+ }
@@ -0,0 +1,4 @@
1
+ import { Spec } from '../../../../types';
2
+ import { FieldValue } from '../../types';
3
+ import './useSearch.css';
4
+ export declare const useSearch: (spec: Spec, value: FieldValue, name: string) => (children: JSX.Element | null) => JSX.Element;
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { block } from '../../../../../kit/utils';
3
+ import { useSearchContext } from '../useSearchContext';
4
+ import './useSearch.css';
5
+ const b = block('use-search');
6
+ export const useSearch = (spec, value, name) => {
7
+ const { setField, removeField, isHiddenField, searchFunction } = useSearchContext();
8
+ const searchResult = React.useMemo(() => !searchFunction(spec, value, name), [name, searchFunction, spec, value]);
9
+ const hidden = React.useMemo(() => isHiddenField(name), [isHiddenField, name]);
10
+ const withSearch = React.useCallback((children) => React.createElement("div", { className: b({ hidden: hidden }) }, children), [hidden]);
11
+ React.useEffect(() => {
12
+ setField(name, searchResult);
13
+ }, [searchResult]);
14
+ React.useEffect(() => {
15
+ return () => removeField(name);
16
+ }, []);
17
+ return withSearch;
18
+ };
@@ -0,0 +1 @@
1
+ export declare const useSearchContext: () => import("..").SearchContext;
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import { useCreateSearchContext } from './index';
3
+ export const useSearchContext = () => {
4
+ const SearchContext = useCreateSearchContext();
5
+ const context = React.useContext(SearchContext);
6
+ return context;
7
+ };
@@ -0,0 +1,8 @@
1
+ export declare const useSearchStore: (name: string) => {
2
+ store: {
3
+ [x: string]: boolean;
4
+ };
5
+ setField: (name: string, search: boolean) => void;
6
+ removeField: (name: string) => void;
7
+ isHiddenField: (name: string) => boolean;
8
+ };
@@ -0,0 +1,33 @@
1
+ import React from 'react';
2
+ import _ from 'lodash';
3
+ import { getParentName } from '../';
4
+ export const useSearchStore = (name) => {
5
+ const [store, setStore] = React.useState({ [name]: false });
6
+ const isHiddenField = React.useCallback((name) => {
7
+ const selfFlag = store[name];
8
+ if (selfFlag === false) {
9
+ return false;
10
+ }
11
+ let parentName = getParentName(name);
12
+ while (parentName) {
13
+ if (store[parentName] === false) {
14
+ return false;
15
+ }
16
+ parentName = getParentName(parentName);
17
+ }
18
+ for (const key of Object.keys(store)) {
19
+ if (key.includes(name + '.') && !store[key]) {
20
+ return false;
21
+ }
22
+ }
23
+ return true;
24
+ }, [store]);
25
+ return {
26
+ store,
27
+ setField: (name, search) => setStore((store) => (Object.assign(Object.assign({}, store), { [name]: search }))),
28
+ removeField: (name) => {
29
+ setStore((store) => _.omit(store, name));
30
+ },
31
+ isHiddenField,
32
+ };
33
+ };
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import _ from 'lodash';
3
3
  import { Field as FinalFormField, useForm } from 'react-final-form';
4
- import { transformArrIn, transformArrOut } from '../helpers';
4
+ import { transformArrIn, transformArrOut } from '../utils';
5
5
  export const useStore = (name) => {
6
6
  const form = useForm();
7
7
  const firstRenderRef = React.useRef(true);
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import _ from 'lodash';
3
3
  import { isCorrectSpec } from '../../../helpers';
4
- import { isCorrectConfig } from '../helpers';
4
+ import { isCorrectConfig } from '../utils';
5
5
  import { useDynamicFormsCtx } from './';
6
6
  export const useValidate = (spec) => {
7
7
  const { config } = useDynamicFormsCtx();
@@ -1,5 +1,5 @@
1
1
  export * from './constants';
2
2
  export * from './Controller';
3
3
  export * from './DynamicField';
4
- export * from './helpers';
5
4
  export * from './types';
5
+ export * from './utils';
@@ -1,5 +1,5 @@
1
1
  export * from './constants';
2
2
  export * from './Controller';
3
3
  export * from './DynamicField';
4
- export * from './helpers';
5
4
  export * from './types';
5
+ export * from './utils';
@@ -10,3 +10,4 @@ export * from './object';
10
10
  export * from './string';
11
11
  export * from './validators';
12
12
  export * from './value';
13
+ export * from './search';
@@ -10,3 +10,4 @@ export * from './object';
10
10
  export * from './string';
11
11
  export * from './validators';
12
12
  export * from './value';
13
+ export * from './search';
@@ -0,0 +1,8 @@
1
+ import { Spec } from '../../../types';
2
+ import { FieldValue } from './value';
3
+ export interface SearchContext {
4
+ setField: (name: string, search: boolean) => void;
5
+ removeField: (name: string) => void;
6
+ isHiddenField: (name: string) => boolean;
7
+ searchFunction: (spec: Spec, value: FieldValue, name: string) => boolean;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
- import { FormValue } from '../../types';
1
+ import { FormValue } from '../../../types';
2
2
  export declare const isCorrectConfig: (candidate: any) => boolean;
3
3
  export declare const transformArrIn: <Type extends FormValue, ReturnType_1 extends FormValue = Type>(value: Type) => ReturnType_1;
4
4
  export declare const transformArrOut: <Type extends FormValue, ReturnType_1 extends FormValue = Type>(value: Type) => ReturnType_1;
@@ -1,6 +1,6 @@
1
1
  import _ from 'lodash';
2
- import { SpecTypes } from '../../constants';
3
- import { OBJECT_ARRAY_CNT, OBJECT_ARRAY_FLAG, REMOVED_ITEM } from './constants';
2
+ import { SpecTypes } from '../../../constants';
3
+ import { OBJECT_ARRAY_CNT, OBJECT_ARRAY_FLAG, REMOVED_ITEM } from '../constants';
4
4
  export const isCorrectConfig = (candidate) => Object.values(SpecTypes).every((type) => _.isObjectLike(candidate) &&
5
5
  _.isObjectLike(candidate[type]) &&
6
6
  _.isObjectLike(candidate[type].inputs) &&
@@ -0,0 +1,2 @@
1
+ export * from './common';
2
+ export * from './search';
@@ -0,0 +1,2 @@
1
+ export * from './common';
2
+ export * from './search';
@@ -0,0 +1,3 @@
1
+ import { Spec } from '../../../types';
2
+ export declare const getParentName: (name: string) => string | undefined;
3
+ export declare const getDefaultSearchFunction: (search?: string) => (spec: Spec) => boolean;
@@ -0,0 +1,14 @@
1
+ export const getParentName = (name) => {
2
+ const index = name.lastIndexOf('.');
3
+ if (index !== -1) {
4
+ return name.substring(0, index);
5
+ }
6
+ return undefined;
7
+ };
8
+ export const getDefaultSearchFunction = (search) => (spec) => {
9
+ var _a;
10
+ if (search) {
11
+ return Boolean((_a = spec.viewSpec.layoutTitle) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(search.trim().toLowerCase()));
12
+ }
13
+ return true;
14
+ };
@@ -1,6 +1,16 @@
1
1
  .df-table-array__table {
2
2
  margin-bottom: 10px;
3
3
  }
4
+ .df-table-array__table .yc-table__cell {
5
+ border-bottom: 0px transparent;
6
+ }
7
+ .df-table-array__row .yc-table__cell {
8
+ border-bottom: 0px transparent;
9
+ border-top: 1px solid var(--yc-color-line-generic);
10
+ }
11
+ .df-table-array__row_hidden {
12
+ display: none;
13
+ }
4
14
  .df-table-array__cell .yc-text-input,
5
15
  .df-table-array__cell .yc-select-control,
6
16
  .df-table-array__cell .yc-select,
@@ -3,16 +3,21 @@ import { Plus, Xmark } from '@gravity-ui/icons';
3
3
  import { Button, Icon, Table } from '@gravity-ui/uikit';
4
4
  import _ from 'lodash';
5
5
  import { Controller, OBJECT_ARRAY_CNT, OBJECT_ARRAY_FLAG, REMOVED_ITEM, isArraySpec, isBooleanSpec, isObjectSpec, transformArrIn, } from '../../../../core';
6
+ import { useSearchContext } from '../../../../core/components/Form/hooks';
6
7
  import { block } from '../../../utils';
7
8
  import './TableArrayInput.css';
8
9
  const b = block('table-array');
9
10
  export const TableArrayInput = ({ spec, name, arrayInput, input }) => {
11
+ const { isHiddenField } = useSearchContext();
10
12
  const keys = React.useMemo(() => Object.keys(arrayInput.value || {})
11
13
  .filter((k) => k !== OBJECT_ARRAY_FLAG &&
12
14
  k !== OBJECT_ARRAY_CNT &&
13
15
  arrayInput.value[k] !== REMOVED_ITEM)
14
16
  .map((k) => k.split('<').join('').split('>').join(''))
15
- .sort((a, b) => Number(a) - Number(b)), [arrayInput.value]);
17
+ .sort((a, b) => Number(a) - Number(b))
18
+ .map((key) => ({
19
+ key,
20
+ })), [arrayInput.value]);
16
21
  const onItemAdd = React.useCallback(() => {
17
22
  arrayInput.onItemAdd({});
18
23
  }, [arrayInput.onItemAdd]);
@@ -30,39 +35,44 @@ export const TableArrayInput = ({ spec, name, arrayInput, input }) => {
30
35
  id: 'idx',
31
36
  name: '',
32
37
  sticky: 'left',
33
- template: (key, idx) => (React.createElement("div", { className: b('idx'), key: `idx-${key}` }, idx + 1)),
38
+ template: ({ key }, idx) => (React.createElement("div", { className: b('idx'), key: `idx-${key}` }, idx + 1)),
34
39
  };
35
40
  const removeColumn = {
36
41
  id: 'remove',
37
42
  name: '',
38
43
  sticky: 'right',
39
- template: (key) => (React.createElement(Button, { view: "flat", onClick: () => onItemRemove(key), key: `remove-${key}` },
44
+ template: ({ key }) => (React.createElement(Button, { view: "flat", onClick: () => onItemRemove(key), key: `remove-${key}` },
40
45
  React.createElement(Icon, { data: Xmark, size: 16 }))),
41
46
  };
42
47
  const columns = table.map(({ property, label }) => ({
43
48
  id: property,
44
49
  name: label,
45
- template: (key) => {
50
+ template: ({ key, }, idx) => {
46
51
  var _a, _b, _c;
47
52
  const entitySpec = (_a = items === null || items === void 0 ? void 0 : items.properties) === null || _a === void 0 ? void 0 : _a[property];
48
53
  if (!entitySpec) {
49
54
  return null;
50
55
  }
56
+ const preparedEntitySpec = Object.assign(Object.assign({}, entitySpec), { viewSpec: Object.assign(Object.assign({}, entitySpec.viewSpec), { layoutTitle: table.map(({ label }) => label).join(` ${idx + 1} `) + ` ${idx + 1}` }) });
51
57
  return (React.createElement("div", { className: b('cell', {
52
- bool: isBooleanSpec(entitySpec),
53
- arr: isArraySpec(entitySpec),
54
- obj: isObjectSpec(entitySpec),
58
+ bool: isBooleanSpec(preparedEntitySpec),
59
+ arr: isArraySpec(preparedEntitySpec),
60
+ obj: isObjectSpec(preparedEntitySpec),
55
61
  }), key: `${name}.<${key}>.${property}` },
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 })));
62
+ 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: preparedEntitySpec, name: `${name}.<${key}>.${property}`, parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount })));
57
63
  },
58
64
  }));
59
65
  return [idxColumn, ...columns, removeColumn];
60
66
  }, [name, spec, onItemRemove, parentOnChange, parentOnUnmount, input.value]);
67
+ const getRowClassNames = React.useCallback(({ key }) => {
68
+ const searchResult = isHiddenField(`${name}.<${key}>`);
69
+ return [b('row', { hidden: searchResult })];
70
+ }, [isHiddenField, name]);
61
71
  if (!columns) {
62
72
  return null;
63
73
  }
64
74
  return (React.createElement("div", { className: b() },
65
- keys.length ? (React.createElement(Table, { className: b('table'), data: keys, columns: columns, getRowId: (_, idx) => `${name}-${idx}`, verticalAlign: "top" })) : null,
75
+ keys.length ? (React.createElement(Table, { className: b('table'), data: keys, columns: columns, getRowId: (_, idx) => `${name}-${idx}`, verticalAlign: "top", getRowClassNames: getRowClassNames })) : null,
66
76
  !arrayInput.value && spec.defaultValue ? (React.createElement(Button, { onClick: () => input.onChange(transformArrIn(spec.defaultValue)), disabled: spec.viewSpec.disabled },
67
77
  React.createElement(Icon, { data: Plus, size: 14 }),
68
78
  spec.viewSpec.layoutTitle || null)) : (React.createElement(Button, { onClick: onItemAdd, disabled: spec.viewSpec.disabled },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dynamic-forms",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "build/cjs/index.js",