@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,21 @@
1
1
  // cSpell:words LPAREN RPAREN
2
2
  // FIXME: TR (Several constructs in this file need to be localized)
3
3
  import { hasProp } from '@pega/cosmos-react-core';
4
+ import { getFormattedValue } from '@pega/cosmos-react-core/lib/components/Number/utils';
5
+ import { getQuarter } from '@pega/cosmos-react-core/lib/components/DateTime/Input/utils';
4
6
  import { convertMsToTimeValue } from './time-utils';
5
7
  const LPAREN = '(';
6
8
  const RPAREN = ')';
9
+ export function formatRelativeDate(translate, timePeriod, datePart, interval) {
10
+ const translationKey = timePeriod === 'CURRENT'
11
+ ? `condition_builder_current_${datePart.toLowerCase().slice(0, -1)}`
12
+ : `condition_builder_${timePeriod.toLowerCase()}_X_${datePart.toLowerCase()}`;
13
+ return translate(translationKey, [interval ?? 0], {
14
+ count: interval ?? 0
15
+ });
16
+ }
7
17
  /** Returns a user-friendly text representation of a given leaf condition */
8
- function formatLeafCondition(leaf, fields) {
18
+ function formatLeafCondition(leaf, fields, translate, { locale = 'en-US' } = {}) {
9
19
  const { lhs, comparator, rhs } = leaf;
10
20
  // Determine texts for LHS and RHS
11
21
  const lhsField = fields.find(f => f.name === lhs.field); // Expecting valid inputs
@@ -18,15 +28,87 @@ function formatLeafCondition(leaf, fields) {
18
28
  rhsText = rhsField.label || rhsField.name; // label is optional
19
29
  }
20
30
  else if (hasProp(rhs, 'value')) {
21
- // If RHS is a single value
22
- if (lhsField.type === 'TIME_ONLY') {
23
- // For these cases, rhs.value is stored as # of milliseconds since day-start
24
- rhsText = convertMsToTimeValue(rhs.value);
31
+ if (hasProp(rhs, 'dateFunction')) {
32
+ // If RHS is a date function value
33
+ switch (rhs.dateFunction) {
34
+ case 'YEARS':
35
+ rhsText = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {
36
+ year: 'numeric'
37
+ });
38
+ break;
39
+ case 'QUARTERS': {
40
+ const formattedYear = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {
41
+ year: 'numeric'
42
+ });
43
+ const quarterNumber = getQuarter(rhs.value);
44
+ rhsText = `${translate(`date_quarter_q${quarterNumber}`, [formattedYear])}`;
45
+ break;
46
+ }
47
+ case 'MONTHS':
48
+ rhsText = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {
49
+ year: 'numeric',
50
+ month: 'short'
51
+ });
52
+ break;
53
+ case 'WEEKS':
54
+ rhsText = `Week of ${new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {
55
+ year: 'numeric',
56
+ month: 'short',
57
+ day: 'numeric'
58
+ })}`;
59
+ break;
60
+ case 'DAYS':
61
+ rhsText = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {
62
+ year: 'numeric',
63
+ month: 'short',
64
+ day: 'numeric'
65
+ });
66
+ break;
67
+ case 'HOURS':
68
+ rhsText = new Date(rhs.value).toLocaleString(locale, {
69
+ year: 'numeric',
70
+ month: 'short',
71
+ day: 'numeric',
72
+ hour: 'numeric',
73
+ hour12: true
74
+ });
75
+ break;
76
+ case 'MONTHS_OF_YEAR':
77
+ rhsText = new Date(2021, rhs.value - 1, 1).toLocaleString(locale, {
78
+ month: 'long'
79
+ });
80
+ break;
81
+ case 'DAYS_OF_MONTH':
82
+ rhsText = `Day ${rhs.value} of month`;
83
+ break;
84
+ case 'DAYS_OF_WEEK':
85
+ // Choosing Feb-2021 as it starts on a Monday
86
+ rhsText = new Date(2021, 1, rhs.value).toLocaleString(locale, {
87
+ weekday: 'long'
88
+ });
89
+ break;
90
+ default: // Not needed
91
+ }
25
92
  }
26
93
  else {
27
- rhsText = rhs.value.toString();
94
+ // If RHS is a single literal value
95
+ switch (lhsField.type) {
96
+ case 'TIME_ONLY':
97
+ // For these cases, rhs.value is stored as # of milliseconds since day-start
98
+ rhsText = convertMsToTimeValue(rhs.value);
99
+ break;
100
+ case 'NUMBER':
101
+ rhsText = getFormattedValue(rhs.value.toString(), locale, true, 4);
102
+ break;
103
+ default:
104
+ rhsText = rhs.value;
105
+ }
28
106
  }
29
107
  }
108
+ else if (hasProp(rhs, 'relativeDate')) {
109
+ const { relativeDate: { timePeriod, interval, datePart } } = rhs;
110
+ rhsText = formatRelativeDate(translate, timePeriod, datePart, interval);
111
+ }
30
112
  else {
31
113
  rhsText = rhs.values.join(', '); // If RHS is a list of values
32
114
  }
@@ -73,32 +155,32 @@ function formatLeafCondition(leaf, fields) {
73
155
  }
74
156
  }
75
157
  /** Returns a user-friendly text representation of the given node in a condition */
