@truedat/df 6.6.6 → 6.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 (35) hide show
  1. package/package.json +5 -5
  2. package/src/components/DynamicFieldValue.js +7 -1
  3. package/src/components/DynamicForm.js +4 -1
  4. package/src/components/DynamicFormViewer.js +0 -1
  5. package/src/components/FieldGroupDetail.js +3 -3
  6. package/src/components/FieldGroupSegment.js +1 -1
  7. package/src/components/OriginLabel.js +34 -0
  8. package/src/components/__tests__/DynamicFieldValue.spec.js +2 -2
  9. package/src/components/__tests__/DynamicForm.spec.js +4 -1
  10. package/src/components/__tests__/FieldGroupDetail.spec.js +12 -12
  11. package/src/components/__tests__/SelectableDynamicForm.spec.js +1 -1
  12. package/src/components/__tests__/__snapshots__/EditableDynamicFieldValue.spec.js.snap +2 -2
  13. package/src/components/widgets/DynamicField.js +71 -63
  14. package/src/components/widgets/__tests__/DynamicField.spec.js +34 -14
  15. package/src/components/widgets/__tests__/HierarchyPreview.spec.js +1 -2
  16. package/src/templates/components/templateForm/ActiveGroupForm.js +4 -1
  17. package/src/templates/components/templateForm/DefaultValue.js +13 -10
  18. package/src/templates/components/templateForm/FieldForm.js +8 -2
  19. package/src/templates/components/templateForm/__tests__/DefaultValue.spec.js +2 -2
  20. package/src/templates/components/templateForm/__tests__/FieldForm.spec.js +2 -2
  21. package/src/templates/utils/__tests__/applyDefaults.spec.js +101 -51
  22. package/src/templates/utils/__tests__/applyTemplate.spec.js +81 -37
  23. package/src/templates/utils/__tests__/filterDepends.spec.js +9 -6
  24. package/src/templates/utils/__tests__/filterDomains.spec.js +76 -31
  25. package/src/templates/utils/__tests__/filterSwitches.spec.js +35 -6
  26. package/src/templates/utils/__tests__/filterValues.spec.js +19 -7
  27. package/src/templates/utils/__tests__/parseFieldOptions.spec.js +18 -12
  28. package/src/templates/utils/__tests__/parseGroups.spec.js +57 -18
  29. package/src/templates/utils/applyDefaults.js +62 -21
  30. package/src/templates/utils/filterDepends.js +4 -2
  31. package/src/templates/utils/filterDomains.js +1 -1
  32. package/src/templates/utils/filterSwitches.js +6 -6
  33. package/src/templates/utils/filterValues.js +7 -4
  34. package/src/templates/utils/parseFieldOptions.js +1 -1
  35. package/src/templates/utils/parseGroups.js +2 -2
