@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.
Files changed (42) hide show
  1. package/package.json +4 -4
  2. package/src/components/DynamicFieldValue.js +1 -1
  3. package/src/components/DynamicFormViewer.js +4 -3
  4. package/src/components/DynamicFormWithTranslations.js +3 -3
  5. package/src/components/EditableDynamicFieldValue.js +1 -1
  6. package/src/components/FieldViewerValue.js +44 -3
  7. package/src/components/__tests__/FieldViewerValue.spec.js +10 -6
  8. package/src/components/__tests__/__snapshots__/FieldViewerValue.spec.js.snap +53 -0
  9. package/src/components/widgets/DynamicField.js +6 -62
  10. package/src/components/widgets/DynamicTableField.js +150 -0
  11. package/src/components/widgets/FieldByWidget.js +63 -0
  12. package/src/components/widgets/StandardDropdown.js +2 -2
  13. package/src/components/widgets/StringField.js +2 -1
  14. package/src/components/widgets/__tests__/DynamicField.spec.js +10 -1
  15. package/src/components/widgets/__tests__/DynamicTableField.spec.js +257 -0
  16. package/src/components/widgets/__tests__/__snapshots__/DynamicField.spec.js.snap +97 -0
  17. package/src/components/widgets/__tests__/__snapshots__/DynamicTableField.spec.js.snap +114 -0
  18. package/src/templates/components/templateForm/ActiveGroupForm.js +5 -16
  19. package/src/templates/components/templateForm/FieldDefinition.js +158 -0
  20. package/src/templates/components/templateForm/FieldForm.js +32 -135
  21. package/src/templates/components/templateForm/TableValuesForm.js +258 -0
  22. package/src/templates/components/templateForm/TemplateForm.js +43 -26
  23. package/src/templates/components/templateForm/ValuesConfiguration.js +67 -0
  24. package/src/templates/components/templateForm/ValuesField.js +60 -96
  25. package/src/templates/components/templateForm/ValuesListForm.js +1 -3
  26. package/src/templates/components/templateForm/__tests__/FieldDefinition.spec.js +227 -0
  27. package/src/templates/components/templateForm/__tests__/TableValuesForm.spec.js +215 -0
  28. package/src/templates/components/templateForm/__tests__/ValuesField.spec.js +28 -83
  29. package/src/templates/components/templateForm/__tests__/__snapshots__/ActiveGroupForm.spec.js.snap +17 -0
  30. package/src/templates/components/templateForm/__tests__/__snapshots__/FieldDefinition.spec.js.snap +443 -0
  31. package/src/templates/components/templateForm/__tests__/__snapshots__/FieldForm.spec.js.snap +51 -0
  32. package/src/templates/components/templateForm/__tests__/__snapshots__/TemplateForm.spec.js.snap +17 -0
  33. package/src/templates/components/templateForm/__tests__/__snapshots__/ValuesField.spec.js.snap +61 -387
  34. package/src/templates/components/templateForm/contentValidation.js +22 -3
  35. package/src/templates/components/templateForm/valueDefinitions.js +16 -2
  36. package/src/templates/components/templateForm/widgetDefinitions.js +28 -2
  37. package/src/templates/utils/__tests__/validateContent.spec.js +6 -6
  38. package/src/templates/utils/applyTemplate.js +72 -23
  39. package/src/templates/utils/filterValues.js +3 -3
  40. package/src/templates/utils/parseFieldOptions.js +73 -58
  41. package/src/templates/utils/parseGroups.js +47 -48
  42. package/src/templates/utils/validateContent.js +70 -25
@@ -293,6 +293,23 @@ exports[`<FieldForm /> matches the latest snapshot 1`] = `
293
293
  Table
294
294
  </span>
295
295
  </div>
296
+ <div
297
+ aria-checked="false"
298
+ aria-selected="false"
299
+ class="item"
300
+ role="option"
301
+ style="pointer-events: all;"
302
+ >
303
+ <i
304
+ aria-hidden="true"
305
+ class="table icon"
306
+ />
307
+ <span
308
+ class="text"
309
+ >
310
+ Dynamic Table
311
+ </span>
312
+ </div>
296
313
  <div
297
314
  aria-checked="false"
298
315
  aria-selected="false"
@@ -891,6 +908,23 @@ exports[`<FieldForm /> renders MandatoryConditional 1`] = `
891
908
  Table
892
909
  </span>
893
910
  </div>
