@truedat/dq 4.28.5 → 4.29.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.
@@ -7,19 +7,19 @@ import FiltersFormGroup from "./FiltersFormGroup";
7
7
 
8
8
  export const ValueConditions = ({
9
9
  allOperators,
10
+ operators,
10
11
  composeValue,
11
12
  onChange,
12
13
  population = [],
13
14
  parentStructures,
14
- getOperators,
15
- getOperatorValue,
16
15
  scope,
17
16
  siblings,
18
17
  }) => {
19
- const onStructureChange = (index, value) => {
18
+ const onStructureChange = (index, value, opts) => {
20
19
  const structure = {
20
+ ..._.pick(["field_type", "name", "data_structure_id"])(value),
21
21
  id: value?.data_structure_id,
22
- ..._.pick(["field_type", "name"])(value),
22
+ opts,
23
23
  };
24
24
  const updatedCondition = { structure };
25
25
  const modifiedPopulation = replaceAt(index, updatedCondition)(population);
@@ -70,8 +70,6 @@ export const ValueConditions = ({
70
70
  <Grid.Column width={14}>
71
71
  <FiltersFormGroup
72
72
  clause={clause}
73
- getOperators={getOperators}
74
- getOperatorValue={getOperatorValue}
75
73
  index={index}
76
74
  onOperatorChange={onOperatorChange}
77
75
  onStructureChange={onStructureChange}
@@ -79,6 +77,7 @@ export const ValueConditions = ({
79
77
  parentStructures={parentStructures}
80
78
  scope={scope}
81
79
  siblings={siblings}
80
+ operators={operators}
82
81
  />
83
82
  </Grid.Column>
84
83
  <Grid.Column width={2} floated={"right"}>
@@ -100,9 +99,8 @@ export const ValueConditions = ({
100
99
 
101
100
  ValueConditions.propTypes = {
102
101
  allOperators: PropTypes.array,
102
+ operators: PropTypes.array,
103
103
  composeValue: PropTypes.func,
104
- getOperators: PropTypes.func,
105
- getOperatorValue: PropTypes.func,
106
104
  population: PropTypes.array,
107
105
  onChange: PropTypes.func,
108
106
  parentStructures: PropTypes.array,
@@ -6,9 +6,15 @@ exports[`<FiltersFormGroup /> matches the latest snapshot 1`] = `
6
6
  class="fields force-margin-bottom"
7
7
  style="display: none;"
8
8
  >
9
- <div
10
- class="four wide field"
11
- />
9
+ <div>
10
+ <div
11
+ class="flex-row-align-end"
12
+ >
13
+ <div
14
+ class="field"
15
+ />
16
+ </div>
17
+ </div>
12
18
  <div
13
19
  class="field"
14
20
  />
@@ -12,9 +12,15 @@ exports[`<FiltersGroup /> matches the latest snapshot when siblings provided 1`]
12
12
  <div
13
13
  class="fields force-margin-bottom"
14
14
  >
15
- <div
16
- class="four wide field"
17
- />
15
+ <div>
16
+ <div
17
+ class="flex-row-align-end"
18
+ >
19
+ <div
20
+ class="field"
21
+ />
22
+ </div>
23
+ </div>
18
24
  <div
19
25
  class="field"
20
26
  />
@@ -12,9 +12,15 @@ exports[`<ValueConditions /> matches the latest snapshot when siblings provided
12
12
  <div
13
13
  class="fields force-margin-bottom"
14
14
  >
15
- <div
16
- class="four wide field"
17
- />
15
+ <div>
16
+ <div
17
+ class="flex-row-align-end"
18
+ >
19
+ <div
20
+ class="field"
21
+ />
22
+ </div>
23
+ </div>
18
24
  <div
19
25
  class="field"
20
26
  />
@@ -0,0 +1,82 @@
1
+ import _ from "lodash/fp";
2
+
3
+ export default (operators, type, nested, scope, formatMessage) => {
4
+ const filterFieldType = (operators) =>
5
+ nested ? _.filter((o) => o?.value_type !== "field")(operators) : operators;
6
+
7
+ const withValueType = (value, valueType) =>
8
+ valueType ? `${value}.${valueType}` : value;
9
+
10
+ const getOptions = (operators) =>
11
+ _.flow(
12
+ _.groupBy("group"),
13
+ _.reduce.convert({ cap: false })((acc, v, k) => {
14
+ return _.isNil(k) || k === "undefined" || _.size(v) <= 1
15
+ ? [...acc, ...v]
16
+ : [...acc, { label: k, options: v }];
17
+ }, []),
18
+ _.sortBy(["label"]),
19
+ _.map(renderOperatorOptions)
20
+ )(operators);
21
+
22
+ const renderOperatorOptions = (operator) =>
23
+ _.has("options")(operator)
24
+ ? {
25
+ icon: "random",
26
+ label: formatMessage({
27
+ id: `ruleImplementation.operator.group.${operator.label}`,
28
+ }),
29
+ options: _.map(renderOperatorOption)(operator.options),
30
+ }
31
+ : renderOperatorOption(operator);
32
+
33
+ const renderOperatorOption = (operator) => ({
34
+ text: formatMessage({
35
+ id: withValueType(
36
+ `ruleImplementation.operator.${operator.name}`,
37
+ operator.value_type
38
+ ),
39
+ }),
40
+ id: operator.id,
41
+ value: withValueType(`${type}.${operator.name}`, operator.value_type),
42
+ });
43
+ const operatorsOptions = !type
44
+ ? []
45
+ : _.flow(
46
+ _.pick([type, "any"]),
47
+ _.values,
48
+ _.map(_.prop("operators")),
49
+ _.flatten,
50
+ _.filter(
51
+ ({ scope: op_scope }) =>
52
+ _.isNull(op_scope) ||
53
+ _.isEmpty(op_scope) ||
54
+ _.isEqual(scope)(op_scope)
55
+ ),
56
+ filterFieldType,
57
+ getOptions
58
+ )(operators);
59
+
60
+ const getOperatorValue = (row) =>
61
+ _.has("operator")(row) && !_.isEmpty(row.operator)
62
+ ? withValueType(
63
+ `${type}.${_.path("operator.name")(row)}`,
64
+ _.path("operator.value_type")(row)
65
+ )
66
+ : null;
67
+
68
+ const typeCastModifiers = _.flow(
69
+ _.toPairs,
70
+ _.map(([key, value]) =>
71
+ _.map((m) => ({ ...m, sourceType: key }))(value.modifiers || [])
72
+ ),
73
+ _.flatten,
74
+ _.filter(({ cast_as }) => cast_as === type)
75
+ )(operators);
76
+
77
+ return {
78
+ operatorsOptions,
79
+ getOperatorValue,
80
+ typeCastModifiers,
81
+ };
82
+ };
@@ -287,6 +287,7 @@ export const getRuleImplementationOperators = createSelector(
287
287
  (acc, value, key) =>
288
288
  _.set(key, {
289
289
  operators: _.map((o) => _.omit(["category"])(o))(value),
290
+ modifiers: _.propOr([], `${key}.modifiers`)(operators),
290
291
  })(acc),
291
292
  {}
292
293
  )