@truedat/df 4.48.0 → 4.48.4
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/CHANGELOG.md +12 -0
- package/package.json +4 -4
- package/src/components/DynamicFieldValue.js +52 -44
- package/src/components/DynamicForm.js +19 -14
- package/src/components/DynamicFormViewer.js +23 -21
- package/src/components/EditableDynamicFieldValue.js +21 -22
- package/src/components/FieldGroupSegment.js +2 -2
- package/src/components/FieldGroupSubSegment/__tests__/FieldGroupSubSegment.spec.js +22 -22
- package/src/components/FieldGroupSubSegment/__tests__/__snapshots__/FieldGroupSubSegment.spec.js.snap +4 -4
- package/src/components/FieldGroupSubSegment/handleCopyModule.js +18 -18
- package/src/components/__tests__/__snapshots__/DynamicForm.spec.js.snap +74 -80
- package/src/components/widgets/CheckboxField.js +8 -8
- package/src/components/widgets/DynamicField.js +3 -1
- package/src/components/widgets/RadioField.js +7 -7
- package/src/components/widgets/StandardDropdown.js +32 -22
- package/src/components/widgets/__tests__/CheckboxField.spec.js +4 -7
- package/src/components/widgets/__tests__/RadioField.spec.js +3 -3
- package/src/components/widgets/__tests__/__snapshots__/RadioField.spec.js.snap +5 -1
- package/src/components/widgets/__tests__/__snapshots__/StandardDropdown.spec.js.snap +31 -33
- package/src/selectors/__tests__/getOptions.spec.js +2 -2
- package/src/selectors/getOptions.js +1 -1
- package/src/templates/components/Template.js +7 -2
- package/src/templates/components/TemplateCard.js +2 -1
- package/src/templates/components/__tests__/Template.spec.js +12 -10
- package/src/templates/components/__tests__/__snapshots__/Template.spec.js.snap +278 -27
- package/src/templates/components/templateForm/ActiveGroupForm.js +8 -7
- package/src/templates/components/templateForm/ConditionalFieldForm.js +12 -4
- package/src/templates/components/templateForm/GroupsList.js +2 -2
- package/src/templates/components/templateForm/__tests__/__snapshots__/ActiveGroupForm.spec.js.snap +1 -1
- package/src/templates/utils/__tests__/parseFieldOptions.spec.js +15 -12
- package/src/templates/utils/__tests__/parseGroups.spec.js +20 -11
- package/src/templates/utils/parseFieldOptions.js +67 -56
- package/src/templates/utils/parseGroups.js +24 -24
|
@@ -1,61 +1,72 @@
|
|
|
1
1
|
import _ from "lodash/fp";
|
|
2
|
-
|
|
2
|
+
import { accentInsensitivePathOrder } from "@truedat/core/services/sort";
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const makeOptions = (formatMessage, label) =>
|
|
5
|
+
_.map((v) => ({
|
|
6
|
+
value: v,
|
|
7
|
+
text: formatMessage({ id: `fields.${label}.${v}`, defaultMessage: v }),
|
|
8
|
+
}));
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
const parseFixed = _.flow(_.get("fixed"), stringToValueTextList);
|
|
14
|
-
const parseRoleUsers = _.flow(
|
|
15
|
-
_.get("processed_users"),
|
|
16
|
-
_.cond([
|
|
17
|
-
[_.isArray, _.identity],
|
|
18
|
-
[_.stubTrue, _.constant([])],
|
|
19
|
-
]),
|
|
20
|
-
stringToValueTextList
|
|
21
|
-
);
|
|
22
|
-
const parseRoleGroups = (values) =>
|
|
23
|
-
_.concat(
|
|
24
|
-
_.flow(
|
|
25
|
-
_.get("processed_users"),
|
|
26
|
-
_.map((name) => ({
|
|
27
|
-
value: `user:${name}`,
|
|
28
|
-
text: name,
|
|
29
|
-
icon: "user",
|
|
30
|
-
}))
|
|
31
|
-
)(values),
|
|
32
|
-
_.flow(
|
|
33
|
-
_.get("processed_groups"),
|
|
34
|
-
_.map((name) => ({
|
|
35
|
-
value: `group:${name}`,
|
|
36
|
-
text: name,
|
|
37
|
-
icon: "group",
|
|
38
|
-
}))
|
|
39
|
-
)(values)
|
|
40
|
-
);
|
|
41
|
-
const parseDomain = _.flow(
|
|
42
|
-
_.get("domain"),
|
|
43
|
-
_.propOr([], _.toString(selectedDomain?.id)),
|
|
44
|
-
stringToValueTextList
|
|
45
|
-
);
|
|
10
|
+
export const parseFieldOptions =
|
|
11
|
+
(formatMessage) => (content, selectedDomain) => (field) => {
|
|
12
|
+
const value = _.prop(field?.name)(content);
|
|
13
|
+
if (!field?.values) return { ...field, value };
|
|
46
14
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
15
|
+
const translateValues = _.flow(
|
|
16
|
+
makeOptions(formatMessage, field?.label),
|
|
17
|
+
_.sortBy(accentInsensitivePathOrder("text"))
|
|
18
|
+
);
|
|
19
|
+
const parseSwitch = (values) => {
|
|
20
|
+
const switchOn = _.prop("switch.on")(values);
|
|
21
|
+
const switchedValues = _.prop(`switch.values.${content[switchOn]}`)(
|
|
22
|
+
values
|
|
23
|
+
);
|
|
24
|
+
return translateValues(switchedValues);
|
|
25
|
+
};
|
|
26
|
+
const parseFixed = _.flow(_.get("fixed"), translateValues);
|
|
27
|
+
const parseRoleUsers = _.flow(
|
|
28
|
+
_.get("processed_users"),
|
|
29
|
+
_.cond([
|
|
30
|
+
[_.isArray, _.identity],
|
|
31
|
+
[_.stubTrue, _.constant([])],
|
|
32
|
+
]),
|
|
33
|
+
translateValues
|
|
34
|
+
);
|
|
35
|
+
const parseRoleGroups = (values) =>
|
|
36
|
+
_.concat(
|
|
37
|
+
_.flow(
|
|
38
|
+
_.get("processed_users"),
|
|
39
|
+
_.map((name) => ({
|
|
40
|
+
value: `user:${name}`,
|
|
41
|
+
text: name,
|
|
42
|
+
icon: "user",
|
|
43
|
+
}))
|
|
44
|
+
)(values),
|
|
45
|
+
_.flow(
|
|
46
|
+
_.get("processed_groups"),
|
|
47
|
+
_.map((name) => ({
|
|
48
|
+
value: `group:${name}`,
|
|
49
|
+
text: name,
|
|
50
|
+
icon: "group",
|
|
51
|
+
}))
|
|
52
|
+
)(values)
|
|
53
|
+
);
|
|
54
|
+
const parseDomain = _.flow(
|
|
55
|
+
_.get("domain"),
|
|
56
|
+
_.propOr([], _.toString(selectedDomain?.id)),
|
|
57
|
+
translateValues
|
|
58
|
+
);
|
|
60
59
|
|
|
61
|
-
|
|
60
|
+
const parsedValues = _.flow(
|
|
61
|
+
_.get("values"),
|
|
62
|
+
_.cond([
|
|
63
|
+
[_.has("switch"), parseSwitch],
|
|
64
|
+
[_.has("fixed"), parseFixed],
|
|
65
|
+
[_.has("fixed_tuple"), _.get("fixed_tuple")],
|
|
66
|
+
[_.has("role_users"), parseRoleUsers],
|
|
67
|
+
[_.has("role_groups"), parseRoleGroups],
|
|
68
|
+
[_.has("domain"), parseDomain],
|
|
69
|
+
])
|
|
70
|
+
)(field);
|
|
71
|
+
return { ...field, value, parsedValues };
|
|
72
|
+
};
|
|
@@ -17,27 +17,27 @@ const checkDependency = (field, content) => {
|
|
|
17
17
|
const enrichIsSecret = (isSecret) => (field) =>
|
|
18
18
|
isSecret ? { ...field, isSecret } : field;
|
|
19
19
|
|
|
20
|
-
const parseGroups =
|
|
21
|
-
|
|
22
|
-
_.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
_.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
(
|
|
29
|
-
(
|
|
30
|
-
(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
_.prop("values.switch.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
20
|
+
export const parseGroups =
|
|
21
|
+
(formatMessage) => (template, content, fieldsToOmit, selectedDomain) =>
|
|
22
|
+
_.flow(
|
|
23
|
+
_.getOr([], "content"),
|
|
24
|
+
_.map((group) => {
|
|
25
|
+
const fields = _.flow(
|
|
26
|
+
_.get("fields"),
|
|
27
|
+
_.reject((field) => _.includes(fieldsToOmit)(field?.name)),
|
|
28
|
+
_.filter(
|
|
29
|
+
(field) =>
|
|
30
|
+
(!("depends" in field) ||
|
|
31
|
+
(hasDependentKeys(field) && checkDependency(field, content))) &&
|
|
32
|
+
(!(field.values && "switch" in field.values) ||
|
|
33
|
+
_.prop(_.prop("values.switch.on")(field))(content) in
|
|
34
|
+
_.prop("values.switch.values")(field))
|
|
35
|
+
),
|
|
36
|
+
_.map(parseFieldOptions(formatMessage)(content, selectedDomain)),
|
|
37
|
+
_.map(enrichRequired(content)),
|
|
38
|
+
_.map(enrichIsSecret(_.get("is_secret")(group)))
|
|
39
|
+
)(group);
|
|
40
|
+
return { ...group, fields };
|
|
41
|
+
}),
|
|
42
|
+
_.filter(({ fields }) => _.negate(_.isEmpty)(fields))
|
|
43
|
+
)(template);
|