911
+ <div
912
+ aria-checked="false"
913
+ aria-selected="false"
914
+ class="item"
915
+ role="option"
916
+ style="pointer-events: all;"
917
+ >
918
+ <i
919
+ aria-hidden="true"
920
+ class="table icon"
921
+ />
922
+ <span
923
+ class="text"
924
+ >
925
+ Dynamic Table
926
+ </span>
927
+ </div>
894
928
  <div
895
929
  aria-checked="false"
896
930
  aria-selected="false"
@@ -1647,6 +1681,23 @@ exports[`<FieldForm /> renders ValuesField and manages onChange 1`] = `
1647
1681
  Table
1648
1682
  </span>
1649
1683
  </div>
1684
+ <div
1685
+ aria-checked="false"
1686
+ aria-selected="false"
1687
+ class="item"
1688
+ role="option"
1689
+ style="pointer-events: all;"
1690
+ >
1691
+ <i
1692
+ aria-hidden="true"
1693
+ class="table icon"
1694
+ />
1695
+ <span
1696
+ class="text"
1697
+ >
1698
+ Dynamic Table
1699
+ </span>
1700
+ </div>
1650
1701
  <div
1651
1702
  aria-checked="false"
1652
1703
  aria-selected="false"
@@ -1233,6 +1233,23 @@ exports[`<TemplateForm /> matches the latest snapshot for filled template 1`] =
1233
1233
  Table
1234
1234
  </span>
1235
1235
  </div>
1236
+ <div
1237
+ aria-checked="false"
1238
+ aria-selected="false"
1239
+ class="item"
1240
+ role="option"
1241
+ style="pointer-events: all;"
1242
+ >
1243
+ <i
1244
+ aria-hidden="true"
1245
+ class="table icon"
1246
+ />
1247
+ <span
1248
+ class="text"
1249
+ >
1250
+ Dynamic Table
1251
+ </span>
1252
+ </div>
1236
1253
  <div
1237
1254
  aria-checked="false"
1238
1255
  aria-selected="false"
@@ -51,129 +51,6 @@ exports[`<ValuesField /> fixed matches the latest snapshot for null values 1`] =
51
51
  </div>
52
52
  `;
53
53
 
54
- exports[`<ValuesField /> fixed_tuple matches the latest snapshot for null values 1`] = `
55
- <div>
56
- <div
57
- class="ui segment"
58
- >
59
- <div
60
- class="ui middle aligned list"
61
- role="list"
62
- >
63
- <div
64
- class="item"
65
- role="listitem"
66
- >
67
- <i
68
- aria-hidden="true"
69
- class="remove circle link icon"
70
- />
71
- <i
72
- aria-hidden="true"
73
- class="chevron circle up disabled link icon"
74
- />
75
- <i
76
- aria-hidden="true"
77
- class="chevron circle down disabled link icon"
78
- />
79
- <div
80
- class="content"
81
- >
82
- Foo
83
- /
84
- Bar
85
- </div>
86
- </div>
87
- <div
88
- class="item"
89
- role="listitem"
90
- >
91
- <div
92
- class="equal width fields"
93
- >
94
- <div
95
- class="field"
96
- >
97
- <div
98
- class="ui input"
99
- >
100
- <input
101
- name="tuple_value"
102
- placeholder="template.field.values.add_value"
103
- type="text"
104
- value=""
105
- />
106
- </div>
107
- </div>
108
- <div
109
- class="field"
110
- >
111
- <div
112
- class="ui icon input"
113
- >
114
- <input
115
- name="tuple_text"
116
- placeholder="template.field.values.add_text"
117
- type="text"
118
- value=""
119
- />
120
- <i
121
- aria-hidden="true"
122
- class="add circle link icon"
123
- />
124
- </div>
125
- </div>
126
- </div>
127
- </div>
128
- </div>
129
- <div
130
- class="equal width fields"
131
- >
132
- <div
133
- class="field"
134
- >
135
- <div
136
- class="field"
137
- >
138
- <div
139
- class="ui checked checkbox"
140
- >
141
- <input
142
- checked=""
143
- class="hidden"
144
- name="undefined.editable"
145
- readonly=""
146
- tabindex="0"
147
- type="checkbox"
148
- />
149
- <label>
150
- Editable
151
- </label>
152
- </div>
153
- </div>
154
- </div>
155
- <div
156
- class="field"
157
- >
158
- <div
159
- class="ui checkbox"
160
- >
161
- <input
162
- class="hidden"
163
- readonly=""
164
- tabindex="0"
165
- type="checkbox"
166
- />
167
- <label>
168
- template.field.subscribable
169
- </label>
170
- </div>
171
- </div>
172
- </div>
173
- </div>
174
- </div>
175
- `;
176
-
177
54
  exports[`<ValuesField /> noPrefix matches the latest snapshot for null values 1`] = `
178
55
  <div>
179
56
  <div
@@ -225,58 +102,7 @@ exports[`<ValuesField /> noPrefix matches the latest snapshot for null values 1`
225
102
  </div>
226
103
  `;