@@ -13,53 +13,98 @@ describe("filterDomains", () => {
13
13
 
14
14
  it("filters domains on content if value not present", () => {
15
15
  const result = {
16
- foo: "foo",
16
+ foo: { value: "foo", origin: "default" },
17
17
  };
18
- expect(filterDomains(templateContent)({ foo: "foo", bar: "z" })).toEqual(
19
- result
20
- );
21
- expect(filterDomains(templateContent)({ foo: "foo", bar: "z" }, 1)).toEqual(
22
- result
23
- );
18
+ expect(
19
+ filterDomains(templateContent)({
20
+ foo: { value: "foo", origin: "default" },
21
+ bar: { value: "z", origin: "default" },
22
+ })
23
+ ).toEqual(result);
24
+ expect(
25
+ filterDomains(templateContent)(
26
+ {
27
+ foo: { value: "foo", origin: "default" },
28
+ bar: { value: "z", origin: "default" },
29
+ },
30
+ 1
31
+ )
32
+ ).toEqual(result);
24
33
 
25
- expect(filterDomains(templateContent)({ foo: "foo", bar: "z" }, 2)).toEqual(
26
- result
27
- );
34
+ expect(
35
+ filterDomains(templateContent)(
36
+ {
37
+ foo: { value: "foo", origin: "default" },
38
+ bar: { value: "z", origin: "default" },
39
+ },
40
+ 2
41
+ )
42
+ ).toEqual(result);
28
43
 
29
- expect(filterDomains(templateContent)({ foo: "foo", bar: "a" }, 3)).toEqual(
30
- result
31
- );
44
+ expect(
45
+ filterDomains(templateContent)(
46
+ {
47
+ foo: { value: "foo", origin: "default" },
48
+ bar: { value: "a", origin: "default" },
49
+ },
50
+ 3
51
+ )
52
+ ).toEqual(result);
32
53
  });
33
54
 
34
55
  it("do not filter domain single value if correct", () => {
35
- expect(filterDomains(templateContent)({ foo: "foo", bar: "a" }, 1)).toEqual(
36
- {
37
- foo: "foo",
38
- bar: "a",
39
- }
40
- );
56
+ expect(
57
+ filterDomains(templateContent)(
58
+ {
59
+ foo: { value: "foo", origin: "default" },
60
+ bar: { value: "a", origin: "default" },
61
+ },
62
+ 1
63
+ )
64
+ ).toEqual({
65
+ foo: { value: "foo", origin: "default" },
66
+ bar: { value: "a", origin: "default" },
67
+ });
41
68
 
42
- expect(filterDomains(templateContent)({ foo: "foo", bar: "e" }, 2)).toEqual(
43
- {
44
- foo: "foo",
45
- bar: "e",
46
- }
47
- );
69
+ expect(
70
+ filterDomains(templateContent)(
71
+ {
72
+ foo: { value: "foo", origin: "default" },
73
+ bar: { value: "e", origin: "default" },
74
+ },
75
+ 2
76
+ )
77
+ ).toEqual({
78
+ foo: { value: "foo", origin: "default" },
79
+ bar: { value: "e", origin: "default" },
80
+ });
48
81
  });
49
82
 
50
83
  it("do not filter domain multiple value if correct", () => {
51
84
  expect(
52
- filterDomains(templateContent)({ foo: "foo", bar: ["a"] }, 1)
85
+ filterDomains(templateContent)(
86
+ {
87
+ foo: { value: "foo", origin: "default" },
88
+ bar: { value: ["a"], origin: "default" },
89
+ },
90
+ 1
91
+ )
53
92
  ).toEqual({
54
- foo: "foo",
55
- bar: ["a"],
93
+ foo: { value: "foo", origin: "default" },
94
+ bar: { value: ["a"], origin: "default" },
56
95
  });
57
96
 
58
97
  expect(
59
- filterDomains(templateContent)({ foo: "foo", bar: ["e"] }, 2)
98
+ filterDomains(templateContent)(
99
+ {
100
+ foo: { value: "foo", origin: "default" },
101
+ bar: { value: ["e"], origin: "default" },
102
+ },
103
+ 2
104
+ )
60
105
  ).toEqual({
61
- foo: "foo",
62
- bar: ["e"],
106
+ foo: { value: "foo", origin: "default" },
107
+ bar: { value: ["e"], origin: "default" },
63
108
  });
64
109
  });
65
110
  });
