@pega/cosmos-react-condition-builder 2.0.0-dev.2.1 → 2.0.0-dev.20.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 (89) hide show
  1. package/lib/components/ConditionBuilder/AtomicCondition.d.ts +11 -4
  2. package/lib/components/ConditionBuilder/AtomicCondition.d.ts.map +1 -1
  3. package/lib/components/ConditionBuilder/AtomicCondition.js +22 -24
  4. package/lib/components/ConditionBuilder/AtomicCondition.js.map +1 -1
  5. package/lib/components/ConditionBuilder/ConditionBuilder.d.ts.map +1 -1
  6. package/lib/components/ConditionBuilder/ConditionBuilder.js +23 -44
  7. package/lib/components/ConditionBuilder/ConditionBuilder.js.map +1 -1
  8. package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts +42 -2
  9. package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts.map +1 -1
  10. package/lib/components/ConditionBuilder/ConditionBuilder.types.js.map +1 -1
  11. package/lib/components/ConditionBuilder/FieldCondition.d.ts.map +1 -1
  12. package/lib/components/ConditionBuilder/FieldCondition.js +6 -9
  13. package/lib/components/ConditionBuilder/FieldCondition.js.map +1 -1
  14. package/lib/components/ConditionBuilder/FieldCondition.types.d.ts +10 -2
  15. package/lib/components/ConditionBuilder/FieldCondition.types.d.ts.map +1 -1
  16. package/lib/components/ConditionBuilder/FieldCondition.types.js.map +1 -1
  17. package/lib/components/ConditionBuilder/HelpButton.d.ts.map +1 -1
  18. package/lib/components/ConditionBuilder/HelpButton.js +2 -4
  19. package/lib/components/ConditionBuilder/HelpButton.js.map +1 -1
  20. package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.d.ts +18 -0
  21. package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.d.ts.map +1 -0
  22. package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.js +115 -0
  23. package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.js.map +1 -0
  24. package/lib/components/ConditionBuilder/{FieldSelector.d.ts → RhsControls/FieldSelector.d.ts} +1 -1
  25. package/lib/components/ConditionBuilder/RhsControls/FieldSelector.d.ts.map +1 -0
  26. package/lib/components/ConditionBuilder/{FieldSelector.js → RhsControls/FieldSelector.js} +5 -5
  27. package/lib/components/ConditionBuilder/RhsControls/FieldSelector.js.map +1 -0
  28. package/lib/components/ConditionBuilder/{MultiValueSelector.d.ts → RhsControls/MultiValueSelector.d.ts} +1 -1
  29. package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.d.ts.map +1 -0
  30. package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.js +43 -0
  31. package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.js.map +1 -0
  32. package/lib/components/ConditionBuilder/RhsControls/NumericInput.d.ts +18 -0
  33. package/lib/components/ConditionBuilder/RhsControls/NumericInput.d.ts.map +1 -0
  34. package/lib/components/ConditionBuilder/RhsControls/NumericInput.js +19 -0
  35. package/lib/components/ConditionBuilder/RhsControls/NumericInput.js.map +1 -0
  36. package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.d.ts +18 -0
  37. package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.d.ts.map +1 -0
  38. package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.js +109 -0
  39. package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.js.map +1 -0
  40. package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.d.ts +24 -0
  41. package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.d.ts.map +1 -0
  42. package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.js +122 -0
  43. package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.js.map +1 -0
  44. package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.d.ts +8 -0
  45. package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.d.ts.map +1 -0
  46. package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.js +89 -0
  47. package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.js.map +1 -0
  48. package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.d.ts +20 -0
  49. package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.d.ts.map +1 -0
  50. package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.js +11 -0
  51. package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.js.map +1 -0
  52. package/lib/components/ConditionBuilder/{RhsControls.d.ts → RhsControls/index.d.ts} +16 -6
  53. package/lib/components/ConditionBuilder/RhsControls/index.d.ts.map +1 -0
  54. package/lib/components/ConditionBuilder/RhsControls/index.js +219 -0
  55. package/lib/components/ConditionBuilder/RhsControls/index.js.map +1 -0
  56. package/lib/components/ConditionBuilder/core/evaluator.d.ts.map +1 -1
  57. package/lib/components/ConditionBuilder/core/evaluator.js +110 -9
  58. package/lib/components/ConditionBuilder/core/evaluator.js.map +1 -1
  59. package/lib/components/ConditionBuilder/core/extendDayJs.d.ts +2 -0
  60. package/lib/components/ConditionBuilder/core/extendDayJs.d.ts.map +1 -0
  61. package/lib/components/ConditionBuilder/core/extendDayJs.js +4 -0
  62. package/lib/components/ConditionBuilder/core/extendDayJs.js.map +1 -0
  63. package/lib/components/ConditionBuilder/core/formatter.d.ts +10 -1
  64. package/lib/components/ConditionBuilder/core/formatter.d.ts.map +1 -1
  65. package/lib/components/ConditionBuilder/core/formatter.js +95 -13
  66. package/lib/components/ConditionBuilder/core/formatter.js.map +1 -1
  67. package/lib/components/ConditionBuilder/core/transformer.d.ts +7 -0
  68. package/lib/components/ConditionBuilder/core/transformer.d.ts.map +1 -0
  69. package/lib/components/ConditionBuilder/core/transformer.js +164 -0
  70. package/lib/components/ConditionBuilder/core/transformer.js.map +1 -0
  71. package/lib/components/ConditionBuilder/core/types.d.ts +7 -1
  72. package/lib/components/ConditionBuilder/core/types.d.ts.map +1 -1
  73. package/lib/components/ConditionBuilder/core/types.js.map +1 -1
  74. package/lib/components/ConditionBuilder/core/utils.d.ts.map +1 -1
  75. package/lib/components/ConditionBuilder/core/utils.js +4 -8
  76. package/lib/components/ConditionBuilder/core/utils.js.map +1 -1
  77. package/lib/components/ConditionBuilder/index.d.ts +2 -1
  78. package/lib/components/ConditionBuilder/index.d.ts.map +1 -1
  79. package/lib/components/ConditionBuilder/index.js +2 -1
  80. package/lib/components/ConditionBuilder/index.js.map +1 -1
  81. package/package.json +17 -15
  82. package/lib/components/ConditionBuilder/FieldSelector.d.ts.map +0 -1
  83. package/lib/components/ConditionBuilder/FieldSelector.js.map +0 -1
  84. package/lib/components/ConditionBuilder/MultiValueSelector.d.ts.map +0 -1
  85. package/lib/components/ConditionBuilder/MultiValueSelector.js +0 -77
  86. package/lib/components/ConditionBuilder/MultiValueSelector.js.map +0 -1
  87. package/lib/components/ConditionBuilder/RhsControls.d.ts.map +0 -1
  88. package/lib/components/ConditionBuilder/RhsControls.js +0 -277
  89. package/lib/components/ConditionBuilder/RhsControls.js.map +0 -1
@@ -1,11 +1,16 @@
1
1
  import { FunctionComponent } from 'react';
2
2
  import { BaseProps, ForwardProps } from '@pega/cosmos-react-core';
3
- import { LeafCondition, Field } from './ConditionBuilder.types';
3
+ import { LeafCondition, Field, DateFunctionsByType } from './ConditionBuilder.types';
4
4
  import { ComparatorsByType, RHSType } from './core/types';
5
5
  /** Determines the default condition object for a given LHS value */
6
- export declare function getInitConditionForLhs(lhs: LeafCondition['lhs'], fields: Field[], validRhsTypes: Set<RHSType>, validComparators?: ComparatorsByType[]): LeafCondition;
7
- /** Verifies if all the values in the condition are valid */
8
- export declare function isValidCondition(condition: LeafCondition, fields: Field[], validRhsTypes: Set<RHSType>, trimValues?: boolean): boolean;
6
+ export declare function getInitConditionForLhs(lhs: LeafCondition['lhs'], fields: Field[], validRhsTypes: Set<RHSType>, validComparators?: ComparatorsByType[], dateFunctions?: DateFunctionsByType): LeafCondition;
7
+ /**
8
+ * Verifies if all the values in the condition are valid.
9
+ * NOTES:
10
+ * - This is intended to be used only on conditions emitted by the components in this package.
11
+ * - If a condition is manually constructed outside these components, this utility could miss some malformed conditions.
12
+ */
13
+ export declare function isValidCondition(condition: LeafCondition, fields: Field[], trimValues?: boolean): boolean;
9
14
  /** Type definition for the input props of AtomicCondition */