227
104
 
228
- exports[`<ValuesField /> role_users matches the latest snapshot for not null values 1`] = `
229
- <div>
230
- <div
231
- class="ui segment"
232
- >
233
- <div
234
- class="equal width fields"
235
- >
236
- <div
237
- class="field"
238
- >
239
- <div
240
- class="field"
241
- >
242
- <div
243
- class="ui checked checkbox"
244
- >
245
- <input
246
- checked=""
247
- class="hidden"
248
- name="undefined.editable"
249
- readonly=""
250
- tabindex="0"
251
- type="checkbox"
252
- />
253
- <label>
254
- Editable
255
- </label>
256
- </div>
257
- </div>
258
- </div>
259
- </div>
260
- <div
261
- class="field"
262
- >
263
- <label>
264
- template.field.values.default_value
265
- </label>
266
- <div
267
- class="ui input"
268
- >
269
- <input
270
- name="default_value"
271
- type="text"
272
- />
273
- </div>
274
- </div>
275
- </div>
276
- </div>
277
- `;
278
-
279
- exports[`<ValuesField /> switch matches the latest snapshot for null values 1`] = `
105
+ exports[`<ValuesField /> table_columns matches the latest snapshot 1`] = `
280
106
  <div>
281
107
  <div
282
108
  class="ui segment"
@@ -288,174 +114,52 @@ exports[`<ValuesField /> switch matches the latest snapshot for null values 1`]
288
114
  <div
289
115
  class="item"
290
116
  role="listitem"
291
- >
292
- <div
293
- class="field"
294
- >
295
- <label>
296
- template.field.values.switch_field.label
297
- </label>
298
- <div
299
- class="ui input"
300
- >
301
- <input
302
- placeholder="template.field.values.switch_field"
303
- type="text"
304
- value="test"
305
- />
306
- </div>
307
- </div>
308
- </div>
309
- <div
310
- class="ui segment"
311
117
  >
312
118
  <i
313
119
  aria-hidden="true"
314
120
  class="remove circle link icon"
315
121
  />
316
- a
122
+ <i
123
+ aria-hidden="true"
124
+ class="chevron circle up disabled link icon"
125
+ />
126
+ <i
127
+ aria-hidden="true"
128
+ class="chevron circle down link icon"
129
+ />
317
130
  <div
318
- class="ui middle aligned list"
319
- role="list"
131
+ class="content"
320
132
  >
321
- <div
322
- class="item"
323
- role="listitem"
324
- >
325
- <i
326
- aria-hidden="true"
327
- class="remove circle link icon"
328
- />
329
- <i
330
- aria-hidden="true"
331
- class="chevron circle up disabled link icon"
332
- />
333
- <i
334
- aria-hidden="true"
335
- class="chevron circle down disabled link icon"
336
- />
337
- <i
338
- aria-hidden="true"
339
- class="circle outline link icon"
340
- />
341
- <div
342
- class="content"
343
- >
344
- 1
345
- </div>
346
- </div>
347
- <div
348
- class="item"
349
- role="listitem"
133
+ field1
134
+
135
+ <span
136
+ class="is_required"
350
137
  >
351
- <div
352
- class="field"
353
- >
354
- <div
355
- class="ui icon input"
356
- >
357
- <input
358
- name="fixed_value"
359
- placeholder="template.field.values.add_value"
360
- type="text"
361
- value=""
362
- />
363
- <i
364
- aria-hidden="true"
365
- class="add circle link icon"
366
- />
367
- </div>
368
- </div>
369
- </div>
138
+ *
139
+ </span>
370
140
  </div>
371
141
  </div>
372
142
  <div
373
- class="ui segment"
143
+ class="item"
144
+ role="listitem"
374
145
  >
375
146
  <i
376
147
  aria-hidden="true"
377
148
  class="remove circle link icon"
378
149
  />
379
- b
150
+ <i
151
+ aria-hidden="true"
152
+ class="chevron circle up link icon"
153
+ />
154
+ <i
155
+ aria-hidden="true"
156
+ class="chevron circle down disabled link icon"
157
+ />
380
158
  <div
381
- class="ui middle aligned list"
382
- role="list"
159
+ class="content"
383
160
  >
