@truedat/df 7.4.5 → 7.5.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 (31) hide show
  1. package/package.json +5 -5
  2. package/src/messages/en.js +4 -0
  3. package/src/messages/es.js +5 -1
  4. package/src/styles/template.less +12 -0
  5. package/src/templates/components/__tests__/Template.spec.js +25 -9
  6. package/src/templates/components/__tests__/__snapshots__/Template.spec.js.snap +364 -5
  7. package/src/templates/components/templateForm/ActiveGroupForm.js +16 -2
  8. package/src/templates/components/templateForm/ConditionalFieldForm.js +28 -4
  9. package/src/templates/components/templateForm/DependentDomain.js +27 -1
  10. package/src/templates/components/templateForm/DependentFormField.js +1 -1
  11. package/src/templates/components/templateForm/FieldForm.js +33 -5
  12. package/src/templates/components/templateForm/HierarchiesList.js +0 -1
  13. package/src/templates/components/templateForm/MandatoryConditional.js +28 -5
  14. package/src/templates/components/templateForm/SwitchListForm.js +48 -2
  15. package/src/templates/components/templateForm/TemplateForm.js +58 -11
  16. package/src/templates/components/templateForm/TemplateFormActions.js +3 -2
  17. package/src/templates/components/templateForm/ValuesListForm.js +72 -1
  18. package/src/templates/components/templateForm/ValuesSelector.js +46 -7
  19. package/src/templates/components/templateForm/__tests__/DependentDomain.spec.js +2 -0
  20. package/src/templates/components/templateForm/__tests__/SwitchSegment.spec.js +1 -0
  21. package/src/templates/components/templateForm/__tests__/TemplateForm.spec.js +46 -2
  22. package/src/templates/components/templateForm/__tests__/TemplateFormActions.spec.js +7 -0
  23. package/src/templates/components/templateForm/__tests__/__snapshots__/ActiveGroupForm.spec.js.snap +6 -1
  24. package/src/templates/components/templateForm/__tests__/__snapshots__/DependentDomain.spec.js.snap +3 -0
  25. package/src/templates/components/templateForm/__tests__/__snapshots__/FieldForm.spec.js.snap +33 -7
  26. package/src/templates/components/templateForm/__tests__/__snapshots__/MandatoryConditional.spec.js.snap +3 -1
  27. package/src/templates/components/templateForm/__tests__/__snapshots__/SwitchListForm.spec.js.snap +10 -0
  28. package/src/templates/components/templateForm/__tests__/__snapshots__/TemplateForm.spec.js.snap +1250 -4
  29. package/src/templates/components/templateForm/__tests__/__snapshots__/TemplateFormActions.spec.js.snap +28 -0
  30. package/src/templates/components/templateForm/__tests__/__snapshots__/ValuesListForm.spec.js.snap +4 -0
  31. package/src/templates/components/templateForm/contentValidation.js +100 -15
@@ -28,6 +28,34 @@ exports[`<TemplateFormActions /> matches the latest snapshot (deleting) 1`] = `
28
28
  </Container>
29
29
  `;
30
30
 
31
+ exports[`<TemplateFormActions /> matches the latest snapshot (invalid) 1`] = `
32
+ <Container
33
+ textAlign="right"
34
+ >
35
+ <Button
36
+ as="button"
37
+ content={
38
+ <Memo(MemoizedFormattedMessage)
39
+ id="actions.save"
40
+ />
41
+ }
42
+ disabled={true}
43
+ loading={false}
44
+ onClick={[MockFunction]}
45
+ primary={true}
46
+ />
47
+ <Button
48
+ as="button"
49
+ content={
50
+ <Memo(MemoizedFormattedMessage)
51
+ id="actions.cancel"
52
+ />
53
+ }
54
+ onClick={[Function]}
55
+ />
56
+ </Container>
57
+ `;
58
+
31
59
  exports[`<TemplateFormActions /> matches the latest snapshot (saving) 1`] = `
32
60
  <Container
33
61
  textAlign="right"
@@ -71,6 +71,7 @@ exports[`<ValuesListForm /> fixed matches the latest snapshot for fixed 1`] = `
71
71
  onClick={[Function]}
72
72
  />
73
73
  }
74
+ label={null}
74
75
  name="fixed_value"
75
76
  onChange={[Function]}
76
77
  onKeyPress={[Function]}
@@ -152,6 +153,7 @@ exports[`<ValuesListForm /> fixed_tuple matches the latest snapshot for fixed_tu
152
153
  as={[Function]}
153
154
  control={[Function]}
154
155
  error={false}
156
+ label={null}
155
157
  name="tuple_value"
156
158
  onChange={[Function]}
157
159
  onKeyPress={[Function]}
@@ -169,6 +171,7 @@ exports[`<ValuesListForm /> fixed_tuple matches the latest snapshot for fixed_tu
169
171
  onClick={[Function]}
170
172
  />
171
173
  }
174
+ label={null}
172
175
  name="tuple_text"
173
176
  onChange={[Function]}
174
177
  onKeyPress={[Function]}
