@pega/cosmos-react-condition-builder 2.2.1 → 2.2.4
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.
- package/lib/components/ConditionBuilder/AtomicCondition.d.ts +51 -0
- package/lib/components/ConditionBuilder/AtomicCondition.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/AtomicCondition.js +119 -0
- package/lib/components/ConditionBuilder/AtomicCondition.js.map +1 -0
- package/lib/components/ConditionBuilder/ConditionBuilder.d.ts +6 -0
- package/lib/components/ConditionBuilder/ConditionBuilder.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/ConditionBuilder.js +234 -0
- package/lib/components/ConditionBuilder/ConditionBuilder.js.map +1 -0
- package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts +112 -0
- package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/ConditionBuilder.types.js +2 -0
- package/lib/components/ConditionBuilder/ConditionBuilder.types.js.map +1 -0
- package/lib/components/ConditionBuilder/FieldCondition.d.ts +7 -0
- package/lib/components/ConditionBuilder/FieldCondition.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/FieldCondition.js +26 -0
- package/lib/components/ConditionBuilder/FieldCondition.js.map +1 -0
- package/lib/components/ConditionBuilder/FieldCondition.types.d.ts +25 -0
- package/lib/components/ConditionBuilder/FieldCondition.types.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/FieldCondition.types.js +2 -0
- package/lib/components/ConditionBuilder/FieldCondition.types.js.map +1 -0
- package/lib/components/ConditionBuilder/HelpButton.d.ts +10 -0
- package/lib/components/ConditionBuilder/HelpButton.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/HelpButton.js +11 -0
- package/lib/components/ConditionBuilder/HelpButton.js.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.d.ts +18 -0
- package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.js +115 -0
- package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.js.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/FieldSelector.d.ts +19 -0
- package/lib/components/ConditionBuilder/RhsControls/FieldSelector.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/FieldSelector.js +67 -0
- package/lib/components/ConditionBuilder/RhsControls/FieldSelector.js.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.d.ts +16 -0
- package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.js +43 -0
- package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.js.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/NumericInput.d.ts +18 -0
- package/lib/components/ConditionBuilder/RhsControls/NumericInput.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/NumericInput.js +19 -0
- package/lib/components/ConditionBuilder/RhsControls/NumericInput.js.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.d.ts +18 -0
- package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.js +109 -0
- package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.js.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.d.ts +24 -0
- package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.js +122 -0
- package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.js.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.d.ts +8 -0
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.js +89 -0
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.js.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.d.ts +20 -0
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.js +11 -0
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.js.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/index.d.ts +39 -0
- package/lib/components/ConditionBuilder/RhsControls/index.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/index.js +219 -0
- package/lib/components/ConditionBuilder/RhsControls/index.js.map +1 -0
- package/lib/components/ConditionBuilder/core/comparators.d.ts +12 -0
- package/lib/components/ConditionBuilder/core/comparators.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/core/comparators.js +74 -0
- package/lib/components/ConditionBuilder/core/comparators.js.map +1 -0
- package/lib/components/ConditionBuilder/core/evaluator.d.ts +14 -0
- package/lib/components/ConditionBuilder/core/evaluator.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/core/evaluator.js +257 -0
- package/lib/components/ConditionBuilder/core/evaluator.js.map +1 -0
- package/lib/components/ConditionBuilder/core/extendDayJs.d.ts +2 -0
- package/lib/components/ConditionBuilder/core/extendDayJs.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/core/extendDayJs.js +4 -0
- package/lib/components/ConditionBuilder/core/extendDayJs.js.map +1 -0
- package/lib/components/ConditionBuilder/core/formatter.d.ts +16 -0
- package/lib/components/ConditionBuilder/core/formatter.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/core/formatter.js +190 -0
- package/lib/components/ConditionBuilder/core/formatter.js.map +1 -0
- package/lib/components/ConditionBuilder/core/rows-reducer.d.ts +27 -0
- package/lib/components/ConditionBuilder/core/rows-reducer.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/core/rows-reducer.js +50 -0
- package/lib/components/ConditionBuilder/core/rows-reducer.js.map +1 -0
- package/lib/components/ConditionBuilder/core/time-utils.d.ts +5 -0
- package/lib/components/ConditionBuilder/core/time-utils.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/core/time-utils.js +23 -0
- package/lib/components/ConditionBuilder/core/time-utils.js.map +1 -0
- package/lib/components/ConditionBuilder/core/transformer.d.ts +7 -0
- package/lib/components/ConditionBuilder/core/transformer.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/core/transformer.js +154 -0
- package/lib/components/ConditionBuilder/core/transformer.js.map +1 -0
- package/lib/components/ConditionBuilder/core/types.d.ts +47 -0
- package/lib/components/ConditionBuilder/core/types.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/core/types.js +2 -0
- package/lib/components/ConditionBuilder/core/types.js.map +1 -0
- package/lib/components/ConditionBuilder/core/utils.d.ts +37 -0
- package/lib/components/ConditionBuilder/core/utils.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/core/utils.js +439 -0
- package/lib/components/ConditionBuilder/core/utils.js.map +1 -0
- package/lib/components/ConditionBuilder/index.d.ts +11 -0
- package/lib/components/ConditionBuilder/index.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/index.js +8 -0
- package/lib/components/ConditionBuilder/index.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +4 -0
- package/lib/index.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rows-reducer.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/rows-reducer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAIpD,oCAAoC;AACpC,MAAM,SAAS,GAAG,GAAiB,EAAE;IACnC,OAAO;QACL,EAAE,EAAE,SAAS,EAAE;QACf,KAAK,EAAE,EAAE;QACT,UAAU,EAAE,aAAa;QACzB,GAAG,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;KACnB,CAAC;AACJ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,CAAC,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC;YAC1E,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;gBACxB,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,+CAA+C;aAC3E;YACD,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;gBAC7B,iHAAiH;gBACjH,GAAG,CAAC,KAAK,GAAG,GAAG,KAAK,GAAG,CAAC,EAAE,CAAC;YAC7B,CAAC,CAAC,CAAC;YACH,OAAO,OAAO,CAAC;SAChB;QAED;YACE,OAAO,IAAI,CAAC;KACf;AACH,CAAC","sourcesContent":["import { createUID } from '@pega/cosmos-react-core';\n\nimport { ConditionRow } from '../ConditionBuilder.types';\n\n// Returns a new empty condition row\nconst getNewRow = (): ConditionRow => {\n return {\n id: createUID(),\n label: '',\n comparator: 'IS_NOT_NULL',\n lhs: { field: '' }\n };\n};\n\n// Action types as variables. Helps avoid errors due to typos\nexport const INSERT_ROW = 'INSERT_ROW';\nexport const UPDATE_ROW = 'UPDATE_ROW';\nexport const REMOVE_ROW = 'REMOVE_ROW';\n\n// Set up the reducer action-type as a union of different possible actions\ninterface InsertAction {\n type: 'INSERT_ROW'; // String-literal type to force a single value\n payload: { insertAt: number };\n}\ninterface UpdateAction {\n type: 'UPDATE_ROW'; // String-literal type to force a single value\n payload: {\n updateAt: number;\n newRow: ConditionRow;\n };\n}\ninterface RemoveAction {\n type: 'REMOVE_ROW'; // String-literal type to force a single value\n payload: { removeAt: number };\n}\ntype RowAction = InsertAction | UpdateAction | RemoveAction;\n\n// Reducer for the condition rows\nexport default function rowsReducer(rows: ConditionRow[], action: RowAction): ConditionRow[] {\n switch (action.type) {\n // Insert an empty condition at the given index\n case INSERT_ROW: {\n const { insertAt } = action.payload;\n const newRows = [...rows.slice(0, insertAt), getNewRow(), ...rows.slice(insertAt)];\n newRows.forEach((row, index) => {\n // Update `label`s to have intuitive row-labels. NOTE: The logicString is updated separately for the label-change\n row.label = `${index + 1}`;\n });\n return newRows;\n }\n\n // Update existing condition at the given index\n case UPDATE_ROW: {\n const { updateAt, newRow } = action.payload;\n return [...rows.slice(0, updateAt), newRow, ...rows.slice(updateAt + 1)];\n }\n\n // Remove existing condition at the given index\n case REMOVE_ROW: {\n const { removeAt } = action.payload;\n const newRows = [...rows.slice(0, removeAt), ...rows.slice(removeAt + 1)];\n if (newRows.length === 0) {\n newRows.push(getNewRow()); // Ensure that there is always at least one row\n }\n newRows.forEach((row, index) => {\n // Update `label`s to have intuitive row-labels. NOTE: The logicString is updated separately for the label-change\n row.label = `${index + 1}`;\n });\n return newRows;\n }\n\n default:\n return rows;\n }\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Converts an `hh:mm:ss` value into the number of milliseconds since 00:00:00 */
|
|
2
|
+
export declare function convertTimeValueToMs(value: string): number;
|
|
3
|
+
/** Converts a milliseconds value into an `hh:mm:ss` format */
|
|
4
|
+
export declare function convertMsToTimeValue(value: number): string;
|
|
5
|
+
//# sourceMappingURL=time-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time-utils.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/time-utils.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQ1D;AAED,8DAA8D;AAC9D,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAa1D"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Converts an `hh:mm:ss` value into the number of milliseconds since 00:00:00 */
|
|
2
|
+
export function convertTimeValueToMs(value) {
|
|
3
|
+
// Determine the different time components
|
|
4
|
+
const hh = Number(value.slice(0, 2));
|
|
5
|
+
const mm = Number(value.slice(3, 5));
|
|
6
|
+
const ss = Number(value.slice(6, 8));
|
|
7
|
+
// Return the number of seconds since 00:00:00
|
|
8
|
+
return hh * 60 * 60 * 1000 + mm * 60 * 1000 + ss * 1000;
|
|
9
|
+
}
|
|
10
|
+
/** Converts a milliseconds value into an `hh:mm:ss` format */
|
|
11
|
+
export function convertMsToTimeValue(value) {
|
|
12
|
+
// Determine the different time components
|
|
13
|
+
const hours = Math.floor(value / (60 * 60 * 1000));
|
|
14
|
+
value -= hours * 60 * 60 * 1000;
|
|
15
|
+
const minutes = Math.floor(value / (60 * 1000));
|
|
16
|
+
value -= minutes * 60 * 1000;
|
|
17
|
+
const seconds = Math.floor(value / 1000);
|
|
18
|
+
const hh = hours.toString().padStart(2, '0');
|
|
19
|
+
const mm = minutes.toString().padStart(2, '0');
|
|
20
|
+
const ss = seconds.toString().padStart(2, '0');
|
|
21
|
+
return `${hh}:${mm}:${ss}`;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=time-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time-utils.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/time-utils.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,0CAA0C;IAC1C,MAAM,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACrC,MAAM,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACrC,MAAM,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAErC,8CAA8C;IAC9C,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,GAAG,EAAE,GAAG,IAAI,CAAC;AAC1D,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,0CAA0C;IAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;IACnD,KAAK,IAAI,KAAK,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAChC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;IAChD,KAAK,IAAI,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC;IAC7B,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IAEzC,MAAM,EAAE,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC7C,MAAM,EAAE,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC/C,MAAM,EAAE,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAE/C,OAAO,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC;AAC7B,CAAC","sourcesContent":["/** Converts an `hh:mm:ss` value into the number of milliseconds since 00:00:00 */\nexport function convertTimeValueToMs(value: string): number {\n // Determine the different time components\n const hh = Number(value.slice(0, 2));\n const mm = Number(value.slice(3, 5));\n const ss = Number(value.slice(6, 8));\n\n // Return the number of seconds since 00:00:00\n return hh * 60 * 60 * 1000 + mm * 60 * 1000 + ss * 1000;\n}\n\n/** Converts a milliseconds value into an `hh:mm:ss` format */\nexport function convertMsToTimeValue(value: number): string {\n // Determine the different time components\n const hours = Math.floor(value / (60 * 60 * 1000));\n value -= hours * 60 * 60 * 1000;\n const minutes = Math.floor(value / (60 * 1000));\n value -= minutes * 60 * 1000;\n const seconds = Math.floor(value / 1000);\n\n const hh = hours.toString().padStart(2, '0');\n const mm = minutes.toString().padStart(2, '0');\n const ss = seconds.toString().padStart(2, '0');\n\n return `${hh}:${mm}:${ss}`;\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;AAiJ5E;;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,154 @@
|
|
|
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
|
+
/** Construct a date-range filter based on the given date bounds and the comparator */
|
|
15
|
+
function getConditionFromRange(startDate, endDate, node, lhsFieldType) {
|
|
16
|
+
const dateFormat = lhsFieldType === 'DATE_ONLY' ? 'YYYY-MM-DD' : 'YYYY-MM-DDTHH:mm:ss';
|
|
17
|
+
switch (node.comparator) {
|
|
18
|
+
case 'EQ':
|
|
19
|
+
return {
|
|
20
|
+
AND: [
|
|
21
|
+
{
|
|
22
|
+
condition: {
|
|
23
|
+
lhs: node.lhs,
|
|
24
|
+
comparator: 'LTE',
|
|
25
|
+
rhs: { value: endDate.format(dateFormat) }
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
condition: {
|
|
30
|
+
lhs: node.lhs,
|
|
31
|
+
comparator: 'GTE',
|
|
32
|
+
rhs: { value: startDate.format(dateFormat) }
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
};
|
|
37
|
+
case 'NEQ':
|
|
38
|
+
return {
|
|
39
|
+
OR: [
|
|
40
|
+
{
|
|
41
|
+
condition: {
|
|
42
|
+
lhs: node.lhs,
|
|
43
|
+
comparator: 'GT',
|
|
44
|
+
rhs: { value: endDate.format(dateFormat) }
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
condition: {
|
|
49
|
+
lhs: node.lhs,
|
|
50
|
+
comparator: 'LT',
|
|
51
|
+
rhs: { value: startDate.format(dateFormat) }
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
};
|
|
56
|
+
case 'GT':
|
|
57
|
+
return {
|
|
58
|
+
condition: {
|
|
59
|
+
lhs: node.lhs,
|
|
60
|
+
comparator: 'GT',
|
|
61
|
+
rhs: { value: endDate.format(dateFormat) }
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
case 'GTE':
|
|
65
|
+
return {
|
|
66
|
+
condition: {
|
|
67
|
+
lhs: node.lhs,
|
|
68
|
+
comparator: 'GTE',
|
|
69
|
+
rhs: { value: startDate.format(dateFormat) }
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
case 'LT':
|
|
73
|
+
return {
|
|
74
|
+
condition: {
|
|
75
|
+
lhs: node.lhs,
|
|
76
|
+
comparator: 'LT',
|
|
77
|
+
rhs: { value: startDate.format(dateFormat) }
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
case 'LTE':
|
|
81
|
+
return {
|
|
82
|
+
condition: {
|
|
83
|
+
lhs: node.lhs,
|
|
84
|
+
comparator: 'LTE',
|
|
85
|
+
rhs: { value: endDate.format(dateFormat) }
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
default:
|
|
89
|
+
return { condition: node };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function transformLeafCondition(node, fields, currentDateTime) {
|
|
93
|
+
const field = fields.find(f => f.name === node.lhs.field);
|
|
94
|
+
if (!field) {
|
|
95
|
+
return { condition: node }; // Safety check
|
|
96
|
+
}
|
|
97
|
+
// Transform Relative date filters into equivalent date range filters
|
|
98
|
+
if (node.rhs && hasProp(node.rhs, 'relativeDate')) {
|
|
99
|
+
const { timePeriod, interval, datePart } = node.rhs.relativeDate;
|
|
100
|
+
const dayjsDatePart = dayjsDateParts[datePart];
|
|
101
|
+
const now = dayjs(currentDateTime);
|
|
102
|
+
let startDate = now;
|
|
103
|
+
let endDate = now;
|
|
104
|
+
if (timePeriod === 'CURRENT') {
|
|
105
|
+
startDate = now.startOf(dayjsDatePart);
|
|
106
|
+
endDate = now.endOf(dayjsDatePart);
|
|
107
|
+
}
|
|
108
|
+
else if (timePeriod === 'LAST' && interval && interval >= 1) {
|
|
109
|
+
startDate = now.subtract(interval, dayjsDatePart);
|
|
110
|
+
}
|
|
111
|
+
else if (timePeriod === 'PREVIOUS' && interval && interval >= 1) {
|
|
112
|
+
startDate = now.startOf(dayjsDatePart).subtract(interval, dayjsDatePart);
|
|
113
|
+
endDate = now.subtract(1, dayjsDatePart).endOf(dayjsDatePart);
|
|
114
|
+
}
|
|
115
|
+
else if (timePeriod === 'NEXT' && interval && interval >= 1) {
|
|
116
|
+
startDate = now.add(1, dayjsDatePart).startOf(dayjsDatePart);
|
|
117
|
+
endDate = now.endOf(dayjsDatePart).add(interval, dayjsDatePart);
|
|
118
|
+
}
|
|
119
|
+
return getConditionFromRange(startDate, endDate, node, field.type);
|
|
120
|
+
}
|
|
121
|
+
// Transform WEEKS-filters into equivalent date-range filters
|
|
122
|
+
// NOTE: This is a work-around until we make startOfDay customizable for Weeks
|
|
123
|
+
if (node.rhs && hasProp(node.rhs, 'dateFunction') && node.rhs.dateFunction === 'WEEKS') {
|
|
124
|
+
const startDate = dayjs(node.rhs.value); // Since we store it as YYYY-MM-DD, it's already the start of day
|
|
125
|
+
const endDate = startDate.add(6, 'day').endOf('day'); // Last millisecond on the 7th day from startDate
|
|
126
|
+
return getConditionFromRange(startDate, endDate, node, field.type);
|
|
127
|
+
}
|
|
128
|
+
// For all other cases
|
|
129
|
+
return { condition: node };
|
|
130
|
+
}
|
|
131
|
+
/** This function transforms Conditions with Relative Dates into Conditions with Date Ranges.
|
|
132
|
+
* Do not use this function unless you need to convert Relative Dates into Date Ranges.
|
|
133
|
+
*/
|
|
134
|
+
export default function transformComplexCondition(condition, fields, currentDateTime) {
|
|
135
|
+
if (hasProp(condition, 'AND')) {
|
|
136
|
+
const childNodes = condition.AND.map(n => transformComplexCondition(n, fields, currentDateTime));
|
|
137
|
+
return {
|
|
138
|
+
AND: childNodes
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (hasProp(condition, 'OR')) {
|
|
142
|
+
const childNodes = condition.OR.map(n => transformComplexCondition(n, fields, currentDateTime));
|
|
143
|
+
return {
|
|
144
|
+
OR: childNodes
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
if (hasProp(condition, 'NOT')) {
|
|
148
|
+
return {
|
|
149
|
+
NOT: transformComplexCondition(condition.NOT, fields, currentDateTime)
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
return transformLeafCondition(condition.condition, fields, currentDateTime);
|
|
153
|
+
}
|
|
154
|
+
//# 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,KAA2B,MAAM,OAAO,CAAC;AAChD,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,sFAAsF;AACtF,SAAS,qBAAqB,CAC5B,SAAgB,EAChB,OAAc,EACd,IAAmB,EACnB,YAAuB;IAEvB,MAAM,UAAU,GAAG,YAAY,KAAK,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,qBAAqB,CAAC;IAEvF,QAAQ,IAAI,CAAC,UAAU,EAAE;QACvB,KAAK,IAAI;YACP,OAAO;gBACL,GAAG,EAAE;oBACH;wBACE,SAAS,EAAE;4BACT,GAAG,EAAE,IAAI,CAAC,GAAG;4BACb,UAAU,EAAE,KAAK;4BACjB,GAAG,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;yBAC3C;qBACF;oBACD;wBACE,SAAS,EAAE;4BACT,GAAG,EAAE,IAAI,CAAC,GAAG;4BACb,UAAU,EAAE,KAAK;4BACjB,GAAG,EAAE,EAAE,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;yBAC7C;qBACF;iBACF;aACF,CAAC;QACJ,KAAK,KAAK;YACR,OAAO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AAC,GAAG,CAAC,GAAG,CAAC,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, Dayjs } from 'dayjs';\nimport './extendDayJs';\n\nimport { hasProp } from '@pega/cosmos-react-core';\n\nimport { Condition, LeafCondition, Field } from '../ConditionBuilder.types';\n\nimport { DatePart, FieldType } 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\n/** Construct a date-range filter based on the given date bounds and the comparator */\nfunction getConditionFromRange(\n startDate: Dayjs,\n endDate: Dayjs,\n node: LeafCondition,\n lhsFieldType: FieldType\n): Condition {\n const dateFormat = lhsFieldType === 'DATE_ONLY' ? 'YYYY-MM-DD' : 'YYYY-MM-DDTHH:mm:ss';\n\n switch (node.comparator) {\n case 'EQ':\n return {\n AND: [\n {\n condition: {\n lhs: node.lhs,\n comparator: 'LTE',\n rhs: { value: endDate.format(dateFormat) }\n }\n },\n {\n condition: {\n lhs: node.lhs,\n comparator: 'GTE',\n rhs: { value: startDate.format(dateFormat) }\n }\n }\n ]\n };\n case 'NEQ':\n return {\n OR: [\n {\n condition: {\n lhs: node.lhs,\n comparator: 'GT',\n rhs: { value: endDate.format(dateFormat) }\n }\n },\n {\n condition: {\n lhs: node.lhs,\n comparator: 'LT',\n rhs: { value: startDate.format(dateFormat) }\n }\n }\n ]\n };\n case 'GT':\n return {\n condition: {\n lhs: node.lhs,\n comparator: 'GT',\n rhs: { value: endDate.format(dateFormat) }\n }\n };\n case 'GTE':\n return {\n condition: {\n lhs: node.lhs,\n comparator: 'GTE',\n rhs: { value: startDate.format(dateFormat) }\n }\n };\n case 'LT':\n return {\n condition: {\n lhs: node.lhs,\n comparator: 'LT',\n rhs: { value: startDate.format(dateFormat) }\n }\n };\n case 'LTE':\n return {\n condition: {\n lhs: node.lhs,\n comparator: 'LTE',\n rhs: { value: endDate.format(dateFormat) }\n }\n };\n default:\n return { condition: node };\n }\n}\n\nfunction transformLeafCondition(\n node: LeafCondition,\n fields: Field[],\n currentDateTime?: string\n): Condition {\n const field = fields.find(f => f.name === node.lhs.field);\n if (!field) {\n return { condition: node }; // Safety check\n }\n\n // Transform Relative date filters into equivalent date range filters\n if (node.rhs && hasProp(node.rhs, 'relativeDate')) {\n const { timePeriod, interval, datePart } = node.rhs.relativeDate;\n const dayjsDatePart = dayjsDateParts[datePart];\n const now = dayjs(currentDateTime);\n\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\n return getConditionFromRange(startDate, endDate, node, field.type);\n }\n\n // Transform WEEKS-filters into equivalent date-range filters\n // NOTE: This is a work-around until we make startOfDay customizable for Weeks\n if (node.rhs && hasProp(node.rhs, 'dateFunction') && node.rhs.dateFunction === 'WEEKS') {\n const startDate = dayjs(node.rhs.value); // Since we store it as YYYY-MM-DD, it's already the start of day\n const endDate = startDate.add(6, 'day').endOf('day'); // Last millisecond on the 7th day from startDate\n return getConditionFromRange(startDate, endDate, node, field.type);\n }\n\n // For all other cases\n return { condition: node };\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"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Supported field types */
|
|
2
|
+
export declare type FieldType = 'BOOLEAN' | 'TEXT' | 'NUMBER' | 'DATE_TIME' | 'DATE_ONLY' | 'TIME_ONLY';
|
|
3
|
+
declare type NullComparator = 'IS_NULL' | 'IS_NOT_NULL';
|
|
4
|
+
declare type EqualityComparator = 'EQ' | 'NEQ';
|
|
5
|
+
declare type RangeComparator = 'GT' | 'GTE' | 'LT' | 'LTE';
|
|
6
|
+
declare type TruenessComparator = 'IS_TRUE' | 'IS_FALSE';
|
|
7
|
+
declare type ListComparator = 'IN' | 'NOT_IN';
|
|
8
|
+
declare type TextMatchComparator = 'STARTS_WITH' | 'NOT_STARTS_WITH' | 'ENDS_WITH' | 'NOT_ENDS_WITH' | 'CONTAINS' | 'NOT_CONTAINS';
|
|
9
|
+
/** All supported Comparators */
|
|
10
|
+
export declare type Comparator = TruenessComparator | NullComparator | EqualityComparator | ListComparator | RangeComparator | TextMatchComparator;
|
|
11
|
+
/** Comparators supported for BOOLEAN fields */
|
|
12
|
+
declare type BooleanComparator = TruenessComparator | EqualityComparator | NullComparator;
|
|
13
|
+
/** Comparators supported for TEXT fields */
|
|
14
|
+
declare type TextComparator = EqualityComparator | ListComparator | TextMatchComparator | NullComparator;
|
|
15
|
+
/** Comparators supported for NUMBER fields */
|
|
16
|
+
declare type NumberComparator = EqualityComparator | ListComparator | RangeComparator | NullComparator;
|
|
17
|
+
/** Comparators supported for DATE_TIME/DATE_ONLY/TIME_ONLY fields */
|
|
18
|
+
declare type DateTimeComparator = EqualityComparator | RangeComparator | NullComparator;
|
|
19
|
+
/** Type definition to specify supported comparators by field-type */
|
|
20
|
+
export declare type ComparatorsByType = {
|
|
21
|
+
type: 'BOOLEAN';
|
|
22
|
+
comparators: BooleanComparator[];
|
|
23
|
+
} | {
|
|
24
|
+
type: 'TEXT';
|
|
25
|
+
comparators: TextComparator[];
|
|
26
|
+
} | {
|
|
27
|
+
type: 'NUMBER';
|
|
28
|
+
comparators: NumberComparator[];
|
|
29
|
+
} | {
|
|
30
|
+
type: 'DATE_TIME';
|
|
31
|
+
comparators: DateTimeComparator[];
|
|
32
|
+
} | {
|
|
33
|
+
type: 'DATE_ONLY';
|
|
34
|
+
comparators: DateTimeComparator[];
|
|
35
|
+
} | {
|
|
36
|
+
type: 'TIME_ONLY';
|
|
37
|
+
comparators: DateTimeComparator[];
|
|
38
|
+
};
|
|
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';
|
|
46
|
+
export {};
|
|
47
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/types.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,oBAAY,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,WAAW,GAAG,WAAW,CAAC;AAEhG,aAAK,cAAc,GAAG,SAAS,GAAG,aAAa,CAAC;AAChD,aAAK,kBAAkB,GAAG,IAAI,GAAG,KAAK,CAAC;AACvC,aAAK,eAAe,GAAG,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,CAAC;AACnD,aAAK,kBAAkB,GAAG,SAAS,GAAG,UAAU,CAAC;AACjD,aAAK,cAAc,GAAG,IAAI,GAAG,QAAQ,CAAC;AACtC,aAAK,mBAAmB,GACpB,aAAa,GACb,iBAAiB,GACjB,WAAW,GACX,eAAe,GACf,UAAU,GACV,cAAc,CAAC;AAEnB,gCAAgC;AAChC,oBAAY,UAAU,GAClB,kBAAkB,GAClB,cAAc,GACd,kBAAk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AElE,sDAAsD;AACtD,oBAAY,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +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' | '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"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Condition, ConditionRow, LeafCondition } from '../ConditionBuilder.types';
|
|
2
|
+
/** Parses a logic-expression into a condition object. */
|
|
3
|
+
export declare function parseLogicString(expression: string, conditionLookup: {
|
|
4
|
+
[label: string]: LeafCondition;
|
|
5
|
+
}, // To look up condition-rows from the labels
|
|
6
|
+
disallowNOT?: boolean, ignoreUnusedLabels?: boolean): {
|
|
7
|
+
condition: Condition;
|
|
8
|
+
} | {
|
|
9
|
+
error: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Takes a valid logic string and formats it with parentheses at appropriate places to keep things unambiguous
|
|
13
|
+
* For example, `1 AND 2 OR 3` is disambiguated as `(1 AND 2) OR 3`
|
|
14
|
+
* NOTE: This expects only valid logic strings to be passed as an input
|
|
15
|
+
*/
|
|
16
|
+
export declare function disambiguateLogic(expression: string): string;
|
|
17
|
+
/** Splits the input condition tree into a logic-string and a list of condition-rows */
|
|
18
|
+
export declare function splitConditionForBuilder(tree: Condition): {
|
|
19
|
+
logic: string;
|
|
20
|
+
rows: ConditionRow[];
|
|
21
|
+
};
|
|
22
|
+
/** Converts the input nested condition into a flat tree with the leaf-conditions and a logic string representing the input tree */
|
|
23
|
+
export declare function splitConditionTree(tree: Condition, labelPrefix?: string): {
|
|
24
|
+
logic: string;
|
|
25
|
+
conditions: {
|
|
26
|
+
[label: string]: LeafCondition;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/** Checks if the input Condition is simple enough to be displayed in the `Basic mode` without loss of information */
|
|
30
|
+
export declare function isBasicModeApplicable(condition: Condition): boolean;
|
|
31
|
+
/** Returns a list of operators to show in the Basic mode, using a logicString as the input */
|
|
32
|
+
export declare function getBasicModeOperators(logic: string): ('AND' | 'OR')[];
|
|
33
|
+
/**
|
|
34
|
+
* Takes a list of operators from between the Basic mode rows and constructs a logic-string out of them
|
|
35
|
+
*/
|
|
36
|
+
export declare function getLogicFromBasicMode(operatorsList: ('AND' | 'OR')[]): string;
|
|
37
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +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;AAiQnF,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,EAA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