384
- <div
385
- class="item"
386
- role="listitem"
387
- >
388
- <i
389
- aria-hidden="true"
390
- class="remove circle link icon"
391
- />
392
- <i
393
- aria-hidden="true"
394
- class="chevron circle up disabled link icon"
395
- />
396
- <i
397
- aria-hidden="true"
398
- class="chevron circle down link icon"
399
- />
400
- <i
401
- aria-hidden="true"
402
- class="circle outline link icon"
403
- />
404
- <div
405
- class="content"
406
- >
407
- 2
408
- </div>
409
- </div>
410
- <div
411
- class="item"
412
- role="listitem"
413
- >
414
- <i
415
- aria-hidden="true"
416
- class="remove circle link icon"
417
- />
418
- <i
419
- aria-hidden="true"
420
- class="chevron circle up link icon"
421
- />
422
- <i
423
- aria-hidden="true"
424
- class="chevron circle down disabled link icon"
425
- />
426
- <i
427
- aria-hidden="true"
428
- class="circle outline link icon"
429
- />
430
- <div
431
- class="content"
432
- >
433
- 3
434
- </div>
435
- </div>
436
- <div
437
- class="item"
438
- role="listitem"
439
- >
440
- <div
441
- class="field"
442
- >
443
- <div
444
- class="ui icon input"
445
- >
446
- <input
447
- name="fixed_value"
448
- placeholder="template.field.values.add_value"
449
- type="text"
450
- value=""
451
- />
452
- <i
453
- aria-hidden="true"
454
- class="add circle link icon"
455
- />
456
- </div>
457
- </div>
458
- </div>
161
+ field2
162
+
459
163
  </div>
460
164
  </div>
461
165
  <div
@@ -463,63 +167,48 @@ exports[`<ValuesField /> switch matches the latest snapshot for null values 1`]
463
167
  role="listitem"
464
168
  >
465
169
  <div
466
- class="field"
170
+ class="equal width fields vertical_align"
467
171
  >
468
- <label>
469
- template.field.values.add_switch_value.label
470
- </label>
471
172
  <div
472
- class="ui icon input"
173
+ class="field"
473
174
  >
474
- <input
475
- placeholder="template.field.values.add_switch_value"
476
- type="text"
477
- value=""
478
- />
479
- <i
480
- aria-hidden="true"
481
- class="add circle icon"
482
- />
175
+ <div
176
+ class="ui icon input"
177
+ >
178
+ <input
179
+ name="column_name"
180
+ placeholder="template.field.values.column_name"
181
+ type="text"
182
+ value=""
183
+ />
184
+ <i
185
+ aria-hidden="true"
186
+ class="add circle link icon"
187
+ />
188
+ </div>
483
189
  </div>
484
- </div>
485
- </div>
486
- </div>
487
- <div
488
- class="equal width fields"
489
- >
490
- <div
491
- class="field"
492
- >
493
- <div
494
- class="field"
495
- >
496
190
  <div
497
- class="ui checked checkbox"
191
+ class="required field"
498
192
  >
499
- <input
500
- checked=""
501
- class="hidden"
502
- name="undefined.editable"
503
- readonly=""
504
- tabindex="0"
505
- type="checkbox"
506
- />
507
- <label>
508
- Editable
509
- </label>
193
+ <div
194
+ class="ui checkbox"
195
+ >
196
+ <input
197
+ class="hidden"
198
+ name="column_mandatory"
199
+ readonly=""
200
+ required=""
201
+ tabindex="0"
202
+ type="checkbox"
203
+ />
204
+ <label>
205
+ template.field.values.column_mandatory
206
+ </label>
207
+ </div>
510
208
  </div>
511
209
  </div>
512
210
  </div>
513
211
  </div>
514
- </div>
515
- </div>
516
- `;
517
-
518
- exports[`<ValuesField /> table_columns matches the latest snapshot 1`] = `
519
- <div>
520
- <div
521
- class="ui segment"
522
- >
523
212
  <div
524
213
  class="equal width fields"
525
214
  >
@@ -547,21 +236,6 @@ exports[`<ValuesField /> table_columns matches the latest snapshot 1`] = `
547
236
  </div>
548
237
  </div>
549
238
  </div>
550
- <div
551
- class="field"
552
- >
553
- <label>
554
- template.field.values.default_value
555
- </label>
556
- <div
557
- class="ui input"
558
- >
559
- <input
560
- name="default_value"
561
- type="text"
562
- />
563
- </div>
564
- </div>
565
239
  </div>
566
240
  </div>
567
241
  `;
@@ -2,6 +2,14 @@ import _ from "lodash/fp";
2
2
 
