@gravity-ui/dynamic-forms 4.5.0 → 4.7.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 (86) hide show
  1. package/build/cjs/lib/core/components/View/DynamicView.js +8 -2
  2. package/build/cjs/lib/core/components/View/index.js +3 -0
  3. package/build/cjs/lib/kit/components/Inputs/CheckboxGroup/CheckboxGroup.css +18 -0
  4. package/build/cjs/lib/kit/components/Inputs/CheckboxGroup/CheckboxGroup.js +40 -0
  5. package/build/cjs/lib/kit/components/Inputs/CheckboxGroup/index.js +4 -0
  6. package/build/cjs/lib/kit/components/Inputs/DateInput/DateInput.css +3 -0
  7. package/build/cjs/lib/kit/components/Inputs/DateInput/DateInput.js +50 -0
  8. package/build/cjs/lib/kit/components/Inputs/DateInput/index.js +4 -0
  9. package/build/cjs/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.js +7 -2
  10. package/build/cjs/lib/kit/components/Inputs/TimeRangeSelector/TimeRangeSelector.js +81 -0
  11. package/build/cjs/lib/kit/components/Inputs/TimeRangeSelector/components/TimeRangeSelect/TimeRangeSelect.css +6 -0
  12. package/build/cjs/lib/kit/components/Inputs/TimeRangeSelector/components/TimeRangeSelect/TimeRangeSelect.js +33 -0
  13. package/build/cjs/lib/kit/components/Inputs/TimeRangeSelector/components/TimeRangeSelect/index.js +4 -0
  14. package/build/cjs/lib/kit/components/Inputs/TimeRangeSelector/components/index.js +4 -0
  15. package/build/cjs/lib/kit/components/Inputs/TimeRangeSelector/index.js +4 -0
  16. package/build/cjs/lib/kit/components/Inputs/TimeRangeSelector/utils.js +26 -0
  17. package/build/cjs/lib/kit/components/Inputs/index.js +3 -0
  18. package/build/cjs/lib/kit/components/ViewLayouts/ViewAccordeon/ViewAccordeon.js +5 -1
  19. package/build/cjs/lib/kit/components/ViewLayouts/ViewRow/ViewRow.css +3 -0
  20. package/build/cjs/lib/kit/components/ViewLayouts/ViewRow/ViewRow.js +4 -0
  21. package/build/cjs/lib/kit/components/Views/CheckboxGroupView/CheckboxGroupView.css +27 -0
  22. package/build/cjs/lib/kit/components/Views/CheckboxGroupView/CheckboxGroupView.js +19 -0
  23. package/build/cjs/lib/kit/components/Views/CheckboxGroupView/index.js +4 -0
  24. package/build/cjs/lib/kit/components/Views/DateView/DateView.js +22 -0
  25. package/build/cjs/lib/kit/components/Views/DateView/index.js +4 -0
  26. package/build/cjs/lib/kit/components/Views/TableArrayView/TableArrayView.js +9 -3
  27. package/build/cjs/lib/kit/components/Views/TimeRangeSelectorView/TimeRangeSelectorView.js +34 -0
  28. package/build/cjs/lib/kit/components/Views/TimeRangeSelectorView/index.js +4 -0
  29. package/build/cjs/lib/kit/components/Views/index.js +3 -0
  30. package/build/cjs/lib/kit/constants/common.js +3 -1
  31. package/build/cjs/lib/kit/constants/config.js +6 -0
  32. package/build/esm/lib/core/components/View/DynamicView.d.ts +2 -1
  33. package/build/esm/lib/core/components/View/DynamicView.js +8 -2
  34. package/build/esm/lib/core/components/View/index.d.ts +1 -0
  35. package/build/esm/lib/core/components/View/index.js +1 -0
  36. package/build/esm/lib/core/components/View/types/context.d.ts +1 -0
  37. package/build/esm/lib/core/types/specs.d.ts +9 -0
  38. package/build/esm/lib/kit/components/Inputs/CheckboxGroup/CheckboxGroup.css +18 -0
  39. package/build/esm/lib/kit/components/Inputs/CheckboxGroup/CheckboxGroup.d.ts +6 -0
  40. package/build/esm/lib/kit/components/Inputs/CheckboxGroup/CheckboxGroup.js +36 -0
  41. package/build/esm/lib/kit/components/Inputs/CheckboxGroup/index.d.ts +1 -0
  42. package/build/esm/lib/kit/components/Inputs/CheckboxGroup/index.js +1 -0
  43. package/build/esm/lib/kit/components/Inputs/DateInput/DateInput.css +3 -0
  44. package/build/esm/lib/kit/components/Inputs/DateInput/DateInput.d.ts +9 -0
  45. package/build/esm/lib/kit/components/Inputs/DateInput/DateInput.js +46 -0
  46. package/build/esm/lib/kit/components/Inputs/DateInput/index.d.ts +1 -0
  47. package/build/esm/lib/kit/components/Inputs/DateInput/index.js +1 -0
  48. package/build/esm/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.js +8 -3
  49. package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/TimeRangeSelector.d.ts +2 -0
  50. package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/TimeRangeSelector.js +76 -0
  51. package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/components/TimeRangeSelect/TimeRangeSelect.css +6 -0
  52. package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/components/TimeRangeSelect/TimeRangeSelect.d.ts +14 -0
  53. package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/components/TimeRangeSelect/TimeRangeSelect.js +29 -0
  54. package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/components/TimeRangeSelect/index.d.ts +1 -0
  55. package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/components/TimeRangeSelect/index.js +1 -0
  56. package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/components/index.d.ts +1 -0
  57. package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/components/index.js +1 -0
  58. package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/index.d.ts +1 -0
  59. package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/index.js +1 -0
  60. package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/utils.d.ts +15 -0
  61. package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/utils.js +20 -0
  62. package/build/esm/lib/kit/components/Inputs/index.d.ts +3 -0
  63. package/build/esm/lib/kit/components/Inputs/index.js +3 -0
  64. package/build/esm/lib/kit/components/ViewLayouts/ViewAccordeon/ViewAccordeon.js +5 -1
  65. package/build/esm/lib/kit/components/ViewLayouts/ViewRow/ViewRow.css +3 -0
  66. package/build/esm/lib/kit/components/ViewLayouts/ViewRow/ViewRow.js +4 -0
  67. package/build/esm/lib/kit/components/Views/CheckboxGroupView/CheckboxGroupView.css +27 -0
  68. package/build/esm/lib/kit/components/Views/CheckboxGroupView/CheckboxGroupView.d.ts +3 -0
  69. package/build/esm/lib/kit/components/Views/CheckboxGroupView/CheckboxGroupView.js +15 -0
  70. package/build/esm/lib/kit/components/Views/CheckboxGroupView/index.d.ts +1 -0
  71. package/build/esm/lib/kit/components/Views/CheckboxGroupView/index.js +1 -0
  72. package/build/esm/lib/kit/components/Views/DateView/DateView.d.ts +3 -0
  73. package/build/esm/lib/kit/components/Views/DateView/DateView.js +18 -0
  74. package/build/esm/lib/kit/components/Views/DateView/index.d.ts +1 -0
  75. package/build/esm/lib/kit/components/Views/DateView/index.js +1 -0
  76. package/build/esm/lib/kit/components/Views/TableArrayView/TableArrayView.js +11 -5
  77. package/build/esm/lib/kit/components/Views/TimeRangeSelectorView/TimeRangeSelectorView.d.ts +2 -0
  78. package/build/esm/lib/kit/components/Views/TimeRangeSelectorView/TimeRangeSelectorView.js +30 -0
  79. package/build/esm/lib/kit/components/Views/TimeRangeSelectorView/index.d.ts +1 -0
  80. package/build/esm/lib/kit/components/Views/TimeRangeSelectorView/index.js +1 -0
  81. package/build/esm/lib/kit/components/Views/index.d.ts +3 -0
  82. package/build/esm/lib/kit/components/Views/index.js +3 -0
  83. package/build/esm/lib/kit/constants/common.d.ts +2 -0
  84. package/build/esm/lib/kit/constants/common.js +2 -0
  85. package/build/esm/lib/kit/constants/config.js +7 -1
  86. package/package.json +3 -1