76
- function formatConditionNode(node, fields) {
158
+ function formatConditionNode(node, fields, translate, options) {
77
159
  if (hasProp(node, 'AND')) {
78
- const childStrings = node.AND.map(n => formatConditionNode(n, fields));
160
+ const childStrings = node.AND.map(n => formatConditionNode(n, fields, translate, options));
79
161
  return `(${childStrings.join(' AND ')})`;
80
162
  }
81
163
  if (hasProp(node, 'OR')) {
82
- const childStrings = node.OR.map(n => formatConditionNode(n, fields));
164
+ const childStrings = node.OR.map(n => formatConditionNode(n, fields, translate, options));
83
165
  return `(${childStrings.join(' OR ')})`;
84
166
  }
85
167
  if (hasProp(node, 'NOT')) {
86
- const childString = formatConditionNode(node.NOT, fields);
168
+ const childString = formatConditionNode(node.NOT, fields, translate, options);
87
169
  if (childString.startsWith(LPAREN) && childString.endsWith(RPAREN)) {
88
170
  // Avoid double brackets when the child node is an AND/OR node
89
171
  return `NOT ${childString}`;
90
172
  }
91
173
  return `NOT (${childString})`;
92
174
  }
93
- return formatLeafCondition(node.condition, fields); // If leaf-level is reached
175
+ return formatLeafCondition(node.condition, fields, translate, options); // If leaf-level is reached
94
176
  }
95
177
  /**
96
178
  * Returns a user-friendly text representation of a given complex condition
97
179
  * The input `fields` are used to look up display labels for the fields
98
180
  */
99
- export default function formatCondition(condition, fields) {
181
+ export default function formatCondition(condition, fields, translate, options) {
100
182
  // Recursively format the tree, starting at the root node
101
- let text = formatConditionNode(condition, fields);
183
+ let text = formatConditionNode(condition, fields, translate, options);
102
184
  // If the root node is AND/OR, there will be extra parentheses. Remove them
103
185
  if (text.startsWith(LPAREN) && text.endsWith(RPAREN)) {
104
186
  text = text.slice(1, -1);
@@ -1 +1 @@
1
- {"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/formatter.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,mEAAmE;AAEnE,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAIlD,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD,MAAM,MAAM,GAAG,GAAG,CAAC;AACnB,MAAM,MAAM,GAAG,GAAG,CAAC;AAEnB,4EAA4E;AAC5E,SAAS,mBAAmB,CAAC,IAAmB,EAAE,MAAe;IAC/D,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAEtC,kCAAkC;IAClC,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,KAAK,CAAU,CAAC,CAAC,yBAAyB;I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AAY,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,mBAAmB,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;QACtE,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;KACzC;IAED,IAAI,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE;QACxB,MAAM,WAAW,GAAG,mBAAmB,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC1D,IAAI,WAAW,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YAClE,8DAA8D;YAC9D,OAAO,OAAO,WAAW,EAAE,CAAC;SAC7B;QACD,OAAO,QAAQ,WAAW,GAAG,CAAC;KAC/B;IAED,OAAO,mBAAmB,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,2BAA2B;AACjF,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,SAAoB,EAAE,MAAe;IAC3E,yDAAyD;IACzD,IAAI,IAAI,GAAG,mBAAmB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAElD,2EAA2E;IAC3E,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QACpD,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;KAC1B;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["// cSpell:words LPAREN RPAREN\n// FIXME: TR (Several constructs in this file need to be localized)\n\nimport { hasProp } from '@pega/cosmos-react-core';\n\nimport { Condition, LeafCondition, Field } from '../ConditionBuilder.types';\n\nimport { convertMsToTimeValue } from './time-utils';\n\nconst LPAREN = '(';\nconst RPAREN = ')';\n\n/** Returns a user-friendly text representation of a given leaf condition */\nfunction formatLeafCondition(leaf: LeafCondition, fields: Field[]): string {\n const { lhs, comparator, rhs } = leaf;\n\n // Determine texts for LHS and RHS\n const lhsField = fields.find(f => f.name === lhs.field) as Field; // Expecting valid inputs\n const lhsText = lhsField.label || lhsField.name; // label is optional\n let rhsText = '';\n if (rhs) {\n if (hasProp(rhs, 'field')) {\n // If RHS is another field\n const rhsField = fields.find(f => f.name === rhs.field) as Field; // Expecting valid inputs\n rhsText = rhsField.label || rhsField.name; // label is optional\n } else if (hasProp(rhs, 'value')) {\n // If RHS is a single value\n if (lhsField.type === 'TIME_ONLY') {\n // For these cases, rhs.value is stored as # of milliseconds since day-start\n rhsText = convertMsToTimeValue(rhs.value as number);\n } else {\n rhsText = rhs.value.toString();\n }\n } else {\n rhsText = rhs.values.join(', '); // If RHS is a list of values\n }\n }\n\n switch (comparator) {\n case 'IS_NULL':\n return `${lhsText} is null`;\n case 'IS_NOT_NULL':\n return `${lhsText} is not null`;\n case 'IS_TRUE':\n return `${lhsText} is true`;\n case 'IS_FALSE':\n return `${lhsText} is false`;\n case 'EQ':\n return `${lhsText} is ${rhsText}`;\n case 'NEQ':\n return `${lhsText} isn't ${rhsText}`;\n case 'IN':\n return `${lhsText} is among ${rhsText}`;\n case 'NOT_IN':\n return `${lhsText} is not among ${rhsText}`;\n case 'GT':\n return `${lhsText} > ${rhsText}`;\n case 'GTE':\n return `${lhsText} >= ${rhsText}`;\n case 'LT':\n return `${lhsText} < ${rhsText}`;\n case 'LTE':\n return `${lhsText} <= ${rhsText}`;\n case 'STARTS_WITH':\n return `${lhsText} starts with ${rhsText}`;\n case 'NOT_STARTS_WITH':\n return `${lhsText} doesn't start with ${rhsText}`;\n case 'ENDS_WITH':\n return `${lhsText} ends with ${rhsText}`;\n case 'NOT_ENDS_WITH':\n return `${lhsText} doesn't end with ${rhsText}`;\n case 'CONTAINS':\n return `${lhsText} contains ${rhsText}`;\n case 'NOT_CONTAINS':\n return `${lhsText} doesn't contain ${rhsText}`;\n default:\n return ''; // Not needed\n }\n}\n\n/** Returns a user-friendly text representation of the given node in a condition */\nfunction formatConditionNode(node: Condition, fields: Field[]): string {\n if (hasProp(node, 'AND')) {\n const childStrings = node.AND.map(n => formatConditionNode(n, fields));\n return `(${childStrings.join(' AND ')})`;\n }\n\n if (hasProp(node, 'OR')) {\n const childStrings = node.OR.map(n => formatConditionNode(n, fields));\n return `(${childStrings.join(' OR ')})`;\n }\n\n if (hasProp(node, 'NOT')) {\n const childString = formatConditionNode(node.NOT, fields);\n if (childString.startsWith(LPAREN) && childString.endsWith(RPAREN)) {\n // Avoid double brackets when the child node is an AND/OR node\n return `NOT ${childString}`;\n }\n return `NOT (${childString})`;\n }\n\n return formatLeafCondition(node.condition, fields); // If leaf-level is reached\n}\n\n/**\n * Returns a user-friendly text representation of a given complex condition\n * The input `fields` are used to look up display labels for the fields\n */\nexport default function formatCondition(condition: Condition, fields: Field[]): string {\n // Recursively format the tree, starting at the root node\n let text = formatConditionNode(condition, fields);\n\n // If the root node is AND/OR, there will be extra parentheses. Remove them\n if (text.startsWith(LPAREN) && text.endsWith(RPAREN)) {\n text = text.slice(1, -1);\n }\n\n return text;\n}\n"]}
1
+ {"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/formatter.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,mEAAmE;AACnE,OAAO,EAAE,OAAO,EAAmB,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qDAAqD,CAAC;AAExF,OAAO,EAAE,UAAU,EAAE,MAAM,6DAA6D,CAAC;AAKzF,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD,MAAM,MAAM,GAAG,GAAG,CAAC;AACnB,MAAM,MAAM,GAAG,GAAG,CAAC;AAOnB,MAAM,UAAU,kBAAkB,CAChC,SAA+C,EAC/C,UAAsB,EACtB,QAAkB,EAClB,QAAiB;IAEjB,MAAM,cAA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,CAAC,MAAM,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YAClE,8DAA8D;YAC9D,OAAO,OAAO,WAAW,EAAE,CAAC;SAC7B;QACD,OAAO,QAAQ,WAAW,GAAG,CAAC;KAC/B;IAED,OAAO,mBAAmB,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,2BAA2B;AACrG,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,SAAoB,EACpB,MAAe,EACf,SAA+C,EAC/C,OAAgC;IAEhC,yDAAyD;IACzD,IAAI,IAAI,GAAG,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IAEtE,2EAA2E;IAC3E,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QACpD,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;KAC1B;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["// cSpell:words LPAREN RPAREN\n// FIXME: TR (Several constructs in this file need to be localized)\nimport { hasProp, TranslationPack } from '@pega/cosmos-react-core';\nimport { getFormattedValue } from '@pega/cosmos-react-core/lib/components/Number/utils';\nimport { TranslationFunction } from '@pega/cosmos-react-core/lib/i18n/translate';\nimport { getQuarter } from '@pega/cosmos-react-core/lib/components/DateTime/Input/utils';\n\nimport { Condition, LeafCondition, Field } from '../ConditionBuilder.types';\n\nimport { DatePart, TimePeriod } from './types';\nimport { convertMsToTimeValue } from './time-utils';\n\nconst LPAREN = '(';\nconst RPAREN = ')';\n\n/** Options object optionally passed to formatCondition method. */\ninterface ConditionFormatOptions {\n locale?: string;\n}\n\nexport function formatRelativeDate(\n translate: TranslationFunction<TranslationPack>,\n timePeriod: TimePeriod,\n datePart: DatePart,\n interval?: number\n): string {\n const translationKey =\n timePeriod === 'CURRENT'\n ? `condition_builder_current_${datePart.toLowerCase().slice(0, -1)}`\n : `condition_builder_${timePeriod.toLowerCase()}_X_${datePart.toLowerCase()}`;\n return translate(translationKey as keyof TranslationPack, [interval ?? 0], {\n count: interval ?? 0\n });\n}\n\n/** Returns a user-friendly text representation of a given leaf condition */\nfunction formatLeafCondition(\n leaf: LeafCondition,\n fields: Field[],\n translate: TranslationFunction<TranslationPack>,\n { locale = 'en-US' }: ConditionFormatOptions = {}\n): string {\n const { lhs, comparator, rhs } = leaf;\n\n // Determine texts for LHS and RHS\n const lhsField = fields.find(f => f.name === lhs.field) as Field; // Expecting valid inputs\n const lhsText = lhsField.label || lhsField.name; // label is optional\n let rhsText = '';\n if (rhs) {\n if (hasProp(rhs, 'field')) {\n // If RHS is another field\n const rhsField = fields.find(f => f.name === rhs.field) as Field; // Expecting valid inputs\n rhsText = rhsField.label || rhsField.name; // label is optional\n } else if (hasProp(rhs, 'value')) {\n if (hasProp(rhs, 'dateFunction')) {\n // If RHS is a date function value\n switch (rhs.dateFunction) {\n case 'YEARS':\n rhsText = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric'\n });\n break;\n case 'QUARTERS': {\n const formattedYear = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric'\n });\n const quarterNumber = getQuarter(rhs.value);\n rhsText = `${translate(`date_quarter_q${quarterNumber}`, [formattedYear])}`;\n break;\n }\n case 'MONTHS':\n rhsText = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric',\n month: 'short'\n });\n break;\n case 'WEEKS':\n rhsText = `Week of ${new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric',\n month: 'short',\n day: 'numeric'\n })}`;\n break;\n case 'DAYS':\n rhsText = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric',\n month: 'short',\n day: 'numeric'\n });\n break;\n case 'HOURS':\n rhsText = new Date(rhs.value).toLocaleString(locale, {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n hour: 'numeric',\n hour12: true\n });\n break;\n case 'MONTHS_OF_YEAR':\n rhsText = new Date(2021, (rhs.value as number) - 1, 1).toLocaleString(locale, {\n month: 'long'\n });\n break;\n case 'DAYS_OF_MONTH':\n rhsText = `Day ${rhs.value} of month`;\n break;\n case 'DAYS_OF_WEEK':\n // Choosing Feb-2021 as it starts on a Monday\n rhsText = new Date(2021, 1, rhs.value as number).toLocaleString(locale, {\n weekday: 'long'\n });\n break;\n default: // Not needed\n }\n } else {\n // If RHS is a single literal value\n switch (lhsField.type) {\n case 'TIME_ONLY':\n // For these cases, rhs.value is stored as # of milliseconds since day-start\n rhsText = convertMsToTimeValue(rhs.value as number);\n break;\n case 'NUMBER':\n rhsText = getFormattedValue(rhs.value.toString(), locale, true, 4);\n break;\n default:\n rhsText = rhs.value as string;\n }\n }\n } else if (hasProp(rhs, 'relativeDate')) {\n const {\n relativeDate: { timePeriod, interval, datePart }\n } = rhs;\n rhsText = formatRelativeDate(translate, timePeriod, datePart, interval);\n } else {\n rhsText = rhs.values.join(', '); // If RHS is a list of values\n }\n }\n\n switch (comparator) {\n case 'IS_NULL':\n return `${lhsText} is null`;\n case 'IS_NOT_NULL':\n return `${lhsText} is not null`;\n case 'IS_TRUE':\n return `${lhsText} is true`;\n case 'IS_FALSE':\n return `${lhsText} is false`;\n case 'EQ':\n return `${lhsText} is ${rhsText}`;\n case 'NEQ':\n return `${lhsText} isn't ${rhsText}`;\n case 'IN':\n return `${lhsText} is among ${rhsText}`;\n case 'NOT_IN':\n return `${lhsText} is not among ${rhsText}`;\n case 'GT':\n return `${lhsText} > ${rhsText}`;\n case 'GTE':\n return `${lhsText} >= ${rhsText}`;\n case 'LT':\n return `${lhsText} < ${rhsText}`;\n case 'LTE':\n return `${lhsText} <= ${rhsText}`;\n case 'STARTS_WITH':\n return `${lhsText} starts with ${rhsText}`;\n case 'NOT_STARTS_WITH':\n return `${lhsText} doesn't start with ${rhsText}`;\n case 'ENDS_WITH':\n return `${lhsText} ends with ${rhsText}`;\n case 'NOT_ENDS_WITH':\n return `${lhsText} doesn't end with ${rhsText}`;\n case 'CONTAINS':\n return `${lhsText} contains ${rhsText}`;\n case 'NOT_CONTAINS':\n return `${lhsText} doesn't contain ${rhsText}`;\n default:\n return ''; // Not needed\n }\n}\n\n/** Returns a user-friendly text representation of the given node in a condition */\nfunction formatConditionNode(\n node: Condition,\n fields: Field[],\n translate: TranslationFunction<TranslationPack>,\n options?: ConditionFormatOptions\n): string {\n if (hasProp(node, 'AND')) {\n const childStrings = node.AND.map(n => formatConditionNode(n, fields, translate, options));\n return `(${childStrings.join(' AND ')})`;\n }\n\n if (hasProp(node, 'OR')) {\n const childStrings = node.OR.map(n => formatConditionNode(n, fields, translate, options));\n return `(${childStrings.join(' OR ')})`;\n }\n\n if (hasProp(node, 'NOT')) {\n const childString = formatConditionNode(node.NOT, fields, translate, options);\n if (childString.startsWith(LPAREN) && childString.endsWith(RPAREN)) {\n // Avoid double brackets when the child node is an AND/OR node\n return `NOT ${childString}`;\n }\n return `NOT (${childString})`;\n }\n\n return formatLeafCondition(node.condition, fields, translate, options); // If leaf-level is reached\n}\n\n/**\n * Returns a user-friendly text representation of a given complex condition\n * The input `fields` are used to look up display labels for the fields\n */\nexport default function formatCondition(\n condition: Condition,\n fields: Field[],\n translate: TranslationFunction<TranslationPack>,\n options?: ConditionFormatOptions\n): string {\n // Recursively format the tree, starting at the root node\n let text = formatConditionNode(condition, fields, translate, options);\n\n // If the root node is AND/OR, there will be extra parentheses. Remove them\n if (text.startsWith(LPAREN) && text.endsWith(RPAREN)) {\n text = text.slice(1, -1);\n }\n\n return text;\n}\n"]}
@@ -0,0 +1,7 @@
1
+ import './extendDayJs';
2
+ import { Condition, Field } from '../ConditionBuilder.types';
3
+ /** This function transforms Conditions with Relative Dates into Conditions with Date Ranges.
4
+ * Do not use this function unless you need to convert Relative Dates into Date Ranges.
5
+ */
6
+ export default function transformComplexCondition(condition: Condition, fields: Field[], currentDateTime?: string): Condition;
7
+ //# sourceMappingURL=transformer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/transformer.ts"],"names":[],"mappings":"AAGA,OAAO,eAAe,CAAC;AAIvB,OAAO,EAAE,SAAS,EAAiB,KAAK,EAAE,MAAM,2BAA2B,CAAC;AA+I5E;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,KAAK,EAAE,EACf,eAAe,CAAC,EAAE,MAAM,GACvB,SAAS,CA0BX"}
@@ -0,0 +1,164 @@
1
+ // cSpell:words DDTHH
2
+ import dayjs from 'dayjs';
3
+ import './extendDayJs';
4
+ import { hasProp } from '@pega/cosmos-react-core';
5
+ const dayjsDateParts = {
6
+ MINUTES: 'minute',
7
+ HOURS: 'hour',
8
+ DAYS: 'day',
9
+ WEEKS: 'week',
10
+ QUARTERS: 'quarter',
11
+ MONTHS: 'month',
12
+ YEARS: 'year'
13
+ };
14
+ function transformLeafCondition(node, fields, currentDateTime) {
15
+ if (node.rhs && hasProp(node.rhs, 'relativeDate')) {
16
+ const { lhs, comparator, rhs } = node;
17
+ const field = fields.find(f => f.name === lhs.field);
18
+ if (field === undefined) {
19
+ return {
20
+ condition: node
21
+ };
22
+ }
23
+ const { timePeriod, interval, datePart } = rhs.relativeDate;
24
+ const dateFormat = field.type === 'DATE_ONLY' ? 'YYYY-MM-DD' : 'YYYY-MM-DDTHH:mm:ss';
25
+ const dayjsDatePart = dayjsDateParts[datePart];
26
+ const now = dayjs(currentDateTime);
27
+ let startDate = now;
28
+ let endDate = now;
29
+ if (timePeriod === 'CURRENT') {
30
+ startDate = now.startOf(dayjsDatePart);
31
+ endDate = now.endOf(dayjsDatePart);
32
+ }
33
+ else if (timePeriod === 'LAST' && interval && interval >= 1) {
34
+ startDate = now.subtract(interval, dayjsDatePart);
35
+ }
36
+ else if (timePeriod === 'PREVIOUS' && interval && interval >= 1) {
37
+ startDate = now.startOf(dayjsDatePart).subtract(interval, dayjsDatePart);
38
+ endDate = now.subtract(1, dayjsDatePart).endOf(dayjsDatePart);
39
+ }
40
+ else if (timePeriod === 'NEXT' && interval && interval >= 1) {
41
+ startDate = now.add(1, dayjsDatePart).startOf(dayjsDatePart);
42
+ endDate = now.endOf(dayjsDatePart).add(interval, dayjsDatePart);
43
+ }
44
+ switch (comparator) {
45
+ case 'EQ':
46
+ return {
47
+ AND: [
48
+ {
49
+ condition: {
50
+ lhs: node.lhs,
51
+ comparator: 'LTE',
52
+ rhs: {
53
+ value: endDate.format(dateFormat)
54
+ }
55
+ }
56
+ },
57
+ {
58
+ condition: {
59
+ lhs: node.lhs,
60
+ comparator: 'GTE',
61
+ rhs: {
62
+ value: startDate.format(dateFormat)
63
+ }
64
+ }
65
+ }
66
+ ]
67
+ };
68
+ case 'NEQ':
69
+ return {
70
+ OR: [
71
+ {
72
+ condition: {
73
+ lhs: node.lhs,
74
+ comparator: 'GT',
75
+ rhs: {
76
+ value: endDate.format(dateFormat)
77
+ }
78
+ }
79
+ },
80
+ {
81
+ condition: {
82
+ lhs: node.lhs,
83
+ comparator: 'LT',
84
+ rhs: {
85
+ value: startDate.format(dateFormat)
86
+ }
87
+ }
88
+ }
89
+ ]
90
+ };
91
+ case 'GT':
92
+ return {
93
+ condition: {
94
+ lhs: node.lhs,
95
+ comparator: 'GT',
96
+ rhs: {
97
+ value: endDate.format(dateFormat)
98
+ }
99
+ }
100
+ };
101
+ case 'GTE':
102
+ return {
103
+ condition: {
104
+ lhs: node.lhs,
105
+ comparator: 'GTE',
106
+ rhs: {
107
+ value: startDate.format(dateFormat)
108
+ }
109
+ }
110
+ };
111
+ case 'LT':
112
+ return {
113
+ condition: {
114
+ lhs: node.lhs,
115
+ comparator: 'LT',
116
+ rhs: {
117
+ value: startDate.format(dateFormat)
118
+ }
119
+ }
120
+ };
121
+ case 'LTE':
122
+ return {
123
+ condition: {
124
+ lhs: node.lhs,
125
+ comparator: 'LTE',
126
+ rhs: {
127
+ value: endDate.format(dateFormat)
128
+ }
129
+ }
130
+ };
131
+ default:
132
+ return {
133
+ condition: node
134
+ };
135
+ }
136
+ }
137
+ return {
138
+ condition: node
139
+ };
140
+ }
141
+ /** This function transforms Conditions with Relative Dates into Conditions with Date Ranges.
142
+ * Do not use this function unless you need to convert Relative Dates into Date Ranges.
143
+ */
144
+ export default function transformComplexCondition(condition, fields, currentDateTime) {
145
+ if (hasProp(condition, 'AND')) {
146
+ const childNodes = condition.AND.map(n => transformComplexCondition(n, fields, currentDateTime));
147
+ return {
148
+ AND: childNodes
149
+ };
150
+ }
151
+ if (hasProp(condition, 'OR')) {
152
+ const childNodes = condition.OR.map(n => transformComplexCondition(n, fields, currentDateTime));
153
+ return {
154
+ OR: childNodes
155
+ };
156
+ }
157
+ if (hasProp(condition, 'NOT')) {
158
+ return {
159
+ NOT: transformComplexCondition(condition.NOT, fields, currentDateTime)
160
+ };
161
+ }
162
+ return transformLeafCondition(condition.condition, fields, currentDateTime);
163
+ }
164
+ //# sourceMappingURL=transformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformer.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/transformer.ts"],"names":[],"mappings":"AAAA,qBAAqB;AAErB,OAAO,KAAoB,MAAM,OAAO,CAAC;AACzC,OAAO,eAAe,CAAC;AAEvB,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAMlD,MAAM,cAAc,GAAgC;IAClD,OAAO,EAAE,QAAQ;IACjB,KAAK,EAAE,MAAM;IACb,IAAI,EAAE,KAAK;IACX,KAAK,EAAE,MAAmB;IAC1B,QAAQ,EAAE,SAAS;IACnB,MAAM,EAAE,OAAO;IACf,KAAK,EAAE,MAAM;CACd,CAAC;AAEF,SAAS,sBAAsB,CAC7B,IAAmB,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AC,CAAC,CAAC,EAAE,CACpD,yBAAyB,CAAC,CAAC,EAAE,MAAM,EAAE,eAAe,CAAC,CACtD,CAAC;QACF,OAAO;YACL,GAAG,EAAE,UAAU;SAChB,CAAC;KACH;IAED,IAAI,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE;QAC5B,MAAM,UAAU,GAAgB,SAAS,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CACnD,yBAAyB,CAAC,CAAC,EAAE,MAAM,EAAE,eAAe,CAAC,CACtD,CAAC;QACF,OAAO;YACL,EAAE,EAAE,UAAU;SACf,CAAC;KACH;IAED,IAAI,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE;QAC7B,OAAO;YACL,GAAG,EAAE,yBAAyB,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,eAAe,CAAC;SACvE,CAAC;KACH;IAED,OAAO,sBAAsB,CAAC,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC;AAC9E,CAAC","sourcesContent":["// cSpell:words DDTHH\n\nimport dayjs, { QUnitType } from 'dayjs';\nimport './extendDayJs';\n\nimport { hasProp } from '@pega/cosmos-react-core';\n\nimport { Condition, LeafCondition, Field } from '../ConditionBuilder.types';\n\nimport { DatePart } from './types';\n\nconst dayjsDateParts: Record<DatePart, QUnitType> = {\n MINUTES: 'minute',\n HOURS: 'hour',\n DAYS: 'day',\n WEEKS: 'week' as QUnitType,\n QUARTERS: 'quarter',\n MONTHS: 'month',\n YEARS: 'year'\n};\n\nfunction transformLeafCondition(\n node: LeafCondition,\n fields: Field[],\n currentDateTime?: string\n): Condition {\n if (node.rhs && hasProp(node.rhs, 'relativeDate')) {\n const { lhs, comparator, rhs } = node;\n const field = fields.find(f => f.name === lhs.field);\n if (field === undefined) {\n return {\n condition: node\n };\n }\n const { timePeriod, interval, datePart } = rhs.relativeDate;\n const dateFormat = field.type === 'DATE_ONLY' ? 'YYYY-MM-DD' : 'YYYY-MM-DDTHH:mm:ss';\n const dayjsDatePart = dayjsDateParts[datePart];\n const now = dayjs(currentDateTime);\n let startDate = now;\n let endDate = now;\n if (timePeriod === 'CURRENT') {\n startDate = now.startOf(dayjsDatePart);\n endDate = now.endOf(dayjsDatePart);\n } else if (timePeriod === 'LAST' && interval && interval >= 1) {\n startDate = now.subtract(interval, dayjsDatePart);\n } else if (timePeriod === 'PREVIOUS' && interval && interval >= 1) {\n startDate = now.startOf(dayjsDatePart).subtract(interval, dayjsDatePart);\n endDate = now.subtract(1, dayjsDatePart).endOf(dayjsDatePart);\n } else if (timePeriod === 'NEXT' && interval && interval >= 1) {\n startDate = now.add(1, dayjsDatePart).startOf(dayjsDatePart);\n endDate = now.endOf(dayjsDatePart).add(interval, dayjsDatePart);\n }\n switch (comparator) {\n case 'EQ':\n return {\n AND: [\n {\n condition: {\n lhs: node.lhs,\n comparator: 'LTE',\n rhs: {\n value: endDate.format(dateFormat)\n }\n }\n },\n {\n condition: {\n lhs: node.lhs,\n comparator: 'GTE',\n rhs: {\n value: startDate.format(dateFormat)\n }\n }\n }\n ]\n };\n case 'NEQ':\n return {\n OR: [\n {\n condition: {\n lhs: node.lhs,\n comparator: 'GT',\n rhs: {\n value: endDate.format(dateFormat)\n }\n }\n },\n {\n condition: {\n lhs: node.lhs,\n comparator: 'LT',\n rhs: {\n value: startDate.format(dateFormat)\n }\n }\n }\n ]\n };\n case 'GT':\n return {\n condition: {\n lhs: node.lhs,\n comparator: 'GT',\n rhs: {\n value: endDate.format(dateFormat)\n }\n }\n };\n case 'GTE':\n return {\n condition: {\n lhs: node.lhs,\n comparator: 'GTE',\n rhs: {\n value: startDate.format(dateFormat)\n }\n }\n };\n case 'LT':\n return {\n condition: {\n lhs: node.lhs,\n comparator: 'LT',\n rhs: {\n value: startDate.format(dateFormat)\n }\n }\n };\n case 'LTE':\n return {\n condition: {\n lhs: node.lhs,\n comparator: 'LTE',\n rhs: {\n value: endDate.format(dateFormat)\n }\n }\n };\n default:\n return {\n condition: node\n };\n }\n }\n return {\n condition: node\n };\n}\n\n/** This function transforms Conditions with Relative Dates into Conditions with Date Ranges.\n * Do not use this function unless you need to convert Relative Dates into Date Ranges.\n */\nexport default function transformComplexCondition(\n condition: Condition,\n fields: Field[],\n currentDateTime?: string\n): Condition {\n if (hasProp(condition, 'AND')) {\n const childNodes: Condition[] = condition.AND.map(n =>\n transformComplexCondition(n, fields, currentDateTime)\n );\n return {\n AND: childNodes\n };\n }\n\n if (hasProp(condition, 'OR')) {\n const childNodes: Condition[] = condition.OR.map(n =>\n transformComplexCondition(n, fields, currentDateTime)\n );\n return {\n OR: childNodes\n };\n }\n\n if (hasProp(condition, 'NOT')) {\n return {\n NOT: transformComplexCondition(condition.NOT, fields, currentDateTime)\n };\n }\n\n return transformLeafCondition(condition.condition, fields, currentDateTime);\n}\n"]}
@@ -36,6 +36,12 @@ export declare type ComparatorsByType = {
36
36
  type: 'TIME_ONLY';
37
37
  comparators: DateTimeComparator[];
38
38
  };
39
- export declare type RHSType = 'LITERAL' | 'FIELD';
39
+ export declare type RHSType = 'LITERAL' | 'FIELD' | 'DATE_FUNCTION' | 'RELATIVE_DATE';
40
+ /** Date function types supported on the RHS */
41
+ export declare type DateFunction = 'YEARS' | 'QUARTERS' | 'MONTHS' | 'WEEKS' | 'DAYS' | 'HOURS' | 'MONTHS_OF_YEAR' | 'DAYS_OF_MONTH' | 'DAYS_OF_WEEK';
42
+ /** "Relative Date" Time Periods supported on the RHS */
43
+ export declare type TimePeriod = 'LAST' | 'PREVIOUS' | 'CURRENT' | 'NEXT';
44
+ /** "Relative Date" Date Parts supported on the RHS */
45
+ export declare type DatePart = 'MINUTES' | 'HOURS' | 'DAYS' | 'WEEKS' | 'MONTHS' | 'QUARTERS' | 'YEARS';
40
46
  export {};
41
47
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/types.ts"],"names":[],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,eAAe,GAAG,cAAc,CAAC;AAE/F,qEAAqE;AACrE,aAAK,kBAAkB,GAAG,kBAAkB,GAAG,eAAe,GAAG,cAAc,CAAC;AAEhF,qEAAqE;AACrE,oBAAY,iBAAiB,GACzB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,WAAW,EAAE,iBAAiB,EAAE,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,cAAc,EAAE,CAAA;CAAE,GAC/C;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,WAAW,EAAE,gBAAgB,EAAE,CAAA;CAAE,GACnD;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,WAAW,EAAE,kBAAkB,EAAE,CAAA;CAAE,GACxD;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,WAAW,EAAE,kBAAkB,EAAE,CAAA;CAAE,GACxD;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,WAAW,EAAE,kBAAkB,EAAE,CAAA;CAAE,CAAC;AAE7D,oBAAY,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,eAAe,GAAG,eAAe,CAAC;AAE9E,+CAA+C;AAC/C,oBAAY,YAAY,GACpB,OAAO,GACP,UAAU,GACV,QAAQ,GACR,OAAO,GACP,MAAM,GACN,OAAO,GACP,gBAAgB,GAChB,eAAe,GACf,cAAc,CAAC;AAEnB,wDAAwD;AACxD,oBAAY,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,SAAS,GAAG,MAAM,CAAC;AAElE,sDAAsD;AACtD,oBAAY,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/types.ts"],"names":[],"mappings":"","sourcesContent":["/** Supported field types */\nexport type FieldType = 'BOOLEAN' | 'TEXT' | 'NUMBER' | 'DATE_TIME' | 'DATE_ONLY' | 'TIME_ONLY';\n\ntype NullComparator = 'IS_NULL' | 'IS_NOT_NULL';\ntype EqualityComparator = 'EQ' | 'NEQ';\ntype RangeComparator = 'GT' | 'GTE' | 'LT' | 'LTE';\ntype TruenessComparator = 'IS_TRUE' | 'IS_FALSE';\ntype ListComparator = 'IN' | 'NOT_IN';\ntype TextMatchComparator =\n | 'STARTS_WITH'\n | 'NOT_STARTS_WITH'\n | 'ENDS_WITH'\n | 'NOT_ENDS_WITH'\n | 'CONTAINS'\n | 'NOT_CONTAINS';\n\n/** All supported Comparators */\nexport type Comparator =\n | TruenessComparator\n | NullComparator\n | EqualityComparator\n | ListComparator\n | RangeComparator\n | TextMatchComparator;\n\n/** Comparators supported for BOOLEAN fields */\ntype BooleanComparator = TruenessComparator | EqualityComparator | NullComparator;\n\n/** Comparators supported for TEXT fields */\ntype TextComparator = EqualityComparator | ListComparator | TextMatchComparator | NullComparator;\n\n/** Comparators supported for NUMBER fields */\ntype NumberComparator = EqualityComparator | ListComparator | RangeComparator | NullComparator;\n\n/** Comparators supported for DATE_TIME/DATE_ONLY/TIME_ONLY fields */\ntype DateTimeComparator = EqualityComparator | RangeComparator | NullComparator;\n\n/** Type definition to specify supported comparators by field-type */\nexport type ComparatorsByType =\n | { type: 'BOOLEAN'; comparators: BooleanComparator[] }\n | { type: 'TEXT'; comparators: TextComparator[] }\n | { type: 'NUMBER'; comparators: NumberComparator[] }\n | { type: 'DATE_TIME'; comparators: DateTimeComparator[] }\n | { type: 'DATE_ONLY'; comparators: DateTimeComparator[] }\n | { type: 'TIME_ONLY'; comparators: DateTimeComparator[] };\n\nexport type RHSType = 'LITERAL' | 'FIELD';\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/types.ts"],"names":[],"mappings":"","sourcesContent":["/** Supported field types */\nexport type FieldType = 'BOOLEAN' | 'TEXT' | 'NUMBER' | 'DATE_TIME' | 'DATE_ONLY' | 'TIME_ONLY';\n\ntype NullComparator = 'IS_NULL' | 'IS_NOT_NULL';\ntype EqualityComparator = 'EQ' | 'NEQ';\ntype RangeComparator = 'GT' | 'GTE' | 'LT' | 'LTE';\ntype TruenessComparator = 'IS_TRUE' | 'IS_FALSE';\ntype ListComparator = 'IN' | 'NOT_IN';\ntype TextMatchComparator =\n | 'STARTS_WITH'\n | 'NOT_STARTS_WITH'\n | 'ENDS_WITH'\n | 'NOT_ENDS_WITH'\n | 'CONTAINS'\n | 'NOT_CONTAINS';\n\n/** All supported Comparators */\nexport type Comparator =\n | TruenessComparator\n | NullComparator\n | EqualityComparator\n | ListComparator\n | RangeComparator\n | TextMatchComparator;\n\n/** Comparators supported for BOOLEAN fields */\ntype BooleanComparator = TruenessComparator | EqualityComparator | NullComparator;\n\n/** Comparators supported for TEXT fields */\ntype TextComparator = EqualityComparator | ListComparator | TextMatchComparator | NullComparator;\n\n/** Comparators supported for NUMBER fields */\ntype NumberComparator = EqualityComparator | ListComparator | RangeComparator | NullComparator;\n\n/** Comparators supported for DATE_TIME/DATE_ONLY/TIME_ONLY fields */\ntype DateTimeComparator = EqualityComparator | RangeComparator | NullComparator;\n\n/** Type definition to specify supported comparators by field-type */\nexport type ComparatorsByType =\n | { type: 'BOOLEAN'; comparators: BooleanComparator[] }\n | { type: 'TEXT'; comparators: TextComparator[] }\n | { type: 'NUMBER'; comparators: NumberComparator[] }\n | { type: 'DATE_TIME'; comparators: DateTimeComparator[] }\n | { type: 'DATE_ONLY'; comparators: DateTimeComparator[] }\n | { type: 'TIME_ONLY'; comparators: DateTimeComparator[] };\n\nexport type RHSType = 'LITERAL' | 'FIELD' | 'DATE_FUNCTION' | 'RELATIVE_DATE';\n\n/** Date function types supported on the RHS */\nexport type DateFunction =\n | 'YEARS'\n | 'QUARTERS'\n | 'MONTHS'\n | 'WEEKS'\n | 'DAYS'\n | 'HOURS'\n | 'MONTHS_OF_YEAR'\n | 'DAYS_OF_MONTH'\n | 'DAYS_OF_WEEK';\n\n/** \"Relative Date\" Time Periods supported on the RHS */\nexport type TimePeriod = 'LAST' | 'PREVIOUS' | 'CURRENT' | 'NEXT';\n\n/** \"Relative Date\" Date Parts supported on the RHS */\nexport type DatePart = 'MINUTES' | 'HOURS' | 'DAYS' | 'WEEKS' | 'MONTHS' | 'QUARTERS' | 'YEARS';\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAqQnF,yDAAyD;AACzD,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAAA;CAAE,EAAE,4CAA4C;AACjG,WAAW,GAAE,OAAe,EAC5B,kBAAkB,GAAE,OAAe,GAClC;IAAE,SAAS,EAAE,SAAS,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAqB9C;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CA0D5D;AAkDD,uFAAuF;AACvF,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,SAAS,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,YAAY,EAAE,CAAA;CAAE,CAUjG;AAGD,mIAAmI;AACnI,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,SAAS,EACf,WAAW,GAAE,MAAW,GACvB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE;QAAE,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAAA;KAAE,CAAA;CAAE,CAkBnE;AAED,qHAAqH;AACrH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAwBnE;AAED,8FAA8F;AAC9F,wBA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AAM,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,CAMrE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,GAAG,MAAM,CAG7E"}
@@ -53,16 +53,12 @@ function findInvalidPatterns(tokens) {
53
53
  const token = tokens[i];
54
54
  const tokenType = isIntegerToken(token) ? NUMBER : token; // To simplify comparisons below
55
55
  // The expression can only start with NOT, LPAREN or NUMBER
56
- if (i === 0) {
57
- if (![NOT, LPAREN, NUMBER].includes(tokenType)) {
58
- return `Unexpected "${token}" at the beginning.`; // FIXME: TR
59
- }
56
+ if (i === 0 && ![NOT, LPAREN, NUMBER].includes(tokenType)) {
57
+ return `Unexpected "${token}" at the beginning.`; // FIXME: TR
60
58
  }
61
59
  // The expression can only end with RPAREN or NUMBER
62
- if (i === tokens.length - 1) {
63
- if (![RPAREN, NUMBER].includes(tokenType)) {
64
- return `Unexpected "${token}" at the end.`; // FIXME: TR
65
- }
60
+ if (i === tokens.length - 1 && ![RPAREN, NUMBER].includes(tokenType)) {
61
+ return `Unexpected "${token}" at the end.`; // FIXME: TR
66
62
  }
67
63
  // If there is a previous token, check if it is supposed to precede the current token
68
64
  if (i > 0) {