@truedat/df 7.12.5 → 7.12.7
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/package.json +4 -4
- package/src/components/DynamicFieldValue.js +1 -1
- package/src/components/DynamicFormViewer.js +4 -3
- package/src/components/DynamicFormWithTranslations.js +3 -3
- package/src/components/EditableDynamicFieldValue.js +1 -1
- package/src/components/FieldViewerValue.js +44 -3
- package/src/components/__tests__/FieldViewerValue.spec.js +10 -6
- package/src/components/__tests__/__snapshots__/FieldViewerValue.spec.js.snap +53 -0
- package/src/components/widgets/DynamicField.js +6 -62
- package/src/components/widgets/DynamicTableField.js +150 -0
- package/src/components/widgets/FieldByWidget.js +63 -0
- package/src/components/widgets/StandardDropdown.js +2 -2
- package/src/components/widgets/StringField.js +2 -1
- package/src/components/widgets/__tests__/DynamicField.spec.js +10 -1
- package/src/components/widgets/__tests__/DynamicTableField.spec.js +257 -0
- package/src/components/widgets/__tests__/__snapshots__/DynamicField.spec.js.snap +97 -0
- package/src/components/widgets/__tests__/__snapshots__/DynamicTableField.spec.js.snap +114 -0
- package/src/templates/components/templateForm/ActiveGroupForm.js +5 -16
- package/src/templates/components/templateForm/FieldDefinition.js +158 -0
- package/src/templates/components/templateForm/FieldForm.js +32 -135
- package/src/templates/components/templateForm/TableValuesForm.js +258 -0
- package/src/templates/components/templateForm/TemplateForm.js +43 -26
- package/src/templates/components/templateForm/ValuesConfiguration.js +67 -0
- package/src/templates/components/templateForm/ValuesField.js +60 -96
- package/src/templates/components/templateForm/ValuesListForm.js +1 -3
- package/src/templates/components/templateForm/__tests__/FieldDefinition.spec.js +227 -0
- package/src/templates/components/templateForm/__tests__/TableValuesForm.spec.js +215 -0
- package/src/templates/components/templateForm/__tests__/ValuesField.spec.js +28 -83
- package/src/templates/components/templateForm/__tests__/__snapshots__/ActiveGroupForm.spec.js.snap +17 -0
- package/src/templates/components/templateForm/__tests__/__snapshots__/FieldDefinition.spec.js.snap +443 -0
- package/src/templates/components/templateForm/__tests__/__snapshots__/FieldForm.spec.js.snap +51 -0
- package/src/templates/components/templateForm/__tests__/__snapshots__/TemplateForm.spec.js.snap +17 -0
- package/src/templates/components/templateForm/__tests__/__snapshots__/ValuesField.spec.js.snap +61 -387
- package/src/templates/components/templateForm/contentValidation.js +22 -3
- package/src/templates/components/templateForm/valueDefinitions.js +16 -2
- package/src/templates/components/templateForm/widgetDefinitions.js +28 -2
- package/src/templates/utils/__tests__/validateContent.spec.js +6 -6
- package/src/templates/utils/applyTemplate.js +72 -23
- package/src/templates/utils/filterValues.js +3 -3
- package/src/templates/utils/parseFieldOptions.js +73 -58
- package/src/templates/utils/parseGroups.js +47 -48
- package/src/templates/utils/validateContent.js +70 -25
|
@@ -1,30 +1,14 @@
|
|
|
1
1
|
import _ from "lodash/fp";
|
|
2
|
-
import { useEffect } from "react";
|
|
3
2
|
import PropTypes from "prop-types";
|
|
4
3
|
import { FormattedMessage, useIntl } from "react-intl";
|
|
5
4
|
import { Form, Button, Divider, Label, Segment } from "semantic-ui-react";
|
|
6
5
|
import ValuesField from "./ValuesField";
|
|
7
6
|
import ConditionalFieldForm from "./ConditionalFieldForm";
|
|
8
7
|
import MandatoryConditional from "./MandatoryConditional";
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
getWidgetOptions,
|
|
12
|
-
getTypeOptions,
|
|
13
|
-
WIDGETS,
|
|
14
|
-
} from "./widgetDefinitions";
|
|
8
|
+
import FieldDefinition from "./FieldDefinition";
|
|
9
|
+
import TableValuesForm from "./TableValuesForm";
|
|
15
10
|
import { getValues } from "./valueDefinitions";
|
|
16
11
|
|
|
17
|
-
const typeFromKey = (keys) =>
|
|
18
|
-
_.includes("role_groups")(keys)
|
|
19
|
-
? "role_groups"
|
|
20
|
-
: _.includes("role_users")(keys)
|
|
21
|
-
? "role_users"
|
|
22
|
-
: _.includes("hierarchy")(keys)
|
|
23
|
-
? "hierarchy"
|
|
24
|
-
: _.first(keys);
|
|
25
|
-
|
|
26
|
-
const defaultType = (values) => _.flow(_.map("value"), _.first)(values);
|
|
27
|
-
|
|
28
12
|
export const FieldForm = ({
|
|
29
13
|
allFields,
|
|
30
14
|
field,
|
|
@@ -53,83 +37,8 @@ export const FieldForm = ({
|
|
|
53
37
|
const defaultField = `${fieldNamePrefix}.default`;
|
|
54
38
|
const subscribableField = `${fieldNamePrefix}.subscribable`;
|
|
55
39
|
const values = getValues(widget, type);
|
|
56
|
-
const keyType = _.flow([_.getOr({}, "values"), _.keys, typeFromKey])(field);
|
|
57
40
|
const hasDependencies = _.negate(_.isEmpty)(dependencies);
|
|
58
41
|
|
|
59
|
-
const typeCheckOnChange = (widgetOptions) => {
|
|
60
|
-
if (widgetOptions && _.indexOf(type)(widgetOptions.types) < 0)
|
|
61
|
-
onChange(null, {
|
|
62
|
-
name: `${fieldNamePrefix}.type`,
|
|
63
|
-
value: widgetOptions.types[0],
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const cardinalityCheckOnChange = (widgetOptions) => {
|
|
68
|
-
if (
|
|
69
|
-
widgetOptions &&
|
|
70
|
-
_.indexOf(cardinality)(widgetOptions.cardinalities) < 0
|
|
71
|
-
)
|
|
72
|
-
onChange(null, {
|
|
73
|
-
name: `${fieldNamePrefix}.cardinality`,
|
|
74
|
-
value: widgetOptions.cardinalities[0],
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const changeValue = (name, value) =>
|
|
79
|
-
value == "null"
|
|
80
|
-
? onChange(null, { name, value: null })
|
|
81
|
-
: onChange(null, {
|
|
82
|
-
name,
|
|
83
|
-
value: { [value]: null },
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
const handleCardinalityChange = (e, data) => {
|
|
87
|
-
const value = data?.value;
|
|
88
|
-
onChange(e, data);
|
|
89
|
-
if (_.includes(value)(["1", "+"]) && !_.isEmpty(field?.mandatory))
|
|
90
|
-
onChange(e, { name: `${fieldNamePrefix}.mandatory`, value: null });
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const handleWidgetChange = (e, data) => {
|
|
94
|
-
const { value } = data;
|
|
95
|
-
const types = _.find({ value })(WIDGETS).types;
|
|
96
|
-
const updatedType = _.indexOf(type)(types) < 0 ? _.head(types) : type;
|
|
97
|
-
changeValue(
|
|
98
|
-
valueName,
|
|
99
|
-
defaultType(getValues(value, updatedType)) || "null"
|
|
100
|
-
);
|
|
101
|
-
onChange(e, {
|
|
102
|
-
name: defaultField,
|
|
103
|
-
value: { value: "", origin: "default" },
|
|
104
|
-
});
|
|
105
|
-
onChange(e, { name: subscribableField, value: false });
|
|
106
|
-
onChange(e, data);
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const handleTypeChange = (e, data) => {
|
|
110
|
-
const { value } = data;
|
|
111
|
-
changeValue(valueName, defaultType(getValues(widget, value)) || "null");
|
|
112
|
-
onChange(e, {
|
|
113
|
-
name: defaultField,
|
|
114
|
-
value: { value: "", origin: "default" },
|
|
115
|
-
});
|
|
116
|
-
onChange(e, { name: subscribableField, value: false });
|
|
117
|
-
onChange(e, data);
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const onValueSelectionChange = (e, { value }) => {
|
|
121
|
-
onChange(e, { name: subscribableField, value: false });
|
|
122
|
-
changeValue(valueName, value);
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
//On widget change, verify if type and cardinality are still valid
|
|
126
|
-
useEffect(() => {
|
|
127
|
-
const widgetOptions = _.find({ value: widget })(WIDGETS);
|
|
128
|
-
typeCheckOnChange(widgetOptions);
|
|
129
|
-
cardinalityCheckOnChange(widgetOptions);
|
|
130
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
131
|
-
}, [widget, type]);
|
|
132
|
-
|
|
133
42
|
const isNullOrEmpty = (value) =>
|
|
134
43
|
!_.isNumber(value) && (!value || _.isEmpty(value));
|
|
135
44
|
|
|
@@ -223,51 +132,39 @@ export const FieldForm = ({
|
|
|
223
132
|
value={description || ""}
|
|
224
133
|
onChange={onChange}
|
|
225
134
|
/>
|
|
226
|
-
<
|
|
227
|
-
<Form.Dropdown
|
|
228
|
-
name={`${fieldNamePrefix}.widget`}
|
|
229
|
-
fluid
|
|
230
|
-
selection
|
|
231
|
-
label={formatMessage({ id: "template.field.widget" })}
|
|
232
|
-
value={widget}
|
|
233
|
-
options={getWidgetOptions()}
|
|
234
|
-
required
|
|
235
|
-
onChange={handleWidgetChange}
|
|
236
|
-
/>
|
|
237
|
-
<Form.Dropdown
|
|
238
|
-
fluid
|
|
239
|
-
selection
|
|
240
|
-
label={formatMessage({ id: "template.field.type" })}
|
|
241
|
-
onChange={handleTypeChange}
|
|
242
|
-
name={`${fieldNamePrefix}.type`}
|
|
243
|
-
value={type}
|
|
244
|
-
required
|
|
245
|
-
options={getTypeOptions(formatMessage)(widget)}
|
|
246
|
-
/>
|
|
247
|
-
<Form.Dropdown
|
|
248
|
-
fluid
|
|
249
|
-
selection
|
|
250
|
-
label={formatMessage({ id: "template.field.cardinality" })}
|
|
251
|
-
onChange={handleCardinalityChange}
|
|
252
|
-
name={`${fieldNamePrefix}.cardinality`}
|
|
253
|
-
value={cardinality}
|
|
254
|
-
required
|
|
255
|
-
options={getCardinalityOptions(formatMessage)(widget)}
|
|
256
|
-
/>
|
|
257
|
-
</Form.Group>
|
|
258
|
-
<ValuesField
|
|
135
|
+
<FieldDefinition
|
|
259
136
|
defaultField={defaultField}
|
|
260
|
-
field={field}
|
|
261
|
-
fieldType={type}
|
|
262
|
-
keyType={keyType}
|
|
263
|
-
name={valueName}
|
|
264
|
-
onChange={onChange}
|
|
265
|
-
onSelectionChange={onValueSelectionChange}
|
|
266
|
-
subscribableField={subscribableField}
|
|
267
137
|
fieldNamePrefix={fieldNamePrefix}
|
|
268
|
-
|
|
269
|
-
|
|
138
|
+
type={type}
|
|
139
|
+
widget={widget}
|
|
140
|
+
cardinality={cardinality}
|
|
141
|
+
mandatory={field?.mandatory}
|
|
142
|
+
subscribableField={subscribableField}
|
|
143
|
+
onChange={onChange}
|
|
144
|
+
valueName={valueName}
|
|
270
145
|
/>
|
|
146
|
+
{field?.type == "dynamic_table" ? (
|
|
147
|
+
<TableValuesForm
|
|
148
|
+
name={valueName}
|
|
149
|
+
fieldNamePrefix={fieldNamePrefix}
|
|
150
|
+
values={_.path(`values.table_columns`)(field) || []}
|
|
151
|
+
type={"table_columns"}
|
|
152
|
+
field={field}
|
|
153
|
+
onChange={onChange}
|
|
154
|
+
scope={scope}
|
|
155
|
+
/>
|
|
156
|
+
) : (
|
|
157
|
+
<ValuesField
|
|
158
|
+
defaultField={defaultField}
|
|
159
|
+
field={field}
|
|
160
|
+
name={valueName}
|
|
161
|
+
onChange={onChange}
|
|
162
|
+
subscribableField={subscribableField}
|
|
163
|
+
fieldNamePrefix={fieldNamePrefix}
|
|
164
|
+
scope={scope}
|
|
165
|
+
values={values}
|
|
166
|
+
/>
|
|
167
|
+
)}
|
|
271
168
|
<ConditionalFieldForm
|
|
272
169
|
allFields={allFields}
|
|
273
170
|
fieldNamePrefix={fieldNamePrefix}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import _ from "lodash/fp";
|
|
2
|
+
import { Accordion, Button, Divider, Form, Icon, Label } from "semantic-ui-react";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { useIntl } from "react-intl";
|
|
5
|
+
import { FormattedMessage } from "react-intl";
|
|
6
|
+
import FieldDefinition from "./FieldDefinition";
|
|
7
|
+
import ValuesField from "./ValuesField";
|
|
8
|
+
import { defaultFieldDefinition } from "./widgetDefinitions";
|
|
9
|
+
import { getValues, getKeyType } from "./valueDefinitions";
|
|
10
|
+
import ValuesConfiguration from "./ValuesConfiguration";
|
|
11
|
+
|
|
12
|
+
const AccordionButtonGroup = ({
|
|
13
|
+
fieldIndex,
|
|
14
|
+
fieldCount,
|
|
15
|
+
onColumnUp,
|
|
16
|
+
onColumnDown,
|
|
17
|
+
onColumnRemoval,
|
|
18
|
+
}) => {
|
|
19
|
+
return (
|
|
20
|
+
<Button.Group
|
|
21
|
+
basic
|
|
22
|
+
floated="right"
|
|
23
|
+
color="orange"
|
|
24
|
+
size="tiny"
|
|
25
|
+
buttons={[
|
|
26
|
+
{
|
|
27
|
+
key: "up",
|
|
28
|
+
icon: "arrow up",
|
|
29
|
+
type: "button",
|
|
30
|
+
onClick: () => onColumnUp(),
|
|
31
|
+
disabled: fieldIndex === 0,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
key: "down",
|
|
35
|
+
icon: "arrow down",
|
|
36
|
+
type: "button",
|
|
37
|
+
onClick: () => onColumnDown(),
|
|
38
|
+
disabled: fieldIndex === fieldCount - 1,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
key: "delete",
|
|
42
|
+
icon: "trash alternate outline",
|
|
43
|
+
type: "button",
|
|
44
|
+
onClick: () => onColumnRemoval(),
|
|
45
|
+
},
|
|
46
|
+
]}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const TableContent = ({
|
|
52
|
+
field,
|
|
53
|
+
fieldIndex,
|
|
54
|
+
fieldCount,
|
|
55
|
+
onChange,
|
|
56
|
+
onColumnUp,
|
|
57
|
+
onColumnDown,
|
|
58
|
+
onColumnRemoval,
|
|
59
|
+
prefix,
|
|
60
|
+
scope,
|
|
61
|
+
}) => {
|
|
62
|
+
const valueName = `${prefix}.values`;
|
|
63
|
+
const defaultField = `${prefix}.default`;
|
|
64
|
+
const widget = field?.widget || defaultFieldDefinition.widget;
|
|
65
|
+
const type = field?.type || defaultFieldDefinition.type;
|
|
66
|
+
const values = getValues(widget, type);
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<>
|
|
70
|
+
<AccordionButtonGroup
|
|
71
|
+
fieldIndex={fieldIndex}
|
|
72
|
+
fieldCount={fieldCount}
|
|
73
|
+
onColumnUp={onColumnUp}
|
|
74
|
+
onColumnDown={onColumnDown}
|
|
75
|
+
onColumnRemoval={onColumnRemoval}
|
|
76
|
+
/>
|
|
77
|
+
<Divider hidden fitted />
|
|
78
|
+
<FieldDefinition
|
|
79
|
+
allowedTypes={["string", "user", "user_group"]}
|
|
80
|
+
allowedWidgets={["string", "dropdown"]}
|
|
81
|
+
defaultField={defaultField}
|
|
82
|
+
cardinality={field?.cardinality || defaultFieldDefinition.cardinality}
|
|
83
|
+
fieldNamePrefix={prefix}
|
|
84
|
+
mandatory={field?.mandatory || false}
|
|
85
|
+
onChange={onChange}
|
|
86
|
+
type={type}
|
|
87
|
+
valueName={valueName}
|
|
88
|
+
widget={widget}
|
|
89
|
+
/>
|
|
90
|
+
<ValuesField
|
|
91
|
+
defaultField={defaultField}
|
|
92
|
+
field={field}
|
|
93
|
+
name={valueName}
|
|
94
|
+
onChange={onChange}
|
|
95
|
+
fieldNamePrefix={prefix}
|
|
96
|
+
scope={scope}
|
|
97
|
+
values={values}
|
|
98
|
+
/>
|
|
99
|
+
</>
|
|
100
|
+
);
|
|
101
|
+
};
|
|
102
|
+
export const TableValuesForm = ({ name, onChange, type, values, scope, field, fieldNamePrefix }) => {
|
|
103
|
+
const fieldCount = _.size(values);
|
|
104
|
+
const [activeField, setActiveField] = useState();
|
|
105
|
+
const [fieldValue, setFieldValue] = useState();
|
|
106
|
+
const { formatMessage } = useIntl();
|
|
107
|
+
|
|
108
|
+
const swap = (targetKey, sourceKey) => {
|
|
109
|
+
const tagetValue = values[targetKey];
|
|
110
|
+
const sourceValue = values[sourceKey];
|
|
111
|
+
|
|
112
|
+
return _.flow(
|
|
113
|
+
_.set(sourceKey, tagetValue),
|
|
114
|
+
_.set(targetKey, sourceValue),
|
|
115
|
+
)(values);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const handleColumnUp = (key) => {
|
|
119
|
+
const updatedValues = swap(key - 1, key);
|
|
120
|
+
onChange(null, { name, value: { [type]: updatedValues } });
|
|
121
|
+
setActiveField(key - 1);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const handleColumnDown = (key) => {
|
|
125
|
+
const updatedValues = swap(key + 1, key);
|
|
126
|
+
onChange(null, { name, value: { [type]: updatedValues } });
|
|
127
|
+
setActiveField(key + 1);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const handleRemove = (key) => {
|
|
131
|
+
const updatedValues = values.toSpliced(key, 1);
|
|
132
|
+
onChange(null, { name, value: { [type]: updatedValues } });
|
|
133
|
+
if (_.size(updatedValues) > 0) {
|
|
134
|
+
setActiveField(key - 1);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const onSelectField = (e, { index }) =>
|
|
139
|
+
setActiveField((x) => (x == index ? null : index));
|
|
140
|
+
|
|
141
|
+
const handleAddColumnClick = (e) => {
|
|
142
|
+
e.preventDefault();
|
|
143
|
+
if (!fieldValue || fieldValue.trim() === "") {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
addColumn({ key: "Enter" });
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const addColumn = ({ key }) => {
|
|
150
|
+
if (key === "Enter") {
|
|
151
|
+
if (!fieldValue || fieldValue.trim() === "") {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const updatedValues = [
|
|
155
|
+
...values,
|
|
156
|
+
{ ...defaultFieldDefinition, name: fieldValue, ai_suggestion: false, label: fieldValue },
|
|
157
|
+
];
|
|
158
|
+
onChange(null, { name, value: { [type]: updatedValues } });
|
|
159
|
+
setFieldValue("");
|
|
160
|
+
setActiveField(_.size(updatedValues) - 1);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const keyType = getKeyType(field);
|
|
165
|
+
|
|
166
|
+
const panels = values.map((value, i) => ({
|
|
167
|
+
title: {
|
|
168
|
+
content: (
|
|
169
|
+
<>
|
|
170
|
+
<Label key={i} color="orange">
|
|
171
|
+
{value?.errors?.hasErrors && (
|
|
172
|
+
<Icon
|
|
173
|
+
key={i}
|
|
174
|
+
style={{ marginLeft: "5px" }}
|
|
175
|
+
name="warning sign"
|
|
176
|
+
/>
|
|
177
|
+
)}
|
|
178
|
+
{value.name}
|
|
179
|
+
</Label>
|
|
180
|
+
{value?.errors?.nameDuplicated && <Label basic color="red" size={"small"} pointing={"left"}>
|
|
181
|
+
{formatMessage({
|
|
182
|
+
id: "template.form.validation.name_duplicated",
|
|
183
|
+
})}
|
|
184
|
+
</Label>}
|
|
185
|
+
</>
|
|
186
|
+
)
|
|
187
|
+
},
|
|
188
|
+
key: i,
|
|
189
|
+
onTitleClick: onSelectField,
|
|
190
|
+
active: activeField == i,
|
|
191
|
+
content: {
|
|
192
|
+
content: (
|
|
193
|
+
<TableContent
|
|
194
|
+
prefix={`${name}.${type}[${i}]`}
|
|
195
|
+
fieldIndex={i}
|
|
196
|
+
fieldCount={fieldCount}
|
|
197
|
+
onColumnUp={() => {
|
|
198
|
+
handleColumnUp(i);
|
|
199
|
+
}}
|
|
200
|
+
onColumnDown={() => {
|
|
201
|
+
handleColumnDown(i);
|
|
202
|
+
}}
|
|
203
|
+
onColumnRemoval={() => {
|
|
204
|
+
handleRemove(i);
|
|
205
|
+
}}
|
|
206
|
+
onChange={onChange}
|
|
207
|
+
field={value}
|
|
208
|
+
scope={scope}
|
|
209
|
+
/>
|
|
210
|
+
),
|
|
211
|
+
},
|
|
212
|
+
}));
|
|
213
|
+
|
|
214
|
+
return (
|
|
215
|
+
<>
|
|
216
|
+
<Accordion panels={panels} />
|
|
217
|
+
{activeField == _.size(panels) - 1 && <Divider hidden />}
|
|
218
|
+
<Form.Input
|
|
219
|
+
label={
|
|
220
|
+
<label>
|
|
221
|
+
Header
|
|
222
|
+
{(!fieldValue || fieldValue.trim() === "") && (
|
|
223
|
+
<Label pointing="left" style={{ marginLeft: "10px" }}>
|
|
224
|
+
<FormattedMessage id="template.form.validation.empty_required" />
|
|
225
|
+
</Label>
|
|
226
|
+
)}
|
|
227
|
+
|
|
228
|
+
</label>
|
|
229
|
+
}
|
|
230
|
+
required
|
|
231
|
+
icon={
|
|
232
|
+
<Icon
|
|
233
|
+
name="add circle"
|
|
234
|
+
link
|
|
235
|
+
onClick={handleAddColumnClick}
|
|
236
|
+
/>
|
|
237
|
+
}
|
|
238
|
+
value={fieldValue}
|
|
239
|
+
onChange={(e, { value }) => setFieldValue(value)}
|
|
240
|
+
onKeyPress={addColumn}
|
|
241
|
+
/>
|
|
242
|
+
<Divider hidden />
|
|
243
|
+
<ValuesConfiguration
|
|
244
|
+
aiSuggestion={field?.ai_suggestion || false}
|
|
245
|
+
editable={field?.editable || true}
|
|
246
|
+
keyType={keyType}
|
|
247
|
+
onChange={onChange}
|
|
248
|
+
searchable={field?.searchable || false}
|
|
249
|
+
fieldNamePrefix={fieldNamePrefix}
|
|
250
|
+
hasAiSuggestion={false}
|
|
251
|
+
subscribable={field?.subscribable}
|
|
252
|
+
scope={scope}
|
|
253
|
+
/>
|
|
254
|
+
</>
|
|
255
|
+
);
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
export default TableValuesForm;
|
|
@@ -61,38 +61,54 @@ export const TemplateForm = ({ loading, template, onSubmit }) => {
|
|
|
61
61
|
content: [...editedTemplate.content, { name: "", fields: [] }],
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
+
const formattedFields = (fields) => _.flow(
|
|
65
|
+
_.map((field) => {
|
|
66
|
+
const fieldProperties = [
|
|
67
|
+
"label",
|
|
68
|
+
"name",
|
|
69
|
+
"description",
|
|
70
|
+
"type",
|
|
71
|
+
"widget",
|
|
72
|
+
"cardinality",
|
|
73
|
+
"values",
|
|
74
|
+
"default",
|
|
75
|
+
"subscribable",
|
|
76
|
+
"editable",
|
|
77
|
+
"searchable",
|
|
78
|
+
"ai_suggestion",
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
const dependsProperty = _.isEmpty(_.path("depends.on")(field))
|
|
82
|
+
? []
|
|
83
|
+
: ["depends"];
|
|
84
|
+
const mandatoryProperty = _.isEmpty(_.path("mandatory.on")(field))
|
|
85
|
+
? []
|
|
86
|
+
: ["mandatory"];
|
|
87
|
+
const allFields = _.flow(
|
|
88
|
+
_.concat(dependsProperty),
|
|
89
|
+
_.concat(mandatoryProperty))
|
|
90
|
+
(fieldProperties);
|
|
91
|
+
|
|
92
|
+
if (field?.type === "dynamic_table") {
|
|
93
|
+
const tableColumns = formattedFields(field?.values?.table_columns);
|
|
94
|
+
return _.flow(
|
|
95
|
+
_.set("values.table_columns", tableColumns),
|
|
96
|
+
_.pick(allFields),
|
|
97
|
+
_.omit(["default"]))
|
|
98
|
+
(field);
|
|
99
|
+
}
|
|
100
|
+
return _.pick(allFields)(field);
|
|
101
|
+
})
|
|
102
|
+
)(fields);
|
|
103
|
+
|
|
64
104
|
const handleSubmit = () => {
|
|
65
105
|
const formattedContent = _.flow(
|
|
66
106
|
_.prop("content"),
|
|
67
107
|
_.map(({ name, fields }) => {
|
|
68
|
-
|
|
69
|
-
_.map((field) => {
|
|
70
|
-
const fieldProperties = [
|
|
71
|
-
"label",
|
|
72
|
-
"name",
|
|
73
|
-
"description",
|
|
74
|
-
"type",
|
|
75
|
-
"widget",
|
|
76
|
-
"cardinality",
|
|
77
|
-
"values",
|
|
78
|
-
"default",
|
|
79
|
-
"subscribable",
|
|
80
|
-
"mandatory",
|
|
81
|
-
"editable",
|
|
82
|
-
"searchable",
|
|
83
|
-
"ai_suggestion",
|
|
84
|
-
];
|
|
85
|
-
|
|
86
|
-
const dependsProperty = _.isEmpty(_.path("depends.on")(field))
|
|
87
|
-
? []
|
|
88
|
-
: ["depends"];
|
|
89
|
-
const allFields = _.concat(dependsProperty)(fieldProperties);
|
|
90
|
-
return _.pick(allFields)(field);
|
|
91
|
-
})
|
|
92
|
-
)(fields);
|
|
93
|
-
return { name, fields: formattedFields };
|
|
108
|
+
return { name, fields: formattedFields(fields) };
|
|
94
109
|
})
|
|
95
110
|
)(editedTemplate);
|
|
111
|
+
|
|
96
112
|
onSubmit({ template: { ...editedTemplate, content: formattedContent } });
|
|
97
113
|
};
|
|
98
114
|
|
|
@@ -115,6 +131,7 @@ export const TemplateForm = ({ loading, template, onSubmit }) => {
|
|
|
115
131
|
const labelValue = editedTemplate.label || "";
|
|
116
132
|
const scopeValue = editedTemplate.scope || "";
|
|
117
133
|
const subscopeValue = editedTemplate.subscope || "";
|
|
134
|
+
|
|
118
135
|
return (
|
|
119
136
|
<Form loading={loading} className="template-form">
|
|
120
137
|
<Divider horizontal>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import _ from "lodash/fp";
|
|
2
|
+
import { Form } from "semantic-ui-react";
|
|
3
|
+
import { useIntl } from "react-intl";
|
|
4
|
+
|
|
5
|
+
const searchableEnabledScopes = ["bg", "dq", "ie", "ri", "dd"];
|
|
6
|
+
|
|
7
|
+
const ValuesConfiguration = ({ aiSuggestion, editable, searchable, fieldNamePrefix, hasAiSuggestion, keyType, onChange, scope, subscribable, subscribableField }) => {
|
|
8
|
+
const { formatMessage } = useIntl();
|
|
9
|
+
|
|
10
|
+
return <Form.Group size="small" widths="equal">
|
|
11
|
+
<Form.Field>
|
|
12
|
+
<Form.Checkbox
|
|
13
|
+
name={`${fieldNamePrefix}.editable`}
|
|
14
|
+
label={formatMessage({
|
|
15
|
+
id: "template.field.editable",
|
|
16
|
+
defaultMessage: "Editable",
|
|
17
|
+
})}
|
|
18
|
+
checked={editable}
|
|
19
|
+
onChange={(e, { name, checked: value }) =>
|
|
20
|
+
onChange(null, { name, value })
|
|
21
|
+
}
|
|
22
|
+
/>
|
|
23
|
+
</Form.Field>
|
|
24
|
+
{hasAiSuggestion ? (
|
|
25
|
+
<Form.Field>
|
|
26
|
+
<Form.Checkbox
|
|
27
|
+
name={`${fieldNamePrefix}.ai_suggestion`}
|
|
28
|
+
label={formatMessage({
|
|
29
|
+
id: "template.field.ai_suggestion",
|
|
30
|
+
defaultMessage: "AI Suggestions",
|
|
31
|
+
})}
|
|
32
|
+
checked={aiSuggestion}
|
|
33
|
+
onChange={(_e, { name, checked: value }) =>
|
|
34
|
+
onChange(null, { name, value })
|
|
35
|
+
}
|
|
36
|
+
/>
|
|
37
|
+
</Form.Field>
|
|
38
|
+
) : null}
|
|
39
|
+
{_.includes(scope)(searchableEnabledScopes) ? (
|
|
40
|
+
<Form.Field>
|
|
41
|
+
<Form.Checkbox
|
|
42
|
+
name={`${fieldNamePrefix}.searchable`}
|
|
43
|
+
label={formatMessage({
|
|
44
|
+
id: "template.field.searchable",
|
|
45
|
+
defaultMessage: "Sercheable",
|
|
46
|
+
})}
|
|
47
|
+
checked={searchable}
|
|
48
|
+
onChange={(_e, { name, checked: value }) =>
|
|
49
|
+
onChange(null, { name, value })
|
|
50
|
+
}
|
|
51
|
+
/>
|
|
52
|
+
</Form.Field>
|
|
53
|
+
) : null}
|
|
54
|
+
{_.includes(keyType)(["fixed", "fixed_tuple"]) ? (
|
|
55
|
+
<Form.Checkbox
|
|
56
|
+
name={subscribableField}
|
|
57
|
+
label={formatMessage({ id: "template.field.subscribable" })}
|
|
58
|
+
checked={subscribable}
|
|
59
|
+
onChange={(_e, { name, checked: value }) =>
|
|
60
|
+
onChange(null, { name, value })
|
|
61
|
+
}
|
|
62
|
+
/>
|
|
63
|
+
) : null}
|
|
64
|
+
</Form.Group>
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export default ValuesConfiguration;
|