@@ -8,9 +8,15 @@ const helpers_1 = require("../../helpers");
8
8
  const ViewController_1 = require("./ViewController");
9
9
  const helpers_2 = require("./helpers");
10
10
  const hooks_1 = require("./hooks");
11
- const DynamicView = ({ value, spec, config, Link, Monaco }) => {
11
+ const DynamicView = ({ value, spec, config, Link, Monaco, showLayoutDescription, }) => {
12
12
  const DynamicFormsCtx = (0, hooks_1.useCreateContext)();
13
- const context = react_1.default.useMemo(() => ({ config, value, Link, Monaco: (0, react_is_1.isValidElementType)(Monaco) ? Monaco : undefined }), [config, value, Link, Monaco]);
13
+ const context = react_1.default.useMemo(() => ({
14
+ config,
15
+ value,
16
+ showLayoutDescription,
17
+ Link,
18
+ Monaco: (0, react_is_1.isValidElementType)(Monaco) ? Monaco : undefined,
19
+ }), [config, value, Link, Monaco, showLayoutDescription]);
14
20
  if ((0, helpers_1.isCorrectSpec)(spec) && (0, helpers_2.isCorrectViewConfig)(config)) {
15
21
  return (react_1.default.createElement(DynamicFormsCtx.Provider, { value: context },
16
22
  react_1.default.createElement(ViewController_1.ViewController, { spec: spec, name: "" })));
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useDynamicFormsCtx = void 0;
3
4
  const tslib_1 = require("tslib");
4
5
  tslib_1.__exportStar(require("./DynamicView"), exports);
5
6
  tslib_1.__exportStar(require("./ViewController"), exports);
6
7
  tslib_1.__exportStar(require("./helpers"), exports);
7
8
  tslib_1.__exportStar(require("./types"), exports);
9
+ var hooks_1 = require("./hooks");
10
+ Object.defineProperty(exports, "useDynamicFormsCtx", { enumerable: true, get: function () { return hooks_1.useDynamicFormsCtx; } });
@@ -0,0 +1,18 @@
1
+ .df-checkbox-group {
2
+ display: flex;
3
+ align-items: center;
4
+ height: 28px;
5
+ }
6
+ .df-checkbox-group > *:not(:last-child) {
7
+ margin-right: 6px;
8
+ }
9
+ .df-checkbox-group_vertical {
10
+ flex-direction: column;
11
+ align-items: flex-start;
12
+ margin-top: 8px;
13
+ height: auto;
14
+ }
15
+ .df-checkbox-group_vertical > *:not(:last-child) {
16
+ margin-right: 0px;
17
+ margin-bottom: 6px;
18
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CheckboxGroup = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const core_1 = require("../../../../core");
7
+ const uikit_1 = require("@gravity-ui/uikit");
8
+ const utils_1 = require("../../../utils");
9
+ const b = (0, utils_1.block)('checkbox-group');
10
+ const CheckboxGroup = ({ name, input, spec, inputProps }) => {
11
+ var _a;
12
+ const { value, onBlur, onChange, onFocus } = input;
13
+ const _value = react_1.default.useMemo(() => (0, core_1.transformArrOut)(value), [value]);
14
+ const options = react_1.default.useMemo(() => {
15
+ var _a;
16
+ return (_a = spec.enum) === null || _a === void 0 ? void 0 : _a.map((id) => {
17
+ var _a;
18
+ return ({
19
+ value: id,
20
+ text: ((_a = spec.description) === null || _a === void 0 ? void 0 : _a[id]) || id,
21
+ });
22
+ });
23
+ }, [spec.enum, spec.description]);
24
+ const handleUpdate = react_1.default.useCallback((optionValue, selected) => {
25
+ let newValue = _value || [];
26
+ if (selected) {
27
+ newValue.push(optionValue);
28
+ }
29
+ else {
30
+ newValue = newValue.filter((id) => id !== optionValue);
31
+ }
32
+ onChange((0, core_1.transformArrIn)(newValue));
33
+ }, [_value, onChange]);
34
+ return (react_1.default.createElement("div", { className: b({ vertical: ((_a = spec.viewSpec.checkboxGroupParams) === null || _a === void 0 ? void 0 : _a.placement) === 'vertical' }), "data-qa": name }, options === null || options === void 0 ? void 0 : options.map(({ value: optionValue, text }) => {
35
+ var _a, _b;
36
+ return (react_1.default.createElement(uikit_1.Checkbox, Object.assign({}, inputProps, { qa: name && `${name}-${optionValue}`, key: optionValue, checked: _value === null || _value === void 0 ? void 0 : _value.includes(optionValue), onUpdate: (selected) => handleUpdate(optionValue, selected), disabled: spec.viewSpec.disabled ||
37
+ ((_b = (_a = spec.viewSpec.checkboxGroupParams) === null || _a === void 0 ? void 0 : _a.disabled) === null || _b === void 0 ? void 0 : _b[optionValue]), content: text, onBlur: onBlur, onFocus: onFocus })));
38
+ })));
39
+ };
40
+ exports.CheckboxGroup = CheckboxGroup;
@@ -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("./CheckboxGroup"), exports);
@@ -0,0 +1,3 @@
1
+ .df-date-input {
2
+ width: 100%;
3
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DateInput = exports.DEFAULT_DATE_FORMAT = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importStar(require("react"));
6
+ const date_components_1 = require("@gravity-ui/date-components");
7
+ const date_utils_1 = require("@gravity-ui/date-utils");
8
+ const utils_1 = require("../../../utils");
9
+ exports.DEFAULT_DATE_FORMAT = 'DD-MM-YYYY';
10
+ const b = (0, utils_1.block)('date-input');
11
+ const DateInput = ({ name, input, spec, inputProps, }) => {
12
+ const { value, onChange, onBlur, onFocus } = input;
13
+ const dateInput = spec.viewSpec.dateInput;
14
+ const outputFormat = dateInput === null || dateInput === void 0 ? void 0 : dateInput.outputFormat;
15
+ const onUpdate = (0, react_1.useCallback)((date) => {
16
+ if (!date) {
17
+ onChange(undefined);
18
+ }
19
+ else {
20
+ switch (outputFormat) {
21
+ case 'date_time':
22
+ onChange(date);
23
+ break;
24
+ case 'date':
25
+ onChange(date.toDate());
26
+ break;
27
+ case 'timestamp':
28
+ onChange({
29
+ seconds: Math.floor((date === null || date === void 0 ? void 0 : date.toDate().getTime()) / 1000),
30
+ nanos: 0,
31
+ });
32
+ break;
33
+ case 'string':
34
+ case undefined:
35
+ case '':
36
+ onChange(date.toISOString());
37
+ break;
38
+ default:
39
+ onChange(date.format(outputFormat));
40
+ break;
41
+ }
42
+ }
43
+ }, [outputFormat]);
44
+ const props = Object.assign(Object.assign({ hasClear: true, format: (dateInput === null || dateInput === void 0 ? void 0 : dateInput.printFormat) || exports.DEFAULT_DATE_FORMAT }, inputProps), { onBlur: onBlur, onFocus: onFocus, value: value
45
+ ? (0, date_utils_1.dateTimeParse)(value.seconds ? value.seconds * 1000 : value) || null
46
+ : null, onUpdate, disabled: spec.viewSpec.disabled, placeholder: spec.viewSpec.placeholder });
47
+ return react_1.default.createElement(date_components_1.DatePicker, Object.assign({ className: b(), "data-qa": name }, props));
48
+ };
49
+ exports.DateInput = DateInput;
50
+ exports.default = exports.DateInput;
@@ -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("./DateInput"), exports);
@@ -5,6 +5,7 @@ const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importDefault(require("react"));
6
6
  const icons_1 = require("@gravity-ui/icons");
7
7
  const uikit_1 = require("@gravity-ui/uikit");
8
+ const components_1 = require("@gravity-ui/components");
8
9
  const noop_1 = tslib_1.__importDefault(require("lodash/noop"));
9
10
  const set_1 = tslib_1.__importDefault(require("lodash/set"));
10
11
  const core_1 = require("../../../../core");
@@ -45,9 +46,13 @@ const TableArrayInput = ({ spec, name, arrayInput, input }) => {
45
46
  template: ({ key }) => (react_1.default.createElement(uikit_1.Button, { view: "flat-secondary", onClick: () => onItemRemove(key), key: `remove-${key}`, qa: `${name}-item-remove-${key}` },
46
47
  react_1.default.createElement(uikit_1.Icon, { data: icons_1.TrashBin, size: 16 }))),
47
48
  };
48
- const columns = table.map(({ property, label }) => ({
49
+ const columns = table.map(({ property, label, description }) => ({
49
50
  id: property,
50
- name: label,
51
+ name: !description
52
+ ? label
53
+ : () => (react_1.default.createElement(uikit_1.Flex, { gap: 0.5, alignItems: "center" },
54
+ label,
55
+ react_1.default.createElement(components_1.HelpPopover, { htmlContent: description, placement: ['bottom', 'top'] }))),
51
56
  template: ({ key, }, idx) => {
52
57
  var _a, _b, _c;
53
58
  const entitySpec = (_a = items === null || items === void 0 ? void 0 : items.properties) === null || _a === void 0 ? void 0 : _a[property];
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TimeRangeSelector = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const uikit_1 = require("@gravity-ui/uikit");
7
+ const isString_1 = tslib_1.__importDefault(require("lodash/isString"));
8
+ const set_1 = tslib_1.__importDefault(require("lodash/set"));
9
+ const core_1 = require("../../../../core");
10
+ const common_1 = require("../../../constants/common");
11
+ const components_1 = require("./components");
12
+ const utils_1 = require("./utils");
13
+ const TimeRangeSelector = (props) => {
14
+ var _a, _b;
15
+ const { spec, input, name, Layout } = props;
16
+ const [startTimeSpec, endTimeSpec] = react_1.default.useMemo(() => [common_1.START_TIME, common_1.END_TIME].map((key) => {
17
+ var _a, _b;
18
+ return (0, core_1.isStringSpec)((_a = spec.properties) === null || _a === void 0 ? void 0 : _a[key])
19
+ ? (_b = spec.properties) === null || _b === void 0 ? void 0 : _b[key]
20
+ : undefined;
21
+ }), [spec.properties]);
22
+ const { initialStartTimeOptions, initialEndTimeOptions, canBeFiltered } = react_1.default.useMemo(() => {
23
+ const [initialStartTimeOptions, initialEndTimeOptions] = [startTimeSpec, endTimeSpec].map((spec) => {
24
+ if (spec && spec.enum) {
25
+ return spec.enum.map((id) => {
26
+ var _a, _b, _c, _d;
27
+ return ({
28
+ id,
29
+ value: id,
30
+ content: ((_b = (_a = spec.viewSpec.selectParams) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b[id]) ? (react_1.default.createElement("div", { key: id },
31
+ react_1.default.createElement(uikit_1.Text, null, ((_c = spec.description) === null || _c === void 0 ? void 0 : _c[id]) || id),
32
+ react_1.default.createElement(uikit_1.Text, { color: "secondary", as: "div" }, spec.viewSpec.selectParams.meta[id]))) : (((_d = spec.description) === null || _d === void 0 ? void 0 : _d[id]) || id),
33
+ key: id,
34
+ });
35
+ });
36
+ }
37
+ return undefined;
38
+ });
39
+ const canBeFiltered = initialStartTimeOptions &&
40
+ initialEndTimeOptions &&
41
+ (0, utils_1.validateArray)(initialStartTimeOptions) &&
42
+ (0, utils_1.validateArray)(initialEndTimeOptions);
43
+ return {
44
+ initialStartTimeOptions,
45
+ initialEndTimeOptions,
46
+ canBeFiltered,
47
+ };
48
+ }, [endTimeSpec, startTimeSpec]);
49
+ const { startTimeOptions, endTimeOptions } = react_1.default.useMemo(() => {
50
+ let startTimeOptions = initialStartTimeOptions;
51
+ let endTimeOptions = initialEndTimeOptions;
52
+ [common_1.START_TIME, common_1.END_TIME].forEach((key) => {
53
+ var _a;
54
+ const time = (_a = input.value) === null || _a === void 0 ? void 0 : _a[key];
55
+ if ((0, isString_1.default)(time) &&
56
+ canBeFiltered &&
57
+ initialEndTimeOptions &&
58
+ initialStartTimeOptions) {
59
+ if (common_1.START_TIME === key) {
60
+ endTimeOptions = (0, utils_1.filterTimeArray)(initialEndTimeOptions, time, 'greater');
61
+ }
62
+ else {
63
+ startTimeOptions = (0, utils_1.filterTimeArray)(initialStartTimeOptions, time, 'less');
64
+ }
65
+ }
66
+ });
67
+ return { startTimeOptions, endTimeOptions };
68
+ }, [canBeFiltered, initialEndTimeOptions, initialStartTimeOptions, input.value]);
69
+ const parentOnChange = react_1.default.useCallback((childName, childValue, childErrors) => input.onChange((currentValue) => (0, set_1.default)(Object.assign({}, currentValue), childName.split(`${name}.`).join(''), childValue), childErrors), [input, name]);
70
+ if (!startTimeSpec || !endTimeSpec || !startTimeOptions || !endTimeOptions) {
71
+ return null;
72
+ }
73
+ const content = (react_1.default.createElement(react_1.default.Fragment, null,
74
+ react_1.default.createElement(components_1.TimeRangeSelect, { spec: startTimeSpec, name: `${name}.${common_1.START_TIME}`, options: startTimeOptions, value: (_a = input.value) === null || _a === void 0 ? void 0 : _a[common_1.START_TIME], handleChange: (value) => parentOnChange(common_1.START_TIME, value[0]), props: props }),
75
+ react_1.default.createElement(components_1.TimeRangeSelect, { spec: endTimeSpec, name: `${name}.${common_1.END_TIME}`, options: endTimeOptions, value: (_b = input.value) === null || _b === void 0 ? void 0 : _b[common_1.END_TIME], handleChange: (value) => parentOnChange(common_1.END_TIME, value[0]), props: props })));
76
+ if (Layout) {
77
+ return react_1.default.createElement(Layout, Object.assign({}, props), content);
78
+ }
79
+ return react_1.default.createElement(react_1.default.Fragment, null, content);
80
+ };
81
+ exports.TimeRangeSelector = TimeRangeSelector;
@@ -0,0 +1,6 @@
1
+ .df-time-range-select__select {
2
+ min-width: 100px;
3
+ }
4
+ .df-time-range-select__select-popup {
5
+ max-height: 250px;
6
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TimeRangeSelect = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const isString_1 = tslib_1.__importDefault(require("lodash/isString"));
7
+ const uikit_1 = require("@gravity-ui/uikit");
8
+ const utils_1 = require("../../../../../utils");
9
+ const Row_1 = require("../../../../Layouts/Row");
10
+ const b = (0, utils_1.block)('time-range-select');
11
+ const TimeRangeSelect = ({ name, spec, options, value, props, handleChange, }) => {
12
+ var _a, _b;
13
+ const filterable = react_1.default.useMemo(() => ((options === null || options === void 0 ? void 0 : options.length) || 0) > 9, [options === null || options === void 0 ? void 0 : options.length]);
14
+ const _value = react_1.default.useMemo(() => {
15
+ if ((0, isString_1.default)(value)) {
16
+ return [value];
17
+ }
18
+ return undefined;
19
+ }, [value]);
20
+ const renderOption = react_1.default.useCallback((option) => {
21
+ return react_1.default.createElement(react_1.default.Fragment, { key: option.value }, option.content || option.value);
22
+ }, []);
23
+ const getOptionHeight = react_1.default.useCallback(() => {
24
+ var _a;
25
+ if ((_a = spec.viewSpec.selectParams) === null || _a === void 0 ? void 0 : _a.meta) {
26
+ return 44;
27
+ }
28
+ return 28;
29
+ }, [(_a = spec.viewSpec.selectParams) === null || _a === void 0 ? void 0 : _a.meta]);
30
+ return (react_1.default.createElement(Row_1.Row, Object.assign({}, Object.assign(Object.assign({}, props), { spec })),
31
+ react_1.default.createElement(uikit_1.Select, { className: b('select'), filterable: filterable, value: _value, options: options, onUpdate: handleChange, disabled: spec.viewSpec.disabled, placeholder: spec.viewSpec.placeholder, filterPlaceholder: (_b = spec.viewSpec.selectParams) === null || _b === void 0 ? void 0 : _b.filterPlaceholder, renderOption: renderOption, getOptionHeight: getOptionHeight, qa: name, popupClassName: b('select-popup') })));
32
+ };
33
+ exports.TimeRangeSelect = TimeRangeSelect;
@@ -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("./TimeRangeSelect"), exports);
@@ -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("./TimeRangeSelect"), exports);
@@ -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("./TimeRangeSelector"), exports);
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateArray = exports.filterTimeArray = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const uikit_1 = require("@gravity-ui/uikit");
7
+ const filterTimeArray = (times, cutoff, direction) => {
8
+ const isTimeFormat = (value) => /^\d{1,2}:\d{2}$/.test(value);
9
+ const compareValues = (a, b) => {
10
+ if (isTimeFormat(a) && isTimeFormat(b)) {
11
+ return direction === 'less' ? a >= b : a <= b;
12
+ }
13
+ else {
14
+ const aNum = parseInt(a, 10);
15
+ const bNum = parseInt(b, 10);
16
+ return direction === 'less' ? aNum >= bNum : aNum <= bNum;
17
+ }
18
+ };
19
+ return times.map((time) => {
20
+ const disabled = compareValues(time.value, cutoff);
21
+ return Object.assign(Object.assign({}, time), { content: disabled ? react_1.default.createElement(uikit_1.Text, { color: "secondary" }, time.content) : time.content, disabled });
22
+ });
23
+ };
24
+ exports.filterTimeArray = filterTimeArray;
25
+ const validateArray = (arr) => arr.every((obj) => /^(\d+|\d{1,2}:\d{1,2})$/.test(obj.value));
26
+ exports.validateArray = validateArray;
@@ -4,7 +4,9 @@ const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./ArrayBase"), exports);
5
5
  tslib_1.__exportStar(require("./CardOneOf"), exports);
6
6
  tslib_1.__exportStar(require("./Checkbox"), exports);
7
+ tslib_1.__exportStar(require("./CheckboxGroup"), exports);
7
8
  tslib_1.__exportStar(require("./FileInput"), exports);
9
+ tslib_1.__exportStar(require("./DateInput"), exports);
8
10
  tslib_1.__exportStar(require("./MonacoInput"), exports);
9
11
  tslib_1.__exportStar(require("./MultiOneOf"), exports);
10
12
  tslib_1.__exportStar(require("./MultiSelect"), exports);
@@ -20,3 +22,4 @@ tslib_1.__exportStar(require("./Text"), exports);
20
22
  tslib_1.__exportStar(require("./TextArea"), exports);
21
23
  tslib_1.__exportStar(require("./TextContent"), exports);
22
24
  tslib_1.__exportStar(require("./TextLink"), exports);
25
+ tslib_1.__exportStar(require("./TimeRangeSelector"), exports);
@@ -4,13 +4,17 @@ exports.ViewAccordeon = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importDefault(require("react"));
6
6
  const isBoolean_1 = tslib_1.__importDefault(require("lodash/isBoolean"));
7
+ const core_1 = require("../../../../core");
7
8
  const utils_1 = require("../../../utils");
8
9
  const SimpleVerticalAccordeon_1 = require("../../SimpleVerticalAccordeon");
9
10
  const ViewAccordeon = ({ name, value, spec, children, }) => {
11
+ const { showLayoutDescription } = (0, core_1.useDynamicFormsCtx)();
10
12
  const [open, setOpen] = react_1.default.useState((0, isBoolean_1.default)(spec.viewSpec.layoutOpen) ? spec.viewSpec.layoutOpen : true);
11
13
  if (!(0, utils_1.isNotEmptyValue)(value, spec)) {
12
14
  return null;
13
15
  }
14
- return (react_1.default.createElement(SimpleVerticalAccordeon_1.SimpleVerticalAccordeon, { name: name, title: spec.viewSpec.layoutTitle || '', open: open, onOpenChange: setOpen, hideInsteadOfDestroy: true, withBranchView: true, viewLayout: true }, children));
16
+ return (react_1.default.createElement(SimpleVerticalAccordeon_1.SimpleVerticalAccordeon, { name: name, title: spec.viewSpec.layoutTitle || '', note: showLayoutDescription && spec.viewSpec.layoutDescription
17
+ ? spec.viewSpec.layoutDescription
18
+ : undefined, open: open, onOpenChange: setOpen, hideInsteadOfDestroy: true, withBranchView: true, viewLayout: true }, children));
15
19
  };
16
20
  exports.ViewAccordeon = ViewAccordeon;
@@ -14,6 +14,9 @@
14
14
  align-items: baseline;
15
15
  overflow: hidden;
16
16
  }
17
+ .df-view-row__note {
18
+ margin-inline-start: var(--g-spacing-half);
19
+ }
17
20
  .df-view-row__dots {
18
21
  min-width: 40px;
19
22
  flex-grow: 1;
@@ -4,16 +4,20 @@ exports.ViewRow = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importDefault(require("react"));
6
6
  const uikit_1 = require("@gravity-ui/uikit");
7
+ const components_1 = require("@gravity-ui/components");
8
+ const core_1 = require("../../../../core");
7
9
  const kit_1 = require("../../../../kit");
8
10
  const utils_1 = require("../../../utils");
9
11
  const b = (0, utils_1.block)('view-row');
10
12
  const ViewRow = ({ value, spec, children, }) => {
13
+ const { showLayoutDescription } = (0, core_1.useDynamicFormsCtx)();
11
14
  if (!(0, utils_1.isNotEmptyValue)(value, spec)) {
12
15
  return null;
13
16
  }
14
17
  return (react_1.default.createElement("div", { className: b() },
15
18
  react_1.default.createElement("div", { className: b('left') },
16
19
  react_1.default.createElement(uikit_1.Text, { whiteSpace: "nowrap", color: "secondary", ellipsis: true }, spec.viewSpec.layoutTitle),
20
+ showLayoutDescription && spec.viewSpec.layoutDescription ? (react_1.default.createElement(components_1.HelpPopover, { className: b('note'), htmlContent: spec.viewSpec.layoutDescription, placement: ['bottom', 'top'] })) : null,
17
21
  react_1.default.createElement("div", { className: b('dots') })),
18
22
  react_1.default.createElement("div", { className: b('right') }, children),
19
23
  react_1.default.createElement(kit_1.CopyButton, { spec: spec, value: value })));
@@ -0,0 +1,27 @@
1
+ .df-checkbox-group-view {
2
+ display: flex;
3
+ }
4
+ .df-checkbox-group-view > *:not(:last-child) {
5
+ margin-right: 6px;
6
+ }
7
+ .df-checkbox-group-view_vertical {
8
+ flex-direction: column;
9
+ align-items: flex-start;
10
+ }
11
+ .df-checkbox-group-view_vertical > *:not(:last-child) {
12
+ margin-right: 0px;
13
+ margin-bottom: 6px;
14
+ }
15
+ .df-checkbox-group-view__tooltip {
16
+ overflow-wrap: break-word;
17
+ }
18
+ .df-checkbox-group-view__tooltip-container {
19
+ max-width: 100%;
20
+ overflow: hidden;
21
+ text-overflow: ellipsis;
22
+ display: block;
23
+ margin-bottom: 6px;
24
+ }
25
+ .df-checkbox-group-view__tooltip-container:last-child {
26
+ margin-bottom: 0;
27
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CheckboxGroupView = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const uikit_1 = require("@gravity-ui/uikit");
7
+ const common_1 = require("../../../constants/common");
8
+ const utils_1 = require("../../../utils");
9
+ const b = (0, utils_1.block)('checkbox-group-view');
10
+ const CheckboxGroupView = ({ spec, value = [] }) => {
11
+ var _a;
12
+ const _value = value;
13
+ const items = react_1.default.useMemo(() => _value.map((item) => { var _a; return ((_a = spec.description) === null || _a === void 0 ? void 0 : _a[item]) || item; }), [spec.description, _value]);
14
+ const verticalPlacement = react_1.default.useMemo(() => { var _a; return ((_a = spec.viewSpec.checkboxGroupParams) === null || _a === void 0 ? void 0 : _a.placement) === 'vertical'; }, [(_a = spec.viewSpec.checkboxGroupParams) === null || _a === void 0 ? void 0 : _a.placement]);
15
+ return (react_1.default.createElement("div", { className: b({ vertical: verticalPlacement }) }, items.map((item, idx) => (react_1.default.createElement(uikit_1.Popover, { placement: common_1.COMMON_POPOVER_PLACEMENT, key: item, content: item, className: b('tooltip-container'), contentClassName: b('tooltip'), disabled: item.length < 51 },
16
+ item,
17
+ !verticalPlacement && idx !== items.length - 1 ? ', ' : null)))));
18
+ };
19
+ exports.CheckboxGroupView = CheckboxGroupView;
@@ -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("./CheckboxGroupView"), exports);
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DateView = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const components_1 = require("../../../components");
7
+ const date_utils_1 = require("@gravity-ui/date-utils");
8
+ const isObject_1 = tslib_1.__importDefault(require("lodash/isObject"));
9
+ const DateView = (_a) => {
10
+ var _b, _c, _d;
11
+ var { value, spec } = _a, restProps = tslib_1.__rest(_a, ["value", "spec"]);
12
+ let formatedValue = value && (0, isObject_1.default)(value) && value.seconds
13
+ ? (value === null || value === void 0 ? void 0 : value.seconds) * 1000
14
+ : value;
15
+ const localSpec = spec.viewSpec;
16
+ const format = ((_b = localSpec.inputProps) === null || _b === void 0 ? void 0 : _b.format) || ((_c = localSpec.dateInput) === null || _c === void 0 ? void 0 : _c.printFormat) || components_1.DEFAULT_DATE_FORMAT;
17
+ if (formatedValue && format) {
18
+ formatedValue = ((_d = (0, date_utils_1.dateTimeParse)(formatedValue)) === null || _d === void 0 ? void 0 : _d.format(format)) || formatedValue;
19
+ }
20
+ return react_1.default.createElement(components_1.BaseView, Object.assign({ spec: spec, value: String(formatedValue) }, restProps));
21
+ };
22
+ exports.DateView = DateView;
@@ -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("./DateView"), exports);
@@ -6,8 +6,10 @@ const react_1 = tslib_1.__importDefault(require("react"));
6
6
  const uikit_1 = require("@gravity-ui/uikit");
7
7
  const core_1 = require("../../../../core");
8
8
  const utils_1 = require("../../../utils");
9
+ const components_1 = require("@gravity-ui/components");
9
10
  const b = (0, utils_1.block)('table-array-view');
10
11
  const TableArrayView = ({ value = [], spec, name }) => {
12
+ const { showLayoutDescription } = (0, core_1.useDynamicFormsCtx)();
11
13
  const columns = react_1.default.useMemo(() => {
12
14
  const { items, viewSpec: { table }, } = spec;
13
15
  if (!(table === null || table === void 0 ? void 0 : table.length) || !(0, core_1.isObjectSpec)(items)) {
@@ -19,9 +21,13 @@ const TableArrayView = ({ value = [], spec, name }) => {
19
21
  sticky: 'left',
20
22
  template: (__, idx) => (react_1.default.createElement("div", { className: b('idx'), key: `idx-${idx}` }, idx + 1)),
21
23
  };
22
- const columns = table.map(({ property, label }) => ({
24
+ const columns = table.map(({ property, label, description }) => ({
23
25
  id: property,
24
- name: label,
26
+ name: description && showLayoutDescription
27
+ ? () => (react_1.default.createElement(uikit_1.Flex, { gap: 0.5, alignItems: "center" },
28
+ label,
29
+ react_1.default.createElement(components_1.HelpPopover, { htmlContent: description, placement: ['bottom', 'top'] })))
30
+ : label,
25
31
  template: (_, idx) => {
26
32
  var _a;
27
33
  const entitySpec = (_a = items === null || items === void 0 ? void 0 : items.properties) === null || _a === void 0 ? void 0 : _a[property];
@@ -37,7 +43,7 @@ const TableArrayView = ({ value = [], spec, name }) => {
37
43
  },
38
44
  }));
39
45
  return [idxColumn, ...columns];
40
- }, [name, spec]);
46
+ }, [name, spec, showLayoutDescription]);
41
47
  if (!columns) {
42
48
  return null;
43
49
  }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TimeRangeSelectorView = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const cloneDeep_1 = tslib_1.__importDefault(require("lodash/cloneDeep"));
7
+ const core_1 = require("../../../../core");
8
+ const common_1 = require("../../../constants/common");
9
+ const TimeRangeSelectorView = (_a) => {
10
+ var { value, spec, name, Layout } = _a, restProps = tslib_1.__rest(_a, ["value", "spec", "name", "Layout"]);
11
+ const { startTimeSpec, endTimeSpec } = react_1.default.useMemo(() => {
12
+ const [startTimeSpec, endTimeSpec] = [common_1.START_TIME, common_1.END_TIME].map((key) => {
13
+ var _a;
14
+ if (((_a = spec.properties) === null || _a === void 0 ? void 0 : _a[key]) && (0, core_1.isStringSpec)(spec.properties[key])) {
15
+ const _spec = (0, cloneDeep_1.default)(spec.properties[key]);
16
+ _spec.viewSpec.layout = 'row';
17
+ return _spec;
18
+ }
19
+ return undefined;
20
+ });
21
+ return { startTimeSpec, endTimeSpec };
22
+ }, [spec.properties]);
23
+ if (!startTimeSpec || !endTimeSpec) {
24
+ return null;
25
+ }
26
+ const content = (react_1.default.createElement(react_1.default.Fragment, null,
27
+ react_1.default.createElement(core_1.ViewController, { spec: startTimeSpec, name: `${name ? name + '.' : ''}${common_1.START_TIME}` }),
28
+ react_1.default.createElement(core_1.ViewController, { spec: endTimeSpec, name: `${name ? name + '.' : ''}${common_1.END_TIME}` })));
29
+ if (Layout) {
30
+ return (react_1.default.createElement(Layout, Object.assign({ spec: spec, name: name, value: value }, restProps), content));
31
+ }
32
+ return react_1.default.createElement(react_1.default.Fragment, null, content);
33
+ };
34
+ exports.TimeRangeSelectorView = TimeRangeSelectorView;
@@ -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("./TimeRangeSelectorView"), exports);
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./ArrayBaseView"), exports);
5
5
  tslib_1.__exportStar(require("./BaseView"), exports);
6
+ tslib_1.__exportStar(require("./CheckboxGroupView"), exports);
6
7
  tslib_1.__exportStar(require("./CardOneOfView"), exports);
7
8
  tslib_1.__exportStar(require("./FileInputView"), exports);
8
9
  tslib_1.__exportStar(require("./MonacoInputView"), exports);
@@ -15,3 +16,5 @@ tslib_1.__exportStar(require("./OneOfView"), exports);
15
16
  tslib_1.__exportStar(require("./TableArrayView"), exports);
16
17
  tslib_1.__exportStar(require("./TextAreaView"), exports);
17
18
  tslib_1.__exportStar(require("./TextLinkView"), exports);
19
+ tslib_1.__exportStar(require("./TimeRangeSelectorView"), exports);
20
+ tslib_1.__exportStar(require("./DateView"), exports);
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OBJECT_VALUE_PROPERTY_NAME = exports.COMMON_TITLE_MAX_WIDTH = exports.COMMON_POPOVER_PLACEMENT = void 0;
3
+ exports.END_TIME = exports.START_TIME = exports.OBJECT_VALUE_PROPERTY_NAME = exports.COMMON_TITLE_MAX_WIDTH = exports.COMMON_POPOVER_PLACEMENT = void 0;
4
4
  exports.COMMON_POPOVER_PLACEMENT = ['bottom', 'top'];
5
5
  exports.COMMON_TITLE_MAX_WIDTH = 533;
6
6
  exports.OBJECT_VALUE_PROPERTY_NAME = 'value';
7
+ exports.START_TIME = 'start';
8
+ exports.END_TIME = 'end';