3
3
  const arrayAnd = (list) => _.indexOf(true)(list) >= 0;
4
4
 
5
+ const reduceField = (field) => {
6
+ if (field.type === "dynamic_table") {
7
+ const tableColumns = _.defaultTo([])(field?.values?.table_columns);
8
+ return [field, ...tableColumns];
9
+ }
10
+ return field;
11
+ }
12
+
5
13
  export const parseContentValidation = (content) => {
6
14
  const duplicatedGroupNames = _.flow([
7
15
  _.countBy("name"),
@@ -11,6 +19,7 @@ export const parseContentValidation = (content) => {
11
19
  const duplicatedFieldNames = _.flow([
12
20
  _.map("fields"),
13
21
  _.reduce((acc, f) => [...acc, ...f], []),
22
+ _.flatMap(reduceField),
14
23
  _.countBy("name"),
15
24
  _.omitBy((v) => v == 1),
16
25
  _.keys,
@@ -74,8 +83,8 @@ export const parseContentValidation = (content) => {
74
83
  ],
75
84
  ])();
76
85
 
77
- const tableCoulmnEmpty =
78
- checkFieldType(field, "table") &&
86
+ const tableColumnEmpty =
87
+ (checkFieldType(field, "table") || checkFieldType(field, "dynamic_table")) &&
79
88
  _.has("table_columns", field.values) &&
80
89
  _.isEmpty(field.values.table_columns);
81
90
 
@@ -94,7 +103,7 @@ export const parseContentValidation = (content) => {
94
103
  nameEmpty,
95
104
  labelEmpty,
96
105
  dropdownWidgetInvalid,
97
- tableCoulmnEmpty,
106
+ tableColumnEmpty,
98
107
  conditionalVisibilityValueEmpty,
99
108
  mandatoryDependingOnValueEmpty,
100
109
  ]);
@@ -102,6 +111,16 @@ export const parseContentValidation = (content) => {
102
111
  hasErrors,
103
112
  nameDuplicated,
104
113
  };
114
+
115
+ if (field?.type === "dynamic_table") {
116
+ const validatedTableColumns = parseFieldsValidation(field.values.table_columns);
117
+ const hasChildrenErrors = _.any(_.propOr(false, "errors.hasErrors"))(validatedTableColumns);
118
+
119
+ return _.flow(
120
+ _.set("errors", { ...errors, hasErrors: errors?.hasErrors || hasChildrenErrors }),
121
+ _.set("values.table_columns", validatedTableColumns)
122
+ )(field);
123
+ }
105
124
  return { ...field, errors };
106
125
  })(fields);
107
126
  };
@@ -29,6 +29,7 @@ const eligibleValues = {
29
29
  color_picker: { string: [null] },
30
30
  enriched_text: { enriched_text: [null] },
31
31
  table: { table: ["table_columns"] },
32
+ dynamic_table: { dynamic_table: ["table_columns"] },
32
33
  password: { string: [null] },
33
34
  image: { image: [null] },
34
35
  };
@@ -38,8 +39,7 @@ export const getValues = (widget, fieldType) => {
38
39
  return _.filter(({ value }) => available.includes(value))(valueTypes);
39
40
  };
40
41
 
41
- export const listFormat = (type) =>
42
- ["fixed", "fixed_tuple", "table_columns"].includes(type);
42
+ export const listFormat = (type) => ["fixed", "fixed_tuple", "table_columns"].includes(type);
43
43
 
44
44
  export const defaultValue = (type, fieldType) =>
45
45
  (!type && _.negate(_.includes(fieldType))(["url", "system", "domain"])) ||
@@ -54,3 +54,17 @@ export const valuesSelector = (type) =>
54
54
 
55
55
  export const valueSegment = (values, type, fieldType) =>
56
56
  _.size(values) > 1 || valuesSelector(type) || defaultValue(type, fieldType);
57
+
58
+ export const hasAiSuggestions = (fieldType, keyType) => _.includes(fieldType)(["string", "enriched_text"]) &&
59
+ _.includes(keyType)(["fixed", "fixed_tuple", undefined]);
60
+
61
+ const typeFromKey = (keys) =>
62
+ _.includes("role_groups")(keys)
63
+ ? "role_groups"
64
+ : _.includes("role_users")(keys)
65
+ ? "role_users"
66
+ : _.includes("hierarchy")(keys)
67
+ ? "hierarchy"
68
+ : _.first(keys);
69
+
70
+ export const getKeyType = (field) => _.flow([_.getOr({}, "values"), _.keys, typeFromKey])(field);