@gravity-ui/dynamic-forms 4.6.0 → 4.7.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/kit/components/Inputs/CheckboxGroup/CheckboxGroup.css +18 -0
- package/build/cjs/lib/kit/components/Inputs/CheckboxGroup/CheckboxGroup.js +40 -0
- package/build/cjs/lib/kit/components/Inputs/CheckboxGroup/index.js +4 -0
- package/build/cjs/lib/kit/components/Inputs/TimeRangeSelector/TimeRangeSelector.js +81 -0
- package/build/cjs/lib/kit/components/Inputs/TimeRangeSelector/components/TimeRangeSelect/TimeRangeSelect.css +6 -0
- package/build/cjs/lib/kit/components/Inputs/TimeRangeSelector/components/TimeRangeSelect/TimeRangeSelect.js +33 -0
- package/build/cjs/lib/kit/components/Inputs/TimeRangeSelector/components/TimeRangeSelect/index.js +4 -0
- package/build/cjs/lib/kit/components/Inputs/TimeRangeSelector/components/index.js +4 -0
- package/build/cjs/lib/kit/components/Inputs/TimeRangeSelector/index.js +4 -0
- package/build/cjs/lib/kit/components/Inputs/TimeRangeSelector/utils.js +26 -0
- package/build/cjs/lib/kit/components/Inputs/index.js +2 -0
- package/build/cjs/lib/kit/components/Views/CheckboxGroupView/CheckboxGroupView.css +27 -0
- package/build/cjs/lib/kit/components/Views/CheckboxGroupView/CheckboxGroupView.js +19 -0
- package/build/cjs/lib/kit/components/Views/CheckboxGroupView/index.js +4 -0
- package/build/cjs/lib/kit/components/Views/TimeRangeSelectorView/TimeRangeSelectorView.js +34 -0
- package/build/cjs/lib/kit/components/Views/TimeRangeSelectorView/index.js +4 -0
- package/build/cjs/lib/kit/components/Views/index.js +2 -0
- package/build/cjs/lib/kit/constants/common.js +3 -1
- package/build/cjs/lib/kit/constants/config.js +4 -0
- package/build/esm/lib/core/types/specs.d.ts +4 -0
- package/build/esm/lib/kit/components/Inputs/CheckboxGroup/CheckboxGroup.css +18 -0
- package/build/esm/lib/kit/components/Inputs/CheckboxGroup/CheckboxGroup.d.ts +6 -0
- package/build/esm/lib/kit/components/Inputs/CheckboxGroup/CheckboxGroup.js +36 -0
- package/build/esm/lib/kit/components/Inputs/CheckboxGroup/index.d.ts +1 -0
- package/build/esm/lib/kit/components/Inputs/CheckboxGroup/index.js +1 -0
- package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/TimeRangeSelector.d.ts +2 -0
- package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/TimeRangeSelector.js +76 -0
- package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/components/TimeRangeSelect/TimeRangeSelect.css +6 -0
- package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/components/TimeRangeSelect/TimeRangeSelect.d.ts +14 -0
- package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/components/TimeRangeSelect/TimeRangeSelect.js +29 -0
- package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/components/TimeRangeSelect/index.d.ts +1 -0
- package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/components/TimeRangeSelect/index.js +1 -0
- package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/components/index.d.ts +1 -0
- package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/components/index.js +1 -0
- package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/index.d.ts +1 -0
- package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/index.js +1 -0
- package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/utils.d.ts +15 -0
- package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/utils.js +20 -0
- package/build/esm/lib/kit/components/Inputs/index.d.ts +2 -0
- package/build/esm/lib/kit/components/Inputs/index.js +2 -0
- package/build/esm/lib/kit/components/Views/CheckboxGroupView/CheckboxGroupView.css +27 -0
- package/build/esm/lib/kit/components/Views/CheckboxGroupView/CheckboxGroupView.d.ts +3 -0
- package/build/esm/lib/kit/components/Views/CheckboxGroupView/CheckboxGroupView.js +15 -0
- package/build/esm/lib/kit/components/Views/CheckboxGroupView/index.d.ts +1 -0
- package/build/esm/lib/kit/components/Views/CheckboxGroupView/index.js +1 -0
- package/build/esm/lib/kit/components/Views/TimeRangeSelectorView/TimeRangeSelectorView.d.ts +2 -0
- package/build/esm/lib/kit/components/Views/TimeRangeSelectorView/TimeRangeSelectorView.js +30 -0
- package/build/esm/lib/kit/components/Views/TimeRangeSelectorView/index.d.ts +1 -0
- package/build/esm/lib/kit/components/Views/TimeRangeSelectorView/index.js +1 -0
- package/build/esm/lib/kit/components/Views/index.d.ts +2 -0
- package/build/esm/lib/kit/components/Views/index.js +2 -0
- package/build/esm/lib/kit/constants/common.d.ts +2 -0
- package/build/esm/lib/kit/constants/common.js +2 -0
- package/build/esm/lib/kit/constants/config.js +5 -1
- package/package.json +3 -3
|
@@ -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,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,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,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,6 +4,7 @@ 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);
|
|
8
9
|
tslib_1.__exportStar(require("./DateInput"), exports);
|
|
9
10
|
tslib_1.__exportStar(require("./MonacoInput"), exports);
|
|
@@ -21,3 +22,4 @@ tslib_1.__exportStar(require("./Text"), exports);
|
|
|
21
22
|
tslib_1.__exportStar(require("./TextArea"), exports);
|
|
22
23
|
tslib_1.__exportStar(require("./TextContent"), exports);
|
|
23
24
|
tslib_1.__exportStar(require("./TextLink"), exports);
|
|
25
|
+
tslib_1.__exportStar(require("./TimeRangeSelector"), exports);
|
|
@@ -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,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;
|
|
@@ -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,4 +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);
|
|
18
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';
|
|
@@ -9,6 +9,7 @@ exports.dynamicConfig = {
|
|
|
9
9
|
select: { Component: components_1.MultiSelect },
|
|
10
10
|
table: { Component: components_1.TableArrayInput },
|
|
11
11
|
base: { Component: components_1.ArrayBase },
|
|
12
|
+
checkbox_group: { Component: components_1.CheckboxGroup },
|
|
12
13
|
},
|
|
13
14
|
layouts: {
|
|
14
15
|
row: components_1.Row,
|
|
@@ -69,6 +70,7 @@ exports.dynamicConfig = {
|
|
|
69
70
|
multi_oneof: { Component: components_1.MultiOneOf, independent: true },
|
|
70
71
|
multi_oneof_flat: { Component: components_1.MultiOneOfFlat, independent: true },
|
|
71
72
|
inline: { Component: components_1.ObjectInline, independent: true },
|
|
73
|
+
time_range_selector: { Component: components_1.TimeRangeSelector, independent: true },
|
|
72
74
|
},
|
|
73
75
|
layouts: {
|
|
74
76
|
row: components_1.Row,
|
|
@@ -122,6 +124,7 @@ exports.dynamicViewConfig = {
|
|
|
122
124
|
select: { Component: components_1.MultiSelectView },
|
|
123
125
|
table: { Component: components_1.TableArrayView },
|
|
124
126
|
base: { Component: components_1.ArrayBaseView },
|
|
127
|
+
checkbox_group: { Component: components_1.CheckboxGroupView },
|
|
125
128
|
},
|
|
126
129
|
layouts: {
|
|
127
130
|
row: components_1.ViewRow,
|
|
@@ -173,6 +176,7 @@ exports.dynamicViewConfig = {
|
|
|
173
176
|
multi_oneof: { Component: components_1.MultiOneOfView, independent: true },
|
|
174
177
|
multi_oneof_flat: { Component: components_1.MultiOneOfFlatView, independent: true },
|
|
175
178
|
inline: { Component: components_1.ObjectInlineView, independent: true },
|
|
179
|
+
time_range_selector: { Component: components_1.TimeRangeSelectorView, independent: true },
|
|
176
180
|
},
|
|
177
181
|
layouts: {
|
|
178
182
|
row: components_1.ViewRow,
|
|
@@ -36,6 +36,10 @@ export interface ArraySpec<LinkType = any, InputComponentProps extends Record<st
|
|
|
36
36
|
};
|
|
37
37
|
inputProps?: InputComponentProps;
|
|
38
38
|
layoutProps?: LayoutComponentProps;
|
|
39
|
+
checkboxGroupParams?: {
|
|
40
|
+
placement?: 'horizontal' | 'vertical';
|
|
41
|
+
disabled?: Record<string, boolean>;
|
|
42
|
+
};
|
|
39
43
|
};
|
|
40
44
|
}
|
|
41
45
|
export interface BooleanSpec<LinkType = any, InputComponentProps extends Record<string, any> | undefined = undefined, LayoutComponentProps extends Record<string, any> | undefined = undefined> {
|
|
@@ -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,6 @@
|
|
|
1
|
+
import { ArrayInput } from '../../../../core';
|
|
2
|
+
import { type CheckboxProps as CheckboxBaseProps } from '@gravity-ui/uikit';
|
|
3
|
+
import './CheckboxGroup.css';
|
|
4
|
+
export interface CheckboxGroupProps extends Omit<CheckboxBaseProps, 'checked' | 'onChange' | 'onBlur' | 'onFocus' | 'disabled' | 'qa' | 'content'> {
|
|
5
|
+
}
|
|
6
|
+
export declare const CheckboxGroup: ArrayInput<CheckboxGroupProps>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { transformArrIn, transformArrOut } from '../../../../core';
|
|
3
|
+
import { Checkbox } from '@gravity-ui/uikit';
|
|
4
|
+
import { block } from '../../../utils';
|
|
5
|
+
import './CheckboxGroup.css';
|
|
6
|
+
const b = block('checkbox-group');
|
|
7
|
+
export const CheckboxGroup = ({ name, input, spec, inputProps }) => {
|
|
8
|
+
var _a;
|
|
9
|
+
const { value, onBlur, onChange, onFocus } = input;
|
|
10
|
+
const _value = React.useMemo(() => transformArrOut(value), [value]);
|
|
11
|
+
const options = React.useMemo(() => {
|
|
12
|
+
var _a;
|
|
13
|
+
return (_a = spec.enum) === null || _a === void 0 ? void 0 : _a.map((id) => {
|
|
14
|
+
var _a;
|
|
15
|
+
return ({
|
|
16
|
+
value: id,
|
|
17
|
+
text: ((_a = spec.description) === null || _a === void 0 ? void 0 : _a[id]) || id,
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}, [spec.enum, spec.description]);
|
|
21
|
+
const handleUpdate = React.useCallback((optionValue, selected) => {
|
|
22
|
+
let newValue = _value || [];
|
|
23
|
+
if (selected) {
|
|
24
|
+
newValue.push(optionValue);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
newValue = newValue.filter((id) => id !== optionValue);
|
|
28
|
+
}
|
|
29
|
+
onChange(transformArrIn(newValue));
|
|
30
|
+
}, [_value, onChange]);
|
|
31
|
+
return (React.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 }) => {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
return (React.createElement(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 ||
|
|
34
|
+
((_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 })));
|
|
35
|
+
})));
|
|
36
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CheckboxGroup';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CheckboxGroup';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Text } from '@gravity-ui/uikit';
|
|
3
|
+
import isString from 'lodash/isString';
|
|
4
|
+
import set from 'lodash/set';
|
|
5
|
+
import { isStringSpec, } from '../../../../core';
|
|
6
|
+
import { END_TIME, START_TIME } from '../../../constants/common';
|
|
7
|
+
import { TimeRangeSelect } from './components';
|
|
8
|
+
import { filterTimeArray, validateArray } from './utils';
|
|
9
|
+
export const TimeRangeSelector = (props) => {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
const { spec, input, name, Layout } = props;
|
|
12
|
+
const [startTimeSpec, endTimeSpec] = React.useMemo(() => [START_TIME, END_TIME].map((key) => {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
return isStringSpec((_a = spec.properties) === null || _a === void 0 ? void 0 : _a[key])
|
|
15
|
+
? (_b = spec.properties) === null || _b === void 0 ? void 0 : _b[key]
|
|
16
|
+
: undefined;
|
|
17
|
+
}), [spec.properties]);
|
|
18
|
+
const { initialStartTimeOptions, initialEndTimeOptions, canBeFiltered } = React.useMemo(() => {
|
|
19
|
+
const [initialStartTimeOptions, initialEndTimeOptions] = [startTimeSpec, endTimeSpec].map((spec) => {
|
|
20
|
+
if (spec && spec.enum) {
|
|
21
|
+
return spec.enum.map((id) => {
|
|
22
|
+
var _a, _b, _c, _d;
|
|
23
|
+
return ({
|
|
24
|
+
id,
|
|
25
|
+
value: id,
|
|
26
|
+
content: ((_b = (_a = spec.viewSpec.selectParams) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b[id]) ? (React.createElement("div", { key: id },
|
|
27
|
+
React.createElement(Text, null, ((_c = spec.description) === null || _c === void 0 ? void 0 : _c[id]) || id),
|
|
28
|
+
React.createElement(Text, { color: "secondary", as: "div" }, spec.viewSpec.selectParams.meta[id]))) : (((_d = spec.description) === null || _d === void 0 ? void 0 : _d[id]) || id),
|
|
29
|
+
key: id,
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return undefined;
|
|
34
|
+
});
|
|
35
|
+
const canBeFiltered = initialStartTimeOptions &&
|
|
36
|
+
initialEndTimeOptions &&
|
|
37
|
+
validateArray(initialStartTimeOptions) &&
|
|
38
|
+
validateArray(initialEndTimeOptions);
|
|
39
|
+
return {
|
|
40
|
+
initialStartTimeOptions,
|
|
41
|
+
initialEndTimeOptions,
|
|
42
|
+
canBeFiltered,
|
|
43
|
+
};
|
|
44
|
+
}, [endTimeSpec, startTimeSpec]);
|
|
45
|
+
const { startTimeOptions, endTimeOptions } = React.useMemo(() => {
|
|
46
|
+
let startTimeOptions = initialStartTimeOptions;
|
|
47
|
+
let endTimeOptions = initialEndTimeOptions;
|
|
48
|
+
[START_TIME, END_TIME].forEach((key) => {
|
|
49
|
+
var _a;
|
|
50
|
+
const time = (_a = input.value) === null || _a === void 0 ? void 0 : _a[key];
|
|
51
|
+
if (isString(time) &&
|
|
52
|
+
canBeFiltered &&
|
|
53
|
+
initialEndTimeOptions &&
|
|
54
|
+
initialStartTimeOptions) {
|
|
55
|
+
if (START_TIME === key) {
|
|
56
|
+
endTimeOptions = filterTimeArray(initialEndTimeOptions, time, 'greater');
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
startTimeOptions = filterTimeArray(initialStartTimeOptions, time, 'less');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return { startTimeOptions, endTimeOptions };
|
|
64
|
+
}, [canBeFiltered, initialEndTimeOptions, initialStartTimeOptions, input.value]);
|
|
65
|
+
const parentOnChange = React.useCallback((childName, childValue, childErrors) => input.onChange((currentValue) => set(Object.assign({}, currentValue), childName.split(`${name}.`).join(''), childValue), childErrors), [input, name]);
|
|
66
|
+
if (!startTimeSpec || !endTimeSpec || !startTimeOptions || !endTimeOptions) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const content = (React.createElement(React.Fragment, null,
|
|
70
|
+
React.createElement(TimeRangeSelect, { spec: startTimeSpec, name: `${name}.${START_TIME}`, options: startTimeOptions, value: (_a = input.value) === null || _a === void 0 ? void 0 : _a[START_TIME], handleChange: (value) => parentOnChange(START_TIME, value[0]), props: props }),
|
|
71
|
+
React.createElement(TimeRangeSelect, { spec: endTimeSpec, name: `${name}.${END_TIME}`, options: endTimeOptions, value: (_b = input.value) === null || _b === void 0 ? void 0 : _b[END_TIME], handleChange: (value) => parentOnChange(END_TIME, value[0]), props: props })));
|
|
72
|
+
if (Layout) {
|
|
73
|
+
return React.createElement(Layout, Object.assign({}, props), content);
|
|
74
|
+
}
|
|
75
|
+
return React.createElement(React.Fragment, null, content);
|
|
76
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type SelectOption } from '@gravity-ui/uikit';
|
|
3
|
+
import { FieldObjectValue, FieldValue, IndependentInputProps, ObjectSpec, StringSpec } from '../../../../../../core';
|
|
4
|
+
import './TimeRangeSelect.css';
|
|
5
|
+
interface TimeRangeSelectProps {
|
|
6
|
+
spec: StringSpec<any, undefined, undefined>;
|
|
7
|
+
name: string;
|
|
8
|
+
options: SelectOption<string>[];
|
|
9
|
+
value?: FieldValue;
|
|
10
|
+
handleChange: (value: string[]) => void;
|
|
11
|
+
props: IndependentInputProps<FieldObjectValue, undefined, undefined, ObjectSpec<undefined, undefined, undefined>>;
|
|
12
|
+
}
|
|
13
|
+
export declare const TimeRangeSelect: React.FC<TimeRangeSelectProps>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import isString from 'lodash/isString';
|
|
3
|
+
import { Select } from '@gravity-ui/uikit';
|
|
4
|
+
import { block } from '../../../../../utils';
|
|
5
|
+
import { Row } from '../../../../Layouts/Row';
|
|
6
|
+
import './TimeRangeSelect.css';
|
|
7
|
+
const b = block('time-range-select');
|
|
8
|
+
export const TimeRangeSelect = ({ name, spec, options, value, props, handleChange, }) => {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
const filterable = React.useMemo(() => ((options === null || options === void 0 ? void 0 : options.length) || 0) > 9, [options === null || options === void 0 ? void 0 : options.length]);
|
|
11
|
+
const _value = React.useMemo(() => {
|
|
12
|
+
if (isString(value)) {
|
|
13
|
+
return [value];
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
}, [value]);
|
|
17
|
+
const renderOption = React.useCallback((option) => {
|
|
18
|
+
return React.createElement(React.Fragment, { key: option.value }, option.content || option.value);
|
|
19
|
+
}, []);
|
|
20
|
+
const getOptionHeight = React.useCallback(() => {
|
|
21
|
+
var _a;
|
|
22
|
+
if ((_a = spec.viewSpec.selectParams) === null || _a === void 0 ? void 0 : _a.meta) {
|
|
23
|
+
return 44;
|
|
24
|
+
}
|
|
25
|
+
return 28;
|
|
26
|
+
}, [(_a = spec.viewSpec.selectParams) === null || _a === void 0 ? void 0 : _a.meta]);
|
|
27
|
+
return (React.createElement(Row, Object.assign({}, Object.assign(Object.assign({}, props), { spec })),
|
|
28
|
+
React.createElement(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') })));
|
|
29
|
+
};
|
package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/components/TimeRangeSelect/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TimeRangeSelect';
|
package/build/esm/lib/kit/components/Inputs/TimeRangeSelector/components/TimeRangeSelect/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TimeRangeSelect';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TimeRangeSelect';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TimeRangeSelect';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TimeRangeSelector';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TimeRangeSelector';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const filterTimeArray: (times: {
|
|
2
|
+
id: string;
|
|
3
|
+
value: string;
|
|
4
|
+
content: string | JSX.Element;
|
|
5
|
+
key: string;
|
|
6
|
+
}[], cutoff: string, direction: 'greater' | 'less') => {
|
|
7
|
+
content: string | JSX.Element;
|
|
8
|
+
disabled: boolean;
|
|
9
|
+
id: string;
|
|
10
|
+
value: string;
|
|
11
|
+
key: string;
|
|
12
|
+
}[];
|
|
13
|
+
export declare const validateArray: (arr: {
|
|
14
|
+
value: string;
|
|
15
|
+
}[]) => boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Text } from '@gravity-ui/uikit';
|
|
3
|
+
export const filterTimeArray = (times, cutoff, direction) => {
|
|
4
|
+
const isTimeFormat = (value) => /^\d{1,2}:\d{2}$/.test(value);
|
|
5
|
+
const compareValues = (a, b) => {
|
|
6
|
+
if (isTimeFormat(a) && isTimeFormat(b)) {
|
|
7
|
+
return direction === 'less' ? a >= b : a <= b;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
const aNum = parseInt(a, 10);
|
|
11
|
+
const bNum = parseInt(b, 10);
|
|
12
|
+
return direction === 'less' ? aNum >= bNum : aNum <= bNum;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
return times.map((time) => {
|
|
16
|
+
const disabled = compareValues(time.value, cutoff);
|
|
17
|
+
return Object.assign(Object.assign({}, time), { content: disabled ? React.createElement(Text, { color: "secondary" }, time.content) : time.content, disabled });
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
export const validateArray = (arr) => arr.every((obj) => /^(\d+|\d{1,2}:\d{1,2})$/.test(obj.value));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './ArrayBase';
|
|
2
2
|
export * from './CardOneOf';
|
|
3
3
|
export * from './Checkbox';
|
|
4
|
+
export * from './CheckboxGroup';
|
|
4
5
|
export * from './FileInput';
|
|
5
6
|
export * from './DateInput';
|
|
6
7
|
export * from './MonacoInput';
|
|
@@ -18,3 +19,4 @@ export * from './Text';
|
|
|
18
19
|
export * from './TextArea';
|
|
19
20
|
export * from './TextContent';
|
|
20
21
|
export * from './TextLink';
|
|
22
|
+
export * from './TimeRangeSelector';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './ArrayBase';
|
|
2
2
|
export * from './CardOneOf';
|
|
3
3
|
export * from './Checkbox';
|
|
4
|
+
export * from './CheckboxGroup';
|
|
4
5
|
export * from './FileInput';
|
|
5
6
|
export * from './DateInput';
|
|
6
7
|
export * from './MonacoInput';
|
|
@@ -18,3 +19,4 @@ export * from './Text';
|
|
|
18
19
|
export * from './TextArea';
|
|
19
20
|
export * from './TextContent';
|
|
20
21
|
export * from './TextLink';
|
|
22
|
+
export * from './TimeRangeSelector';
|
|
@@ -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,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Popover } from '@gravity-ui/uikit';
|
|
3
|
+
import { COMMON_POPOVER_PLACEMENT } from '../../../constants/common';
|
|
4
|
+
import { block } from '../../../utils';
|
|
5
|
+
import './CheckboxGroupView.css';
|
|
6
|
+
const b = block('checkbox-group-view');
|
|
7
|
+
export const CheckboxGroupView = ({ spec, value = [] }) => {
|
|
8
|
+
var _a;
|
|
9
|
+
const _value = value;
|
|
10
|
+
const items = React.useMemo(() => _value.map((item) => { var _a; return ((_a = spec.description) === null || _a === void 0 ? void 0 : _a[item]) || item; }), [spec.description, _value]);
|
|
11
|
+
const verticalPlacement = React.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]);
|
|
12
|
+
return (React.createElement("div", { className: b({ vertical: verticalPlacement }) }, items.map((item, idx) => (React.createElement(Popover, { placement: COMMON_POPOVER_PLACEMENT, key: item, content: item, className: b('tooltip-container'), contentClassName: b('tooltip'), disabled: item.length < 51 },
|
|
13
|
+
item,
|
|
14
|
+
!verticalPlacement && idx !== items.length - 1 ? ', ' : null)))));
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CheckboxGroupView';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CheckboxGroupView';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
4
|
+
import { ViewController, isStringSpec } from '../../../../core';
|
|
5
|
+
import { END_TIME, START_TIME } from '../../../constants/common';
|
|
6
|
+
export const TimeRangeSelectorView = (_a) => {
|
|
7
|
+
var { value, spec, name, Layout } = _a, restProps = __rest(_a, ["value", "spec", "name", "Layout"]);
|
|
8
|
+
const { startTimeSpec, endTimeSpec } = React.useMemo(() => {
|
|
9
|
+
const [startTimeSpec, endTimeSpec] = [START_TIME, END_TIME].map((key) => {
|
|
10
|
+
var _a;
|
|
11
|
+
if (((_a = spec.properties) === null || _a === void 0 ? void 0 : _a[key]) && isStringSpec(spec.properties[key])) {
|
|
12
|
+
const _spec = cloneDeep(spec.properties[key]);
|
|
13
|
+
_spec.viewSpec.layout = 'row';
|
|
14
|
+
return _spec;
|
|
15
|
+
}
|
|
16
|
+
return undefined;
|
|
17
|
+
});
|
|
18
|
+
return { startTimeSpec, endTimeSpec };
|
|
19
|
+
}, [spec.properties]);
|
|
20
|
+
if (!startTimeSpec || !endTimeSpec) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const content = (React.createElement(React.Fragment, null,
|
|
24
|
+
React.createElement(ViewController, { spec: startTimeSpec, name: `${name ? name + '.' : ''}${START_TIME}` }),
|
|
25
|
+
React.createElement(ViewController, { spec: endTimeSpec, name: `${name ? name + '.' : ''}${END_TIME}` })));
|
|
26
|
+
if (Layout) {
|
|
27
|
+
return (React.createElement(Layout, Object.assign({ spec: spec, name: name, value: value }, restProps), content));
|
|
28
|
+
}
|
|
29
|
+
return React.createElement(React.Fragment, null, content);
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TimeRangeSelectorView';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TimeRangeSelectorView';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './ArrayBaseView';
|
|
2
2
|
export * from './BaseView';
|
|
3
|
+
export * from './CheckboxGroupView';
|
|
3
4
|
export * from './CardOneOfView';
|
|
4
5
|
export * from './FileInputView';
|
|
5
6
|
export * from './MonacoInputView';
|
|
@@ -12,4 +13,5 @@ export * from './OneOfView';
|
|
|
12
13
|
export * from './TableArrayView';
|
|
13
14
|
export * from './TextAreaView';
|
|
14
15
|
export * from './TextLinkView';
|
|
16
|
+
export * from './TimeRangeSelectorView';
|
|
15
17
|
export * from './DateView';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './ArrayBaseView';
|
|
2
2
|
export * from './BaseView';
|
|
3
|
+
export * from './CheckboxGroupView';
|
|
3
4
|
export * from './CardOneOfView';
|
|
4
5
|
export * from './FileInputView';
|
|
5
6
|
export * from './MonacoInputView';
|
|
@@ -12,4 +13,5 @@ export * from './OneOfView';
|
|
|
12
13
|
export * from './TableArrayView';
|
|
13
14
|
export * from './TextAreaView';
|
|
14
15
|
export * from './TextLinkView';
|
|
16
|
+
export * from './TimeRangeSelectorView';
|
|
15
17
|
export * from './DateView';
|
|
@@ -2,3 +2,5 @@ import type { PopoverProps } from '@gravity-ui/uikit';
|
|
|
2
2
|
export declare const COMMON_POPOVER_PLACEMENT: PopoverProps['placement'];
|
|
3
3
|
export declare const COMMON_TITLE_MAX_WIDTH = 533;
|
|
4
4
|
export declare const OBJECT_VALUE_PROPERTY_NAME = "value";
|
|
5
|
+
export declare const START_TIME = "start";
|
|
6
|
+
export declare const END_TIME = "end";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Accordeon, AccordeonCardForm, ArrayBase, ArrayBaseView, BaseView, CardAccordeon, CardOneOf, CardOneOfView, CardSection, Checkbox, DateInput, DateView, FileInput, FileInputView, Group, Group2, MonacoInput, MonacoView, MultiOneOf, MultiOneOfFlat, MultiOneOfFlatView, MultiOneOfView, MultiSelect, MultiSelectView, NumberWithScale, NumberWithScaleView, ObjectBase, ObjectBaseView, ObjectInline, ObjectInlineView, ObjectValueInput, ObjectValueInputView, OneOf, OneOfFlat, OneOfFlatView, OneOfView, Row, RowVerbose, Secret, Section, Section2, Select, Switch, TableArrayInput, TableArrayView, TableCell, Text, TextArea, TextAreaView, TextContent, TextLink, TextLinkView, Transparent, ViewAccordeon, ViewAccordeonCard, ViewCardAccordeon, ViewCardSection, ViewGroup, ViewGroup2, ViewRow, ViewSection, ViewSection2, ViewTableCell, ViewTransparent, } from '../components';
|
|
1
|
+
import { Accordeon, AccordeonCardForm, ArrayBase, ArrayBaseView, BaseView, CardAccordeon, CardOneOf, CardOneOfView, CardSection, Checkbox, CheckboxGroup, CheckboxGroupView, DateInput, DateView, FileInput, FileInputView, Group, Group2, MonacoInput, MonacoView, MultiOneOf, MultiOneOfFlat, MultiOneOfFlatView, MultiOneOfView, MultiSelect, MultiSelectView, NumberWithScale, NumberWithScaleView, ObjectBase, ObjectBaseView, ObjectInline, ObjectInlineView, ObjectValueInput, ObjectValueInputView, OneOf, OneOfFlat, OneOfFlatView, OneOfView, Row, RowVerbose, Secret, Section, Section2, Select, Switch, TableArrayInput, TableArrayView, TableCell, Text, TextArea, TextAreaView, TextContent, TextLink, TextLinkView, TimeRangeSelector, TimeRangeSelectorView, Transparent, ViewAccordeon, ViewAccordeonCard, ViewCardAccordeon, ViewCardSection, ViewGroup, ViewGroup2, ViewRow, ViewSection, ViewSection2, ViewTableCell, ViewTransparent, } from '../components';
|
|
2
2
|
import { getArrayValidator, getBooleanValidator, getNumberValidator, getObjectValidator, getStringValidator, } from '../validators';
|
|
3
3
|
export const dynamicConfig = {
|
|
4
4
|
array: {
|
|
@@ -6,6 +6,7 @@ export const dynamicConfig = {
|
|
|
6
6
|
select: { Component: MultiSelect },
|
|
7
7
|
table: { Component: TableArrayInput },
|
|
8
8
|
base: { Component: ArrayBase },
|
|
9
|
+
checkbox_group: { Component: CheckboxGroup },
|
|
9
10
|
},
|
|
10
11
|
layouts: {
|
|
11
12
|
row: Row,
|
|
@@ -66,6 +67,7 @@ export const dynamicConfig = {
|
|
|
66
67
|
multi_oneof: { Component: MultiOneOf, independent: true },
|
|
67
68
|
multi_oneof_flat: { Component: MultiOneOfFlat, independent: true },
|
|
68
69
|
inline: { Component: ObjectInline, independent: true },
|
|
70
|
+
time_range_selector: { Component: TimeRangeSelector, independent: true },
|
|
69
71
|
},
|
|
70
72
|
layouts: {
|
|
71
73
|
row: Row,
|
|
@@ -119,6 +121,7 @@ export const dynamicViewConfig = {
|
|
|
119
121
|
select: { Component: MultiSelectView },
|
|
120
122
|
table: { Component: TableArrayView },
|
|
121
123
|
base: { Component: ArrayBaseView },
|
|
124
|
+
checkbox_group: { Component: CheckboxGroupView },
|
|
122
125
|
},
|
|
123
126
|
layouts: {
|
|
124
127
|
row: ViewRow,
|
|
@@ -170,6 +173,7 @@ export const dynamicViewConfig = {
|
|
|
170
173
|
multi_oneof: { Component: MultiOneOfView, independent: true },
|
|
171
174
|
multi_oneof_flat: { Component: MultiOneOfFlatView, independent: true },
|
|
172
175
|
inline: { Component: ObjectInlineView, independent: true },
|
|
176
|
+
time_range_selector: { Component: TimeRangeSelectorView, independent: true },
|
|
173
177
|
},
|
|
174
178
|
layouts: {
|
|
175
179
|
row: ViewRow,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/dynamic-forms",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "build/cjs/index.js",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@bem-react/classname": "^1.6.0",
|
|
47
47
|
"@gravity-ui/components": "^3.0.0",
|
|
48
|
-
"@gravity-ui/date-components": "^2.
|
|
49
|
-
"@gravity-ui/date-utils": "^2.
|
|
48
|
+
"@gravity-ui/date-components": "^2.4.0",
|
|
49
|
+
"@gravity-ui/date-utils": "^2.4.0",
|
|
50
50
|
"@gravity-ui/i18n": "^1.2.0",
|
|
51
51
|
"@gravity-ui/icons": "^2.8.1",
|
|
52
52
|
"lodash": "^4.17.20"
|