@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,39 @@
|
|
|
1
|
+
import { FunctionComponent } from 'react';
|
|
2
|
+
import { BaseProps, ForwardProps } from '@pega/cosmos-react-core';
|
|
3
|
+
import { FieldType, Comparator, RHSType } from '../core/types';
|
|
4
|
+
import { LeafCondition, Field, DateFunctionsByType } from '../ConditionBuilder.types';
|
|
5
|
+
/**
|
|
6
|
+
* Verifies if the condition has all valid values.
|
|
7
|
+
* NOTES:
|
|
8
|
+
* - This is intended to be used only on conditions emitted by the components in this package.
|
|
9
|
+
* - If a condition is manually constructed outside these components, this utility could miss some malformed conditions.
|
|
10
|
+
* - Also, this does not try to validate if the given `rhs` matches the `lhs`/`comparator`/`validRhsTypes`. Instead, it assumes that the appropriate LHS/Comparator/validRhsTypes must have been already in place for this rhs to be generated.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isValidRhs(rhs: LeafCondition['rhs'], fieldType?: FieldType, trimValues?: boolean): boolean;
|
|
13
|
+
/** For a condition with the given comparator and lhs-field-type, determines an appropriate default value for the Rhs */
|
|
14
|
+
export declare function getDefaultRhs(fieldType: FieldType, comparator: Comparator, validRhsTypes: Set<RHSType>, dateFunctions?: DateFunctionsByType): LeafCondition['rhs'];
|
|
15
|
+
/** Type definition for the input props of RhsControls */
|
|
16
|
+
interface RhsControlProps extends BaseProps {
|
|
17
|
+
/** Lhs for the condition */
|
|
18
|
+
lhs: LeafCondition['lhs'];
|
|
19
|
+
/** Comparator for the condition */
|
|
20
|
+
comparator: Comparator;
|
|
21
|
+
/** Rhs for the condition */
|
|
22
|
+
rhs: LeafCondition['rhs'];
|
|
23
|
+
/** Metadata (data-model) for the Fields to use in the RHS field-selector */
|
|
24
|
+
fields: Field[];
|
|
25
|
+
/** Callback for any modifications to the Rhs */
|
|
26
|
+
onChange: (rhs: LeafCondition['rhs']) => void;
|
|
27
|
+
/** Used to enable inline error indicators on invalid inputs */
|
|
28
|
+
indicateErrors: boolean;
|
|
29
|
+
/** Item flow direction */
|
|
30
|
+
itemDirection: 'row' | 'column';
|
|
31
|
+
/** Restricts RHS values to only specified RHS types */
|
|
32
|
+
validRhsTypes: Set<RHSType>;
|
|
33
|
+
/** Passed to enable additional date controls on the RHS, when a DATE_TIME/DATE_ONLY field is selected on the LHS */
|
|
34
|
+
dateFunctions?: DateFunctionsByType;
|
|
35
|
+
}
|
|
36
|
+
/** A controlled component for controls on a Condition's RHS */
|
|
37
|
+
declare const RhsControls: FunctionComponent<RhsControlProps & ForwardProps>;
|
|
38
|
+
export default RhsControls;
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|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C,OAAO,CAAC,CAAC;IAE5B,oHAAoH;IACpH,aAAa,CAAC,EAAE,mBAAmB,CAAC;CACrC;AAED,+DAA+D;AAC/D,QAAA,MAAM,WAAW,EAAE,iBAAiB,CAAC,eAAe,GAAG,YAAY,CAuQlE,CAAC;AACF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect, useMemo } from 'react';
|
|
3
|
+
import { DateInput, DateTimeInput, Flex, Input, Select, Option, hasProp } from '@pega/cosmos-react-core';
|
|
4
|
+
import { convertTimeValueToMs, convertMsToTimeValue } from '../core/time-utils';
|
|
5
|
+
import MultiValueSelector from './MultiValueSelector';
|
|
6
|
+
import FieldSelector from './FieldSelector';
|
|
7
|
+
import RhsModeSwitch from './RhsModeSwitch';
|
|
8
|
+
import TimePeriodInput from './TimePeriodInput';
|
|
9
|
+
import TimePeriodMenu from './TimePeriodMenu';
|
|
10
|
+
import NumericInput from './NumericInput';
|
|
11
|
+
/**
|
|
12
|
+
* Verifies if the condition has all valid values.
|
|
13
|
+
* NOTES:
|
|
14
|
+
* - This is intended to be used only on conditions emitted by the components in this package.
|
|
15
|
+
* - If a condition is manually constructed outside these components, this utility could miss some malformed conditions.
|
|
16
|
+
* - Also, this does not try to validate if the given `rhs` matches the `lhs`/`comparator`/`validRhsTypes`. Instead, it assumes that the appropriate LHS/Comparator/validRhsTypes must have been already in place for this rhs to be generated.
|
|
17
|
+
*/
|
|
18
|
+
export function isValidRhs(rhs, fieldType, trimValues = false) {
|
|
19
|
+
// RHS would be `undefined` when no RHS is needed. Treat it as a valid value
|
|
20
|
+
if (rhs === undefined) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
// Field-selector on the RHS
|
|
24
|
+
if (hasProp(rhs, 'field')) {
|
|
25
|
+
// RHS is invalid if no field is selected
|
|
26
|
+
return rhs.field !== '';
|
|
27
|
+
}
|
|
28
|
+
// List-input cases
|
|
29
|
+
if (hasProp(rhs, 'values')) {
|
|
30
|
+
// RHS is invalid if the list is empty
|
|
31
|
+
if (rhs.values.length === 0) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
// For numeric fields, RHS is invalid if any NaN values are present in the list
|
|
35
|
+
if (fieldType === 'NUMBER' && rhs.values.some(v => Number.isNaN(v))) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (hasProp(rhs, 'value')) {
|
|
40
|
+
// Identify any invalid numbers (e.g. when `-` is entered)
|
|
41
|
+
if (typeof rhs.value === 'number') {
|
|
42
|
+
return !Number.isNaN(rhs.value);
|
|
43
|
+
}
|
|
44
|
+
// NOTE: Not trimming the value in the change-handler so that users can freely type spaces between words
|
|
45
|
+
if (trimValues) {
|
|
46
|
+
rhs.value = rhs.value.trim();
|
|
47
|
+
}
|
|
48
|
+
// Can be empty on init and on clearing the value
|
|
49
|
+
if (rhs.value.trim() === '') {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
// This check is needed to eliminate invalid dates like `Feb 31` (02/31/2020), which the input allows
|
|
53
|
+
if ((fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY') &&
|
|
54
|
+
Number.isNaN(new Date(rhs.value).getTime())) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (hasProp(rhs, 'relativeDate') &&
|
|
59
|
+
((rhs.relativeDate.timePeriod === 'CURRENT' && rhs.relativeDate.interval) ||
|
|
60
|
+
(rhs.relativeDate.timePeriod !== 'CURRENT' &&
|
|
61
|
+
(!rhs.relativeDate.interval || rhs.relativeDate.interval <= 0)))) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
/** For a condition with the given comparator and lhs-field-type, determines an appropriate default value for the Rhs */
|
|
67
|
+
export function getDefaultRhs(fieldType, comparator, validRhsTypes, dateFunctions) {
|
|
68
|
+
switch (comparator) {
|
|
69
|
+
case 'IS_TRUE':
|
|
70
|
+
case 'IS_FALSE':
|
|
71
|
+
case 'IS_NULL':
|
|
72
|
+
case 'IS_NOT_NULL':
|
|
73
|
+
return undefined; // These comparators do not have an Rhs
|
|
74
|
+
case 'IN':
|
|
75
|
+
case 'NOT_IN':
|
|
76
|
+
return { values: [] };
|
|
77
|
+
default: {
|
|
78
|
+
if (fieldType === 'BOOLEAN' && (comparator === 'EQ' || comparator === 'NEQ')) {
|
|
79
|
+
// For booleans, these comparators can only be used for comparing with other fields
|
|
80
|
+
return { field: '' };
|
|
81
|
+
}
|
|
82
|
+
if (validRhsTypes.has('LITERAL'))
|
|
83
|
+
return { value: '' };
|
|
84
|
+
if (validRhsTypes.has('DATE_FUNCTION') &&
|
|
85
|
+
dateFunctions &&
|
|
86
|
+
(fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY'))
|
|
87
|
+
return { value: '', dateFunction: dateFunctions[fieldType][0] };
|
|
88
|
+
if (validRhsTypes.has('RELATIVE_DATE') &&
|
|
89
|
+
(fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY')) {
|
|
90
|
+
return {
|
|
91
|
+
relativeDate: {
|
|
92
|
+
timePeriod: 'CURRENT',
|
|
93
|
+
datePart: 'DAYS'
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return { field: '' };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// Truncates output values from DateInput/DateTimeInput to return a wall time on the RHS
|
|
102
|
+
// NOTE: This assumes that the input date is set up on the UTC timezone
|
|
103
|
+
function truncateISODateString(dateString, fieldType) {
|
|
104
|
+
const date = new Date(dateString);
|
|
105
|
+
const YYYY = date.getUTCFullYear().toString().padStart(4, '0');
|
|
106
|
+
const MM = (date.getUTCMonth() + 1).toString().padStart(2, '0');
|
|
107
|
+
const DD = date.getUTCDate().toString().padStart(2, '0');
|
|
108
|
+
// For DATE_ONLY fields, returning a YYYY-MM-DD format as per spec
|
|
109
|
+
if (fieldType === 'DATE_ONLY')
|
|
110
|
+
return `${YYYY}-${MM}-${DD}`;
|
|
111
|
+
const hh = date.getUTCHours().toString().padStart(2, '0');
|
|
112
|
+
const mm = date.getUTCMinutes().toString().padStart(2, '0');
|
|
113
|
+
// cspell:disable-next-line
|
|
114
|
+
// For DATE_TIME fields, returning a YYYY-MM-DDTHH:mm format and discarding the time-zone etc. to be consistent with the previous spec which was returning a wall time
|
|
115
|
+
return `${YYYY}-${MM}-${DD}T${hh}:${mm}`;
|
|
116
|
+
}
|
|
117
|
+
/** A controlled component for controls on a Condition's RHS */
|
|
118
|
+
const RhsControls = (props) => {
|
|
119
|
+
const { lhs, comparator, rhs, fields, onChange, indicateErrors, itemDirection, validRhsTypes, dateFunctions } = props;
|
|
120
|
+
// Find the field corresponding to the LHS
|
|
121
|
+
const matchingField = fields.find(f => f.name === lhs.field);
|
|
122
|
+
// Options for the Field-selector (if applicable)
|
|
123
|
+
const fieldOptions = useMemo(() => {
|
|
124
|
+
if (!matchingField)
|
|
125
|
+
return [];
|
|
126
|
+
// Show all other fields of the same data type as the LHS
|
|
127
|
+
return fields.filter(f => f.type === matchingField.type && f.name !== lhs.field);
|
|
128
|
+
}, [fields, lhs]);
|
|
129
|
+
// Set up a CSV input for IN/NOT_IN comparators
|
|
130
|
+
const [csvInput, setCsvInput] = useState(rhs && hasProp(rhs, 'values') ? rhs.values.join(', ') : '');
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
// If moving away from the CSV-mode, clear the CSV Input.
|
|
133
|
+
// This ensures that if a different `rhs.values` is passed (a new empty array can be passed when an applicable comparator is selected), the local state matches the new input.
|
|
134
|
+
if (csvInput && (!rhs || !hasProp(rhs, 'values'))) {
|
|
135
|
+
setCsvInput('');
|
|
136
|
+
}
|
|
137
|
+
}, [rhs]);
|
|
138
|
+
// If a field is not selected or if the comparator doesn't need any RHS, don't render anything
|
|
139
|
+
if (rhs === undefined) {
|
|
140
|
+
return _jsx("div", {}, void 0); // Rendering a placeholder div to keep the layout consistent
|
|
141
|
+
}
|
|
142
|
+
if (matchingField === undefined) {
|
|
143
|
+
// For safety against any rare cases where the LHS from an input condition is not present in the input fields to the ConditionBuilder
|
|
144
|
+
// In those cases, don't render an RHS and wait for a valid value to be picked on LHS
|
|
145
|
+
return _jsx("div", {}, void 0); // Rendering a placeholder div to keep the layout consistent
|
|
146
|
+
}
|
|
147
|
+
const fieldType = matchingField.type;
|
|
148
|
+
// If errors should be indicated inline, validate the current rhs
|
|
149
|
+
let showError = false;
|
|
150
|
+
if (indicateErrors) {
|
|
151
|
+
showError = !isValidRhs(rhs, fieldType, false);
|
|
152
|
+
}
|
|
153
|
+
// Set up Value-selector (if applicable)
|
|
154
|
+
const { possibleValues } = matchingField; // These are passed when possible values are known ahead of time
|
|
155
|
+
const isValueSelectorPossible = fieldType === 'TEXT' &&
|
|
156
|
+
possibleValues !== undefined &&
|
|
157
|
+
['EQ', 'NEQ', 'IN', 'NOT_IN'].includes(comparator); // A ValueSelector in single/multiple mode is possible when these criteria are met
|
|
158
|
+
const useValueSelector = isValueSelectorPossible && !hasProp(rhs, 'field'); // Use the ValueSelector component if it is applicable and if not in ANOTHER_FIELD mode
|
|
159
|
+
// Handle changes from the Value-selector
|
|
160
|
+
const handleValueSelection = (selection) => {
|
|
161
|
+
if (typeof selection === 'string') {
|
|
162
|
+
onChange({ value: selection }); // Submit a new RHS
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
onChange({ values: selection }); // Submit a new RHS
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
// Handle changes from the Field-selector
|
|
169
|
+
const handleFieldChange = (id) => {
|
|
170
|
+
onChange({ field: id }); // Submit a new RHS
|
|
171
|
+
};
|
|
172
|
+
// Handle changes from a Value-input
|
|
173
|
+
const handleValueChange = (e) => {
|
|
174
|
+
// NOTE: Not trimming the value here so that users can freely type spaces between words. Trimming is done on Submit, via the isValidRhs call
|
|
175
|
+
onChange({ value: e.target.value }); // Submit a new RHS
|
|
176
|
+
};
|
|
177
|
+
// Handle changes from a Time-input
|
|
178
|
+
const handleTimeValueChange = (e) => {
|
|
179
|
+
let newValue = e.target.value;
|
|
180
|
+
if (newValue.length === 5) {
|
|
181
|
+
newValue += ':00'; // Enforce a fixed hh:mm:ss format
|
|
182
|
+
}
|
|
183
|
+
onChange({ value: convertTimeValueToMs(newValue) }); // Submit a new RHS
|
|
184
|
+
};
|
|
185
|
+
// Handle changes from a DateInput
|
|
186
|
+
const handleDateValueChange = ({ valueAsISOString, valueAsTimestamp, state }) => {
|
|
187
|
+
// NOTE: Not relying fully on `state` since in some cases state and valueAsTimestamp as both undefined
|
|
188
|
+
if (valueAsTimestamp === undefined || state === 'incomplete' || state === 'invalid')
|
|
189
|
+
return;
|
|
190
|
+
const truncatedValue = truncateISODateString(valueAsISOString, fieldType); // Truncate to return a wall time as per spec
|
|
191
|
+
onChange({ value: truncatedValue });
|
|
192
|
+
};
|
|
193
|
+
// Handle changes from a CSV-input
|
|
194
|
+
const handleCSVChange = (e) => {
|
|
195
|
+
// Update the controlled input
|
|
196
|
+
setCsvInput(e.target.value);
|
|
197
|
+
// Submit a new RHS
|
|
198
|
+
let newValues = e.target.value
|
|
199
|
+
.split(',')
|
|
200
|
+
.map(v => v.trim())
|
|
201
|
+
.filter(v => v.length > 0); // Ignore empty strings
|
|
202
|
+
if (fieldType === 'NUMBER') {
|
|
203
|
+
newValues = newValues.map(v => Number(v)); // This can set up some NaN values. Those are used to show an appropriate feedback when the submit button is hit
|
|
204
|
+
}
|
|
205
|
+
onChange({ values: newValues });
|
|
206
|
+
};
|
|
207
|
+
// Render the menu directly if in a vertical layout
|
|
208
|
+
const TimePeriodComp = itemDirection === 'column' ? TimePeriodMenu : TimePeriodInput;
|
|
209
|
+
return (_jsxs(Flex, { container: {
|
|
210
|
+
direction: itemDirection,
|
|
211
|
+
alignItems: itemDirection === 'column' ? 'stretch' : 'start',
|
|
212
|
+
justify: 'between',
|
|
213
|
+
gap: 0.5
|
|
214
|
+
}, children: [_jsx(RhsModeSwitch, { fieldType: fieldType, comparator: comparator, rhs: rhs, onChange: onChange, mode: itemDirection === 'column' ? 'combo-box' : 'menu-button', validRhsTypes: validRhsTypes, dateFunctions: dateFunctions }, void 0), hasProp(rhs, 'field') && (_jsx(Flex, { item: { grow: 1 }, children: _jsx(FieldSelector, { value: rhs.field, onChange: handleFieldChange, fields: fieldOptions, status: showError ? 'error' : undefined, info: showError ? 'No selection' : undefined }, void 0) }, void 0)), hasProp(rhs, 'value') && !hasProp(rhs, 'dateFunction') && (_jsxs(Flex, { item: { grow: 1 }, children: [fieldType === 'TEXT' && useValueSelector && (_jsxs(Select, { value: rhs.value, onChange: (e) => handleValueSelection(e.target.value), status: showError ? 'error' : undefined, info: showError ? 'No selection' : undefined, label: '-', labelHidden: true, children: [_jsx(Option, { value: '', children: "Select value" }, void 0), possibleValues.map(value => (_jsx(Option, { value: value, children: value }, value)))] }, void 0)), fieldType === 'TEXT' && !useValueSelector && (_jsx(Input, { value: rhs.value, onChange: handleValueChange, status: showError ? 'error' : undefined, info: showError ? 'Empty value' : undefined, name: 'rhs-text-literal-input', label: '-', labelHidden: true }, void 0)), fieldType === 'NUMBER' && (_jsx(NumericInput, { rhs: rhs, onChange: onChange, status: showError ? 'error' : undefined }, void 0)), fieldType === 'TIME_ONLY' && (_jsx(Input, { type: 'time', step: '1', value: typeof rhs.value === 'string' ? rhs.value : convertMsToTimeValue(rhs.value), onChange: handleTimeValueChange, status: showError ? 'error' : undefined, info: showError ? 'Invalid time' : undefined, label: '-', labelHidden: true }, void 0)), fieldType === 'DATE_ONLY' && (_jsx(DateInput, { value: rhs.value, onChange: handleDateValueChange, status: showError ? 'error' : undefined, info: showError ? 'Invalid date' : '', label: '-', labelHidden: true }, void 0)), fieldType === 'DATE_TIME' && (_jsx(DateTimeInput, { value: rhs.value !== '' ? rhs.value : undefined, onChange: handleDateValueChange, status: showError ? 'error' : undefined, info: showError ? 'Invalid date' : '', label: '-', labelHidden: true }, void 0))] }, void 0)), (fieldType === 'DATE_ONLY' || fieldType === 'DATE_TIME') &&
|
|
215
|
+
(hasProp(rhs, 'relativeDate') || hasProp(rhs, 'dateFunction')) && (_jsx(Flex, { item: { grow: 1 }, children: _jsx(TimePeriodComp, { rhs: rhs, fieldType: fieldType, onChange: onChange, dateFunctionsList: dateFunctions ? dateFunctions[fieldType] : [], status: showError ? 'error' : undefined }, void 0) }, void 0)), hasProp(rhs, 'values') && (_jsxs(Flex, { item: { grow: 1 }, children: [useValueSelector && (_jsx(MultiValueSelector, { values: rhs.values, options: possibleValues, onChange: handleValueSelection, status: showError ? 'error' : undefined }, void 0)), !useValueSelector && (_jsx(Input, { value: csvInput, onChange: handleCSVChange, status: showError ? 'error' : undefined, info: showError ? 'Invalid values' : undefined, label: '-', labelHidden: true, placeholder: 'Enter comma separated values' // FIXME: TR
|
|
216
|
+
}, void 0))] }, void 0))] }, void 0));
|
|
217
|
+
};
|
|
218
|
+
export default RhsControls;
|
|
219
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAkC,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAErF,OAAO,EACL,SAAS,EACT,aAAa,EACb,IAAI,EACJ,KAAK,EACL,MAAM,EACN,MAAM,EACN,OAAO,EAGR,MAAM,yBAAyB,CAAC;AAKjC,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAEhF,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AACtD,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAC5C,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAC5C,OAAO,eAAe,MAAM,mBAAmB,C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AAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS,EAC9C,KAAK,EAAC,GAAG,EACT,WAAW,QACX,WAAW,EAAC,8BAA8B,CAAC,YAAY;+BACvD,CACH,YACI,CACR,YACI,CACR,CAAC;AACJ,CAAC,CAAC;AACF,eAAe,WAAW,CAAC","sourcesContent":["import { FunctionComponent, ChangeEvent, useState, useEffect, useMemo } from 'react';\n\nimport {\n DateInput,\n DateTimeInput,\n Flex,\n Input,\n Select,\n Option,\n hasProp,\n BaseProps,\n ForwardProps\n} from '@pega/cosmos-react-core';\nimport type { DateTimeCallbackParameter } from '@pega/cosmos-react-core/lib/components/DateTime/DateTime.types';\n\nimport { FieldType, Comparator, RHSType } from '../core/types';\nimport { LeafCondition, Field, DateFunctionsByType } from '../ConditionBuilder.types';\nimport { convertTimeValueToMs, convertMsToTimeValue } from '../core/time-utils';\n\nimport MultiValueSelector from './MultiValueSelector';\nimport FieldSelector from './FieldSelector';\nimport RhsModeSwitch from './RhsModeSwitch';\nimport TimePeriodInput from './TimePeriodInput';\nimport TimePeriodMenu from './TimePeriodMenu';\nimport NumericInput from './NumericInput';\n\n/**\n * Verifies if the condition has all valid values.\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 * - Also, this does not try to validate if the given `rhs` matches the `lhs`/`comparator`/`validRhsTypes`. Instead, it assumes that the appropriate LHS/Comparator/validRhsTypes must have been already in place for this rhs to be generated.\n */\nexport function isValidRhs(\n rhs: LeafCondition['rhs'],\n fieldType?: FieldType,\n trimValues: boolean = false\n): boolean {\n // RHS would be `undefined` when no RHS is needed. Treat it as a valid value\n if (rhs === undefined) {\n return true;\n }\n\n // Field-selector on the RHS\n if (hasProp(rhs, 'field')) {\n // RHS is invalid if no field is selected\n return rhs.field !== '';\n }\n\n // List-input cases\n if (hasProp(rhs, 'values')) {\n // RHS is invalid if the list is empty\n if (rhs.values.length === 0) {\n return false;\n }\n // For numeric fields, RHS is invalid if any NaN values are present in the list\n if (fieldType === 'NUMBER' && (rhs.values as number[]).some(v => Number.isNaN(v))) {\n return false;\n }\n }\n\n if (hasProp(rhs, 'value')) {\n // Identify any invalid numbers (e.g. when `-` is entered)\n if (typeof rhs.value === 'number') {\n return !Number.isNaN(rhs.value);\n }\n\n // NOTE: Not trimming the value in the change-handler so that users can freely type spaces between words\n if (trimValues) {\n rhs.value = rhs.value.trim();\n }\n\n // Can be empty on init and on clearing the value\n if (rhs.value.trim() === '') {\n return false;\n }\n\n // This check is needed to eliminate invalid dates like `Feb 31` (02/31/2020), which the input allows\n if (\n (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY') &&\n Number.isNaN(new Date(rhs.value).getTime())\n ) {\n return false;\n }\n }\n\n if (\n hasProp(rhs, 'relativeDate') &&\n ((rhs.relativeDate.timePeriod === 'CURRENT' && rhs.relativeDate.interval) ||\n (rhs.relativeDate.timePeriod !== 'CURRENT' &&\n (!rhs.relativeDate.interval || rhs.relativeDate.interval <= 0)))\n ) {\n return false;\n }\n\n return true;\n}\n\n/** For a condition with the given comparator and lhs-field-type, determines an appropriate default value for the Rhs */\nexport function getDefaultRhs(\n fieldType: FieldType,\n comparator: Comparator,\n validRhsTypes: Set<RHSType>,\n dateFunctions?: DateFunctionsByType\n): LeafCondition['rhs'] {\n switch (comparator) {\n case 'IS_TRUE':\n case 'IS_FALSE':\n case 'IS_NULL':\n case 'IS_NOT_NULL':\n return undefined; // These comparators do not have an Rhs\n\n case 'IN':\n case 'NOT_IN':\n return { values: [] };\n\n default: {\n if (fieldType === 'BOOLEAN' && (comparator === 'EQ' || comparator === 'NEQ')) {\n // For booleans, these comparators can only be used for comparing with other fields\n return { field: '' };\n }\n\n if (validRhsTypes.has('LITERAL')) return { value: '' };\n if (\n validRhsTypes.has('DATE_FUNCTION') &&\n dateFunctions &&\n (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY')\n )\n return { value: '', dateFunction: dateFunctions[fieldType][0] };\n\n if (\n validRhsTypes.has('RELATIVE_DATE') &&\n (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY')\n ) {\n return {\n relativeDate: {\n timePeriod: 'CURRENT',\n datePart: 'DAYS'\n }\n };\n }\n\n return { field: '' };\n }\n }\n}\n\n// Truncates output values from DateInput/DateTimeInput to return a wall time on the RHS\n// NOTE: This assumes that the input date is set up on the UTC timezone\nfunction truncateISODateString(dateString: string, fieldType: FieldType): string {\n const date = new Date(dateString);\n const YYYY = date.getUTCFullYear().toString().padStart(4, '0');\n const MM = (date.getUTCMonth() + 1).toString().padStart(2, '0');\n const DD = date.getUTCDate().toString().padStart(2, '0');\n\n // For DATE_ONLY fields, returning a YYYY-MM-DD format as per spec\n if (fieldType === 'DATE_ONLY') return `${YYYY}-${MM}-${DD}`;\n\n const hh = date.getUTCHours().toString().padStart(2, '0');\n const mm = date.getUTCMinutes().toString().padStart(2, '0');\n\n // cspell:disable-next-line\n // For DATE_TIME fields, returning a YYYY-MM-DDTHH:mm format and discarding the time-zone etc. to be consistent with the previous spec which was returning a wall time\n return `${YYYY}-${MM}-${DD}T${hh}:${mm}`;\n}\n\n/** Type definition for the input props of RhsControls */\ninterface RhsControlProps extends BaseProps {\n /** Lhs for the condition */\n lhs: LeafCondition['lhs'];\n\n /** Comparator for the condition */\n comparator: Comparator;\n\n /** Rhs for the condition */\n rhs: LeafCondition['rhs'];\n\n /** Metadata (data-model) for the Fields to use in the RHS field-selector */\n fields: Field[];\n\n /** Callback for any modifications to the Rhs */\n onChange: (rhs: LeafCondition['rhs']) => void;\n\n /** Used to enable inline error indicators on invalid inputs */\n indicateErrors: boolean;\n\n /** Item flow direction */\n itemDirection: 'row' | 'column';\n\n /** Restricts RHS values to only specified RHS types */\n validRhsTypes: Set<RHSType>;\n\n /** Passed to enable additional date controls on the RHS, when a DATE_TIME/DATE_ONLY field is selected on the LHS */\n dateFunctions?: DateFunctionsByType;\n}\n\n/** A controlled component for controls on a Condition's RHS */\nconst RhsControls: FunctionComponent<RhsControlProps & ForwardProps> = (props: RhsControlProps) => {\n const {\n lhs,\n comparator,\n rhs,\n fields,\n onChange,\n indicateErrors,\n itemDirection,\n validRhsTypes,\n dateFunctions\n } = props;\n\n // Find the field corresponding to the LHS\n const matchingField = fields.find(f => f.name === lhs.field);\n\n // Options for the Field-selector (if applicable)\n const fieldOptions = useMemo(() => {\n if (!matchingField) return [];\n // Show all other fields of the same data type as the LHS\n return fields.filter(f => f.type === matchingField.type && f.name !== lhs.field);\n }, [fields, lhs]);\n\n // Set up a CSV input for IN/NOT_IN comparators\n const [csvInput, setCsvInput] = useState(\n rhs && hasProp(rhs, 'values') ? rhs.values.join(', ') : ''\n );\n useEffect(() => {\n // If moving away from the CSV-mode, clear the CSV Input.\n // This ensures that if a different `rhs.values` is passed (a new empty array can be passed when an applicable comparator is selected), the local state matches the new input.\n if (csvInput && (!rhs || !hasProp(rhs, 'values'))) {\n setCsvInput('');\n }\n }, [rhs]);\n\n // If a field is not selected or if the comparator doesn't need any RHS, don't render anything\n if (rhs === undefined) {\n return <div />; // Rendering a placeholder div to keep the layout consistent\n }\n\n if (matchingField === undefined) {\n // For safety against any rare cases where the LHS from an input condition is not present in the input fields to the ConditionBuilder\n // In those cases, don't render an RHS and wait for a valid value to be picked on LHS\n return <div />; // Rendering a placeholder div to keep the layout consistent\n }\n const fieldType = matchingField.type;\n\n // If errors should be indicated inline, validate the current rhs\n let showError = false;\n if (indicateErrors) {\n showError = !isValidRhs(rhs, fieldType, false);\n }\n\n // Set up Value-selector (if applicable)\n const { possibleValues } = matchingField; // These are passed when possible values are known ahead of time\n const isValueSelectorPossible =\n fieldType === 'TEXT' &&\n possibleValues !== undefined &&\n ['EQ', 'NEQ', 'IN', 'NOT_IN'].includes(comparator); // A ValueSelector in single/multiple mode is possible when these criteria are met\n const useValueSelector = isValueSelectorPossible && !hasProp(rhs, 'field'); // Use the ValueSelector component if it is applicable and if not in ANOTHER_FIELD mode\n\n // Handle changes from the Value-selector\n const handleValueSelection = (selection: string | string[]) => {\n if (typeof selection === 'string') {\n onChange({ value: selection }); // Submit a new RHS\n } else {\n onChange({ values: selection }); // Submit a new RHS\n }\n };\n\n // Handle changes from the Field-selector\n const handleFieldChange = (id: string) => {\n onChange({ field: id }); // Submit a new RHS\n };\n\n // Handle changes from a Value-input\n const handleValueChange = (e: ChangeEvent<HTMLInputElement>) => {\n // NOTE: Not trimming the value here so that users can freely type spaces between words. Trimming is done on Submit, via the isValidRhs call\n onChange({ value: e.target.value }); // Submit a new RHS\n };\n\n // Handle changes from a Time-input\n const handleTimeValueChange = (e: ChangeEvent<HTMLInputElement>) => {\n let newValue = e.target.value;\n if (newValue.length === 5) {\n newValue += ':00'; // Enforce a fixed hh:mm:ss format\n }\n onChange({ value: convertTimeValueToMs(newValue) }); // Submit a new RHS\n };\n\n // Handle changes from a DateInput\n const handleDateValueChange = ({\n valueAsISOString,\n valueAsTimestamp,\n state\n }: DateTimeCallbackParameter) => {\n // NOTE: Not relying fully on `state` since in some cases state and valueAsTimestamp as both undefined\n if (valueAsTimestamp === undefined || state === 'incomplete' || state === 'invalid') return;\n\n const truncatedValue = truncateISODateString(valueAsISOString, fieldType); // Truncate to return a wall time as per spec\n onChange({ value: truncatedValue });\n };\n\n // Handle changes from a CSV-input\n const handleCSVChange = (e: ChangeEvent<HTMLInputElement>) => {\n // Update the controlled input\n setCsvInput(e.target.value);\n\n // Submit a new RHS\n let newValues: string[] | number[] = e.target.value\n .split(',')\n .map(v => v.trim())\n .filter(v => v.length > 0); // Ignore empty strings\n if (fieldType === 'NUMBER') {\n newValues = newValues.map(v => Number(v)); // This can set up some NaN values. Those are used to show an appropriate feedback when the submit button is hit\n }\n onChange({ values: newValues });\n };\n\n // Render the menu directly if in a vertical layout\n const TimePeriodComp = itemDirection === 'column' ? TimePeriodMenu : TimePeriodInput;\n\n return (\n <Flex\n container={{\n direction: itemDirection,\n alignItems: itemDirection === 'column' ? 'stretch' : 'start',\n justify: 'between',\n gap: 0.5\n }}\n >\n {/* Gear MenuButton */}\n <RhsModeSwitch\n fieldType={fieldType}\n comparator={comparator}\n rhs={rhs}\n onChange={onChange}\n mode={itemDirection === 'column' ? 'combo-box' : 'menu-button'}\n validRhsTypes={validRhsTypes}\n dateFunctions={dateFunctions}\n />\n\n {/* Field-selector */}\n {hasProp(rhs, 'field') && (\n <Flex item={{ grow: 1 }}>\n <FieldSelector\n value={rhs.field}\n onChange={handleFieldChange}\n fields={fieldOptions}\n status={showError ? 'error' : undefined}\n info={showError ? 'No selection' : undefined} // FIXME: TR\n />\n </Flex>\n )}\n\n {/* Value input */}\n {hasProp(rhs, 'value') && !hasProp(rhs, 'dateFunction') && (\n <Flex item={{ grow: 1 }}>\n {fieldType === 'TEXT' && useValueSelector && (\n <Select\n value={rhs.value as string}\n onChange={(e: ChangeEvent<HTMLSelectElement>) => handleValueSelection(e.target.value)}\n status={showError ? 'error' : undefined}\n info={showError ? 'No selection' : undefined} // FIXME: TR\n label='-'\n labelHidden\n >\n <Option value=''>Select value</Option>\n {possibleValues!.map(value => (\n <Option key={value} value={value}>\n {value}\n </Option>\n ))}\n </Select>\n )}\n {fieldType === 'TEXT' && !useValueSelector && (\n <Input\n value={rhs.value as string}\n onChange={handleValueChange}\n status={showError ? 'error' : undefined}\n info={showError ? 'Empty value' : undefined} // FIXME: TR\n name='rhs-text-literal-input'\n label='-'\n labelHidden\n />\n )}\n {fieldType === 'NUMBER' && (\n <NumericInput rhs={rhs} onChange={onChange} status={showError ? 'error' : undefined} />\n )}\n {fieldType === 'TIME_ONLY' && (\n <Input\n type='time'\n step='1'\n value={typeof rhs.value === 'string' ? rhs.value : convertMsToTimeValue(rhs.value)}\n onChange={handleTimeValueChange}\n status={showError ? 'error' : undefined}\n info={showError ? 'Invalid time' : undefined} // FIXME: TR\n label='-'\n labelHidden\n />\n )}\n {fieldType === 'DATE_ONLY' && (\n <DateInput\n value={rhs.value}\n onChange={handleDateValueChange}\n status={showError ? 'error' : undefined}\n info={showError ? 'Invalid date' : ''} // FIXME: TR , NOTE: Using empty quotes to disable the default info which indicates the format\n label='-'\n labelHidden\n />\n )}\n {fieldType === 'DATE_TIME' && (\n <DateTimeInput\n value={rhs.value !== '' ? rhs.value : undefined}\n onChange={handleDateValueChange}\n status={showError ? 'error' : undefined}\n info={showError ? 'Invalid date' : ''} // FIXME: TR , NOTE: Using empty quotes to disable the default info which indicates the format\n label='-'\n labelHidden\n />\n )}\n </Flex>\n )}\n\n {(fieldType === 'DATE_ONLY' || fieldType === 'DATE_TIME') &&\n (hasProp(rhs, 'relativeDate') || hasProp(rhs, 'dateFunction')) && (\n <Flex item={{ grow: 1 }}>\n <TimePeriodComp\n rhs={rhs}\n fieldType={fieldType}\n onChange={onChange}\n dateFunctionsList={dateFunctions ? dateFunctions[fieldType] : []}\n status={showError ? 'error' : undefined}\n />\n </Flex>\n )}\n\n {/* Multiple-values input */}\n {hasProp(rhs, 'values') && (\n <Flex item={{ grow: 1 }}>\n {useValueSelector && (\n <MultiValueSelector\n values={rhs.values as string[]}\n options={possibleValues!}\n onChange={handleValueSelection}\n status={showError ? 'error' : undefined}\n />\n )}\n {!useValueSelector && (\n <Input\n value={csvInput}\n onChange={handleCSVChange}\n status={showError ? 'error' : undefined}\n info={showError ? 'Invalid values' : undefined} // FIXME: TR\n label='-'\n labelHidden\n placeholder='Enter comma separated values' // FIXME: TR\n />\n )}\n </Flex>\n )}\n </Flex>\n );\n};\nexport default RhsControls;\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FieldType, Comparator, ComparatorsByType } from './types';
|
|
2
|
+
interface ComparatorOption {
|
|
3
|
+
id: Comparator;
|
|
4
|
+
label: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Returns Comparator-options applicable to the input fieldType
|
|
8
|
+
* If `validComparators` is passed, limits the options based on that
|
|
9
|
+
*/
|
|
10
|
+
export default function getComparatorOptions(fieldType: FieldType, validComparators?: ComparatorsByType[]): ComparatorOption[];
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=comparators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comparators.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/comparators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEnE,UAAU,gBAAgB;IACxB,EAAE,EAAE,UAAU,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AA+DD;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAC1C,SAAS,EAAE,SAAS,EACpB,gBAAgB,CAAC,EAAE,iBAAiB,EAAE,GACrC,gBAAgB,EAAE,CAapB"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// FIXME: TR
|
|
2
|
+
const boolFieldOptions = [
|
|
3
|
+
{ id: 'IS_TRUE', label: 'is true' },
|
|
4
|
+
{ id: 'IS_FALSE', label: 'is false' },
|
|
5
|
+
{ id: 'EQ', label: 'is equal to' },
|
|
6
|
+
{ id: 'NEQ', label: 'is not equal to' },
|
|
7
|
+
{ id: 'IS_NULL', label: 'is null' },
|
|
8
|
+
{ id: 'IS_NOT_NULL', label: 'is not null' }
|
|
9
|
+
];
|
|
10
|
+
// FIXME: TR
|
|
11
|
+
const textFieldOptions = [
|
|
12
|
+
{ id: 'EQ', label: 'is equal to' },
|
|
13
|
+
{ id: 'NEQ', label: 'is not equal to' },
|
|
14
|
+
{ id: 'IN', label: 'is in list' },
|
|
15
|
+
{ id: 'NOT_IN', label: 'is not in list' },
|
|
16
|
+
{ id: 'STARTS_WITH', label: 'starts with' },
|
|
17
|
+
{ id: 'NOT_STARTS_WITH', label: 'not starts with' },
|
|
18
|
+
{ id: 'ENDS_WITH', label: 'ends with' },
|
|
19
|
+
{ id: 'NOT_ENDS_WITH', label: 'not ends with' },
|
|
20
|
+
{ id: 'CONTAINS', label: 'contains' },
|
|
21
|
+
{ id: 'NOT_CONTAINS', label: 'not contains' },
|
|
22
|
+
{ id: 'IS_NULL', label: 'is null' },
|
|
23
|
+
{ id: 'IS_NOT_NULL', label: 'is not null' }
|
|
24
|
+
];
|
|
25
|
+
// FIXME: TR
|
|
26
|
+
const numericFieldOptions = [
|
|
27
|
+
{ id: 'EQ', label: 'is equal to' },
|
|
28
|
+
{ id: 'NEQ', label: 'is not equal to' },
|
|
29
|
+
{ id: 'IN', label: 'is in list' },
|
|
30
|
+
{ id: 'NOT_IN', label: 'is not in list' },
|
|
31
|
+
{ id: 'GT', label: 'greater than' },
|
|
32
|
+
{ id: 'GTE', label: 'greater than or equals' },
|
|
33
|
+
{ id: 'LT', label: 'lower than' },
|
|
34
|
+
{ id: 'LTE', label: 'lower than or equals' },
|
|
35
|
+
{ id: 'IS_NULL', label: 'is null' },
|
|
36
|
+
{ id: 'IS_NOT_NULL', label: 'is not null' }
|
|
37
|
+
];
|
|
38
|
+
// FIXME: TR
|
|
39
|
+
const dateTimeFieldOptions = [
|
|
40
|
+
{ id: 'EQ', label: 'is equal to' },
|
|
41
|
+
{ id: 'NEQ', label: 'is not equal to' },
|
|
42
|
+
{ id: 'GT', label: 'after' },
|
|
43
|
+
{ id: 'GTE', label: 'on or after' },
|
|
44
|
+
{ id: 'LT', label: 'before' },
|
|
45
|
+
{ id: 'LTE', label: 'on or before' },
|
|
46
|
+
{ id: 'IS_NULL', label: 'is null' },
|
|
47
|
+
{ id: 'IS_NOT_NULL', label: 'is not null' }
|
|
48
|
+
];
|
|
49
|
+
const typeWiseComparators = {
|
|
50
|
+
BOOLEAN: boolFieldOptions,
|
|
51
|
+
TEXT: textFieldOptions,
|
|
52
|
+
NUMBER: numericFieldOptions,
|
|
53
|
+
DATE_TIME: dateTimeFieldOptions,
|
|
54
|
+
DATE_ONLY: dateTimeFieldOptions,
|
|
55
|
+
TIME_ONLY: dateTimeFieldOptions
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Returns Comparator-options applicable to the input fieldType
|
|
59
|
+
* If `validComparators` is passed, limits the options based on that
|
|
60
|
+
*/
|
|
61
|
+
export default function getComparatorOptions(fieldType, validComparators) {
|
|
62
|
+
// Identify the options by fieldType
|
|
63
|
+
const options = typeWiseComparators[fieldType];
|
|
64
|
+
// If a limited set of comparators is provided for the current fieldType, use those
|
|
65
|
+
if (validComparators !== undefined) {
|
|
66
|
+
const applicableGroup = validComparators.find(group => group.type === fieldType);
|
|
67
|
+
if (applicableGroup !== undefined) {
|
|
68
|
+
const comparators = new Set(applicableGroup.comparators);
|
|
69
|
+
return options.filter(o => comparators.has(o.id));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return options;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=comparators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comparators.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/comparators.ts"],"names":[],"mappings":"AAOA,YAAY;AACZ,MAAM,gBAAgB,GAAuB;IAC3C,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE;IACnC,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE;IACrC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,aAAa,EAAE;IAClC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE;IACvC,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE;IACnC,EAAE,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE;CAC5C,CAAC;AAEF,YAAY;AACZ,MAAM,gBAAgB,GAAuB;IAC3C,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,aAAa,EAAE;IAClC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE;IACvC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAA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AC,CAAC,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;SACnD;KACF;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { FieldType, Comparator, ComparatorsByType } from './types';\n\ninterface ComparatorOption {\n id: Comparator;\n label: string;\n}\n\n// FIXME: TR\nconst boolFieldOptions: ComparatorOption[] = [\n { id: 'IS_TRUE', label: 'is true' },\n { id: 'IS_FALSE', label: 'is false' },\n { id: 'EQ', label: 'is equal to' },\n { id: 'NEQ', label: 'is not equal to' },\n { id: 'IS_NULL', label: 'is null' },\n { id: 'IS_NOT_NULL', label: 'is not null' }\n];\n\n// FIXME: TR\nconst textFieldOptions: ComparatorOption[] = [\n { id: 'EQ', label: 'is equal to' },\n { id: 'NEQ', label: 'is not equal to' },\n { id: 'IN', label: 'is in list' },\n { id: 'NOT_IN', label: 'is not in list' },\n { id: 'STARTS_WITH', label: 'starts with' },\n { id: 'NOT_STARTS_WITH', label: 'not starts with' },\n { id: 'ENDS_WITH', label: 'ends with' },\n { id: 'NOT_ENDS_WITH', label: 'not ends with' },\n { id: 'CONTAINS', label: 'contains' },\n { id: 'NOT_CONTAINS', label: 'not contains' },\n { id: 'IS_NULL', label: 'is null' },\n { id: 'IS_NOT_NULL', label: 'is not null' }\n];\n\n// FIXME: TR\nconst numericFieldOptions: ComparatorOption[] = [\n { id: 'EQ', label: 'is equal to' },\n { id: 'NEQ', label: 'is not equal to' },\n { id: 'IN', label: 'is in list' },\n { id: 'NOT_IN', label: 'is not in list' },\n { id: 'GT', label: 'greater than' },\n { id: 'GTE', label: 'greater than or equals' },\n { id: 'LT', label: 'lower than' },\n { id: 'LTE', label: 'lower than or equals' },\n { id: 'IS_NULL', label: 'is null' },\n { id: 'IS_NOT_NULL', label: 'is not null' }\n];\n\n// FIXME: TR\nconst dateTimeFieldOptions: ComparatorOption[] = [\n { id: 'EQ', label: 'is equal to' },\n { id: 'NEQ', label: 'is not equal to' },\n { id: 'GT', label: 'after' },\n { id: 'GTE', label: 'on or after' },\n { id: 'LT', label: 'before' },\n { id: 'LTE', label: 'on or before' },\n { id: 'IS_NULL', label: 'is null' },\n { id: 'IS_NOT_NULL', label: 'is not null' }\n];\n\nconst typeWiseComparators: Record<FieldType, ComparatorOption[]> = {\n BOOLEAN: boolFieldOptions,\n TEXT: textFieldOptions,\n NUMBER: numericFieldOptions,\n DATE_TIME: dateTimeFieldOptions,\n DATE_ONLY: dateTimeFieldOptions,\n TIME_ONLY: dateTimeFieldOptions\n};\n\n/**\n * Returns Comparator-options applicable to the input fieldType\n * If `validComparators` is passed, limits the options based on that\n */\nexport default function getComparatorOptions(\n fieldType: FieldType,\n validComparators?: ComparatorsByType[]\n): ComparatorOption[] {\n // Identify the options by fieldType\n const options = typeWiseComparators[fieldType];\n\n // If a limited set of comparators is provided for the current fieldType, use those\n if (validComparators !== undefined) {\n const applicableGroup = validComparators.find(group => group.type === fieldType);\n if (applicableGroup !== undefined) {\n const comparators = new Set(applicableGroup.comparators);\n return options.filter(o => comparators.has(o.id));\n }\n }\n return options;\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Condition, Field } from '../ConditionBuilder.types';
|
|
2
|
+
/**
|
|
3
|
+
* Evaluates a condition tree for the given data document
|
|
4
|
+
* NOTE: The output is nondeterministic if:
|
|
5
|
+
* - any of the nodes in the input Condition are in an unexpected format (invalid keys, comparators etc.)
|
|
6
|
+
* - any null/undefined values are encountered in the input data, unless they are used with an IS_NULL/IS_NOT_NULL comparator
|
|
7
|
+
* - stringified values are encountered for BOOLEAN/NUMBER fields
|
|
8
|
+
* - non-ISO strings are passed for DATE_TIME/DATE_ONLY fields
|
|
9
|
+
* - TIME_ONLY data values are not passed as `number of milliseconds since the start of day`
|
|
10
|
+
*/
|
|
11
|
+
export default function evaluateCondition(condition: Condition, data: {
|
|
12
|
+
[fieldName: string]: any;
|
|
13
|
+
}, fields: Field[]): boolean;
|
|
14
|
+
//# sourceMappingURL=evaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/evaluator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAiB,KAAK,EAAuB,MAAM,2BAA2B,CAAC;AAyQjG;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACvC,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE;IAAE,CAAC,SAAS,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAClC,MAAM,EAAE,KAAK,EAAE,GACd,OAAO,CAoBT"}
|