10
15
  interface AtomicConditionProps extends BaseProps {
11
16
  /** Condition to use in the component */
@@ -37,6 +42,8 @@ interface AtomicConditionProps extends BaseProps {
37
42
  * comparators using the validComparators prop.
38
43
  */
39
44
  validRhsTypes?: Set<RHSType>;
45
+ /** (Optional) When enabling 'DATE_FUNCTION's via `validRhsTypes`, pass this to specify which all date functions are applicable per field type */
46
+ dateFunctions?: DateFunctionsByType;
40
47
  }
41
48
  /** A controlled component for Atomic Conditions */
42
49
  declare const AtomicCondition: FunctionComponent<AtomicConditionProps & ForwardProps>;
@@ -1 +1 @@
1
- {"version":3,"file":"AtomicCondition.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/AtomicCondition.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,iBAAiB,EAAe,MAAM,OAAO,CAAC;AAE9D,OAAO,EAOL,SAAS,EACT,YAAY,EACb,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAIhE,OAAO,EAAc,iBAAiB,EAAa,OAAO,EAAE,MAAM,cAAc,CAAC;AA2CjF,oEAAoE;AACpE,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,EACzB,MAAM,EAAE,KAAK,EAAE,EACf,aAAa,EAAE,GAAG,CAAC,OAAO,CAAC,EAC3B,gBAAgB,CAAC,EAAE,iBAAiB,EAAE,GACrC,aAAa,CAcf;AAED,4DAA4D;AAC5D,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,aAAa,EACxB,MAAM,EAAE,KAAK,EAAE,EACf,aAAa,EAAE,GAAG,CAAC,OAAO,CAAC,EAC3B,UAAU,GAAE,OAAe,GAC1B,OAAO,CAST;AAED,6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a,CAcf;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,aAAa,EACxB,MAAM,EAAE,KAAK,EAAE,EACf,UAAU,GAAE,OAAe,GAC1B,OAAO,CAST;AAED,6DAA6D;AAC7D,UAAU,oBAAqB,SAAQ,SAAS;IAC9C,wCAAwC;IACxC,SAAS,EAAE,aAAa,CAAC;IAEzB,mEAAmE;IACnE,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB,+DAA+D;IAC/D,cAAc,EAAE,OAAO,CAAC;IAExB,gFAAgF;IAChF,gBAAgB,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAEvC,sDAAsD;IACtD,QAAQ,EAAE,CAAC,YAAY,EAAE,aAAa,KAAK,IAAI,CAAC;IAEhD,6CAA6C;IAC7C,aAAa,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC;IAEjC;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;;;;;;;;OAUG;IACH,aAAa,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAE7B,iJAAiJ;IACjJ,aAAa,CAAC,EAAE,mBAAmB,CAAC;CACrC;AAED,mDAAmD;AACnD,QAAA,MAAM,eAAe,EAAE,iBAAiB,CAAC,oBAAoB,GAAG,YAAY,CAmH3E,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -1,17 +1,17 @@
1
- import React from 'react';
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Grid, Select, Option, Text, useI18n, hasProp } from '@pega/cosmos-react-core';
3
- import FieldSelector from './FieldSelector';
3
+ import FieldSelector from './RhsControls/FieldSelector';
4
4
  import RhsControls, { getDefaultRhs, isValidRhs } from './RhsControls';
5
5
  import getComparatorOptions from './core/comparators';
6
6
  // Returns field-type for a given field-name
7
7
  function getFieldType(fieldName, fields) {
8
8
  const matchingField = fields.find(f => f.name === fieldName);
9
- return matchingField === null || matchingField === void 0 ? void 0 : matchingField.type;
9
+ return matchingField?.type;
10
10
  }
11
11
  // Returns display label for a given field-name
12
12
  function getFieldLabel(fieldName, fields) {
13
13
  const matchingField = fields.find(f => f.name === fieldName);
14
- return (matchingField === null || matchingField === void 0 ? void 0 : matchingField.label) || (matchingField === null || matchingField === void 0 ? void 0 : matchingField.name);
14
+ return matchingField?.label || matchingField?.name;
15
15
  }
16
16
  /**
17
17
  * Upon changing the comparator, checks if the old RHS is valid for the new comparator
@@ -41,7 +41,7 @@ function isRhsValidForComparator(rhs, comparator) {
41
41
  ].includes(comparator);
42
42
  }
43
43
  /** Determines the default condition object for a given LHS value */
44
- export function getInitConditionForLhs(lhs, fields, validRhsTypes, validComparators) {
44
+ export function getInitConditionForLhs(lhs, fields, validRhsTypes, validComparators, dateFunctions) {
45
45
  let comparator;
46
46
  let rhs;
47
47
  if (lhs.field === '') {
@@ -52,12 +52,17 @@ export function getInitConditionForLhs(lhs, fields, validRhsTypes, validComparat
52
52
  else {
53
53
  const newFieldType = getFieldType(lhs.field, fields);
54
54
  comparator = getComparatorOptions(newFieldType, validComparators)[0].id; // Find the applicable comparators and select the first among them
55
- rhs = getDefaultRhs(newFieldType, comparator, validRhsTypes);
55
+ rhs = getDefaultRhs(newFieldType, comparator, validRhsTypes, dateFunctions);
56
56
  }
57
57
  return { lhs, comparator, rhs };
58
58
  }
59
- /** Verifies if all the values in the condition are valid */
60
- export function isValidCondition(condition, fields, validRhsTypes, trimValues = false) {
59
+ /**
60
+ * Verifies if all the values in the condition are valid.
61
+ * NOTES:
62
+ * - This is intended to be used only on conditions emitted by the components in this package.
63
+ * - If a condition is manually constructed outside these components, this utility could miss some malformed conditions.
64
+ */
65
+ export function isValidCondition(condition, fields, trimValues = false) {
61
66
  // If no field is yet selected on the LHS
62
67
  if (condition.lhs.field === '') {
63
68
  return false;
@@ -65,22 +70,19 @@ export function isValidCondition(condition, fields, validRhsTypes, trimValues =
65
70
  // If a field is present on the LHS, check if the RHS is valid
66
71
  // No need to check the comparator since the comparator is always assigned a valid value
67
72
  const fieldType = getFieldType(condition.lhs.field, fields);
68
- return isValidRhs(condition.rhs, fieldType, trimValues, validRhsTypes);
73
+ return isValidRhs(condition.rhs, fieldType, trimValues);
69
74
  }
70
75
  /** A controlled component for Atomic Conditions */
71
76
  const AtomicCondition = (props) => {
72
- const { condition, fields, indicateErrors, validComparators, onChange, itemDirection, showLhsAsLabel, validRhsTypes } = props;
73
- const rhsTypes = validRhsTypes && validRhsTypes.size !== 0
74
- ? validRhsTypes
75
- : new Set(['LITERAL', 'FIELD']);
77
+ const { condition, fields, indicateErrors, validComparators, onChange, itemDirection, showLhsAsLabel, validRhsTypes = new Set(['LITERAL', 'FIELD']), dateFunctions } = props;
76
78
  const fieldType = getFieldType(condition.lhs.field, fields); // Can be `undefined` if no match or if no previous field
77
79
  const comparatorOptions = fieldType
78
80
  ? getComparatorOptions(fieldType, validComparators)
79
- : [{ id: '', label: 'Select...' }]; // FIXME: TR
81
+ : [{ id: '', label: 'Select' }]; // FIXME: TR
80
82
  // Handle change in the field-selector
81
83
  const handleFieldChange = (id) => {
82
84
  const lhs = { field: id };
83
- const newCondition = getInitConditionForLhs(lhs, fields, rhsTypes, validComparators); // Determine comparator and rhs for the new lhs
85
+ const newCondition = getInitConditionForLhs(lhs, fields, validRhsTypes, validComparators, dateFunctions); // Determine comparator and rhs for the new lhs
84
86
  onChange(newCondition); // Submit the new condition
85
87
  };
86
88
  // Handle change in the comparator
@@ -91,7 +93,7 @@ const AtomicCondition = (props) => {
91
93
  const comparator = e.target.value;
92
94
  const rhs = isRhsValidForComparator(condition.rhs, comparator)
93
95
  ? condition.rhs
94
- : getDefaultRhs(fieldType, comparator, rhsTypes);
96
+ : getDefaultRhs(fieldType, comparator, validRhsTypes, dateFunctions);
95
97
  onChange({ ...condition, comparator, rhs }); // Submit the new condition
96
98
  };
97
99
  // Handle change in the RHS
@@ -101,7 +103,7 @@ const AtomicCondition = (props) => {
101
103
  const t = useI18n();
102
104
  return (
103
105
  // Using minmax() to get equal widths: https://stackoverflow.com/a/61240964/4247448
104
- React.createElement(Grid, { sm: {
106
+ _jsxs(Grid, { sm: {
105
107
  container: { cols: itemDirection === 'column' ? '1fr' : 'repeat(3, minmax(5rem,1fr))' }
106
108
  }, md: {
107
109
  container: { cols: itemDirection === 'column' ? '1fr' : 'repeat(3, minmax(10rem,1fr))' }
@@ -109,13 +111,9 @@ const AtomicCondition = (props) => {
109
111
  justifyItems: 'stretch',
110
112
  colGap: 0.5,
111
113
  rowGap: 0.5
112
- } },
113
- showLhsAsLabel && (React.createElement(Text, { variant: 'secondary' }, getFieldLabel(condition.lhs.field, fields))),
114
- !showLhsAsLabel && (React.createElement(FieldSelector, { value: condition.lhs.field, onChange: handleFieldChange, fields: fields, status: indicateErrors && condition.lhs.field === '' ? 'error' : undefined, info: indicateErrors && condition.lhs.field === ''
115
- ? t('condition_builder_condition_select_info_default')
116
- : undefined })),
117
- React.createElement(Select, { value: condition.comparator, onChange: handleComparatorChange, name: 'comparator', label: '-', labelHidden: true }, comparatorOptions.map(option => (React.createElement(Option, { key: option.id, value: option.id }, option.label)))),
118
- React.createElement(RhsControls, { lhs: condition.lhs, comparator: condition.comparator, rhs: condition.rhs, fields: fields, onChange: handleRHSChange, indicateErrors: indicateErrors, validRhsTypes: rhsTypes })));
114
+ }, children: [showLhsAsLabel && (_jsx(Text, { variant: 'secondary', children: getFieldLabel(condition.lhs.field, fields) }, void 0)), !showLhsAsLabel && (_jsx(FieldSelector, { value: condition.lhs.field, onChange: handleFieldChange, fields: fields, status: indicateErrors && condition.lhs.field === '' ? 'error' : undefined, info: indicateErrors && condition.lhs.field === ''
115
+ ? t('condition_builder_condition_select_info_default')
116
+ : undefined }, void 0)), _jsx(Select, { value: condition.comparator, onChange: handleComparatorChange, name: 'comparator', label: '-', labelHidden: true, children: comparatorOptions.map(option => (_jsx(Option, { value: option.id, children: option.label }, option.id))) }, void 0), _jsx(RhsControls, { lhs: condition.lhs, comparator: condition.comparator, rhs: condition.rhs, fields: fields, onChange: handleRHSChange, indicateErrors: indicateErrors, validRhsTypes: validRhsTypes, dateFunctions: dateFunctions, itemDirection: itemDirection || 'row' }, void 0)] }, void 0));
119
117
  };
120
118
  export default AtomicCondition;
121
119
  //# sourceMappingURL=AtomicCondition.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AtomicCondition.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/AtomicCondition.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAC;AAE9D,OAAO,EACL,IAAI,EACJ,MAAM,EACN,MAAM,EACN,IAAI,EACJ,OAAO,EACP,OAAO,EAGR,MAAM,yBAAyB,CAAC;AAGjC,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAC5C,OAAO,WAAW,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,oBAAoB,MAAM,oBAAoB,CAAC;AAGtD,4CAA4C;AAC5C,SAAS,YAAY,CAAC,SAAiB,EAAE,MAAe;IACtD,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;IAC7D,OAAO,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,IAAI,CAAC;AAC7B,CAAC;AAED,+CAA+C;AAC/C,SAAS,aAAa,CAAC,SAAiB,EAAE,MAAe;IACvD,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;IAC7D,OAAO,CAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,KAAK,MAAI,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,IAAI,CAAA,CAAC;AACrD,CAAC;AAED;;;GAGG;AACH,SAAS,uBAAuB,CAAC,GAAyB,EAAE,UAAsB;IAChF,IAAI,GAAG,KAAK,SAAS,EAAE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CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAQ,CAC9E;QAEA,CAAC,cAAc,IAAI,CAClB,oBAAC,aAAa,IACZ,KAAK,EAAE,SAAS,CAAC,GAAG,CAAC,KAAK,EAC1B,QAAQ,EAAE,iBAAiB,EAC3B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,cAAc,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAC1E,IAAI,EACF,cAAc,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,KAAK,EAAE;gBAC1C,CAAC,CAAC,CAAC,CAAC,iDAAiD,CAAC;gBACtD,CAAC,CAAC,SAAS,GAEf,CACH;QAGD,oBAAC,MAAM,IACL,KAAK,EAAE,SAAS,CAAC,UAAU,EAC3B,QAAQ,EAAE,sBAAsB,EAChC,IAAI,EAAC,YAAY,EACjB,KAAK,EAAC,GAAG,EACT,WAAW,UAEV,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAC/B,oBAAC,MAAM,IAAC,GAAG,EAAE,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,IACrC,MAAM,CAAC,KAAK,CACN,CACV,CAAC,CACK;QAGT,oBAAC,WAAW,IACV,GAAG,EAAE,SAAS,CAAC,GAAG,EAClB,UAAU,EAAE,SAAS,CAAC,UAAU,EAChC,GAAG,EAAE,SAAS,CAAC,GAAG,EAClB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,eAAe,EACzB,cAAc,EAAE,cAAc,EAC9B,aAAa,EAAE,QAAQ,GACvB,CACG,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import React, { FunctionComponent, ChangeEvent } from 'react';\n\nimport {\n Grid,\n Select,\n Option,\n Text,\n useI18n,\n hasProp,\n BaseProps,\n ForwardProps\n} from '@pega/cosmos-react-core';\n\nimport { LeafCondition, Field } from './ConditionBuilder.types';\nimport FieldSelector from './FieldSelector';\nimport RhsControls, { getDefaultRhs, isValidRhs } from './RhsControls';\nimport getComparatorOptions from './core/comparators';\nimport { Comparator, ComparatorsByType, FieldType, RHSType } from './core/types';\n\n// Returns field-type for a given field-name\nfunction getFieldType(fieldName: string, fields: Field[]): FieldType | undefined {\n const matchingField = fields.find(f => f.name === fieldName);\n return matchingField?.type;\n}\n\n// Returns display label for a given field-name\nfunction getFieldLabel(fieldName: string, fields: Field[]): string | undefined {\n const matchingField = fields.find(f => f.name === fieldName);\n return matchingField?.label || matchingField?.name;\n}\n\n/**\n * Upon changing the comparator, checks if the old RHS is valid for the new comparator\n * NOTE: This works under the assumption that the LHS doesn't change\n */\nfunction isRhsValidForComparator(rhs: LeafCondition['rhs'], comparator: Comparator): boolean {\n if (rhs === undefined) {\n return ['IS_NULL', 'IS_NOT_NULL', 'IS_TRUE', 'IS_FALSE'].includes(comparator);\n }\n if (hasProp(rhs, 'values')) {\n return ['IN', 'NOT_IN'].includes(comparator);\n }\n\n // `rhs.field` and `rhs.value` cases\n return [\n 'EQ',\n 'NEQ',\n 'GT',\n 'GTE',\n 'LT',\n 'LTE',\n 'STARTS_WITH',\n 'NOT_STARTS_WITH',\n 'ENDS_WITH',\n 'NOT_ENDS_WITH',\n 'CONTAINS',\n 'NOT_CONTAINS'\n ].includes(comparator);\n}\n\n/** Determines the default condition object for a given LHS value */\nexport function getInitConditionForLhs(\n lhs: LeafCondition['lhs'],\n fields: Field[],\n validRhsTypes: Set<RHSType>,\n validComparators?: ComparatorsByType[]\n): LeafCondition {\n let comparator: Comparator;\n let rhs: LeafCondition['rhs'];\n if (lhs.field === '') {\n // If the empty option is selected, reset the comparator and rhs to their default values\n comparator = 'IS_NOT_NULL';\n rhs = undefined;\n } else {\n const newFieldType = getFieldType(lhs.field, fields) as FieldType;\n comparator = getComparatorOptions(newFieldType, validComparators)[0].id; // Find the applicable comparators and select the first among them\n rhs = getDefaultRhs(newFieldType, comparator, validRhsTypes);\n }\n\n return { lhs, comparator, rhs };\n}\n\n/** Verifies if all the values in the condition are valid */\nexport function isValidCondition(\n condition: LeafCondition,\n fields: Field[],\n validRhsTypes: Set<RHSType>,\n trimValues: boolean = false\n): boolean {\n // If no field is yet selected on the LHS\n if (condition.lhs.field === '') {\n return false;\n }\n // If a field is present on the LHS, check if the RHS is valid\n // No need to check the comparator since the comparator is always assigned a valid value\n const fieldType = getFieldType(condition.lhs.field, fields);\n return isValidRhs(condition.rhs, fieldType, trimValues, validRhsTypes);\n}\n\n/** Type definition for the input props of AtomicCondition */\ninterface AtomicConditionProps extends BaseProps {\n /** Condition to use in the component */\n condition: LeafCondition;\n\n /** Metadata (data-model) for the Fields to use in the Condition */\n fields: Field[];\n\n /** Used to enable inline error indicators on invalid inputs */\n indicateErrors: boolean;\n\n /** (Optional) Lookup used to limit the Comparators allowed in the Condition. */\n validComparators?: ComparatorsByType[];\n\n /** Callback for any modifications to the Condition */\n onChange: (newCondition: LeafCondition) => void;\n\n /** Item flow direction. Defaults to 'row' */\n itemDirection?: 'row' | 'column';\n\n /**\n * Allows showing the LHS as a readonly label.\n * NOTE: Make sure that a valid LHS is passed in the 'condition'\n */\n showLhsAsLabel?: boolean;\n\n /** Restricts RHS values to only specified types of values.\n * DEFAULT: Set(['LITERAL', 'FIELD']).\n * WARNING: There are LHS/Comparator pairings that require specific RHS types. Please be mindful of\n * these incompatibilities when limiting RHS value types using this prop. We do not support\n * limiting RHS field types to incompatible types and it will result in a validation error\n * if you do so. The pairings referred to here are as follows:\n * - BOOLEAN LHS Fields coupled with \"EQ\" or \"NEQ\" comparators, will always yield a Field RHS\n * - Any LHS Fields coupled with \"IN\" or \"NOT_IN\" comparators, will always yield a Literal RHS (Comma separated list)\n * If you would like to limit RHS value types and avoid these incompatibilities, you will need to exclude these\n * comparators using the validComparators prop.\n */\n validRhsTypes?: Set<RHSType>;\n}\n\n/** A controlled component for Atomic Conditions */\nconst AtomicCondition: FunctionComponent<AtomicConditionProps & ForwardProps> = (\n props: AtomicConditionProps\n) => {\n const {\n condition,\n fields,\n indicateErrors,\n validComparators,\n onChange,\n itemDirection,\n showLhsAsLabel,\n validRhsTypes\n } = props;\n\n const rhsTypes =\n validRhsTypes && validRhsTypes.size !== 0\n ? validRhsTypes\n : new Set<RHSType>(['LITERAL', 'FIELD']);\n\n const fieldType = getFieldType(condition.lhs.field, fields); // Can be `undefined` if no match or if no previous field\n const comparatorOptions = fieldType\n ? getComparatorOptions(fieldType, validComparators)\n : [{ id: '', label: 'Select...' }]; // FIXME: TR\n\n // Handle change in the field-selector\n const handleFieldChange = (id: string) => {\n const lhs = { field: id };\n const newCondition = getInitConditionForLhs(lhs, fields, rhsTypes, validComparators); // Determine comparator and rhs for the new lhs\n onChange(newCondition); // Submit the new condition\n };\n\n // Handle change in the comparator\n const handleComparatorChange = (e: ChangeEvent<HTMLSelectElement>) => {\n if (e.target.value === '') {\n return; // The option is shown only when an lhs is not yet selected. Ignore this selection for those cases\n }\n const comparator = e.target.value as Comparator;\n const rhs = isRhsValidForComparator(condition.rhs, comparator)\n ? condition.rhs\n : getDefaultRhs(fieldType as FieldType, comparator, rhsTypes);\n onChange({ ...condition, comparator, rhs }); // Submit the new condition\n };\n\n // Handle change in the RHS\n const handleRHSChange = (rhs: LeafCondition['rhs']) => {\n onChange({ ...condition, rhs }); // Submit the new condition\n };\n\n const t = useI18n();\n\n return (\n // Using minmax() to get equal widths: https://stackoverflow.com/a/61240964/4247448\n <Grid\n sm={{\n container: { cols: itemDirection === 'column' ? '1fr' : 'repeat(3, minmax(5rem,1fr))' }\n }}\n md={{\n container: { cols: itemDirection === 'column' ? '1fr' : 'repeat(3, minmax(10rem,1fr))' }\n }}\n container={{\n justifyItems: 'stretch',\n colGap: 0.5,\n rowGap: 0.5\n }}\n >\n {/* LHS label */}\n {showLhsAsLabel && (\n <Text variant='secondary'>{getFieldLabel(condition.lhs.field, fields)}</Text>\n )}\n {/* LHS selector */}\n {!showLhsAsLabel && (\n <FieldSelector\n value={condition.lhs.field}\n onChange={handleFieldChange}\n fields={fields}\n status={indicateErrors && condition.lhs.field === '' ? 'error' : undefined}\n info={\n indicateErrors && condition.lhs.field === ''\n ? t('condition_builder_condition_select_info_default')\n : undefined\n }\n />\n )}\n\n {/* Comparator selector */}\n <Select\n value={condition.comparator}\n onChange={handleComparatorChange}\n name='comparator'\n label='-'\n labelHidden\n >\n {comparatorOptions.map(option => (\n <Option key={option.id} value={option.id}>\n {option.label}\n </Option>\n ))}\n </Select>\n\n {/* RHS controls */}\n <RhsControls\n lhs={condition.lhs}\n comparator={condition.comparator}\n rhs={condition.rhs}\n fields={fields}\n onChange={handleRHSChange}\n indicateErrors={indicateErrors}\n validRhsTypes={rhsTypes}\n />\n </Grid>\n );\n};\n\nexport default AtomicCondition;\n"]}
1
+ {"version":3,"file":"AtomicCondition.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/AtomicCondition.tsx"],"names":[],"mappings":";AAEA,OAAO,EACL,IAAI,EACJ,MAAM,EACN,MAAM,EACN,IAAI,EACJ,OAAO,EACP,OAAO,EAGR,MAAM,yBAAyB,CAAC;AAGjC,OAAO,aAAa,MAAM,6BAA6B,CAAC;AACxD,OAAO,WAAW,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,oBAAoB,MAAM,oBAAoB,CAAC;AAGtD,4CAA4C;AAC5C,SAAS,YAAY,CAAC,SAAiB,EAAE,MAAe;IACtD,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;IAC7D,OAAO,aAAa,EAAE,IAAI,CAAC;AAC7B,CAAC;AAED,+CAA+C;AAC/C,SAAS,aAAa,CAAC,SAAiB,EAAE,MAAe;IACvD,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAA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WACrC,YACG,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { FunctionComponent, ChangeEvent } from 'react';\n\nimport {\n Grid,\n Select,\n Option,\n Text,\n useI18n,\n hasProp,\n BaseProps,\n ForwardProps\n} from '@pega/cosmos-react-core';\n\nimport { LeafCondition, Field, DateFunctionsByType } from './ConditionBuilder.types';\nimport FieldSelector from './RhsControls/FieldSelector';\nimport RhsControls, { getDefaultRhs, isValidRhs } from './RhsControls';\nimport getComparatorOptions from './core/comparators';\nimport { Comparator, ComparatorsByType, FieldType, RHSType } from './core/types';\n\n// Returns field-type for a given field-name\nfunction getFieldType(fieldName: string, fields: Field[]): FieldType | undefined {\n const matchingField = fields.find(f => f.name === fieldName);\n return matchingField?.type;\n}\n\n// Returns display label for a given field-name\nfunction getFieldLabel(fieldName: string, fields: Field[]): string | undefined {\n const matchingField = fields.find(f => f.name === fieldName);\n return matchingField?.label || matchingField?.name;\n}\n\n/**\n * Upon changing the comparator, checks if the old RHS is valid for the new comparator\n * NOTE: This works under the assumption that the LHS doesn't change\n */\nfunction isRhsValidForComparator(rhs: LeafCondition['rhs'], comparator: Comparator): boolean {\n if (rhs === undefined) {\n return ['IS_NULL', 'IS_NOT_NULL', 'IS_TRUE', 'IS_FALSE'].includes(comparator);\n }\n if (hasProp(rhs, 'values')) {\n return ['IN', 'NOT_IN'].includes(comparator);\n }\n\n // `rhs.field` and `rhs.value` cases\n return [\n 'EQ',\n 'NEQ',\n 'GT',\n 'GTE',\n 'LT',\n 'LTE',\n 'STARTS_WITH',\n 'NOT_STARTS_WITH',\n 'ENDS_WITH',\n 'NOT_ENDS_WITH',\n 'CONTAINS',\n 'NOT_CONTAINS'\n ].includes(comparator);\n}\n\n/** Determines the default condition object for a given LHS value */\nexport function getInitConditionForLhs(\n lhs: LeafCondition['lhs'],\n fields: Field[],\n validRhsTypes: Set<RHSType>,\n validComparators?: ComparatorsByType[],\n dateFunctions?: DateFunctionsByType\n): LeafCondition {\n let comparator: Comparator;\n let rhs: LeafCondition['rhs'];\n if (lhs.field === '') {\n // If the empty option is selected, reset the comparator and rhs to their default values\n comparator = 'IS_NOT_NULL';\n rhs = undefined;\n } else {\n const newFieldType = getFieldType(lhs.field, fields) as FieldType;\n comparator = getComparatorOptions(newFieldType, validComparators)[0].id; // Find the applicable comparators and select the first among them\n rhs = getDefaultRhs(newFieldType, comparator, validRhsTypes, dateFunctions);\n }\n\n return { lhs, comparator, rhs };\n}\n\n/**\n * Verifies if all the values in the condition are valid.\n * NOTES:\n * - This is intended to be used only on conditions emitted by the components in this package.\n * - If a condition is manually constructed outside these components, this utility could miss some malformed conditions.\n */\nexport function isValidCondition(\n condition: LeafCondition,\n fields: Field[],\n trimValues: boolean = false\n): boolean {\n // If no field is yet selected on the LHS\n if (condition.lhs.field === '') {\n return false;\n }\n // If a field is present on the LHS, check if the RHS is valid\n // No need to check the comparator since the comparator is always assigned a valid value\n const fieldType = getFieldType(condition.lhs.field, fields);\n return isValidRhs(condition.rhs, fieldType, trimValues);\n}\n\n/** Type definition for the input props of AtomicCondition */\ninterface AtomicConditionProps extends BaseProps {\n /** Condition to use in the component */\n condition: LeafCondition;\n\n /** Metadata (data-model) for the Fields to use in the Condition */\n fields: Field[];\n\n /** Used to enable inline error indicators on invalid inputs */\n indicateErrors: boolean;\n\n /** (Optional) Lookup used to limit the Comparators allowed in the Condition. */\n validComparators?: ComparatorsByType[];\n\n /** Callback for any modifications to the Condition */\n onChange: (newCondition: LeafCondition) => void;\n\n /** Item flow direction. Defaults to 'row' */\n itemDirection?: 'row' | 'column';\n\n /**\n * Allows showing the LHS as a readonly label.\n * NOTE: Make sure that a valid LHS is passed in the 'condition'\n */\n showLhsAsLabel?: boolean;\n\n /** Restricts RHS values to only specified types of values.\n * DEFAULT: Set(['LITERAL', 'FIELD']).\n * WARNING: There are LHS/Comparator pairings that require specific RHS types. Please be mindful of\n * these incompatibilities when limiting RHS value types using this prop. We do not support\n * limiting RHS field types to incompatible types and it will result in a validation error\n * if you do so. The pairings referred to here are as follows:\n * - BOOLEAN LHS Fields coupled with \"EQ\" or \"NEQ\" comparators, will always yield a Field RHS\n * - Any LHS Fields coupled with \"IN\" or \"NOT_IN\" comparators, will always yield a Literal RHS (Comma separated list)\n * If you would like to limit RHS value types and avoid these incompatibilities, you will need to exclude these\n * comparators using the validComparators prop.\n */\n validRhsTypes?: Set<RHSType>;\n\n /** (Optional) When enabling 'DATE_FUNCTION's via `validRhsTypes`, pass this to specify which all date functions are applicable per field type */\n dateFunctions?: DateFunctionsByType;\n}\n\n/** A controlled component for Atomic Conditions */\nconst AtomicCondition: FunctionComponent<AtomicConditionProps & ForwardProps> = (\n props: AtomicConditionProps\n) => {\n const {\n condition,\n fields,\n indicateErrors,\n validComparators,\n onChange,\n itemDirection,\n showLhsAsLabel,\n validRhsTypes = new Set<RHSType>(['LITERAL', 'FIELD']),\n dateFunctions\n } = props;\n\n const fieldType = getFieldType(condition.lhs.field, fields); // Can be `undefined` if no match or if no previous field\n const comparatorOptions = fieldType\n ? getComparatorOptions(fieldType, validComparators)\n : [{ id: '', label: 'Select…' }]; // FIXME: TR\n\n // Handle change in the field-selector\n const handleFieldChange = (id: string) => {\n const lhs = { field: id };\n const newCondition = getInitConditionForLhs(\n lhs,\n fields,\n validRhsTypes,\n validComparators,\n dateFunctions\n ); // Determine comparator and rhs for the new lhs\n onChange(newCondition); // Submit the new condition\n };\n\n // Handle change in the comparator\n const handleComparatorChange = (e: ChangeEvent<HTMLSelectElement>) => {\n if (e.target.value === '') {\n return; // The option is shown only when an lhs is not yet selected. Ignore this selection for those cases\n }\n const comparator = e.target.value as Comparator;\n const rhs = isRhsValidForComparator(condition.rhs, comparator)\n ? condition.rhs\n : getDefaultRhs(fieldType as FieldType, comparator, validRhsTypes, dateFunctions);\n onChange({ ...condition, comparator, rhs }); // Submit the new condition\n };\n\n // Handle change in the RHS\n const handleRHSChange = (rhs: LeafCondition['rhs']) => {\n onChange({ ...condition, rhs }); // Submit the new condition\n };\n\n const t = useI18n();\n\n return (\n // Using minmax() to get equal widths: https://stackoverflow.com/a/61240964/4247448\n <Grid\n sm={{\n container: { cols: itemDirection === 'column' ? '1fr' : 'repeat(3, minmax(5rem,1fr))' }\n }}\n md={{\n container: { cols: itemDirection === 'column' ? '1fr' : 'repeat(3, minmax(10rem,1fr))' }\n }}\n container={{\n justifyItems: 'stretch',\n colGap: 0.5,\n rowGap: 0.5\n }}\n >\n {/* LHS label */}\n {showLhsAsLabel && (\n <Text variant='secondary'>{getFieldLabel(condition.lhs.field, fields)}</Text>\n )}\n {/* LHS selector */}\n {!showLhsAsLabel && (\n <FieldSelector\n value={condition.lhs.field}\n onChange={handleFieldChange}\n fields={fields}\n status={indicateErrors && condition.lhs.field === '' ? 'error' : undefined}\n info={\n indicateErrors && condition.lhs.field === ''\n ? t('condition_builder_condition_select_info_default')\n : undefined\n }\n />\n )}\n\n {/* Comparator selector */}\n <Select\n value={condition.comparator}\n onChange={handleComparatorChange}\n name='comparator'\n label='-'\n labelHidden\n >\n {comparatorOptions.map(option => (\n <Option key={option.id} value={option.id}>\n {option.label}\n </Option>\n ))}\n </Select>\n\n {/* RHS controls */}\n <RhsControls\n lhs={condition.lhs}\n comparator={condition.comparator}\n rhs={condition.rhs}\n fields={fields}\n onChange={handleRHSChange}\n indicateErrors={indicateErrors}\n validRhsTypes={validRhsTypes}\n dateFunctions={dateFunctions}\n itemDirection={itemDirection || 'row'}\n />\n </Grid>\n );\n};\n\nexport default AtomicCondition;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionBuilder.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,iBAAiB,EAA+C,MAAM,OAAO,CAAC;AAG9F,OAAO,EAOL,YAAY,EAKb,MAAM,yBAAyB,CAAC;AAIjC,OAAO,qBAAmD,MAAM,0BAA0B,CAAC;AAsD3F,QAAA,MAAM,gBAAgB,EAAE,iBAAiB,CAAC,qBAAqB,GAAG,YAAY,CAuU7E,CAAC;AAGF,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"ConditionBuilder.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA+C,MAAM,OAAO,CAAC;AAGvF,OAAO,EAOL,YAAY,EAKb,MAAM,yBAAyB,CAAC;AAIjC,OAAO,qBAAmD,MAAM,0BAA0B,CAAC;AAsD3F,QAAA,MAAM,gBAAgB,EAAE,iBAAiB,CAAC,qBAAqB,GAAG,YAAY,CA0U7E,CAAC;AAGF,eAAe,gBAAgB,CAAC"}
@@ -1,4 +1,5 @@
1
- import React, { Fragment, useState, useReducer } from 'react';
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Fragment, useState, useReducer } from 'react';
2
3
  import styled from 'styled-components';
3
4
  import { Banner, Button, Flex, Icon, Input, MenuButton, createUID, hasProp, defaultThemeProp, useI18n } from '@pega/cosmos-react-core';
4
5
  import AtomicCondition, { isValidCondition } from './AtomicCondition';
@@ -44,7 +45,7 @@ const defaultProps = {
44
45
  };
45
46
  // Component for the builder
46
47
  const ConditionBuilder = (props) => {
47
- const { fields, onConditionSubmit, condition: seedCondition, validComparators, disallowNOT } = props;
48
+ const { fields, onConditionSubmit, condition: seedCondition, validComparators, validRhsTypes = new Set(['LITERAL', 'FIELD']), dateFunctions, disallowNOT } = props;
48
49
  // Split the condition tree into a logic-string and a list of condition-rows.
49
50
  const clonedCondition = JSON.parse(JSON.stringify(seedCondition)); // Cloning to avoid modifying the original
50
51
  const { logic: seedLogic, rows: seedRows } = splitConditionForBuilder(clonedCondition);
@@ -56,7 +57,6 @@ const ConditionBuilder = (props) => {
56
57
  const [logicError, setLogicError] = useState(null); // Used to indicate errors in the logic string
57
58
  const [showModeWarning, setModeWarning] = useState(false); // Used to warn user about losing information when moving away from Advanced mode
58
59
  const [showErrorIndicators, setErrorIndicators] = useState(false); // Used to enable inline error indicators in the condition rows
59
- const validRhsTypes = new Set(['LITERAL', 'FIELD']);
60
60
  const enableShading = isBasicMode && operatorsList.includes('AND') && operatorsList.includes('OR'); // In Basic mode, enable shading to indicate grouping only when both operators are present
61
61
  // Upon adding/removing rows in Advanced mode, update the logic string to reflect the change in labels
62
62
  // NOTE: The input is updated only if the previous logicString was simple enough
@@ -195,7 +195,7 @@ const ConditionBuilder = (props) => {
195
195
  return;
196
196
  }
197
197
  // Identify and indicate any invalid values in the condition rows
198
- const hasInvalidRows = conditionRows.some(row => !isValidCondition(row, fields, validRhsTypes, true));
198
+ const hasInvalidRows = conditionRows.some(row => !isValidCondition(row, fields, true));
199
199
  if (hasInvalidRows) {
200
200
  setErrorIndicators(true); // Enable inline error indications
201
201
  return;
@@ -209,46 +209,25 @@ const ConditionBuilder = (props) => {
209
209
  }
210
210
  };
211
211
  const t = useI18n();
212
- return (React.createElement(Flex, { container: { direction: 'column', itemGap: 4 } },
213
- React.createElement("div", null, conditionRows.map(({ id, label, ...leaf }, index) => (React.createElement(Fragment, { key: id },
214
- isBasicMode && index > 0 && (React.createElement(StyledRowWithSeparator, { container: true, shaded: enableShading && operatorsList[index - 1] === 'AND' },
215
- React.createElement(MenuButton, { text: operatorsList[index - 1].toLowerCase(), variant: 'simple', menu: {
216
- items: [
217
- {
218
- id: 'AND',
219
- primary: 'and',
220
- onClick: () => updateOperator(index - 1, 'AND')
221
- },
222
- {
223
- id: 'OR',
224
- primary: 'or',
225
- onClick: () => updateOperator(index - 1, 'OR')
226
- }
227
- ]
228
- } }))),
229
- React.createElement(StyledRow, { container: { itemGap: 0.5 }, shaded: isBasicMode && enableShading },
230
- !isBasicMode && React.createElement(StyledLabel, null, label),
231
- React.createElement(Flex, { item: { grow: 1 } },
232
- React.createElement(AtomicCondition, { condition: leaf, fields: fields, indicateErrors: showErrorIndicators, validComparators: validComparators, onChange: (newCondition) => {
233
- const newRow = { id, label, ...newCondition };
234
- dispatch({ type: UPDATE_ROW, payload: { updateAt: index, newRow } });
235
- }, validRhsTypes: validRhsTypes })),
236
- React.createElement(Button, { icon: true, variant: 'simple', onClick: () => insertRow(index + 1), "aria-label": t('condition_builder_add_button_label') },
237
- React.createElement(Icon, { name: 'plus' })),
238
- React.createElement(Button, { icon: true, variant: 'simple', onClick: () => removeRow(index), "aria-label": t('condition_builder_remove_button_label') },
239
- React.createElement(Icon, { name: 'trash' }))))))),
240
- !isBasicMode && (React.createElement("div", null,
241
- React.createElement(Input, { type: 'text', placeholder: t('condition_builder_advanced_condition_placeholder').toString(), label: React.createElement(React.Fragment, null,
242
- t('condition_builder_advanced_condition_label'),
243
- "\u00A0",
244
- React.createElement(HelpButton, null, `A logical expression representing an advanced condition.\nUse numbers like 1,2,3,... to represent different condition rows.\nUse ${disallowNOT ? 'AND/OR' : 'AND/OR/NOT'} operators and parentheses to construct advanced conditions.\n\nExample: ${disallowNOT ? '(1 OR 2) AND (3 OR 4 OR 5)' : '(1 AND 2) OR (3 AND NOT 4)'}`)), value: logicString, onChange: (e) => setLogicString(e.target.value), onBlur: () => validateLogicString(logicString), status: logicError !== null ? 'error' : undefined, info: logicError }))),
245
- React.createElement(Flex, { container: { direction: 'column', itemGap: 2 } },
246
- showModeWarning && (React.createElement(Banner, { id: createUID(), variant: 'warning', messages: [t('condition_builder_switch_banner_text').toString()], action: React.createElement(Button, { name: 'force-mode-switch', variant: 'secondary', onClick: () => toggleMode(true) }, t('condition_builder_confirm_button_label')), onDismiss: () => setModeWarning(false) })),
247
- React.createElement(Flex, { container: { justify: 'between' } },
248
- React.createElement(Button, { name: 'mode-switch', variant: 'simple', onClick: () => toggleMode(false) }, isBasicMode
249
- ? t('condition_builder_advanced_mode_button_label')
250
- : t('condition_builder_basic_mode_button_label')),
251
- React.createElement(Button, { type: 'submit', variant: 'primary', onClick: handleSubmission }, t('condition_builder_submit_button_label'))))));
212
+ return (_jsxs(Flex, { container: { direction: 'column', gap: 4 }, children: [_jsx("div", { children: conditionRows.map(({ id, label, ...leaf }, index) => (_jsxs(Fragment, { children: [isBasicMode && index > 0 && (_jsx(StyledRowWithSeparator, { container: true, shaded: enableShading && operatorsList[index - 1] === 'AND', children: _jsx(MenuButton, { text: operatorsList[index - 1].toLowerCase(), variant: 'simple', menu: {
213
+ items: [
214
+ {
215
+ id: 'AND',
216
+ primary: 'and',
217
+ onClick: () => updateOperator(index - 1, 'AND')
218
+ },
219
+ {
220
+ id: 'OR',
221
+ primary: 'or',
222
+ onClick: () => updateOperator(index - 1, 'OR')
223
+ }
224
+ ]
225
+ } }, void 0) }, void 0)), _jsxs(StyledRow, { container: { gap: 0.5, alignItems: 'start' }, shaded: isBasicMode && enableShading, children: [!isBasicMode && _jsx(StyledLabel, { children: label }, void 0), _jsx(Flex, { item: { grow: 1 }, children: _jsx(AtomicCondition, { condition: leaf, fields: fields, indicateErrors: showErrorIndicators, validComparators: validComparators, dateFunctions: dateFunctions, onChange: (newCondition) => {
226
+ const newRow = { id, label, ...newCondition };
227
+ dispatch({ type: UPDATE_ROW, payload: { updateAt: index, newRow } });
228
+ }, validRhsTypes: validRhsTypes }, void 0) }, void 0), _jsx(Button, { icon: true, variant: 'simple', onClick: () => insertRow(index + 1), "aria-label": t('condition_builder_add_button_label'), children: _jsx(Icon, { name: 'plus' }, void 0) }, void 0), _jsx(Button, { icon: true, variant: 'simple', onClick: () => removeRow(index), "aria-label": t('condition_builder_remove_button_label'), children: _jsx(Icon, { name: 'trash' }, void 0) }, void 0)] }, void 0)] }, id))) }, void 0), !isBasicMode && (_jsx("div", { children: _jsx(Input, { type: 'text', placeholder: t('condition_builder_advanced_condition_placeholder'), label: _jsxs(_Fragment, { children: [t('condition_builder_advanced_condition_label'), "\u00A0", _jsx(HelpButton, { children: `A logical expression representing an advanced condition.\nUse numbers like 1,2,3,… to represent different condition rows.\nUse ${disallowNOT ? 'AND/OR' : 'AND/OR/NOT'} operators and parentheses to construct advanced conditions.\n\nExample: ${disallowNOT ? '(1 OR 2) AND (3 OR 4 OR 5)' : '(1 AND 2) OR (3 AND NOT 4)'}` }, void 0)] }, void 0), value: logicString, onChange: (e) => setLogicString(e.target.value), onBlur: () => validateLogicString(logicString), status: logicError !== null ? 'error' : undefined, info: logicError }, void 0) }, void 0)), _jsxs(Flex, { container: { direction: 'column', gap: 2 }, children: [showModeWarning && (_jsx(Banner, { id: createUID(), variant: 'warning', messages: [t('condition_builder_switch_banner_text')], action: _jsx(Button, { name: 'force-mode-switch', variant: 'secondary', onClick: () => toggleMode(true), children: t('condition_builder_confirm_button_label') }, void 0), onDismiss: () => setModeWarning(false) }, void 0)), _jsxs(Flex, { container: { justify: 'between' }, children: [_jsx(Button, { name: 'mode-switch', variant: 'simple', onClick: () => toggleMode(false), children: isBasicMode
229
+ ? t('condition_builder_advanced_mode_button_label')
230
+ : t('condition_builder_basic_mode_button_label') }, void 0), _jsx(Button, { name: 'condition-builder-submit', variant: 'primary', onClick: handleSubmission, children: t('condition_builder_submit_button_label') }, void 0)] }, void 0)] }, void 0)] }, void 0));
252
231
  };
253
232
  ConditionBuilder.defaultProps = defaultProps;
254
233
  export default ConditionBuilder;
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionBuilder.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAqB,QAAQ,EAAe,QAAQ,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC9F,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EACL,MAAM,EACN,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,UAAU,EAEV,SAAS,EACT,OAAO,EACP,gBAAgB,EAChB,OAAO,EACR,MAAM,yBAAyB,CAAC;AAEjC,OAAO,eAAe,EAAE,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,UAAU,MAAM,cAAc,CAAC;AAEtC,O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,SAAS,EAAC,OAAO,EAAE,gBAAgB,IAC9D,CAAC,CAAC,uCAAuC,CAAC,CACpC,CACJ,CACF,CACF,CACR,CAAC;AACJ,CAAC,CAAC;AACF,gBAAgB,CAAC,YAAY,GAAG,YAAY,CAAC;AAE7C,eAAe,gBAAgB,CAAC","sourcesContent":["import React, { FunctionComponent, Fragment, ChangeEvent, useState, useReducer } from 'react';\nimport styled from 'styled-components';\n\nimport {\n Banner,\n Button,\n Flex,\n Icon,\n Input,\n MenuButton,\n ForwardProps,\n createUID,\n hasProp,\n defaultThemeProp,\n useI18n\n} from '@pega/cosmos-react-core';\n\nimport AtomicCondition, { isValidCondition } from './AtomicCondition';\nimport HelpButton from './HelpButton';\nimport ConditionBuilderProps, { Condition, LeafCondition } from './ConditionBuilder.types';\nimport {\n splitConditionForBuilder,\n parseLogicString,\n disambiguateLogic,\n isBasicModeApplicable,\n getBasicModeOperators,\n getLogicFromBasicMode\n} from './core/utils';\nimport rowsReducer, { INSERT_ROW, UPDATE_ROW, REMOVE_ROW } from './core/rows-reducer';\nimport { RHSType } from './core/types';\n\n// Styled wrapper for each Condition row\nconst StyledRow = styled(Flex)`\n padding: 0.25rem;\n background: ${props => (props.shaded ? 'rgba(0, 0, 0, 0.05)' : 'transparent')};\n`;\nStyledRow.defaultProps = defaultThemeProp;\n\n// Styled row-separators for Basic-mode\nconst StyledRowWithSeparator = styled(StyledRow)`\n padding: 0 0.25rem;\n &::after {\n content: '';\n flex-grow: 1;\n background-image: linear-gradient(to right, rgba(0, 0, 0, 0.2) 60%, rgba(0, 0, 0, 0) 0%);\n background-position: left center;\n background-size: 1.75rem 0.0625rem;\n background-repeat: repeat-x;\n }\n`;\n\n// Styled label for the rows in Advanced-mode\nconst StyledLabel = styled.div`\n line-height: 2rem;\n height: 2rem;\n width: 2rem;\n min-width: 2rem;\n text-align: center;\n background: rgba(0, 0, 0, 0.04);\n`;\nStyledLabel.defaultProps = defaultThemeProp;\n\n// Default props for the builder\nconst defaultProps: Partial<ConditionBuilderProps> = {\n condition: {\n condition: {\n comparator: 'IS_NOT_NULL',\n lhs: { field: '' }\n }\n }\n};\n\n// Component for the builder\nconst ConditionBuilder: FunctionComponent<ConditionBuilderProps & ForwardProps> = (\n props: ConditionBuilderProps\n) => {\n const {\n fields,\n onConditionSubmit,\n condition: seedCondition,\n validComparators,\n disallowNOT\n } = props;\n\n // Split the condition tree into a logic-string and a list of condition-rows.\n const clonedCondition: Condition = JSON.parse(JSON.stringify(seedCondition)); // Cloning to avoid modifying the original\n const { logic: seedLogic, rows: seedRows } = splitConditionForBuilder(clonedCondition);\n\n // On load, look to use the Basic-mode if the seed-condition is simple enough\n const [isBasicMode, setBasicMode] = useState(() => isBasicModeApplicable(clonedCondition));\n const [operatorsList, setOperatorsList] = useState(() => getBasicModeOperators(seedLogic)); // Operators-list used in Basic-mode to render dropdowns between the rows. NOTE: When in Advanced-mode, this can contain stale values.\n const [logicString, setLogicString] = useState(seedLogic); // Logic-string used in Advanced-mode. NOTE: When in Basic-mode, this can contain stale values.\n const [conditionRows, dispatch] = useReducer(rowsReducer, seedRows); // Conditions-rows\n const [logicError, setLogicError] = useState<string | null>(null); // Used to indicate errors in the logic string\n const [showModeWarning, setModeWarning] = useState(false); // Used to warn user about losing information when moving away from Advanced mode\n const [showErrorIndicators, setErrorIndicators] = useState(false); // Used to enable inline error indicators in the condition rows\n const validRhsTypes = new Set<RHSType>(['LITERAL', 'FIELD']);\n const enableShading =\n isBasicMode && operatorsList.includes('AND') && operatorsList.includes('OR'); // In Basic mode, enable shading to indicate grouping only when both operators are present\n\n // Upon adding/removing rows in Advanced mode, update the logic string to reflect the change in labels\n // NOTE: The input is updated only if the previous logicString was simple enough\n const updateLogicString = (actionType: string): void => {\n const numNewRows =\n actionType === INSERT_ROW ? conditionRows.length + 1 : conditionRows.length - 1;\n\n // If only one row left after the action, simply use its label as logicString\n // NOTE: If none left, the rowsReducer adds a new empty row\n if (numNewRows <= 1) {\n setLogicString('1');\n return;\n }\n\n // If the previous string was a simple AND/OR between all the rows, update the logicString to follow the same for the new list of rows.\n // If the previous string was a single token like `1` and a new row is inserted, do an AND between the new rows, i.e. `1 AND 2`\n // For all other complex cases, skip automatically updating the string and wait for the user to change it\n // To check this, split the previous string by `OR/AND` and check if each of the resultant token is a simple numeric token\n const splitter = logicString.includes('OR') ? 'OR' : 'AND';\n const tokens = logicString.split(splitter);\n const isEveryTokenInteger = tokens.every(w => /^\\d+$/.test(w.trim()));\n if (isEveryTokenInteger) {\n setLogicString(\n new Array(numNewRows)\n .fill(0)\n .map((w, i) => i + 1)\n .join(` ${splitter} `)\n );\n }\n };\n\n // Insert a new row at the given index\n const insertRow = (insertAt: number): void => {\n dispatch({ type: INSERT_ROW, payload: { insertAt } }); // Insert an entry in conditionRows\n if (isBasicMode) {\n // Set up a new AND/OR selector\n const insertOpAt = insertAt - 1; // Using `insertAt-1` since the operatorsList has one less entry compared to the conditionRows\n setOperatorsList([\n ...operatorsList.slice(0, insertOpAt),\n 'AND',\n ...operatorsList.slice(insertOpAt)\n ]);\n } else {\n updateLogicString(INSERT_ROW); // Update the logicString input to reflect the insertion\n }\n };\n\n // Remove the row at the given index\n const removeRow = (removeAt: number): void => {\n dispatch({ type: REMOVE_ROW, payload: { removeAt } }); // Remove an entry in conditionRows\n if (isBasicMode) {\n // Remove an AND/OR selector\n if (removeAt === 0) {\n // If removing the first of the condition rows, remove the extraneous operator\n setOperatorsList(operatorsList.slice(1));\n } else {\n let removeOpAt = removeAt - 1; // Using `removeAt-1` since the operatorsList has one less entry compared to the conditionRows\n if (operatorsList[removeOpAt] === 'OR' && operatorsList[removeOpAt + 1] === 'AND') {\n // If removing a condition at the start of a nested group, remove the first operator from that group. e.g. Take `(1 AND 2) OR (3 AND 4 AND 5)`. If `3` is being deleted, it should become `(1 AND 2) OR (4 AND 5)` instead of `1 AND 2 AND 4 AND 5`\n removeOpAt += 1;\n }\n setOperatorsList([\n ...operatorsList.slice(0, removeOpAt),\n ...operatorsList.slice(removeOpAt + 1)\n ]);\n }\n } else {\n updateLogicString(REMOVE_ROW); // Update the logicString input to reflect the removal\n }\n };\n\n // Update a Basic-mode operator at the given index\n const updateOperator = (updateAt: number, newValue: 'AND' | 'OR'): void => {\n setOperatorsList([\n ...operatorsList.slice(0, updateAt),\n newValue,\n ...operatorsList.slice(updateAt + 1)\n ]);\n };\n\n // Validate the logic input. Called upon clicking outside the textBox or upon submission.\n // If the expression is invalid, shows appropriate feedback and returns null.\n // If the expression is valid, formats it by setting up brackets at necessary places (to clear any ambiguities e.g. `1 AND 2 OR 3` is formatted as `(1 AND 2) OR 3` ). Returns a save-ready condition\n const validateLogicString = (logicToUse: string): Condition | null => {\n // Set up a lookup with row-labels as keys and rows as values\n const conditionLookup: { [label: string]: LeafCondition } = {};\n conditionRows.forEach(row => {\n const { id, label, ...leaf } = row; // Discard the extra properties added by ConditionRow to the LeafCondition interface\n conditionLookup[row.label] = leaf;\n });\n\n // Convert the logic string into a condition tree\n const parseResult = parseLogicString(logicToUse, conditionLookup, disallowNOT);\n\n // Indicate any parse error\n if (hasProp(parseResult, 'error')) {\n setLogicError(parseResult.error);\n return null;\n }\n\n // If no errors\n setLogicError(null); // Clear any previous error\n setLogicString(disambiguateLogic(logicToUse)); // Disambiguating the logic string by placing parentheses at appropriate places\n return parseResult.condition;\n };\n\n // Toggle between the Basic and Advanced modes\n // `forceToggle:true` is passed when switching from Advanced to Basic mode despite a loss of information\n const toggleMode = (forceToggle?: boolean): void => {\n setModeWarning(false); // Clear any previous warning\n if (isBasicMode) {\n // Update the logicString to match the operatorsList before switching the mode\n setLogicString(getLogicFromBasicMode(operatorsList));\n setBasicMode(false);\n } else if (forceToggle) {\n // If forcibly toggling from Advanced to Basic despite a loss of operators\n // Set up the default `AND` operator between all rows before switching to Basic mode\n setOperatorsList(new Array(conditionRows.length - 1).fill('AND'));\n setBasicMode(true);\n } else {\n // If switching from Advanced mode\n const condition = validateLogicString(logicString); // Validate the logicString. If it is an invalid, an appropriate error is shown for the user to act on\n if (condition !== null) {\n // If it's a valid condition, check if it's simple enough to be shown in Basic mode without any loss of information\n if (isBasicModeApplicable(condition)) {\n // If the logic is simple enough, identify the new set of operators before switching to Basic mode\n setOperatorsList(getBasicModeOperators(logicString));\n setBasicMode(true);\n } else {\n // If the logic is too complex show a warning for the user to act on\n setModeWarning(true);\n }\n }\n }\n };\n\n // Handle submission\n const handleSubmission = (): void => {\n setErrorIndicators(false); // Reset any previous flag\n setLogicError(null); // Clear any previous error\n\n // If there's a single empty condition, submit with an `undefined` value (useful for clearing a previous condition)\n if (conditionRows.length === 1 && conditionRows[0].lhs.field === '') {\n onConditionSubmit(undefined);\n return;\n }\n\n // Identify and indicate any invalid values in the condition rows\n const hasInvalidRows = conditionRows.some(\n row => !isValidCondition(row, fields, validRhsTypes, true)\n );\n if (hasInvalidRows) {\n setErrorIndicators(true); // Enable inline error indications\n return;\n }\n\n // Validate the Logic string\n const logicToUse = isBasicMode ? getLogicFromBasicMode(operatorsList) : logicString; // If in Basic-mode, construct a different logicString based on the operatorsList\n const condition = validateLogicString(logicToUse); // This also takes care of showing an appropriate error feedback as needed\n if (condition !== null) {\n // Can be null when the logic string has errors\n onConditionSubmit(condition); // Submit the new condition\n }\n };\n\n const t = useI18n();\n\n return (\n <Flex container={{ direction: 'column', itemGap: 4 }}>\n {/* Condition Rows */}\n <div>\n {conditionRows.map(({ id, label, ...leaf }, index) => (\n <Fragment key={id}>\n {/* Row with the operator dropdown in Basic mode */}\n {isBasicMode && index > 0 && (\n <StyledRowWithSeparator\n container\n shaded={enableShading && operatorsList[index - 1] === 'AND'}\n >\n <MenuButton\n text={operatorsList[index - 1].toLowerCase()}\n variant='simple'\n menu={{\n items: [\n {\n id: 'AND',\n primary: 'and',\n onClick: () => updateOperator(index - 1, 'AND')\n },\n {\n id: 'OR',\n primary: 'or',\n onClick: () => updateOperator(index - 1, 'OR')\n }\n ]\n }}\n />\n </StyledRowWithSeparator>\n )}\n\n {/* Row with the AtomicCondition */}\n <StyledRow container={{ itemGap: 0.5 }} shaded={isBasicMode && enableShading}>\n {/* Label */}\n {!isBasicMode && <StyledLabel>{label}</StyledLabel>}\n\n {/* Condition controls */}\n <Flex item={{ grow: 1 }}>\n <AtomicCondition\n condition={leaf}\n fields={fields}\n indicateErrors={showErrorIndicators}\n validComparators={validComparators}\n onChange={(newCondition: LeafCondition) => {\n const newRow = { id, label, ...newCondition };\n dispatch({ type: UPDATE_ROW, payload: { updateAt: index, newRow } });\n }}\n validRhsTypes={validRhsTypes}\n />\n </Flex>\n\n {/* Row actions */}\n <Button\n icon\n variant='simple'\n onClick={() => insertRow(index + 1)}\n aria-label={t('condition_builder_add_button_label')}\n >\n <Icon name='plus' />\n </Button>\n <Button\n icon\n variant='simple'\n onClick={() => removeRow(index)}\n aria-label={t('condition_builder_remove_button_label')}\n >\n <Icon name='trash' />\n </Button>\n </StyledRow>\n </Fragment>\n ))}\n </div>\n\n {/* LogicString input */}\n {!isBasicMode && (\n <div>\n <Input\n type='text'\n placeholder={t('condition_builder_advanced_condition_placeholder').toString()}\n label={\n <>\n {t('condition_builder_advanced_condition_label')}&nbsp;\n {/* FIXME: TR */}\n <HelpButton>\n {`A logical expression representing an advanced condition.\\nUse numbers like 1,2,3,... to represent different condition rows.\\nUse ${\n disallowNOT ? 'AND/OR' : 'AND/OR/NOT'\n } operators and parentheses to construct advanced conditions.\\n\\nExample: ${\n disallowNOT ? '(1 OR 2) AND (3 OR 4 OR 5)' : '(1 AND 2) OR (3 AND NOT 4)'\n }`}\n </HelpButton>\n </>\n }\n value={logicString}\n onChange={(e: ChangeEvent<HTMLInputElement>) => setLogicString(e.target.value)}\n onBlur={() => validateLogicString(logicString)}\n status={logicError !== null ? 'error' : undefined}\n info={logicError}\n />\n </div>\n )}\n\n {/* Submit block */}\n <Flex container={{ direction: 'column', itemGap: 2 }}>\n {/* Banner to show a warning when switching from Advanced to Basic mode */}\n {showModeWarning && (\n <Banner\n id={createUID()}\n variant='warning'\n messages={[t('condition_builder_switch_banner_text').toString()]}\n action={\n <Button name='force-mode-switch' variant='secondary' onClick={() => toggleMode(true)}>\n {t('condition_builder_confirm_button_label')}\n </Button>\n }\n onDismiss={() => setModeWarning(false)}\n />\n )}\n\n {/* Footer buttons */}\n <Flex container={{ justify: 'between' }}>\n <Button name='mode-switch' variant='simple' onClick={() => toggleMode(false)}>\n {isBasicMode\n ? t('condition_builder_advanced_mode_button_label')\n : t('condition_builder_basic_mode_button_label')}\n </Button>\n <Button type='submit' variant='primary' onClick={handleSubmission}>\n {t('condition_builder_submit_button_label')}\n </Button>\n </Flex>\n </Flex>\n </Flex>\n );\n};\nConditionBuilder.defaultProps = defaultProps;\n\nexport default ConditionBuilder;\n"]}
1
+ {"version":3,"file":"ConditionBuilder.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAqB,QAAQ,EAAe,QAAQ,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACvF,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EACL,MAAM,EACN,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,UAAU,EAEV,SAAS,EACT,OAAO,EACP,gBAAgB,EAChB,OAAO,EACR,MAAM,yBAAyB,CAAC;AAEjC,OAAO,eAAe,EAAE,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,UAAU,MAAM,cAAc,CAAC;AAEtC,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,cAAc,CAAC;AACtB,OAAO,WAAW,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGtF,wCAAwC;AACxC,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;;gBAEd,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,C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AChB,WACE,CACP,EAGD,MAAC,IAAI,IAAC,SAAS,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,EAAE,aAE7C,eAAe,IAAI,CAClB,KAAC,MAAM,IACL,EAAE,EAAE,SAAS,EAAE,EACf,OAAO,EAAC,SAAS,EACjB,QAAQ,EAAE,CAAC,CAAC,CAAC,sCAAsC,CAAC,CAAC,EACrD,MAAM,EACJ,KAAC,MAAM,IAAC,IAAI,EAAC,mBAAmB,EAAC,OAAO,EAAC,WAAW,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,YACjF,CAAC,CAAC,wCAAwC,CAAC,WACrC,EAEX,SAAS,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,WACtC,CACH,EAGD,MAAC,IAAI,IAAC,SAAS,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,aACrC,KAAC,MAAM,IAAC,IAAI,EAAC,aAAa,EAAC,OAAO,EAAC,QAAQ,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,YACzE,WAAW;oCACV,CAAC,CAAC,CAAC,CAAC,8CAA8C,CAAC;oCACnD,CAAC,CAAC,CAAC,CAAC,2CAA2C,CAAC,WAC3C,EACT,KAAC,MAAM,IAAC,IAAI,EAAC,0BAA0B,EAAC,OAAO,EAAC,SAAS,EAAC,OAAO,EAAE,gBAAgB,YAChF,CAAC,CAAC,uCAAuC,CAAC,WACpC,YACJ,YACF,YACF,CACR,CAAC;AACJ,CAAC,CAAC;AACF,gBAAgB,CAAC,YAAY,GAAG,YAAY,CAAC;AAE7C,eAAe,gBAAgB,CAAC","sourcesContent":["import { FunctionComponent, Fragment, ChangeEvent, useState, useReducer } from 'react';\nimport styled from 'styled-components';\n\nimport {\n Banner,\n Button,\n Flex,\n Icon,\n Input,\n MenuButton,\n ForwardProps,\n createUID,\n hasProp,\n defaultThemeProp,\n useI18n\n} from '@pega/cosmos-react-core';\n\nimport AtomicCondition, { isValidCondition } from './AtomicCondition';\nimport HelpButton from './HelpButton';\nimport ConditionBuilderProps, { Condition, LeafCondition } from './ConditionBuilder.types';\nimport {\n splitConditionForBuilder,\n parseLogicString,\n disambiguateLogic,\n isBasicModeApplicable,\n getBasicModeOperators,\n getLogicFromBasicMode\n} from './core/utils';\nimport rowsReducer, { INSERT_ROW, UPDATE_ROW, REMOVE_ROW } from './core/rows-reducer';\nimport { RHSType } from './core/types';\n\n// Styled wrapper for each Condition row\nconst StyledRow = styled(Flex)`\n padding: 0.25rem;\n background: ${props => (props.shaded ? 'rgba(0, 0, 0, 0.05)' : 'transparent')};\n`;\nStyledRow.defaultProps = defaultThemeProp;\n\n// Styled row-separators for Basic-mode\nconst StyledRowWithSeparator = styled(StyledRow)`\n padding: 0 0.25rem;\n &::after {\n content: '';\n flex-grow: 1;\n background-image: linear-gradient(to right, rgba(0, 0, 0, 0.2) 60%, rgba(0, 0, 0, 0) 0%);\n background-position: left center;\n background-size: 1.75rem 0.0625rem;\n background-repeat: repeat-x;\n }\n`;\n\n// Styled label for the rows in Advanced-mode\nconst StyledLabel = styled.div`\n line-height: 2rem;\n height: 2rem;\n width: 2rem;\n min-width: 2rem;\n text-align: center;\n background: rgba(0, 0, 0, 0.04);\n`;\nStyledLabel.defaultProps = defaultThemeProp;\n\n// Default props for the builder\nconst defaultProps: Partial<ConditionBuilderProps> = {\n condition: {\n condition: {\n comparator: 'IS_NOT_NULL',\n lhs: { field: '' }\n }\n }\n};\n\n// Component for the builder\nconst ConditionBuilder: FunctionComponent<ConditionBuilderProps & ForwardProps> = (\n props: ConditionBuilderProps\n) => {\n const {\n fields,\n onConditionSubmit,\n condition: seedCondition,\n validComparators,\n validRhsTypes = new Set<RHSType>(['LITERAL', 'FIELD']),\n dateFunctions,\n disallowNOT\n } = props;\n\n // Split the condition tree into a logic-string and a list of condition-rows.\n const clonedCondition: Condition = JSON.parse(JSON.stringify(seedCondition)); // Cloning to avoid modifying the original\n const { logic: seedLogic, rows: seedRows } = splitConditionForBuilder(clonedCondition);\n\n // On load, look to use the Basic-mode if the seed-condition is simple enough\n const [isBasicMode, setBasicMode] = useState(() => isBasicModeApplicable(clonedCondition));\n const [operatorsList, setOperatorsList] = useState(() => getBasicModeOperators(seedLogic)); // Operators-list used in Basic-mode to render dropdowns between the rows. NOTE: When in Advanced-mode, this can contain stale values.\n const [logicString, setLogicString] = useState(seedLogic); // Logic-string used in Advanced-mode. NOTE: When in Basic-mode, this can contain stale values.\n const [conditionRows, dispatch] = useReducer(rowsReducer, seedRows); // Conditions-rows\n const [logicError, setLogicError] = useState<string | null>(null); // Used to indicate errors in the logic string\n const [showModeWarning, setModeWarning] = useState(false); // Used to warn user about losing information when moving away from Advanced mode\n const [showErrorIndicators, setErrorIndicators] = useState(false); // Used to enable inline error indicators in the condition rows\n const enableShading =\n isBasicMode && operatorsList.includes('AND') && operatorsList.includes('OR'); // In Basic mode, enable shading to indicate grouping only when both operators are present\n\n // Upon adding/removing rows in Advanced mode, update the logic string to reflect the change in labels\n // NOTE: The input is updated only if the previous logicString was simple enough\n const updateLogicString = (actionType: string): void => {\n const numNewRows =\n actionType === INSERT_ROW ? conditionRows.length + 1 : conditionRows.length - 1;\n\n // If only one row left after the action, simply use its label as logicString\n // NOTE: If none left, the rowsReducer adds a new empty row\n if (numNewRows <= 1) {\n setLogicString('1');\n return;\n }\n\n // If the previous string was a simple AND/OR between all the rows, update the logicString to follow the same for the new list of rows.\n // If the previous string was a single token like `1` and a new row is inserted, do an AND between the new rows, i.e. `1 AND 2`\n // For all other complex cases, skip automatically updating the string and wait for the user to change it\n // To check this, split the previous string by `OR/AND` and check if each of the resultant token is a simple numeric token\n const splitter = logicString.includes('OR') ? 'OR' : 'AND';\n const tokens = logicString.split(splitter);\n const isEveryTokenInteger = tokens.every(w => /^\\d+$/.test(w.trim()));\n if (isEveryTokenInteger) {\n setLogicString(\n new Array(numNewRows)\n .fill(0)\n .map((w, i) => i + 1)\n .join(` ${splitter} `)\n );\n }\n };\n\n // Insert a new row at the given index\n const insertRow = (insertAt: number): void => {\n dispatch({ type: INSERT_ROW, payload: { insertAt } }); // Insert an entry in conditionRows\n if (isBasicMode) {\n // Set up a new AND/OR selector\n const insertOpAt = insertAt - 1; // Using `insertAt-1` since the operatorsList has one less entry compared to the conditionRows\n setOperatorsList([\n ...operatorsList.slice(0, insertOpAt),\n 'AND',\n ...operatorsList.slice(insertOpAt)\n ]);\n } else {\n updateLogicString(INSERT_ROW); // Update the logicString input to reflect the insertion\n }\n };\n\n // Remove the row at the given index\n const removeRow = (removeAt: number): void => {\n dispatch({ type: REMOVE_ROW, payload: { removeAt } }); // Remove an entry in conditionRows\n if (isBasicMode) {\n // Remove an AND/OR selector\n if (removeAt === 0) {\n // If removing the first of the condition rows, remove the extraneous operator\n setOperatorsList(operatorsList.slice(1));\n } else {\n let removeOpAt = removeAt - 1; // Using `removeAt-1` since the operatorsList has one less entry compared to the conditionRows\n if (operatorsList[removeOpAt] === 'OR' && operatorsList[removeOpAt + 1] === 'AND') {\n // If removing a condition at the start of a nested group, remove the first operator from that group. e.g. Take `(1 AND 2) OR (3 AND 4 AND 5)`. If `3` is being deleted, it should become `(1 AND 2) OR (4 AND 5)` instead of `1 AND 2 AND 4 AND 5`\n removeOpAt += 1;\n }\n setOperatorsList([\n ...operatorsList.slice(0, removeOpAt),\n ...operatorsList.slice(removeOpAt + 1)\n ]);\n }\n } else {\n updateLogicString(REMOVE_ROW); // Update the logicString input to reflect the removal\n }\n };\n\n // Update a Basic-mode operator at the given index\n const updateOperator = (updateAt: number, newValue: 'AND' | 'OR'): void => {\n setOperatorsList([\n ...operatorsList.slice(0, updateAt),\n newValue,\n ...operatorsList.slice(updateAt + 1)\n ]);\n };\n\n // Validate the logic input. Called upon clicking outside the textBox or upon submission.\n // If the expression is invalid, shows appropriate feedback and returns null.\n // If the expression is valid, formats it by setting up brackets at necessary places (to clear any ambiguities e.g. `1 AND 2 OR 3` is formatted as `(1 AND 2) OR 3` ). Returns a save-ready condition\n const validateLogicString = (logicToUse: string): Condition | null => {\n // Set up a lookup with row-labels as keys and rows as values\n const conditionLookup: { [label: string]: LeafCondition } = {};\n conditionRows.forEach(row => {\n const { id, label, ...leaf } = row; // Discard the extra properties added by ConditionRow to the LeafCondition interface\n conditionLookup[row.label] = leaf;\n });\n\n // Convert the logic string into a condition tree\n const parseResult = parseLogicString(logicToUse, conditionLookup, disallowNOT);\n\n // Indicate any parse error\n if (hasProp(parseResult, 'error')) {\n setLogicError(parseResult.error);\n return null;\n }\n\n // If no errors\n setLogicError(null); // Clear any previous error\n setLogicString(disambiguateLogic(logicToUse)); // Disambiguating the logic string by placing parentheses at appropriate places\n return parseResult.condition;\n };\n\n // Toggle between the Basic and Advanced modes\n // `forceToggle:true` is passed when switching from Advanced to Basic mode despite a loss of information\n const toggleMode = (forceToggle?: boolean): void => {\n setModeWarning(false); // Clear any previous warning\n if (isBasicMode) {\n // Update the logicString to match the operatorsList before switching the mode\n setLogicString(getLogicFromBasicMode(operatorsList));\n setBasicMode(false);\n } else if (forceToggle) {\n // If forcibly toggling from Advanced to Basic despite a loss of operators\n // Set up the default `AND` operator between all rows before switching to Basic mode\n setOperatorsList(new Array(conditionRows.length - 1).fill('AND'));\n setBasicMode(true);\n } else {\n // If switching from Advanced mode\n const condition = validateLogicString(logicString); // Validate the logicString. If it is an invalid, an appropriate error is shown for the user to act on\n if (condition !== null) {\n // If it's a valid condition, check if it's simple enough to be shown in Basic mode without any loss of information\n if (isBasicModeApplicable(condition)) {\n // If the logic is simple enough, identify the new set of operators before switching to Basic mode\n setOperatorsList(getBasicModeOperators(logicString));\n setBasicMode(true);\n } else {\n // If the logic is too complex show a warning for the user to act on\n setModeWarning(true);\n }\n }\n }\n };\n\n // Handle submission\n const handleSubmission = (): void => {\n setErrorIndicators(false); // Reset any previous flag\n setLogicError(null); // Clear any previous error\n\n // If there's a single empty condition, submit with an `undefined` value (useful for clearing a previous condition)\n if (conditionRows.length === 1 && conditionRows[0].lhs.field === '') {\n onConditionSubmit(undefined);\n return;\n }\n\n // Identify and indicate any invalid values in the condition rows\n const hasInvalidRows = conditionRows.some(row => !isValidCondition(row, fields, true));\n if (hasInvalidRows) {\n setErrorIndicators(true); // Enable inline error indications\n return;\n }\n\n // Validate the Logic string\n const logicToUse = isBasicMode ? getLogicFromBasicMode(operatorsList) : logicString; // If in Basic-mode, construct a different logicString based on the operatorsList\n const condition = validateLogicString(logicToUse); // This also takes care of showing an appropriate error feedback as needed\n if (condition !== null) {\n // Can be null when the logic string has errors\n onConditionSubmit(condition); // Submit the new condition\n }\n };\n\n const t = useI18n();\n\n return (\n <Flex container={{ direction: 'column', gap: 4 }}>\n {/* Condition Rows */}\n <div>\n {conditionRows.map(({ id, label, ...leaf }, index) => (\n <Fragment key={id}>\n {/* Row with the operator dropdown in Basic mode */}\n {isBasicMode && index > 0 && (\n <StyledRowWithSeparator\n container\n shaded={enableShading && operatorsList[index - 1] === 'AND'}\n >\n <MenuButton\n text={operatorsList[index - 1].toLowerCase()}\n variant='simple'\n menu={{\n items: [\n {\n id: 'AND',\n primary: 'and',\n onClick: () => updateOperator(index - 1, 'AND')\n },\n {\n id: 'OR',\n primary: 'or',\n onClick: () => updateOperator(index - 1, 'OR')\n }\n ]\n }}\n />\n </StyledRowWithSeparator>\n )}\n\n {/* Row with the AtomicCondition */}\n <StyledRow\n container={{ gap: 0.5, alignItems: 'start' }}\n shaded={isBasicMode && enableShading}\n >\n {/* Label */}\n {!isBasicMode && <StyledLabel>{label}</StyledLabel>}\n\n {/* Condition controls */}\n <Flex item={{ grow: 1 }}>\n <AtomicCondition\n condition={leaf}\n fields={fields}\n indicateErrors={showErrorIndicators}\n validComparators={validComparators}\n dateFunctions={dateFunctions}\n onChange={(newCondition: LeafCondition) => {\n const newRow = { id, label, ...newCondition };\n dispatch({ type: UPDATE_ROW, payload: { updateAt: index, newRow } });\n }}\n validRhsTypes={validRhsTypes}\n />\n </Flex>\n\n {/* Row actions */}\n <Button\n icon\n variant='simple'\n onClick={() => insertRow(index + 1)}\n aria-label={t('condition_builder_add_button_label')}\n >\n <Icon name='plus' />\n </Button>\n <Button\n icon\n variant='simple'\n onClick={() => removeRow(index)}\n aria-label={t('condition_builder_remove_button_label')}\n >\n <Icon name='trash' />\n </Button>\n </StyledRow>\n </Fragment>\n ))}\n </div>\n\n {/* LogicString input */}\n {!isBasicMode && (\n <div>\n <Input\n type='text'\n placeholder={t('condition_builder_advanced_condition_placeholder')}\n label={\n <>\n {t('condition_builder_advanced_condition_label')}&nbsp;\n {/* FIXME: TR */}\n <HelpButton>\n {`A logical expression representing an advanced condition.\\nUse numbers like 1,2,3,… to represent different condition rows.\\nUse ${\n disallowNOT ? 'AND/OR' : 'AND/OR/NOT'\n } operators and parentheses to construct advanced conditions.\\n\\nExample: ${\n disallowNOT ? '(1 OR 2) AND (3 OR 4 OR 5)' : '(1 AND 2) OR (3 AND NOT 4)'\n }`}\n </HelpButton>\n </>\n }\n value={logicString}\n onChange={(e: ChangeEvent<HTMLInputElement>) => setLogicString(e.target.value)}\n onBlur={() => validateLogicString(logicString)}\n status={logicError !== null ? 'error' : undefined}\n info={logicError}\n />\n </div>\n )}\n\n {/* Submit block */}\n <Flex container={{ direction: 'column', gap: 2 }}>\n {/* Banner to show a warning when switching from Advanced to Basic mode */}\n {showModeWarning && (\n <Banner\n id={createUID()}\n variant='warning'\n messages={[t('condition_builder_switch_banner_text')]}\n action={\n <Button name='force-mode-switch' variant='secondary' onClick={() => toggleMode(true)}>\n {t('condition_builder_confirm_button_label')}\n </Button>\n }\n onDismiss={() => setModeWarning(false)}\n />\n )}\n\n {/* Footer buttons */}\n <Flex container={{ justify: 'between' }}>\n <Button name='mode-switch' variant='simple' onClick={() => toggleMode(false)}>\n {isBasicMode\n ? t('condition_builder_advanced_mode_button_label')\n : t('condition_builder_basic_mode_button_label')}\n </Button>\n <Button name='condition-builder-submit' variant='primary' onClick={handleSubmission}>\n {t('condition_builder_submit_button_label')}\n </Button>\n </Flex>\n </Flex>\n </Flex>\n );\n};\nConditionBuilder.defaultProps = defaultProps;\n\nexport default ConditionBuilder;\n"]}
@@ -1,5 +1,30 @@
1
1
  import { BaseProps } from '@pega/cosmos-react-core';
2
- import { FieldType, Comparator, ComparatorsByType } from './core/types';
2
+ import { FieldType, Comparator, ComparatorsByType, DateFunction, RHSType, TimePeriod, DatePart } from './core/types';
3
+ /** RHS object with a Date function */
4
+ export interface RhsWithDateFunction {
5
+ /**
6
+ * Output format for the value varies based on the dateFunction:
7
+ * YEARS: First day of year as YYYY-MM-DD
8
+ * QUARTERS: First day of quarter as YYYY-MM-DD
9
+ * MONTHS: First day of month as YYYY-MM-DD
10
+ * WEEKS: First day of week as YYYY-MM-DD
11
+ * DAYS: Date as YYYY-MM-DD
12
+ * HOURS: YYYY-MM-DDTHH:mm:ss
13
+ * MONTHS_OF_YEAR: 1-12
14
+ * DAYS_OF_MONTH: 1-31
15
+ * DAYS_OF_WEEK: 1-7
16
+ */
17
+ value: string | number;
18
+ dateFunction: DateFunction;
19
+ }
20
+ /** RHS object with a Relative Date */
21
+ export interface RhsWithRelativeDate {
22
+ relativeDate: {
23
+ timePeriod: TimePeriod;
24
+ interval?: number;
25
+ datePart: DatePart;
26
+ };
27
+ }
3
28
  /** Type definition for the leaf-level nodes in nested conditions */
4
29
  export interface LeafCondition {
5
30
  comparator: Comparator;
@@ -12,7 +37,7 @@ export interface LeafCondition {
12
37
  value: string | number;
13
38
  } | {
14
39
  values: string[] | number[];
15
- };
40
+ } | RhsWithDateFunction | RhsWithRelativeDate;
16
41
  }
17
42
  /** Type definition for objects representing condition-rows in the builder UI */
18
43
  export interface ConditionRow extends LeafCondition {
@@ -53,6 +78,13 @@ export interface Field {
53
78
  */
54
79
  possibleValues?: string[];
55
80
  }
81
+ /** Valid date functions by field type */
82
+ export interface DateFunctionsByType {
83
+ /** Date functions to enable for DATE_TIME fields */
84
+ DATE_TIME: DateFunction[];
85
+ /** Date functions to enable for DATE_ONLY fields */
86
+ DATE_ONLY: DateFunction[];
87
+ }
56
88
  /** Type definition for the input props of ConditionBuilder */
57
89
  export default interface ConditionBuilderProps extends BaseProps {
58
90
  /** Metadata (data-model) for the Fields to use in the builder */
@@ -66,6 +98,14 @@ export default interface ConditionBuilderProps extends BaseProps {
66
98
  condition?: Condition;
67
99
  /** (Optional) Used to limit the Comparators allowed in the builder. */
68
100
  validComparators?: ComparatorsByType[];
101
+ /**
102
+ * (Optional) Pass this to control which all types of RHS are enabled in the component
103
+ * DEFAULT: Set(['LITERAL', 'FIELD'])
104
+ * NOTE: If enabling `DATE_FUNCTION`s, additionally pass a `dateFunctions` prop to specify which functions are enabled
105
+ */
106
+ validRhsTypes?: Set<RHSType>;
107
+ /** (Optional) When enabling 'DATE_FUNCTION's via `validRhsTypes`, pass this to specify which all date functions are applicable per field type */
108
+ dateFunctions?: DateFunctionsByType;
69
109
  /** (Optional) Pass this if the `NOT` operator should be considered as invalid */
70
110
  disallowNOT?: boolean;
71
111
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionBuilder.types.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAExE,oEAAoE;AACpE,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,UAAU,CAAC;IAEvB,GAAG,EAAE;QACH,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IAGF,GAAG,CAAC,EACA;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GACjB;QAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAC1B;QAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAA;KAAE,CAAC;CACrC;AAED,gFAAgF;AAChF,MAAM,WAAW,YAAa,SAAQ,aAAa;IACjD,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,oBAAY,SAAS,GACjB;IAAE,GAAG,EAAE,SAAS,EAAE,CAAA;CAAE,GACpB;IAAE,EAAE,EAAE,SAAS,EAAE,CAAA;CAAE,GACnB;IAAE,GAAG,EAAE,SAAS,CAAA;CAAE,GAClB;IAAE,SAAS,EAAE,aAAa,CAAA;CAAE,CAAC;AAEjC,2EAA2E;AAC3E,MAAM,WAAW,KAAK;IACpB,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC;IAEb,6FAA6F;IAC7F,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;;OAKG;IACH,IAAI,EAAE,SAAS,CAAC;IAEhB,yEAAyE;IACzE,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,8DAA8D;AAC9D,MAAM,CAAC,OAAO,WAAW,qBAAsB,SAAQ,SAAS;IAC9D,iEAAiE;IACjE,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB;;;OAGG;IACH,iBAAiB,EAAE,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,KAAK,IAAI,CAAC;IAE9D,6FAA6F;IAC7F,SAAS,CAAC,EAAE,SAAS,CAAC;IAEtB,uEAAuE;IACvE,gBAAgB,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAEvC,iFAAiF;IACjF,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB"}
1
+ {"version":3,"file":"ConditionBuilder.types.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EACL,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,YAAY,EACZ,OAAO,EACP,UAAU,EACV,QAAQ,EACT,MAAM,c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AE,MAAM,CAAC;IAEpB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,yCAAyC;AACzC,MAAM,WAAW,mBAAmB;IAClC,oDAAoD;IACpD,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,oDAAoD;IACpD,SAAS,EAAE,YAAY,EAAE,CAAC;CAC3B;AAED,8DAA8D;AAC9D,MAAM,CAAC,OAAO,WAAW,qBAAsB,SAAQ,SAAS;IAC9D,iEAAiE;IACjE,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB;;;OAGG;IACH,iBAAiB,EAAE,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,KAAK,IAAI,CAAC;IAE9D,6FAA6F;IAC7F,SAAS,CAAC,EAAE,SAAS,CAAC;IAEtB,uEAAuE;IACvE,gBAAgB,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAEvC;;;;OAIG;IACH,aAAa,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAE7B,iJAAiJ;IACjJ,aAAa,CAAC,EAAE,mBAAmB,CAAC;IAEpC,iFAAiF;IACjF,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB"}
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionBuilder.types.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.types.ts"],"names":[],"mappings":"","sourcesContent":["import { BaseProps } from '@pega/cosmos-react-core';\n\nimport { FieldType, Comparator, ComparatorsByType } from './core/types';\n\n/** Type definition for the leaf-level nodes in nested conditions */\nexport interface LeafCondition {\n comparator: Comparator;\n\n lhs: {\n field: string;\n };\n\n // Optional for some of the comparators like IS_TRUE, IS_NULL, etc.\n rhs?:\n | { field: string } // When comparing the LHS with another field\n | { value: string | number } // When comparing the LHS with a single literal value (for comparators like EQ, GTE etc.)\n | { values: string[] | number[] }; // When comparing the LHS with a list of literal values (for comparators like IN, NOT_IN etc.)\n}\n\n/** Type definition for objects representing condition-rows in the builder UI */\nexport interface ConditionRow extends LeafCondition {\n id: string; // To use as `key` prop when rendering a list of rows\n label: string; // Used to refer the row from a logic-string\n}\n\n/**\n * Type definition for simple/complex conditions\n * At a given node in the condition tree, it can have exactly one of the keys AND/OR/NOT/condition\n */\nexport type Condition =\n | { AND: Condition[] }\n | { OR: Condition[] }\n | { NOT: Condition }\n | { condition: LeafCondition };\n\n/** Type definition for the input Field objects for the ConditionBuilder */\nexport interface Field {\n /** Name of the Field. Saved as part of the output condition */\n name: string;\n\n /** (Optional) Display label for the Field. If none passed, the `name` itself will be used */\n label?: string;\n\n /**\n * Data-type for the field.\n * Has to be one of these values. Convert where necessary\n * e.g. Integer/Decimal/... should be used as `NUMBER`\n * e.g. Text(single value)/Picklist/... should be used as `TEXT`\n */\n type: FieldType;\n\n /** (Optional) Used to add the field to a group during field-selection */\n groupLabel?: string;\n\n /**\n * For TEXT fields, if a list of possible values is known ahead of time, they can be passed.\n * This enables users to select from those values instead of manually typing them\n */\n possibleValues?: string[];\n}\n\n/** Type definition for the input props of ConditionBuilder */\nexport default interface ConditionBuilderProps extends BaseProps {\n /** Metadata (data-model) for the Fields to use in the builder */\n fields: Field[];\n\n /**\n * Callback used from the builder's `Submit` button\n * Called with undefined when an empty condition is submitted (useful for clearing a previous condition)\n */\n onConditionSubmit: (condition: Condition | undefined) => void;\n\n /** (Optional) A seed condition for the builder. To use when editing an existing condition */\n condition?: Condition;\n\n /** (Optional) Used to limit the Comparators allowed in the builder. */\n validComparators?: ComparatorsByType[];\n\n /** (Optional) Pass this if the `NOT` operator should be considered as invalid */\n disallowNOT?: boolean;\n}\n"]}
1
+ {"version":3,"file":"ConditionBuilder.types.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.types.ts"],"names":[],"mappings":"","sourcesContent":["// cspell:ignore words DDTHH\nimport { BaseProps } from '@pega/cosmos-react-core';\n\nimport {\n FieldType,\n Comparator,\n ComparatorsByType,\n DateFunction,\n RHSType,\n TimePeriod,\n DatePart\n} from './core/types';\n\n/** RHS object with a Date function */\nexport interface RhsWithDateFunction {\n /**\n * Output format for the value varies based on the dateFunction:\n * YEARS: First day of year as YYYY-MM-DD\n * QUARTERS: First day of quarter as YYYY-MM-DD\n * MONTHS: First day of month as YYYY-MM-DD\n * WEEKS: First day of week as YYYY-MM-DD\n * DAYS: Date as YYYY-MM-DD\n * HOURS: YYYY-MM-DDTHH:mm:ss\n * MONTHS_OF_YEAR: 1-12\n * DAYS_OF_MONTH: 1-31\n * DAYS_OF_WEEK: 1-7\n */\n value: string | number;\n dateFunction: DateFunction;\n}\n\n/** RHS object with a Relative Date */\nexport interface RhsWithRelativeDate {\n relativeDate: {\n timePeriod: TimePeriod;\n interval?: number;\n datePart: DatePart;\n };\n}\n\n/** Type definition for the leaf-level nodes in nested conditions */\nexport interface LeafCondition {\n comparator: Comparator;\n\n lhs: {\n field: string;\n };\n\n // Optional for some of the comparators like IS_TRUE, IS_NULL, etc.\n rhs?:\n | { field: string } // When comparing the LHS with another field\n | { value: string | number } // When comparing the LHS with a single literal value (for comparators like EQ, GTE etc.)\n | { values: string[] | number[] } // When comparing the LHS with a list of literal values (for comparators like IN, NOT_IN etc.)\n | RhsWithDateFunction // When comparing a date field with a date function on RHS\n | RhsWithRelativeDate; // When comparing a date field with a symbolic date on RHS\n}\n\n/** Type definition for objects representing condition-rows in the builder UI */\nexport interface ConditionRow extends LeafCondition {\n id: string; // To use as `key` prop when rendering a list of rows\n label: string; // Used to refer the row from a logic-string\n}\n\n/**\n * Type definition for simple/complex conditions\n * At a given node in the condition tree, it can have exactly one of the keys AND/OR/NOT/condition\n */\nexport type Condition =\n | { AND: Condition[] }\n | { OR: Condition[] }\n | { NOT: Condition }\n | { condition: LeafCondition };\n\n/** Type definition for the input Field objects for the ConditionBuilder */\nexport interface Field {\n /** Name of the Field. Saved as part of the output condition */\n name: string;\n\n /** (Optional) Display label for the Field. If none passed, the `name` itself will be used */\n label?: string;\n\n /**\n * Data-type for the field.\n * Has to be one of these values. Convert where necessary\n * e.g. Integer/Decimal/... should be used as `NUMBER`\n * e.g. Text(single value)/Picklist/... should be used as `TEXT`\n */\n type: FieldType;\n\n /** (Optional) Used to add the field to a group during field-selection */\n groupLabel?: string;\n\n /**\n * For TEXT fields, if a list of possible values is known ahead of time, they can be passed.\n * This enables users to select from those values instead of manually typing them\n */\n possibleValues?: string[];\n}\n\n/** Valid date functions by field type */\nexport interface DateFunctionsByType {\n /** Date functions to enable for DATE_TIME fields */\n DATE_TIME: DateFunction[];\n /** Date functions to enable for DATE_ONLY fields */\n DATE_ONLY: DateFunction[];\n}\n\n/** Type definition for the input props of ConditionBuilder */\nexport default interface ConditionBuilderProps extends BaseProps {\n /** Metadata (data-model) for the Fields to use in the builder */\n fields: Field[];\n\n /**\n * Callback used from the builder's `Submit` button\n * Called with undefined when an empty condition is submitted (useful for clearing a previous condition)\n */\n onConditionSubmit: (condition: Condition | undefined) => void;\n\n /** (Optional) A seed condition for the builder. To use when editing an existing condition */\n condition?: Condition;\n\n /** (Optional) Used to limit the Comparators allowed in the builder. */\n validComparators?: ComparatorsByType[];\n\n /**\n * (Optional) Pass this to control which all types of RHS are enabled in the component\n * DEFAULT: Set(['LITERAL', 'FIELD'])\n * NOTE: If enabling `DATE_FUNCTION`s, additionally pass a `dateFunctions` prop to specify which functions are enabled\n */\n validRhsTypes?: Set<RHSType>;\n\n /** (Optional) When enabling 'DATE_FUNCTION's via `validRhsTypes`, pass this to specify which all date functions are applicable per field type */\n dateFunctions?: DateFunctionsByType;\n\n /** (Optional) Pass this if the `NOT` operator should be considered as invalid */\n disallowNOT?: boolean;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"FieldCondition.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/FieldCondition.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,iBAAiB,EAAY,MAAM,OAAO,CAAC;AAE3D,OAAO,EAAyB,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE9E,OAAO,mBAAmB,MAAM,wBAAwB,CAAC;AAIzD,kEAAkE;AAClE,QAAA,MAAM,cAAc,EAAE,iBAAiB,CAAC,mBAAmB,GAAG,YAAY,CA6CzE,CAAC;AAEF,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"FieldCondition.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/FieldCondition.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAY,MAAM,OAAO,CAAC;AAEpD,OAAO,EAAyB,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE9E,OAAO,mBAAmB,MAAM,wBAAwB,CAAC;AAIzD,kEAAkE;AAClE,QAAA,MAAM,cAAc,EAAE,iBAAiB,CAAC,mBAAmB,GAAG,YAAY,CA2DzE,CAAC;AAEF,eAAe,cAAc,CAAC"}