@@ -35,17 +35,46 @@ describe("utils: isSwitch", () => {
35
35
  describe("utils: isSwitchValid", () => {
36
36
  it("should detect valid and invalid values", () => {
37
37
  const validator = isSwitchValid("target", "src")(switchValues1);
38
- expect(validator({ src: "foo", target: "foo1" })).toBe(true);
39
- expect(validator({ src: "bar", target: "bar2" })).toBe(true);
40
- expect(validator({ src: "baz", target: "xyzzy" })).toBe(false);
41
- expect(validator({ src: "foo", target: ["foo1"] })).toBe(true);
42
- expect(validator({ src: "foo", target: "" })).toBe(true);
38
+ expect(
39
+ validator({
40
+ src: { value: "foo", origin: "default" },
41
+ target: { value: "foo1", origin: "default" },
42
+ })
43
+ ).toBe(true);
44
+ expect(
45
+ validator({
46
+ src: { value: "bar", origin: "default" },
47
+ target: { value: "bar2", origin: "default" },
48
+ })
49
+ ).toBe(true);
50
+ expect(
51
+ validator({
52
+ src: { value: "baz", origin: "default" },
53
+ target: { value: "xyzzy", origin: "default" },
54
+ })
55
+ ).toBe(false);
56
+ expect(
57
+ validator({
58
+ src: { value: "foo", origin: "default" },
59
+ target: { value: ["foo1"], origin: "default" },
60
+ })
61
+ ).toBe(true);
62
+ expect(
63
+ validator({
64
+ src: { value: "foo", origin: "default" },
65
+ target: { value: "", origin: "default" },
66
+ })
67
+ ).toBe(true);
43
68
  });
44
69
  });
45
70
 
46
71
  describe("utils: filterSwitches", () => {
47
72
  it("should remove keys with unlisted values", () => {
48
- const o = { src: "foo", target: "foo1", xyzzy: "xyzzy" };
73
+ const o = {
74
+ src: { value: "foo", origin: "default" },
75
+ target: { value: "foo1", origin: "default" },
76
+ xyzzy: { value: "xyzzy", origin: "default" },
77
+ };
49
78
  const filter = filterSwitches(templateContent);
50
79
  expect(filter({ ...o, target2: "boo" })).toMatchObject(o);
51
80
  });
@@ -21,12 +21,12 @@ describe("utils: validValues", () => {
21
21
  });
22
22
 
23
23
  describe("utils: filterValues", () => {
24
- const xyzzy = "xyzzy";
24
+ const xyzzy = { value: "xyzzy", origin: "default" };
25
25
 
26
26
  it("should allow valid values to pass through", () => {
27
27
  const o = {
28
- role: "u2",
29
- fixed: "baz",
28
+ role: { value: "u2", origin: "default" },
29
+ fixed: { value: "baz", origin: "default" },
30
30
  xyzzy,
31
31
  };
32
32
  const result = filterValues(templateContent)(o);
@@ -34,13 +34,25 @@ describe("utils: validValues", () => {
34
34
  });
35
35
 
36
36
  it("should nullify unlisted users", () => {
37
- const result = filterValues(templateContent)({ role: "ho", xyzzy });
38
- expect(result).toEqual({ role: null, xyzzy });
37
+ const result = filterValues(templateContent)({
38
+ role: { value: "ho", origin: "default" },
39
+ xyzzy,
40
+ });
41
+ expect(result).toEqual({
42
+ role: { value: null, origin: "default" },
43
+ xyzzy,
44
+ });
39
45
  });
40
46
 
41
47
  it("should nullify unlisted fixed values", () => {
42
- const result = filterValues(templateContent)({ fixed: "ho", xyzzy });
43
- expect(result).toEqual({ fixed: null, xyzzy });
48
+ const result = filterValues(templateContent)({
49
+ fixed: { value: "ho", origin: "default" },
50
+ xyzzy,
51
+ });
52
+ expect(result).toEqual({
53
+ fixed: { value: null, origin: "default" },
54
+ xyzzy,
55
+ });
44
56
  });
45
57
  });
46
58
  });
@@ -6,9 +6,12 @@ const parseFormatFieldOptions = parseFieldOptions(formatMessage);
6
6
  describe("utils: parseFieldOptions", () => {
7
7
  it("adds value to field", () => {
8
8
  const field = { name: "field" };
9
- const content = { field: "1" };
9
+ const content = { field: { value: "1", origin: "default" } };
10
10
  const result = parseFormatFieldOptions(content)(field);
11
- expect(result).toEqual({ ...field, value: "1" });
11
+ expect(result).toEqual({
12
+ ...field,
13
+ value: { value: "1", origin: "default" },
14
+ });
12
15
  });
13
16
 
14
17
  it("handles values switch", () => {
@@ -24,11 +27,14 @@ describe("utils: parseFieldOptions", () => {
24
27
  },
25
28
  },
26
29
  };
27
- const content = { field: "1", switcher: "odd" };
30
+ const content = {
31
+ field: { value: "1", origin: "default" },
32
+ switcher: { value: "odd", origin: "default" },
33
+ };
28
34
  const result = parseFormatFieldOptions(content)(field);
29
35
  expect(result).toEqual({
30
36
  ...field,
31
- value: "1",
37
+ value: { value: "1", origin: "default" },
32
38
  parsedValues: [
33
39
  { text: "1", value: "1" },
34
40
  { text: "3", value: "3" },
@@ -43,11 +49,11 @@ describe("utils: parseFieldOptions", () => {
43
49
  fixed: ["a", "b", "c"],
44
50
  },
45
51
  };
46
- const content = { field: "b" };
52
+ const content = { field: { value: "b", origin: "default" } };
47
53
  const result = parseFormatFieldOptions(content)(field);
48
54
  expect(result).toEqual({
49
55
  ...field,
50
- value: "b",
56
+ value: { value: "b", origin: "default" },
51
57
  parsedValues: [
52
58
  { text: "a", value: "a" },
53
59
  { text: "b", value: "b" },
@@ -66,11 +72,11 @@ describe("utils: parseFieldOptions", () => {
66
72
  ],
67
73
  },
68
74
  };
69
- const content = { field: "a" };
75
+ const content = { field: { value: "a", origin: "default" } };
70
76
  const result = parseFormatFieldOptions(content)(field);
71
77
  expect(result).toEqual({
72
78
  ...field,
73
- value: "a",
79
+ value: { value: "a", origin: "default" },
74
80
  parsedValues: [
75
81
  { text: "a", value: "a" },
76
82
  { text: "b", value: "b" },
@@ -86,11 +92,11 @@ describe("utils: parseFieldOptions", () => {
86
92
  processed_users: ["x", "y", "z"],
87
93
  },
88
94
  };
89
- const content = { field: "y" };
95
+ const content = { field: { value: "y", origin: "default" } };
90
96
  const result = parseFormatFieldOptions(content)(field);
91
97
  expect(result).toEqual({
92
98
  ...field,
93
- value: "y",
99
+ value: { value: "y", origin: "default" },
94
100
  parsedValues: [
95
101
  { text: "x", value: "x" },
96
102
  { text: "y", value: "y" },
@@ -109,11 +115,11 @@ describe("utils: parseFieldOptions", () => {
109
115
  },
110
116
  },
111
117
  };
112
- const content = { field: "bar" };
118
+ const content = { field: { value: "bar", origin: "default" } };
113
119
  const result = parseFormatFieldOptions(content, selectedDomain)(field);
114
120
  expect(result).toEqual({
115
121
  ...field,
116
- value: "bar",
122
+ value: { value: "bar", origin: "default" },
117
123
  parsedValues: [
118
124
  { text: "bar", value: "bar" },
119
125
  { text: "foo", value: "foo" },
@@ -16,16 +16,23 @@ describe("utils: parseGroups", () => {
16
16
  },
17
17
  ],
18
18
  };
19
- const content = { field: "1", field_mandatory: "2" };
19
+ const content = {
20
+ field: { value: "1", origin: "user" },
21
+ field_mandatory: { value: "2", origin: "user" },
22
+ };
20
23
  const result = formatParseGroups(template, content);
21
24
  expect(result).toEqual([
22
25
  {
23
26
  fields: [
24
- { name: "field", required: false, value: "1" },
27
+ {
28
+ name: "field",
29
+ required: false,
30
+ value: { value: "1", origin: "user" },
31
+ },
25
32
  {
26
33
  name: "field_mandatory",
27
34
  required: true,
28
- value: "2",
35
+ value: { value: "2", origin: "user" },
29
36
  cardinality: "1",
30
37
  },
31
38
  ],
@@ -43,12 +50,18 @@ describe("utils: parseGroups", () => {
43
50
  },
44
51
  ],
45
52
  };
46
- const content = { field: "1" };
53
+ const content = { field: { value: "1", origin: "user" } };
47
54
  const fieldsToOmit = ["ommitedField"];
48
55
  const result = formatParseGroups(template, content, fieldsToOmit);
49
56
  expect(result).toEqual([
50
57
  {
51
- fields: [{ name: "field", required: false, value: "1" }],
58
+ fields: [
59
+ {
60
+ name: "field",
61
+ required: false,
62
+ value: { value: "1", origin: "user" },
63
+ },
64
+ ],
52
65
  name: "group1",
53
66
  },
54
67
  ]);
@@ -67,7 +80,10 @@ describe("utils: parseGroups", () => {
67
80
  },
68
81
  ],
69
82
  };
70
- const content = { parent: "b", dependant: "value" };
83
+ const content = {
84
+ parent: { value: "b", origin: "user" },
85
+ dependant: { value: "value", origin: "user" },
86
+ };
71
87
  const fieldsToOmit = ["ommitedField"];
72
88
  const result = formatParseGroups(template, content, fieldsToOmit);
73
89
  expect(result).toEqual([
@@ -81,12 +97,12 @@ describe("utils: parseGroups", () => {
81
97
  ],
82
98
  values: { fixed: ["a", "b"] },
83
99
  required: false,
84
- value: "b",
100
+ value: { value: "b", origin: "user" },
85
101
  },
86
102
  {
87
103
  name: "dependant",
88
104
  depends: { on: "parent", to_be: "b" },
89
- value: "value",
105
+ value: { value: "value", origin: "user" },
90
106
  required: false,
91
107
  },
92
108
  ],
@@ -107,7 +123,7 @@ describe("utils: parseGroups", () => {
107
123
  },
108
124
  ],
109
125
  };
110
- const content = { parent: ["b", "c"] };
126
+ const content = { parent: { value: ["b", "c"], origin: "user" } };
111
127
  const fieldsToOmit = ["ommitedField"];
112
128
  const result = formatParseGroups(template, content, fieldsToOmit);
113
129
  expect(result).toEqual([
@@ -122,7 +138,7 @@ describe("utils: parseGroups", () => {
122
138
  ],
123
139
  values: { fixed: ["a", "b", "c"] },
124
140
  required: false,
125
- value: ["b", "c"],
141
+ value: { value: ["b", "c"], origin: "user" },
126
142
  },
127
143
  ],
128
144
  name: "group1",
@@ -153,7 +169,10 @@ describe("utils: parseGroups", () => {
153
169
  },
154
170
  ],
155
171
  };
156
- const content = { parent: "b", dependant: "1" };
172
+ const content = {
173
+ parent: { value: "b", origin: "user" },
174
+ dependant: { value: "1", origin: "user" },
175
+ };
157
176
  const fieldsToOmit = ["ommitedField"];
158
177
  const result = formatParseGroups(template, content, fieldsToOmit);
159
178
  expect(result).toEqual([
@@ -167,7 +186,7 @@ describe("utils: parseGroups", () => {
167
186
  ],
168
187
  values: { fixed: ["a", "b"] },
169
188
  required: false,
170
- value: "b",
189
+ value: { value: "b", origin: "user" },
171
190
  },
172
191
  {
173
192
  name: "dependant",
@@ -175,7 +194,7 @@ describe("utils: parseGroups", () => {
175
194
  switch: { on: "parent", values: { b: "1" } },
176
195
  },
177
196
  parsedValues: [{ text: "1", value: "1" }],
178
- value: "1",
197
+ value: { value: "1", origin: "user" },
179
198
  required: false,
180
199
  },
181
200
  ],
@@ -194,11 +213,17 @@ describe("utils: parseGroups", () => {
194
213
  { name: "empty_group" },
195
214
  ],
196
215
  };
197
- const content = { field: "1" };
216
+ const content = { field: { value: "1", origin: "user" } };
198
217
  const result = formatParseGroups(template, content);
199
218
  expect(result).toEqual([
200
219
  {
201
- fields: [{ name: "field", required: false, value: "1" }],
220
+ fields: [
221
+ {
222
+ name: "field",
223
+ required: false,
224
+ value: { value: "1", origin: "user" },
225
+ },
226
+ ],
202
227
  name: "group1",
203
228
  },
204
229
  ]);
@@ -218,16 +243,30 @@ describe("utils: parseGroups", () => {
218
243
  },
219
244
  ],
220
245
  };
221
- const content = { secret: "1", not_secret: "2" };
246
+ const content = {
247
+ secret: { value: "1", origin: "user" },
248
+ not_secret: { value: "2", origin: "user" },
249
+ };
222
250
  const result = formatParseGroups(template, content);
223
251
  expect(result).toEqual([
224
252
  {
225
- fields: [{ name: "not_secret", required: false, value: "2" }],
253
+ fields: [
254
+ {
255
+ name: "not_secret",
256
+ required: false,
257
+ value: { value: "2", origin: "user" },
258
+ },
259
+ ],
226
260
  name: "group1",
227
261
  },
228
262
  {
229
263
  fields: [
230
- { name: "secret", required: false, value: "1", isSecret: true },
264
+ {
265
+ name: "secret",
266
+ required: false,
267
+ value: { value: "1", origin: "user" },
268
+ isSecret: true,
269
+ },
231
270
  ],
232
271
  is_secret: true,
233
272
  name: "group2",
@@ -1,18 +1,19 @@
1
1
  import _ from "lodash/fp";
2
+ import { toEnrichedTextFormat } from "@truedat/core/services/format";
2
3
 
3
4
  const meetsDependency = (defaults, content, on, to_be) => {
4
- const field = getDefaultValue(defaults, content, on);
5
+ const field_value = getDefaultValue(defaults, content, on);
5
6
  return (
6
7
  _.every(_.negate(_.isNil))([on, to_be]) &&
7
- (_.isArray(field)
8
- ? _.some((d) => to_be.includes(d))(field)
9
- : to_be.includes(field))
8
+ (_.isArray(field_value)
9
+ ? _.some((d) => to_be.includes(d))(field_value)
10
+ : to_be.includes(field_value))
10
11
  );
11
12
  };
12
13
 
13
- const meetsSwitchCondition = (defaults, content, onSwitch, value) => {
14
- const field = getDefaultValue(defaults, content, onSwitch);
15
- return !_.isNil(onSwitch) && _.isObject(value) && _.has(field)(value);
14
+ const meetsSwitchCondition = (defaults, content, onSwitch, values) => {
15
+ const field_value = getDefaultValue(defaults, content, onSwitch);
16
+ return !_.isNil(onSwitch) && _.isObject(values) && _.has(field_value)(values);
16
17
  };
17
18
 
18
19
  const meetsDomain = (values, domainId) =>
@@ -22,7 +23,21 @@ const standardDefault = (on, toBe, onSwitch, onDomain) =>
22
23
  _.every(_.isNil)([on, toBe, onSwitch, onDomain]);
23
24
 
24
25
  const getDefaultValue = (defaults, content, on) =>
25
- _.defaultTo(_.prop(on)(defaults))(_.prop(on)(content));
26
+ _.get("value")(_.defaultTo(_.prop(on)(defaults))(_.prop(on)(content)));
27
+
28
+ const getDefaultSwitchValue = (defaults, content, onSwitch, value) =>
29
+ _.isObject(value) &&
30
+ (_.has(onSwitch)(defaults) || _.has(onSwitch)(content)) &&
31
+ _.flow(
32
+ (d) => getDefaultValue(d, content, onSwitch),
33
+ (v) => _.getOr(null)(v)(value)
34
+ )(defaults);
35
+
36
+ const getFieldType = (field, templateContent) =>
37
+ _.flow(
38
+ _.find(({ name }) => field === name),
39
+ _.get("type")
40
+ )(templateContent);
26
41
 
27
42
  export const applyDefaults = (templateContent) => (content, domainId) =>
28
43
  _.flow(
@@ -34,29 +49,55 @@ export const applyDefaults = (templateContent) => (content, domainId) =>
34
49
  { name, default: value, depends: { on, to_be: toBe } = {}, values }
35
50
  ) => {
36
51
  const onSwitch = values?.switch?.on;
52
+ const onSwitchValues = values?.switch?.values;
37
53
  const onDomain = values?.domain;
38
54
 
39
55
  if (standardDefault(on, toBe, onSwitch, onDomain)) {
40
- return _.assoc(name, value)(acc);
56
+ const fieldValue =
57
+ getFieldType(name, templateContent) === "enriched_text"
58
+ ? _.set("value", toEnrichedTextFormat(value.value))(value)
59
+ : value;
60
+
61
+ return _.assoc(name, fieldValue)(acc);
41
62
  }
42
63
  if (meetsDependency(acc, content, on, toBe)) {
43
- if (meetsSwitchCondition(acc, content, onSwitch, value)) {
44
- const field = getDefaultValue(acc, content, onSwitch);
45
- const defaultValue = _.prop(field)(value);
46
- return _.assoc(name, defaultValue)(acc);
64
+ if (meetsSwitchCondition(acc, content, onSwitch, onSwitchValues)) {
65
+ const defaultValue = getDefaultSwitchValue(
66
+ acc,
67
+ content,
68
+ onSwitch,
69
+ value.value
70
+ );
71
+ return _.assoc(name, {
72
+ ...value,
73
+ value: defaultValue || value.value,
74
+ })(acc);
47
75
  } else if (meetsDomain(onDomain, domainId)) {
48
- const defaultValue = _.prop(domainId)(value);
49
- return _.assoc(name, defaultValue)(acc);
76
+ const defaultValue = _.prop(domainId)(value.value);
77
+ return defaultValue
78
+ ? _.assoc(name, { ...value, value: defaultValue })(acc)
79
+ : acc;
50
80
  } else {
51
81
  return _.assoc(name, value)(acc);
52
82
  }
53
- } else if (meetsSwitchCondition(acc, content, onSwitch, value)) {
54
- const field = getDefaultValue(acc, content, onSwitch);
55
- const defaultValue = _.prop(field)(value);
56
- return _.assoc(name, defaultValue)(acc);
83
+ } else if (
84
+ meetsSwitchCondition(acc, content, onSwitch, onSwitchValues)
85
+ ) {
86
+ const defaultValue = getDefaultSwitchValue(
87
+ acc,
88
+ content,
89
+ onSwitch,
90
+ value.value
91
+ );
92
+ return _.assoc(name, {
93
+ ...value,
94
+ value: defaultValue || "",
95
+ })(acc);
57
96
  } else if (meetsDomain(onDomain, domainId)) {
58
- const defaultValue = _.prop(domainId)(value);
59
- return _.assoc(name, defaultValue)(acc);
97
+ const defaultValue = _.prop(domainId)(value.value);
98
+ return defaultValue
99
+ ? _.assoc(name, { ...value, value: defaultValue })(acc)
100
+ : acc;
60
101
  }
61
102
  return acc;
62
103
  },
@@ -1,7 +1,9 @@
1
1
  import _ from "lodash/fp";
2
2
 
3
- const checkDependency = (on, to_be) =>
4
- _.isArray(on) ? _.some((d) => to_be.includes(d))(on) : to_be.includes(on);
3
+ const checkDependency = ({ value: on_value }, to_be) =>
4
+ _.isArray(on_value)
5
+ ? _.some((d) => to_be.includes(d))(on_value)
6
+ : to_be.includes(on_value);
5
7
 
6
8
  const arrayOrString = (to_be) => _.isString(to_be) || _.isArray(to_be);
7
9
 
@@ -2,7 +2,7 @@ import _ from "lodash/fp";
2
2
 
3
3
  const validDomainValue = (field, content, domainId) => {
4
4
  const name = _.prop("name")(field);
5
- const value = _.prop(name)(content);
5
+ const value = _.prop("value")(_.prop(name)(content));
6
6
  const values = _.prop(domainId)(field?.values?.domain);
7
7
 
8
8
  return (
@@ -16,13 +16,13 @@ export const isSwitchValid = (prop, on) =>
16
16
  _.flow(
17
17
  _.map.convert({ cap: false })((validValues, onValue) =>
18
18
  _.conformsTo({
19
- [on]: _.eq(onValue),
20
- [prop]: (v) =>
21
- isEmpty(v)
19
+ [on]: _.conforms({ value: _.eq(onValue) }),
20
+ [prop]: ({ value }) =>
21
+ isEmpty(value)
22
22
  ? true
23
- : _.isArray(v)
24
- ? _.isEmpty(_.without(validValues)(v))
25
- : _.includes(v)(validValues),
23
+ : _.isArray(value)
24
+ ? _.isEmpty(_.without(validValues)(value))
25
+ : _.includes(value)(validValues),
26
26
  })
27
27
  ),
28
28
  _.overSome
@@ -32,11 +32,14 @@ export const filterValues = (templateContent) => {
32
32
  const vv = validValues(templateContent);
33
33
  return _.mapValues.convert({ cap: false })((value, key) =>
34
34
  _.has(key)(vv)
35
- ? _.isArray(value)
36
- ? _.filter((v) => _.includes(v)(_.prop(key)(vv)))(value)
37
- : _.includes(value)(_.prop(key)(vv))
35
+ ? _.isArray(value.value)
36
+ ? _.set(
37
+ "value",
38
+ _.filter((v) => _.includes(v)(_.prop(key)(vv)))(value.value)
39
+ )(value)
40
+ : _.includes(value.value)(_.prop(key)(vv))
38
41
  ? value
39
- : null
42
+ : { ...value, value: null }
40
43
  : value
41
44
  );
42
45
  };