@@ -263,6 +266,7 @@ exports[`<ValuesListForm /> table_columns matches the latest snapshot for table_
263
266
  onClick={[Function]}
264
267
  />
265
268
  }
269
+ label={null}
266
270
  name="column_name"
267
271
  onChange={[Function]}
268
272
  onKeyPress={[Function]}
@@ -1,46 +1,131 @@
1
1
  import _ from "lodash/fp";
2
2
 
3
- const arrayAnd = list => _.indexOf(true)(list) >= 0;
3
+ const arrayAnd = (list) => _.indexOf(true)(list) >= 0;
4
4
 
5
- export const parseContentValidation = content => {
5
+ export const parseContentValidation = (content) => {
6
6
  const duplicatedGroupNames = _.flow([
7
7
  _.countBy("name"),
8
- _.omitBy(v => v == 1),
9
- _.keys
8
+ _.omitBy((v) => v == 1),
9
+ _.keys,
10
10
  ])(content);
11
11
  const duplicatedFieldNames = _.flow([
12
12
  _.map("fields"),
13
13
  _.reduce((acc, f) => [...acc, ...f], []),
14
14
  _.countBy("name"),
15
- _.omitBy(v => v == 1),
16
- _.keys
15
+ _.omitBy((v) => v == 1),
16
+ _.keys,
17
17
  ])(content);
18
18
 
19
- const parseFieldsValidation = fields => {
20
- return _.map(field => {
19
+ const parseFieldsValidation = (fields) => {
20
+ return _.map((field) => {
21
21
  const nameDuplicated = _.indexOf(field.name)(duplicatedFieldNames) >= 0;
22
+ const nameEmpty = _.isEmpty(field.name);
23
+ const labelEmpty = _.isEmpty(field.label);
24
+ const isDropdownWidget = _.includes(field.widget, [
25
+ "dropdown",
26
+ "radio",
27
+ "checkbox",
28
+ ]);
29
+ const checkFieldType = (field, type) => field.type === type;
30
+ const dropdownWidgetInvalid = _.cond([
31
+ [() => !isDropdownWidget, () => false],
32
+ [
33
+ () => checkFieldType(field, "user"),
34
+ () => _.isEmpty(field.values.role_users),
35
+ ],
36
+ [
37
+ () => checkFieldType(field, "user_group"),
38
+ () => _.isEmpty(field.values.role_groups),
39
+ ],
40
+ [
41
+ () => checkFieldType(field, "hierarchy"),
42
+ () => _.isEmpty(field.values.hierarchy),
43
+ ],
44
+ [
45
+ () => checkFieldType(field, "string"),
46
+ () =>
47
+ _.cond([
48
+ [
49
+ () => _.has("domain", field.values),
50
+ () =>
51
+ _.isEmpty(field.values.domain) ||
52
+ _.some((domain) => _.every(_.isEmpty)(_.values(domain)))(
53
+ field.values.domain
54
+ ),
55
+ ],
56
+ [
57
+ () => _.has("switch", field.values),
58
+ () =>
59
+ _.isEmpty(field.values.switch) ||
60
+ _.isEmpty(field.values.switch.values) ||
61
+ _.some((switchKey) =>
62
+ _.isEmpty(field.values.switch.values[switchKey])
63
+ )(_.keys(field.values.switch.values)),
64
+ ],
65
+ [
66
+ () => _.has("fixed", field.values),
67
+ () => _.isEmpty(field.values.fixed),
68
+ ],
69
+ [
70
+ () => _.has("fixed_tuple", field.values),
71
+ () => _.isEmpty(field.values.fixed_tuple),
72
+ ],
73
+ ])(),
74
+ ],
75
+ ])();
22
76
 
23
- const hasErrors = arrayAnd([nameDuplicated]);
77
+ const tableCoulmnEmpty =
78
+ checkFieldType(field, "table") &&
79
+ _.has("table_columns", field.values) &&
80
+ _.isEmpty(field.values.table_columns);
81
+
82
+ const conditionalVisibilityValueEmpty =
83
+ _.has("depends", field) &&
84
+ !_.isEmpty(field.depends.on) &&
85
+ _.isEmpty(field.depends.to_be);
86
+
87
+ const mandatoryDependingOnValueEmpty =
88
+ _.has("mandatory", field) &&
89
+ !_.isEmpty(field.mandatory.on) &&
90
+ _.isEmpty(field.mandatory.to_be);
91
+
92
+ const hasErrors = arrayAnd([
93
+ nameDuplicated,
94
+ nameEmpty,
95
+ labelEmpty,
96
+ dropdownWidgetInvalid,
97
+ tableCoulmnEmpty,
98
+ conditionalVisibilityValueEmpty,
99
+ mandatoryDependingOnValueEmpty,
100
+ ]);
24
101
  const errors = {
25
102
  hasErrors,
26
- nameDuplicated
103
+ nameDuplicated,
27
104
  };
28
105
  return { ...field, errors };
29
106
  })(fields);
30
107
  };
31
108
 
32
- return _.map(group => {
109
+ return _.map((group) => {
33
110
  const nameDuplicated = _.indexOf(group.name)(duplicatedGroupNames) >= 0;
34
-
111
+ const nameEmpty = _.isEmpty(group.name);
35
112
  const fields = parseFieldsValidation(group.fields);
36
- const hasFieldErrors = _.flow([_.map(x => x.errors.hasErrors), arrayAnd])(
113
+ const hasNoFields = _.isEmpty(group.fields);
114
+ const hasFieldErrors = _.flow([_.map((x) => x.errors.hasErrors), arrayAnd])(
37
115
  fields
38
116
  );
39
117
 
40
- const hasErrors = _.indexOf(true)([nameDuplicated, hasFieldErrors]) >= 0;
118
+ const hasErrors =
119
+ _.indexOf(true)([
120
+ nameDuplicated,
121
+ nameEmpty,
122
+ hasFieldErrors,
123
+ hasNoFields,
124
+ ]) >= 0;
125
+
41
126
  const errors = {
42
127
  hasErrors,
43
- nameDuplicated
128
+ nameDuplicated,
44
129
  };
45
130
  return { ...group, fields, errors };
46
131
  })(content);