@pega/cosmos-react-condition-builder 3.0.0-dev.28.0 → 3.0.0-dev.30.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.
- package/lib/components/ConditionBuilder/AtomicCondition.d.ts +3 -1
- package/lib/components/ConditionBuilder/AtomicCondition.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/AtomicCondition.js +5 -2
- package/lib/components/ConditionBuilder/AtomicCondition.js.map +1 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts +3 -0
- package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.types.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.js +15 -6
- package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/index.d.ts +4 -1
- package/lib/components/ConditionBuilder/RhsControls/index.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/index.js +50 -4
- package/lib/components/ConditionBuilder/RhsControls/index.js.map +1 -1
- package/lib/components/ConditionBuilder/core/comparators.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/comparators.js +4 -0
- package/lib/components/ConditionBuilder/core/comparators.js.map +1 -1
- package/lib/components/ConditionBuilder/core/evaluator.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/evaluator.js +4 -1
- package/lib/components/ConditionBuilder/core/evaluator.js.map +1 -1
- package/lib/components/ConditionBuilder/core/formatter.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/formatter.js +53 -47
- package/lib/components/ConditionBuilder/core/formatter.js.map +1 -1
- package/lib/components/ConditionBuilder/core/transformer.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/transformer.js +34 -0
- package/lib/components/ConditionBuilder/core/transformer.js.map +1 -1
- package/lib/components/ConditionBuilder/core/types.d.ts +1 -1
- package/lib/components/ConditionBuilder/core/types.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/types.js.map +1 -1
- package/lib/components/ConditionInput/ConditionInput.d.ts.map +1 -1
- package/lib/components/ConditionInput/ConditionInput.js +84 -19
- package/lib/components/ConditionInput/ConditionInput.js.map +1 -1
- package/lib/components/ConditionInput/ConditionInput.styles.d.ts +1 -1
- package/lib/components/ConditionInput/ConditionInput.styles.d.ts.map +1 -1
- package/lib/components/ConditionInput/ConditionInput.styles.js +2 -2
- package/lib/components/ConditionInput/ConditionInput.styles.js.map +1 -1
- package/lib/components/ConditionInput/utils.d.ts +7 -0
- package/lib/components/ConditionInput/utils.d.ts.map +1 -1
- package/lib/components/ConditionInput/utils.js +16 -7
- package/lib/components/ConditionInput/utils.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FunctionComponent } from 'react';
|
|
2
|
-
import { BaseProps, ForwardProps } from '@pega/cosmos-react-core';
|
|
2
|
+
import { BaseProps, ForwardProps, FormControlProps } from '@pega/cosmos-react-core';
|
|
3
3
|
import { LeafCondition, Field, DateFunctionsByType } from './ConditionBuilder.types';
|
|
4
4
|
import { ComparatorsByType, RHSType } from './core/types';
|
|
5
5
|
/** Determines the default condition object for a given LHS value */
|
|
@@ -44,6 +44,8 @@ export interface AtomicConditionProps extends BaseProps {
|
|
|
44
44
|
validRhsTypes?: Set<RHSType>;
|
|
45
45
|
/** (Optional) When enabling 'DATE_FUNCTION's via `validRhsTypes`, pass this to specify which all date functions are applicable per field type */
|
|
46
46
|
dateFunctions?: DateFunctionsByType;
|
|
47
|
+
/** Visually hides the label region of the RHS. */
|
|
48
|
+
rhsLabelHidden?: FormControlProps['labelHidden'];
|
|
47
49
|
}
|
|
48
50
|
/** A controlled component for Atomic Conditions */
|
|
49
51
|
declare const AtomicCondition: FunctionComponent<AtomicConditionProps & ForwardProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AtomicCondition.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/AtomicCondition.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAe,MAAM,OAAO,CAAC;AAEvD,OAAO,EAML,SAAS,EACT,YAAY,
|
|
1
|
+
{"version":3,"file":"AtomicCondition.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/AtomicCondition.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAe,MAAM,OAAO,CAAC;AAEvD,OAAO,EAML,SAAS,EACT,YAAY,EACZ,gBAAgB,EACjB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAIrF,OAAO,EAAc,iBAAiB,EAAa,OAAO,EAAE,MAAM,cAAc,CAAC;AAoDjF,oEAAoE;AACpE,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,EACzB,MAAM,EAAE,KAAK,EAAE,EACf,aAAa,EAAE,GAAG,CAAC,OAAO,CAAC,EAC3B,gBAAgB,CAAC,EAAE,iBAAiB,EAAE,EACtC,aAAa,CAAC,EAAE,mBAAmB,GAClC,aAAa,CAcf;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,aAAa,EACxB,MAAM,EAAE,KAAK,EAAE,EACf,UAAU,GAAE,OAAe,GAC1B,OAAO,CAST;AAED,6DAA6D;AAC7D,MAAM,WAAW,oBAAqB,SAAQ,SAAS;IACrD,wCAAwC;IACxC,SAAS,EAAE,aAAa,CAAC;IAEzB,mEAAmE;IACnE,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB,+DAA+D;IAC/D,cAAc,EAAE,OAAO,CAAC;IAExB,gFAAgF;IAChF,gBAAgB,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAEvC,sDAAsD;IACtD,QAAQ,EAAE,CAAC,YAAY,EAAE,aAAa,KAAK,IAAI,CAAC;IAEhD,6CAA6C;IAC7C,aAAa,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC;IAEjC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;IAEvC;;;;;;;;;;OAUG;IACH,aAAa,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAE7B,iJAAiJ;IACjJ,aAAa,CAAC,EAAE,mBAAmB,CAAC;IAEpC,kDAAkD;IAClD,cAAc,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC;CAClD;AAED,mDAAmD;AACnD,QAAA,MAAM,eAAe,EAAE,iBAAiB,CAAC,oBAAoB,GAAG,YAAY,CAwH3E,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -29,6 +29,9 @@ function isRhsValidForComparator(rhs, comparator) {
|
|
|
29
29
|
if (hasProp(rhs, 'parameterId')) {
|
|
30
30
|
return ['EQ', 'NEQ'].includes(comparator);
|
|
31
31
|
}
|
|
32
|
+
if (hasProp(rhs, 'start')) {
|
|
33
|
+
return ['BTW', 'NOT_BTW'].includes(comparator);
|
|
34
|
+
}
|
|
32
35
|
// `rhs.field` and `rhs.value` cases
|
|
33
36
|
return [
|
|
34
37
|
'EQ',
|
|
@@ -78,7 +81,7 @@ export function isValidCondition(condition, fields, trimValues = false) {
|
|
|
78
81
|
return isValidRhs(condition.rhs, condition.lhs, fields, fieldType, trimValues);
|
|
79
82
|
}
|
|
80
83
|
/** A controlled component for Atomic Conditions */
|
|
81
|
-
const AtomicCondition = ({ condition, fields, indicateErrors, validComparators, onChange, itemDirection, lhsMode = 'input', validRhsTypes = new Set(['LITERAL', 'FIELD']), dateFunctions, ...restProps }) => {
|
|
84
|
+
const AtomicCondition = ({ condition, fields, indicateErrors, validComparators, onChange, itemDirection, lhsMode = 'input', validRhsTypes = new Set(['LITERAL', 'FIELD']), dateFunctions, rhsLabelHidden, ...restProps }) => {
|
|
82
85
|
const t = useI18n();
|
|
83
86
|
const fieldType = getFieldType(condition.lhs.field, fields); // Can be `undefined` if no match or if no previous field
|
|
84
87
|
const comparatorOptions = fieldType
|
|
@@ -120,7 +123,7 @@ const AtomicCondition = ({ condition, fields, indicateErrors, validComparators,
|
|
|
120
123
|
rowGap: 0.5
|
|
121
124
|
}, children: [lhsMode === 'input' && (_jsx(FieldSelector, { value: condition.lhs.field, onChange: handleFieldChange, fields: fields, status: indicateErrors && condition.lhs.field === '' ? 'error' : undefined, info: indicateErrors && condition.lhs.field === ''
|
|
122
125
|
? t('condition_builder_condition_select_info_default')
|
|
123
|
-
: undefined })), _jsx(Select, { value: condition.comparator, onChange: handleComparatorChange, name: 'comparator', label: t('condition_builder_comparator_label'), labelHidden: true, children: comparatorOptions.map(option => (_jsx(Option, { value: option.id, children: option.label }, option.id))) }), _jsx(RhsControls, { lhs: condition.lhs, comparator: condition.comparator, rhs: condition.rhs, fields: fields, onChange: handleRHSChange, indicateErrors: indicateErrors, validRhsTypes: validRhsTypes, dateFunctions: dateFunctions, itemDirection: itemDirection || 'row' })] }) }));
|
|
126
|
+
: undefined })), _jsx(Select, { value: condition.comparator, onChange: handleComparatorChange, name: 'comparator', label: t('condition_builder_comparator_label'), labelHidden: true, children: comparatorOptions.map(option => (_jsx(Option, { value: option.id, children: option.label }, option.id))) }), _jsx(RhsControls, { lhs: condition.lhs, comparator: condition.comparator, rhs: condition.rhs, fields: fields, onChange: handleRHSChange, indicateErrors: indicateErrors, validRhsTypes: validRhsTypes, dateFunctions: dateFunctions, itemDirection: itemDirection || 'row', labelHidden: rhsLabelHidden })] }) }));
|
|
124
127
|
};
|
|
125
128
|
export default AtomicCondition;
|
|
126
129
|
//# sourceMappingURL=AtomicCondition.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AtomicCondition.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/AtomicCondition.tsx"],"names":[],"mappings":";AAE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AAE,cAAc,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAC1E,IAAI,EACF,cAAc,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,KAAK,EAAE;wBAC1C,CAAC,CAAC,CAAC,CAAC,iDAAiD,CAAC;wBACtD,CAAC,CAAC,SAAS,GAEf,CACH,EAGD,KAAC,MAAM,IACL,KAAK,EAAE,SAAS,CAAC,UAAU,EAC3B,QAAQ,EAAE,sBAAsB,EAChC,IAAI,EAAC,YAAY,EACjB,KAAK,EAAE,CAAC,CAAC,oCAAoC,CAAC,EAC9C,WAAW,kBAEV,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAC/B,KAAC,MAAM,IAAiB,KAAK,EAAE,MAAM,CAAC,EAAE,YACrC,MAAM,CAAC,KAAK,IADF,MAAM,CAAC,EAAE,CAEb,CACV,CAAC,GACK,EAGT,KAAC,WAAW,IACV,GAAG,EAAE,SAAS,CAAC,GAAG,EAClB,UAAU,EAAE,SAAS,CAAC,UAAU,EAChC,GAAG,EAAE,SAAS,CAAC,GAAG,EAClB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,eAAe,EACzB,cAAc,EAAE,cAAc,EAC9B,aAAa,EAAE,aAAa,EAC5B,aAAa,EAAE,aAAa,EAC5B,aAAa,EAAE,aAAa,IAAI,KAAK,GACrC,IACG,GACe,CACzB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { FunctionComponent, ChangeEvent } from 'react';\n\nimport {\n Grid,\n Select,\n Option,\n useI18n,\n hasProp,\n BaseProps,\n ForwardProps\n} from '@pega/cosmos-react-core';\n\nimport { getItem } from './core/utils';\nimport { LeafCondition, Field, DateFunctionsByType } from './ConditionBuilder.types';\nimport FieldSelector from './RhsControls/FieldSelector';\nimport RhsControls, { getDefaultRhs, isValidRhs } from './RhsControls';\nimport getComparatorOptions from './core/comparators';\nimport { Comparator, ComparatorsByType, FieldType, RHSType } from './core/types';\nimport { StyledAtomicCondition } from './ConditionBuilder.styles';\n\n// Returns field-type for a given field-name\nfunction getFieldType(fieldName: string, fields: Field[]): FieldType | undefined {\n const matchingField = getItem(fields, fieldName);\n return matchingField && hasProp(matchingField, 'type') ? matchingField.type : undefined;\n}\n\n// Returns display label for a given field-name\nfunction getFieldLabel(fieldName: string, fields: Field[]): string | undefined {\n const matchingField = getItem(fields, fieldName);\n return matchingField?.primary;\n}\n\n/**\n * Upon changing the comparator, checks if the old RHS is valid for the new comparator\n * NOTE: This works under the assumption that the LHS doesn't change\n */\nfunction isRhsValidForComparator(rhs: LeafCondition['rhs'], comparator: Comparator): boolean {\n if (rhs === undefined) {\n return ['IS_NULL', 'IS_NOT_NULL', 'IS_TRUE', 'IS_FALSE'].includes(comparator);\n }\n if (hasProp(rhs, 'values')) {\n return ['IN', 'NOT_IN'].includes(comparator);\n }\n\n if (hasProp(rhs, 'parameterId')) {\n return ['EQ', 'NEQ'].includes(comparator);\n }\n\n // `rhs.field` and `rhs.value` cases\n return [\n 'EQ',\n 'NEQ',\n 'GT',\n 'GTE',\n 'LT',\n 'LTE',\n 'STARTS_WITH',\n 'NOT_STARTS_WITH',\n 'ENDS_WITH',\n 'NOT_ENDS_WITH',\n 'CONTAINS',\n 'NOT_CONTAINS'\n ].includes(comparator);\n}\n\n/** Determines the default condition object for a given LHS value */\nexport function getInitConditionForLhs(\n lhs: LeafCondition['lhs'],\n fields: Field[],\n validRhsTypes: Set<RHSType>,\n validComparators?: ComparatorsByType[],\n dateFunctions?: DateFunctionsByType\n): LeafCondition {\n let comparator: Comparator;\n let rhs: LeafCondition['rhs'];\n if (lhs.field === '') {\n // If the empty option is selected, reset the comparator and rhs to their default values\n comparator = 'IS_NOT_NULL';\n rhs = undefined;\n } else {\n const newFieldType = getFieldType(lhs.field, fields) as FieldType;\n comparator = getComparatorOptions(newFieldType, validComparators)[0].id; // Find the applicable comparators and select the first among them\n rhs = getDefaultRhs(newFieldType, comparator, validRhsTypes, dateFunctions);\n }\n\n return { lhs, comparator, rhs };\n}\n\n/**\n * Verifies if all the values in the condition are valid.\n * NOTES:\n * - This is intended to be used only on conditions emitted by the components in this package.\n * - If a condition is manually constructed outside these components, this utility could miss some malformed conditions.\n */\nexport function isValidCondition(\n condition: LeafCondition,\n fields: Field[],\n trimValues: boolean = false\n): boolean {\n // If no field is yet selected on the LHS\n if (condition.lhs.field === '') {\n return false;\n }\n // If a field is present on the LHS, check if the RHS is valid\n // No need to check the comparator since the comparator is always assigned a valid value\n const fieldType = getFieldType(condition.lhs.field, fields);\n return isValidRhs(condition.rhs, condition.lhs, fields, fieldType, trimValues);\n}\n\n/** Type definition for the input props of AtomicCondition */\nexport interface AtomicConditionProps extends BaseProps {\n /** Condition to use in the component */\n condition: LeafCondition;\n\n /** Metadata (data-model) for the Fields to use in the Condition */\n fields: Field[];\n\n /** Used to enable inline error indicators on invalid inputs */\n indicateErrors: boolean;\n\n /** (Optional) Lookup used to limit the Comparators allowed in the Condition. */\n validComparators?: ComparatorsByType[];\n\n /** Callback for any modifications to the Condition */\n onChange: (newCondition: LeafCondition) => void;\n\n /** Item flow direction. Defaults to 'row' */\n itemDirection?: 'row' | 'column';\n\n /**\n * Allows presenting the LHS as a readonly text, input or hidden. Defaults presenting as 'input'.\n * NOTE: Make sure that a valid LHS is passed in the 'condition'\n */\n lhsMode?: 'input' | 'label' | 'hidden';\n\n /** Restricts RHS values to only specified types of values.\n * DEFAULT: Set(['LITERAL', 'FIELD']).\n * WARNING: There are LHS/Comparator pairings that require specific RHS types. Please be mindful of\n * these incompatibilities when limiting RHS value types using this prop. We do not support\n * limiting RHS field types to incompatible types and it will result in a validation error\n * if you do so. The pairings referred to here are as follows:\n * - BOOLEAN LHS Fields coupled with \"EQ\" or \"NEQ\" comparators, will always yield a Field RHS\n * - Any LHS Fields coupled with \"IN\" or \"NOT_IN\" comparators, will always yield a Literal RHS (Comma separated list)\n * If you would like to limit RHS value types and avoid these incompatibilities, you will need to exclude these\n * comparators using the validComparators prop.\n */\n validRhsTypes?: Set<RHSType>;\n\n /** (Optional) When enabling 'DATE_FUNCTION's via `validRhsTypes`, pass this to specify which all date functions are applicable per field type */\n dateFunctions?: DateFunctionsByType;\n}\n\n/** A controlled component for Atomic Conditions */\nconst AtomicCondition: FunctionComponent<AtomicConditionProps & ForwardProps> = ({\n condition,\n fields,\n indicateErrors,\n validComparators,\n onChange,\n itemDirection,\n lhsMode = 'input',\n validRhsTypes = new Set<RHSType>(['LITERAL', 'FIELD']),\n dateFunctions,\n ...restProps\n}: AtomicConditionProps) => {\n const t = useI18n();\n\n const fieldType = getFieldType(condition.lhs.field, fields); // Can be `undefined` if no match or if no previous field\n const comparatorOptions = fieldType\n ? getComparatorOptions(fieldType, validComparators)\n : [{ id: '', label: t('condition_builder_select_placeholder') }];\n\n // Handle change in the field-selector\n const handleFieldChange = (id: string) => {\n const lhs = { field: id };\n const newCondition = getInitConditionForLhs(\n lhs,\n fields,\n validRhsTypes,\n validComparators,\n dateFunctions\n ); // Determine comparator and rhs for the new lhs\n onChange(newCondition); // Submit the new condition\n };\n\n // Handle change in the comparator\n const handleComparatorChange = (e: ChangeEvent<HTMLSelectElement>) => {\n if (e.target.value === '') {\n return; // The option is shown only when an lhs is not yet selected. Ignore this selection for those cases\n }\n const comparator = e.target.value as Comparator;\n const rhs = isRhsValidForComparator(condition.rhs, comparator)\n ? condition.rhs\n : getDefaultRhs(fieldType as FieldType, comparator, validRhsTypes, dateFunctions);\n onChange({ ...condition, comparator, rhs }); // Submit the new condition\n };\n\n // Handle change in the RHS\n const handleRHSChange = (rhs: LeafCondition['rhs']) => {\n onChange({ ...condition, rhs }); // Submit the new condition\n };\n\n const lhsLabel = getFieldLabel(condition.lhs.field, fields);\n\n return (\n // Using minmax() to get equal widths: https://stackoverflow.com/a/61240964/4247448\n <StyledAtomicCondition\n {...restProps}\n name={lhsMode === 'label' ? lhsLabel : undefined}\n aria-label={lhsLabel}\n >\n <Grid\n sm={{\n container: {\n cols:\n itemDirection === 'column'\n ? '1fr'\n : `repeat(${lhsMode !== 'input' ? 2 : 3}, minmax(0,1fr))`\n }\n }}\n container={{\n justifyItems: 'stretch',\n colGap: 0.5,\n rowGap: 0.5\n }}\n >\n {/* LHS selector */}\n {lhsMode === 'input' && (\n <FieldSelector\n value={condition.lhs.field}\n onChange={handleFieldChange}\n fields={fields}\n status={indicateErrors && condition.lhs.field === '' ? 'error' : undefined}\n info={\n indicateErrors && condition.lhs.field === ''\n ? t('condition_builder_condition_select_info_default')\n : undefined\n }\n />\n )}\n\n {/* Comparator selector */}\n <Select\n value={condition.comparator}\n onChange={handleComparatorChange}\n name='comparator'\n label={t('condition_builder_comparator_label')}\n labelHidden\n >\n {comparatorOptions.map(option => (\n <Option key={option.id} value={option.id}>\n {option.label}\n </Option>\n ))}\n </Select>\n\n {/* RHS controls */}\n <RhsControls\n lhs={condition.lhs}\n comparator={condition.comparator}\n rhs={condition.rhs}\n fields={fields}\n onChange={handleRHSChange}\n indicateErrors={indicateErrors}\n validRhsTypes={validRhsTypes}\n dateFunctions={dateFunctions}\n itemDirection={itemDirection || 'row'}\n />\n </Grid>\n </StyledAtomicCondition>\n );\n};\n\nexport default AtomicCondition;\n"]}
|
|
1
|
+
{"version":3,"file":"AtomicCondition.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/AtomicCondition.tsx"],"names":[],"mappings":";AAEA,OAAO,EACL,IAAI,EACJ,MAAM,EACN,MAAM,EACN,OAAO,EACP,OAAO,EAIR,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,aAAa,MAAM,6BAA6B,CAAC;AACxD,OAAO,WAAW,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,oBAAoB,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EAAE,qBAAqB,EA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EAAE;wBAC1C,CAAC,CAAC,CAAC,CAAC,iDAAiD,CAAC;wBACtD,CAAC,CAAC,SAAS,GAEf,CACH,EAGD,KAAC,MAAM,IACL,KAAK,EAAE,SAAS,CAAC,UAAU,EAC3B,QAAQ,EAAE,sBAAsB,EAChC,IAAI,EAAC,YAAY,EACjB,KAAK,EAAE,CAAC,CAAC,oCAAoC,CAAC,EAC9C,WAAW,kBAEV,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAC/B,KAAC,MAAM,IAAiB,KAAK,EAAE,MAAM,CAAC,EAAE,YACrC,MAAM,CAAC,KAAK,IADF,MAAM,CAAC,EAAE,CAEb,CACV,CAAC,GACK,EAGT,KAAC,WAAW,IACV,GAAG,EAAE,SAAS,CAAC,GAAG,EAClB,UAAU,EAAE,SAAS,CAAC,UAAU,EAChC,GAAG,EAAE,SAAS,CAAC,GAAG,EAClB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,eAAe,EACzB,cAAc,EAAE,cAAc,EAC9B,aAAa,EAAE,aAAa,EAC5B,aAAa,EAAE,aAAa,EAC5B,aAAa,EAAE,aAAa,IAAI,KAAK,EACrC,WAAW,EAAE,cAAc,GAC3B,IACG,GACe,CACzB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { FunctionComponent, ChangeEvent } from 'react';\n\nimport {\n Grid,\n Select,\n Option,\n useI18n,\n hasProp,\n BaseProps,\n ForwardProps,\n FormControlProps\n} from '@pega/cosmos-react-core';\n\nimport { getItem } from './core/utils';\nimport { LeafCondition, Field, DateFunctionsByType } from './ConditionBuilder.types';\nimport FieldSelector from './RhsControls/FieldSelector';\nimport RhsControls, { getDefaultRhs, isValidRhs } from './RhsControls';\nimport getComparatorOptions from './core/comparators';\nimport { Comparator, ComparatorsByType, FieldType, RHSType } from './core/types';\nimport { StyledAtomicCondition } from './ConditionBuilder.styles';\n\n// Returns field-type for a given field-name\nfunction getFieldType(fieldName: string, fields: Field[]): FieldType | undefined {\n const matchingField = getItem(fields, fieldName);\n return matchingField && hasProp(matchingField, 'type') ? matchingField.type : undefined;\n}\n\n// Returns display label for a given field-name\nfunction getFieldLabel(fieldName: string, fields: Field[]): string | undefined {\n const matchingField = getItem(fields, fieldName);\n return matchingField?.primary;\n}\n\n/**\n * Upon changing the comparator, checks if the old RHS is valid for the new comparator\n * NOTE: This works under the assumption that the LHS doesn't change\n */\nfunction isRhsValidForComparator(rhs: LeafCondition['rhs'], comparator: Comparator): boolean {\n if (rhs === undefined) {\n return ['IS_NULL', 'IS_NOT_NULL', 'IS_TRUE', 'IS_FALSE'].includes(comparator);\n }\n if (hasProp(rhs, 'values')) {\n return ['IN', 'NOT_IN'].includes(comparator);\n }\n\n if (hasProp(rhs, 'parameterId')) {\n return ['EQ', 'NEQ'].includes(comparator);\n }\n\n if (hasProp(rhs, 'start')) {\n return ['BTW', 'NOT_BTW'].includes(comparator);\n }\n\n // `rhs.field` and `rhs.value` cases\n return [\n 'EQ',\n 'NEQ',\n 'GT',\n 'GTE',\n 'LT',\n 'LTE',\n 'STARTS_WITH',\n 'NOT_STARTS_WITH',\n 'ENDS_WITH',\n 'NOT_ENDS_WITH',\n 'CONTAINS',\n 'NOT_CONTAINS'\n ].includes(comparator);\n}\n\n/** Determines the default condition object for a given LHS value */\nexport function getInitConditionForLhs(\n lhs: LeafCondition['lhs'],\n fields: Field[],\n validRhsTypes: Set<RHSType>,\n validComparators?: ComparatorsByType[],\n dateFunctions?: DateFunctionsByType\n): LeafCondition {\n let comparator: Comparator;\n let rhs: LeafCondition['rhs'];\n if (lhs.field === '') {\n // If the empty option is selected, reset the comparator and rhs to their default values\n comparator = 'IS_NOT_NULL';\n rhs = undefined;\n } else {\n const newFieldType = getFieldType(lhs.field, fields) as FieldType;\n comparator = getComparatorOptions(newFieldType, validComparators)[0].id; // Find the applicable comparators and select the first among them\n rhs = getDefaultRhs(newFieldType, comparator, validRhsTypes, dateFunctions);\n }\n\n return { lhs, comparator, rhs };\n}\n\n/**\n * Verifies if all the values in the condition are valid.\n * NOTES:\n * - This is intended to be used only on conditions emitted by the components in this package.\n * - If a condition is manually constructed outside these components, this utility could miss some malformed conditions.\n */\nexport function isValidCondition(\n condition: LeafCondition,\n fields: Field[],\n trimValues: boolean = false\n): boolean {\n // If no field is yet selected on the LHS\n if (condition.lhs.field === '') {\n return false;\n }\n // If a field is present on the LHS, check if the RHS is valid\n // No need to check the comparator since the comparator is always assigned a valid value\n const fieldType = getFieldType(condition.lhs.field, fields);\n return isValidRhs(condition.rhs, condition.lhs, fields, fieldType, trimValues);\n}\n\n/** Type definition for the input props of AtomicCondition */\nexport interface AtomicConditionProps extends BaseProps {\n /** Condition to use in the component */\n condition: LeafCondition;\n\n /** Metadata (data-model) for the Fields to use in the Condition */\n fields: Field[];\n\n /** Used to enable inline error indicators on invalid inputs */\n indicateErrors: boolean;\n\n /** (Optional) Lookup used to limit the Comparators allowed in the Condition. */\n validComparators?: ComparatorsByType[];\n\n /** Callback for any modifications to the Condition */\n onChange: (newCondition: LeafCondition) => void;\n\n /** Item flow direction. Defaults to 'row' */\n itemDirection?: 'row' | 'column';\n\n /**\n * Allows presenting the LHS as a readonly text, input or hidden. Defaults presenting as 'input'.\n * NOTE: Make sure that a valid LHS is passed in the 'condition'\n */\n lhsMode?: 'input' | 'label' | 'hidden';\n\n /** Restricts RHS values to only specified types of values.\n * DEFAULT: Set(['LITERAL', 'FIELD']).\n * WARNING: There are LHS/Comparator pairings that require specific RHS types. Please be mindful of\n * these incompatibilities when limiting RHS value types using this prop. We do not support\n * limiting RHS field types to incompatible types and it will result in a validation error\n * if you do so. The pairings referred to here are as follows:\n * - BOOLEAN LHS Fields coupled with \"EQ\" or \"NEQ\" comparators, will always yield a Field RHS\n * - Any LHS Fields coupled with \"IN\" or \"NOT_IN\" comparators, will always yield a Literal RHS (Comma separated list)\n * If you would like to limit RHS value types and avoid these incompatibilities, you will need to exclude these\n * comparators using the validComparators prop.\n */\n validRhsTypes?: Set<RHSType>;\n\n /** (Optional) When enabling 'DATE_FUNCTION's via `validRhsTypes`, pass this to specify which all date functions are applicable per field type */\n dateFunctions?: DateFunctionsByType;\n\n /** Visually hides the label region of the RHS. */\n rhsLabelHidden?: FormControlProps['labelHidden'];\n}\n\n/** A controlled component for Atomic Conditions */\nconst AtomicCondition: FunctionComponent<AtomicConditionProps & ForwardProps> = ({\n condition,\n fields,\n indicateErrors,\n validComparators,\n onChange,\n itemDirection,\n lhsMode = 'input',\n validRhsTypes = new Set<RHSType>(['LITERAL', 'FIELD']),\n dateFunctions,\n rhsLabelHidden,\n ...restProps\n}: AtomicConditionProps) => {\n const t = useI18n();\n\n const fieldType = getFieldType(condition.lhs.field, fields); // Can be `undefined` if no match or if no previous field\n const comparatorOptions = fieldType\n ? getComparatorOptions(fieldType, validComparators)\n : [{ id: '', label: t('condition_builder_select_placeholder') }];\n\n // Handle change in the field-selector\n const handleFieldChange = (id: string) => {\n const lhs = { field: id };\n const newCondition = getInitConditionForLhs(\n lhs,\n fields,\n validRhsTypes,\n validComparators,\n dateFunctions\n ); // Determine comparator and rhs for the new lhs\n onChange(newCondition); // Submit the new condition\n };\n\n // Handle change in the comparator\n const handleComparatorChange = (e: ChangeEvent<HTMLSelectElement>) => {\n if (e.target.value === '') {\n return; // The option is shown only when an lhs is not yet selected. Ignore this selection for those cases\n }\n const comparator = e.target.value as Comparator;\n const rhs = isRhsValidForComparator(condition.rhs, comparator)\n ? condition.rhs\n : getDefaultRhs(fieldType as FieldType, comparator, validRhsTypes, dateFunctions);\n onChange({ ...condition, comparator, rhs }); // Submit the new condition\n };\n\n // Handle change in the RHS\n const handleRHSChange = (rhs: LeafCondition['rhs']) => {\n onChange({ ...condition, rhs }); // Submit the new condition\n };\n\n const lhsLabel = getFieldLabel(condition.lhs.field, fields);\n\n return (\n // Using minmax() to get equal widths: https://stackoverflow.com/a/61240964/4247448\n <StyledAtomicCondition\n {...restProps}\n name={lhsMode === 'label' ? lhsLabel : undefined}\n aria-label={lhsLabel}\n >\n <Grid\n sm={{\n container: {\n cols:\n itemDirection === 'column'\n ? '1fr'\n : `repeat(${lhsMode !== 'input' ? 2 : 3}, minmax(0,1fr))`\n }\n }}\n container={{\n justifyItems: 'stretch',\n colGap: 0.5,\n rowGap: 0.5\n }}\n >\n {/* LHS selector */}\n {lhsMode === 'input' && (\n <FieldSelector\n value={condition.lhs.field}\n onChange={handleFieldChange}\n fields={fields}\n status={indicateErrors && condition.lhs.field === '' ? 'error' : undefined}\n info={\n indicateErrors && condition.lhs.field === ''\n ? t('condition_builder_condition_select_info_default')\n : undefined\n }\n />\n )}\n\n {/* Comparator selector */}\n <Select\n value={condition.comparator}\n onChange={handleComparatorChange}\n name='comparator'\n label={t('condition_builder_comparator_label')}\n labelHidden\n >\n {comparatorOptions.map(option => (\n <Option key={option.id} value={option.id}>\n {option.label}\n </Option>\n ))}\n </Select>\n\n {/* RHS controls */}\n <RhsControls\n lhs={condition.lhs}\n comparator={condition.comparator}\n rhs={condition.rhs}\n fields={fields}\n onChange={handleRHSChange}\n indicateErrors={indicateErrors}\n validRhsTypes={validRhsTypes}\n dateFunctions={dateFunctions}\n itemDirection={itemDirection || 'row'}\n labelHidden={rhsLabelHidden}\n />\n </Grid>\n </StyledAtomicCondition>\n );\n};\n\nexport default AtomicCondition;\n"]}
|
|
@@ -42,6 +42,9 @@ export interface LeafCondition {
|
|
|
42
42
|
value: string | number;
|
|
43
43
|
} | {
|
|
44
44
|
values: string[] | number[];
|
|
45
|
+
} | {
|
|
46
|
+
start: string | number;
|
|
47
|
+
end: string | number;
|
|
45
48
|
} | RhsWithDateFunction | RhsWithRelativeDate | RhsWithParameter;
|
|
46
49
|
}
|
|
47
50
|
/** Type definition for objects representing condition-rows in the builder UI */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConditionBuilder.types.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.types.ts"],"names":[],"mappings":"AACA,OAA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AE,SAAS,GAAG,SAAS,CAAC,CAAC;CACtF;AAED,8DAA8D;AAC9D,MAAM,CAAC,OAAO,WAAW,qBAAsB,SAAQ,SAAS,EAAE,cAAc;IAC9E,iEAAiE;IACjE,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB,6FAA6F;IAC7F,SAAS,CAAC,EAAE,SAAS,CAAC;IAEtB,uEAAuE;IACvE,gBAAgB,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAEvC;;;;OAIG;IACH,aAAa,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAE7B,iJAAiJ;IACjJ,aAAa,CAAC,EAAE,mBAAmB,CAAC;IAEpC,iFAAiF;IACjF,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,2CAA2C;IAC3C,MAAM,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;CAC3B"}
|
|
1
|
+
{"version":3,"file":"ConditionBuilder.types.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExF,OAAO,EACL,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,YAAY,EACZ,OAAO,EACP,UAAU,EACV,QAAQ,EACT,MAAM,cAAc,CAAC;AAEtB,sCAAsC;AACtC,MAAM,WAAW,mBAAmB;IAClC;;;;;;;;;;;OAWG;IACH,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED,sCAAsC;AACtC,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE;QACZ,UAAU,EAAE,UAAU,CAAC;QACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,QAAQ,CAAC;KACpB,CAAC;CACH;AAED,qCAAqC;A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A2C;IAC3C,MAAM,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;CAC3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConditionBuilder.types.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.types.ts"],"names":[],"mappings":"","sourcesContent":["// cspell:ignore words DDTHH\nimport { Ref } from 'react';\n\nimport type { BaseProps, NoChildrenProp, MenuItemProps } from '@pega/cosmos-react-core';\n\nimport {\n FieldType,\n Comparator,\n ComparatorsByType,\n DateFunction,\n RHSType,\n TimePeriod,\n DatePart\n} from './core/types';\n\n/** RHS object with a Date function */\nexport interface RhsWithDateFunction {\n /**\n * Output format for the value varies based on the dateFunction:\n * YEARS: First day of year as YYYY-MM-DD\n * QUARTERS: First day of quarter as YYYY-MM-DD\n * MONTHS: First day of month as YYYY-MM-DD\n * WEEKS: First day of week as YYYY-MM-DD\n * DAYS: Date as YYYY-MM-DD\n * HOURS: YYYY-MM-DDTHH:mm:ss\n * MONTHS_OF_YEAR: 1-12\n * DAYS_OF_MONTH: 1-31\n * DAYS_OF_WEEK: 1-7\n */\n value: string | number;\n dateFunction: DateFunction;\n}\n\n/** RHS object with a Relative Date */\nexport interface RhsWithRelativeDate {\n relativeDate: {\n timePeriod: TimePeriod;\n interval?: number;\n datePart: DatePart;\n };\n}\n\n/** RHS object with PARAMETER type */\nexport interface RhsWithParameter {\n parameterId: string;\n}\n\n/** Type definition for the leaf-level nodes in nested conditions */\nexport interface LeafCondition {\n comparator: Comparator;\n\n lhs: {\n field: string;\n };\n\n // Optional for some of the comparators like IS_TRUE, IS_NULL, etc.\n rhs?:\n | { field: string } // When comparing the LHS with another field\n | { value: string | number } // When comparing the LHS with a single literal value (for comparators like EQ, GTE etc.)\n | { values: string[] | number[] } // When comparing the LHS with a list of literal values (for comparators like IN, NOT_IN etc.)\n | RhsWithDateFunction // When comparing a date field with a date function on RHS\n | RhsWithRelativeDate // When comparing a date field with a symbolic date on RHS\n | RhsWithParameter; // When comparing the LHS with PARAMETER type\n}\n\n/** Type definition for objects representing condition-rows in the builder UI */\nexport interface ConditionRow extends LeafCondition {\n id: string; // To use as `key` prop when rendering a list of rows\n label: string; // Used to refer the row from a logic-string\n}\n\n/**\n * Type definition for simple/complex conditions\n * At a given node in the condition tree, it can have exactly one of the keys AND/OR/NOT/condition\n */\nexport type Condition =\n | { AND: Condition[] }\n | { OR: Condition[] }\n | { NOT: Condition }\n | { condition: LeafCondition };\n\n/** Type definition for the input Field objects for the ConditionBuilder */\n\nexport type ParameterValue = Pick<MenuItemProps, 'id' | 'primary'>;\n\nexport type ReferenceValue = Pick<MenuItemProps, 'id' | 'primary'>;\n\nexport type ValueSelection<F> =\n | string[]\n | ReferenceValue[]\n | (({\n searchString,\n comparator,\n lhs\n }: {\n searchString?: string;\n comparator?: string;\n lhs?: F;\n }) => Promise<string[] | ReferenceValue[]>);\n\ninterface BasicField extends Pick<MenuItemProps, 'id' | 'primary'> {}\n\nexport type Field = BasicField &\n (\n | {\n parameters?: ParameterValue[];\n\n /**\n * For TEXT fields, if a list of possible values is known ahead of time, they can be passed.\n * Otherwise we fetch data from api and pass a promise which returns list of values\n * This enables users to select from those values instead of manually typing them\n */\n possibleValues?: ValueSelection<Field>;\n\n /**\n * Data-type for the field.\n * Has to be one of these values. Convert where necessary\n * e.g. Integer/Decimal/... should be used as `NUMBER`\n * e.g. Text(single value)/Picklist/... should be used as `TEXT`\n */\n type: FieldType;\n }\n | {\n /** An array of type Field to represent the child items. */\n items: Field[];\n }\n );\n\n/** Valid date functions by field type */\nexport interface DateFunctionsByType {\n /** Date functions to enable for DATE_TIME fields */\n DATE_TIME: DateFunction[];\n /** Date functions to enable for DATE_ONLY fields */\n DATE_ONLY: DateFunction[];\n}\n\nexport interface HandleValue {\n /**\n * Returns condition validity and condition or undefined if valid.\n * Undefined indicates no condition.\n */\n getCondition: () => [valid: false] | [valid: true, condition: Condition | undefined];\n}\n\n/** Type definition for the input props of ConditionBuilder */\nexport default interface ConditionBuilderProps extends BaseProps, NoChildrenProp {\n /** Metadata (data-model) for the Fields to use in the builder */\n fields: Field[];\n\n /** (Optional) A seed condition for the builder. To use when editing an existing condition */\n condition?: Condition;\n\n /** (Optional) Used to limit the Comparators allowed in the builder. */\n validComparators?: ComparatorsByType[];\n\n /**\n * (Optional) Pass this to control which all types of RHS are enabled in the component\n * DEFAULT: Set(['LITERAL', 'FIELD'])\n * NOTE: If enabling `DATE_FUNCTION`s, additionally pass a `dateFunctions` prop to specify which functions are enabled\n */\n validRhsTypes?: Set<RHSType>;\n\n /** (Optional) When enabling 'DATE_FUNCTION's via `validRhsTypes`, pass this to specify which all date functions are applicable per field type */\n dateFunctions?: DateFunctionsByType;\n\n /** (Optional) Pass this if the `NOT` operator should be considered as invalid */\n disallowNOT?: boolean;\n\n /** Imperative handle for the component. */\n handle?: Ref<HandleValue>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ConditionBuilder.types.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.types.ts"],"names":[],"mappings":"","sourcesContent":["// cspell:ignore words DDTHH\nimport { Ref } from 'react';\n\nimport type { BaseProps, NoChildrenProp, MenuItemProps } from '@pega/cosmos-react-core';\n\nimport {\n FieldType,\n Comparator,\n ComparatorsByType,\n DateFunction,\n RHSType,\n TimePeriod,\n DatePart\n} from './core/types';\n\n/** RHS object with a Date function */\nexport interface RhsWithDateFunction {\n /**\n * Output format for the value varies based on the dateFunction:\n * YEARS: First day of year as YYYY-MM-DD\n * QUARTERS: First day of quarter as YYYY-MM-DD\n * MONTHS: First day of month as YYYY-MM-DD\n * WEEKS: First day of week as YYYY-MM-DD\n * DAYS: Date as YYYY-MM-DD\n * HOURS: YYYY-MM-DDTHH:mm:ss\n * MONTHS_OF_YEAR: 1-12\n * DAYS_OF_MONTH: 1-31\n * DAYS_OF_WEEK: 1-7\n */\n value: string | number;\n dateFunction: DateFunction;\n}\n\n/** RHS object with a Relative Date */\nexport interface RhsWithRelativeDate {\n relativeDate: {\n timePeriod: TimePeriod;\n interval?: number;\n datePart: DatePart;\n };\n}\n\n/** RHS object with PARAMETER type */\nexport interface RhsWithParameter {\n parameterId: string;\n}\n\n/** Type definition for the leaf-level nodes in nested conditions */\nexport interface LeafCondition {\n comparator: Comparator;\n\n lhs: {\n field: string;\n };\n\n // Optional for some of the comparators like IS_TRUE, IS_NULL, etc.\n rhs?:\n | { field: string } // When comparing the LHS with another field\n | { value: string | number } // When comparing the LHS with a single literal value (for comparators like EQ, GTE etc.)\n | { values: string[] | number[] } // When comparing the LHS with a list of literal values (for comparators like IN, NOT_IN etc.)\n | { start: string | number; end: string | number } // When comparing numeric or date field with two values that determine range\n | RhsWithDateFunction // When comparing a date field with a date function on RHS\n | RhsWithRelativeDate // When comparing a date field with a symbolic date on RHS\n | RhsWithParameter; // When comparing the LHS with PARAMETER type\n}\n\n/** Type definition for objects representing condition-rows in the builder UI */\nexport interface ConditionRow extends LeafCondition {\n id: string; // To use as `key` prop when rendering a list of rows\n label: string; // Used to refer the row from a logic-string\n}\n\n/**\n * Type definition for simple/complex conditions\n * At a given node in the condition tree, it can have exactly one of the keys AND/OR/NOT/condition\n */\nexport type Condition =\n | { AND: Condition[] }\n | { OR: Condition[] }\n | { NOT: Condition }\n | { condition: LeafCondition };\n\n/** Type definition for the input Field objects for the ConditionBuilder */\n\nexport type ParameterValue = Pick<MenuItemProps, 'id' | 'primary'>;\n\nexport type ReferenceValue = Pick<MenuItemProps, 'id' | 'primary'>;\n\nexport type ValueSelection<F> =\n | string[]\n | ReferenceValue[]\n | (({\n searchString,\n comparator,\n lhs\n }: {\n searchString?: string;\n comparator?: string;\n lhs?: F;\n }) => Promise<string[] | ReferenceValue[]>);\n\ninterface BasicField extends Pick<MenuItemProps, 'id' | 'primary'> {}\n\nexport type Field = BasicField &\n (\n | {\n parameters?: ParameterValue[];\n\n /**\n * For TEXT fields, if a list of possible values is known ahead of time, they can be passed.\n * Otherwise we fetch data from api and pass a promise which returns list of values\n * This enables users to select from those values instead of manually typing them\n */\n possibleValues?: ValueSelection<Field>;\n\n /**\n * Data-type for the field.\n * Has to be one of these values. Convert where necessary\n * e.g. Integer/Decimal/... should be used as `NUMBER`\n * e.g. Text(single value)/Picklist/... should be used as `TEXT`\n */\n type: FieldType;\n }\n | {\n /** An array of type Field to represent the child items. */\n items: Field[];\n }\n );\n\n/** Valid date functions by field type */\nexport interface DateFunctionsByType {\n /** Date functions to enable for DATE_TIME fields */\n DATE_TIME: DateFunction[];\n /** Date functions to enable for DATE_ONLY fields */\n DATE_ONLY: DateFunction[];\n}\n\nexport interface HandleValue {\n /**\n * Returns condition validity and condition or undefined if valid.\n * Undefined indicates no condition.\n */\n getCondition: () => [valid: false] | [valid: true, condition: Condition | undefined];\n}\n\n/** Type definition for the input props of ConditionBuilder */\nexport default interface ConditionBuilderProps extends BaseProps, NoChildrenProp {\n /** Metadata (data-model) for the Fields to use in the builder */\n fields: Field[];\n\n /** (Optional) A seed condition for the builder. To use when editing an existing condition */\n condition?: Condition;\n\n /** (Optional) Used to limit the Comparators allowed in the builder. */\n validComparators?: ComparatorsByType[];\n\n /**\n * (Optional) Pass this to control which all types of RHS are enabled in the component\n * DEFAULT: Set(['LITERAL', 'FIELD'])\n * NOTE: If enabling `DATE_FUNCTION`s, additionally pass a `dateFunctions` prop to specify which functions are enabled\n */\n validRhsTypes?: Set<RHSType>;\n\n /** (Optional) When enabling 'DATE_FUNCTION's via `validRhsTypes`, pass this to specify which all date functions are applicable per field type */\n dateFunctions?: DateFunctionsByType;\n\n /** (Optional) Pass this if the `NOT` operator should be considered as invalid */\n disallowNOT?: boolean;\n\n /** Imperative handle for the component. */\n handle?: Ref<HandleValue>;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RhsModeSwitch.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/RhsModeSwitch.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAA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C7D,QAAA,MAAM,aAAa,EAAE,iBAAiB,CAAC,kBAAkB,GAAG,YAAY,CAkJvE,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -9,18 +9,27 @@ var ItemID;
|
|
|
9
9
|
ItemID["ANOTHER_FIELD"] = "ANOTHER_FIELD";
|
|
10
10
|
ItemID["PARAMETER"] = "PARAMETER";
|
|
11
11
|
})(ItemID || (ItemID = {}));
|
|
12
|
+
function isRangeComparator(comparator) {
|
|
13
|
+
return comparator === 'BTW' || comparator === 'NOT_BTW';
|
|
14
|
+
}
|
|
12
15
|
// Label for the `Enter <value>` option on the gear-menu
|
|
13
|
-
function getValueOptionLabel(fieldType, t) {
|
|
16
|
+
function getValueOptionLabel(fieldType, t, comparator) {
|
|
14
17
|
switch (fieldType) {
|
|
15
18
|
case 'TEXT':
|
|
16
19
|
return t('condition_builder_compare_with_text_value');
|
|
17
20
|
case 'NUMBER':
|
|
18
|
-
return
|
|
21
|
+
return isRangeComparator(comparator)
|
|
22
|
+
? t('condition_builder_compare_with_numeric_range_value')
|
|
23
|
+
: t('condition_builder_compare_with_numeric_value');
|
|
19
24
|
case 'DATE_TIME':
|
|
20
25
|
case 'DATE_ONLY':
|
|
21
|
-
return
|
|
26
|
+
return isRangeComparator(comparator)
|
|
27
|
+
? t('condition_builder_compare_with_date_range_value')
|
|
28
|
+
: t('condition_builder_compare_with_date_value');
|
|
22
29
|
case 'TIME_ONLY':
|
|
23
|
-
return
|
|
30
|
+
return isRangeComparator(comparator)
|
|
31
|
+
? t('condition_builder_compare_with_time_range_value')
|
|
32
|
+
: t('condition_builder_compare_with_time_value');
|
|
24
33
|
default:
|
|
25
34
|
return t('condition_builder_value_label'); // Not needed (BOOLEAN is not expected to be passed to the function)
|
|
26
35
|
}
|
|
@@ -53,11 +62,11 @@ const RhsModeSwitch = ({ parameters, fieldType, comparator, rhs, onChange, mode,
|
|
|
53
62
|
// Literal Value inputs
|
|
54
63
|
items.push({
|
|
55
64
|
id: ItemID.LITERAL_VALUE,
|
|
56
|
-
primary: getValueOptionLabel(fieldType, t),
|
|
65
|
+
primary: getValueOptionLabel(fieldType, t, comparator),
|
|
57
66
|
onClick: id => {
|
|
58
67
|
if (id === currentMode)
|
|
59
68
|
return; // Ignore if already in that mode
|
|
60
|
-
onChange({ value: '' }); // Submit a new RHS to re-render with the new mode
|
|
69
|
+
onChange(isRangeComparator(comparator) ? { start: '', end: '' } : { value: '' }); // Submit a new RHS to re-render with the new mode
|
|
61
70
|
},
|
|
62
71
|
selected: currentMode === ItemID.LITERAL_VALUE
|
|
63
72
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RhsModeSwitch.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/RhsModeSwitch.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAqB,OAAO,EAAE,MAAM,OAAO,CAAC;AAEnD,OAAO,EAEL,QAAQ,EAER,OAAO,EACP,UAAU,EACV,WAAW,EAIX,OAAO,EACR,MAAM,yBAAyB,CAAC;AAOjC,IAAK,MAMJ;AAND,WAAK,MAAM;IACT,yCAA+B,CAAA;IAC/B,iCAAuB,CAAA;IACvB,yCAA+B,CAAA;IAC/B,yCAA+B,CAAA;IAC/B,iCAAuB,CAAA;AACzB,CAAC,EANI,MAAM,KAAN,MAAM,QAMV;AAED,wDAAwD;AACxD,SAAS,mBAAmB,CAC1B,SAAoB,EACpB,CAAuC;IAEvC,QAAQ,SAAS,EAAE;QACjB,KAAK,MAAM;YACT,OAAO,CAAC,CAAC,2CAA2C,CAAC,CAAC;QACxD,KAAK,QAAQ;YACX,OAAO,CAAC,CAAC,8CAA8C,CAAC,CAAC;QAC3D,KAAK,WAAW,CAAC;QACjB,KAAK,WAAW;YACd,OAAO,CAAC,CAAC,2CAA2C,CAAC,CAAC;QACxD,KAAK,WAAW;YACd,OAAO,CAAC,CAAC,2CAA2C,CAAC,CAAC;QACxD;YACE,OAAO,CAAC,CAAC,+BAA+B,CAAC,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ponent, useMemo } from 'react';\n\nimport {\n BaseProps,\n ComboBox,\n ForwardProps,\n hasProp,\n MenuButton,\n menuHelpers,\n MenuProps,\n NoChildrenProp,\n TranslationPack,\n useI18n\n} from '@pega/cosmos-react-core';\nimport { TranslationFunction } from '@pega/cosmos-react-core/lib/i18n/translate';\nimport { Selected } from '@pega/cosmos-react-core/lib/components/ComboBox/ComboBox.types';\n\nimport { Comparator, FieldType, RHSType } from '../core/types';\nimport { DateFunctionsByType, LeafCondition, ParameterValue } from '../ConditionBuilder.types';\n\nenum ItemID {\n LITERAL_VALUE = 'LITERAL_VALUE',\n DATE_PART = 'DATE_PART',\n RELATIVE_DATE = 'RELATIVE_DATE',\n ANOTHER_FIELD = 'ANOTHER_FIELD',\n PARAMETER = 'PARAMETER'\n}\n\n// Label for the `Enter <value>` option on the gear-menu\nfunction getValueOptionLabel(\n fieldType: FieldType,\n t: TranslationFunction<TranslationPack>\n): string {\n switch (fieldType) {\n case 'TEXT':\n return t('condition_builder_compare_with_text_value');\n case 'NUMBER':\n return t('condition_builder_compare_with_numeric_value');\n case 'DATE_TIME':\n case 'DATE_ONLY':\n return t('condition_builder_compare_with_date_value');\n case 'TIME_ONLY':\n return t('condition_builder_compare_with_time_value');\n default:\n return t('condition_builder_value_label'); // Not needed (BOOLEAN is not expected to be passed to the function)\n }\n}\n\ninterface RhsMenuButtonProps extends BaseProps, NoChildrenProp {\n /** Passed Parameters array for Rhstype PARAMETER */\n parameters: ParameterValue[];\n\n /** Type of field on the LHS */\n fieldType: FieldType;\n\n /** Comparator for the condition */\n comparator: Comparator;\n\n /** Rhs for the condition */\n rhs: NonNullable<LeafCondition['rhs']>;\n\n /** Callback for any modifications to the Rhs */\n onChange: (rhs: NonNullable<LeafCondition['rhs']>) => void;\n\n /** Display mode */\n mode: 'combo-box' | 'menu-button';\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/** Renders a Gear MenuButton on the RHS (when applicable) */\nconst RhsModeSwitch: FunctionComponent<RhsMenuButtonProps & ForwardProps> = ({\n parameters,\n fieldType,\n comparator,\n rhs,\n onChange,\n mode,\n validRhsTypes,\n dateFunctions\n}: RhsMenuButtonProps) => {\n const t = useI18n();\n\n // Identify current mode\n const currentMode = useMemo(() => {\n if (hasProp(rhs, 'field')) return ItemID.ANOTHER_FIELD;\n if (hasProp(rhs, 'field')) return ItemID.ANOTHER_FIELD;\n if (hasProp(rhs, 'value') && hasProp(rhs, 'dateFunction')) return ItemID.DATE_PART;\n if (hasProp(rhs, 'parameterId')) return ItemID.PARAMETER;\n if (hasProp(rhs, 'relativeDate')) return ItemID.RELATIVE_DATE;\n return ItemID.LITERAL_VALUE;\n }, [rhs]);\n\n // Determine actions for the menu\n const menu = useMemo<MenuProps>(() => {\n const items: MenuProps['items'] = [];\n\n // Boolean conditions either don't use an rhs or always use the field-selector\n // For IN/NOT_IN comparators, only one mode is possible for a given case - CSV Input or a Value-selector\n if (fieldType !== 'BOOLEAN' && !['IN', 'NOT_IN'].includes(comparator)) {\n // Literal value input\n if (validRhsTypes.has('LITERAL')) {\n // Literal Value inputs\n items.push({\n id: ItemID.LITERAL_VALUE,\n primary: getValueOptionLabel(fieldType, t),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({ value: '' }); // Submit a new RHS to re-render with the new mode\n },\n selected: currentMode === ItemID.LITERAL_VALUE\n });\n }\n\n // Field selector\n if (validRhsTypes.has('FIELD')) {\n items.push({\n id: ItemID.ANOTHER_FIELD,\n primary: t('condition_builder_compare_with_another_field'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({ field: '' }); // Submit a new RHS to re-render with the new mode\n },\n selected: currentMode === ItemID.ANOTHER_FIELD\n });\n }\n\n // Rhs of PARAMETER type\n if (\n validRhsTypes.has('PARAMETER') &&\n ['EQ', 'NEQ'].includes(comparator) &&\n parameters.length > 0\n ) {\n items.push({\n id: ItemID.PARAMETER,\n primary: t('condition_builder_compare_with_parameter'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n if (parameters.length === 1) onChange({ parameterId: parameters[0].id });\n else onChange({ parameterId: '' }); // Submit a new RHS to re-render with the new mode\n },\n selected: currentMode === ItemID.PARAMETER\n });\n }\n\n // Relative Date value input\n if (\n validRhsTypes.has('RELATIVE_DATE') &&\n (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY')\n ) {\n items.push({\n id: ItemID.RELATIVE_DATE,\n primary: t('condition_builder_compare_with_relative_date'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({\n relativeDate: {\n timePeriod: 'CURRENT',\n datePart: 'DAYS'\n }\n });\n },\n selected: currentMode === ItemID.RELATIVE_DATE\n });\n }\n\n // Date Part value input\n if (\n validRhsTypes.has('DATE_FUNCTION') &&\n dateFunctions &&\n (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY')\n ) {\n items.push({\n id: ItemID.DATE_PART,\n primary: t('condition_builder_date_part'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({ value: '', dateFunction: dateFunctions[fieldType][0] }); // Submit a new RHS to re-render with the new mode. Initializing with the first available date function\n },\n selected: currentMode === ItemID.DATE_PART\n });\n }\n }\n\n return { items, mode: 'single-select' };\n }, [fieldType, comparator, onChange, validRhsTypes, dateFunctions, currentMode, t]);\n\n // Identify current selection for ComboBox\n const selected = useMemo<Selected | undefined>(() => {\n const selectedItem = menuHelpers.getItem(menu.items, currentMode);\n return selectedItem ? { id: selectedItem.id, text: selectedItem.primary } : undefined;\n }, [menu, currentMode]);\n\n // Render the button only when there are multiple options in the menu\n if (menu.items.length < 2) return null;\n\n if (mode === 'combo-box') {\n return (\n <ComboBox\n label={t('condition_builder_compare_with')}\n labelHidden\n mode='single-select'\n selected={{ items: selected }}\n menu={menu}\n />\n );\n }\n\n return (\n <MenuButton\n text={t('condition_builder_compare_with')}\n icon='gear'\n iconOnly\n variant='simple'\n menu={menu}\n />\n );\n};\n\nexport default RhsModeSwitch;\n"]}
|
|
1
|
+
{"version":3,"file":"RhsModeSwitch.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/RhsModeSwitch.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAqB,OAAO,EAAE,MAAM,OAAO,CAAC;AAEnD,OAAO,EAEL,QAAQ,EAER,OAAO,EACP,UAAU,EACV,WAAW,EAIX,OAAO,EACR,MAAM,yBAAyB,CAAC;AAOjC,IAAK,MAMJ;AAND,WAAK,MAAM;IACT,yCAA+B,CAAA;IAC/B,iCAAuB,CAAA;IACvB,yCAA+B,CAAA;IAC/B,yCAA+B,CAAA;IAC/B,iCAAuB,CAAA;AACzB,CAAC,EANI,MAAM,KAAN,MAAM,QAMV;AAED,SAAS,iBAAiB,CAAC,UAAkC;IAC3D,OAAO,UAAU,KAAK,KAAK,IAAI,UAAU,KAAK,SAAS,CAAC;AAC1D,CAAC;AAED,wDAAwD;AACxD,SAAS,mBAAmB,CAC1B,SAAoB,EACpB,CAAuC,EACvC,UAAuB;IAEvB,QAAQ,SAAS,EAAE;QACjB,KAAK,MAAM;YACT,OAAO,CAAC,CAAC,2CAA2C,CAAC,CAAC;QACxD,KAAK,QAAQ;YACX,OAAO,iBAAiB,CAAC,UAAU,CAAC;gBAClC,CAAC,CAAC,CAAC,CAAC,oDAAoD,CAAC;gBACzD,CAAC,CAAC,CAAC,CAAC,8CAA8C,CAAC,CAAC;QACxD,KAAK,WAAW,CAAC;QACjB,KAAK,WAAW;YACd,OAAO,iBAAiB,CAAC,UAAU,CAAC;gBAClC,CAAC,CAAC,CAAC,CAAC,iDAAiD,CAAC;gBACtD,CAAC,CAAC,CAAC,CAAC,2CAA2C,CAAC,CAAC;QACrD,KAAK,WAAW;YACd,OAAO,iBAAiB,CAAC,UAAU,CAAC;gBAClC,CAAC,CAAC,CAAC,CA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AC;KACH;IAED,OAAO,CACL,KAAC,UAAU,IACT,IAAI,EAAE,CAAC,CAAC,gCAAgC,CAAC,EACzC,IAAI,EAAC,MAAM,EACX,QAAQ,QACR,OAAO,EAAC,QAAQ,EAChB,IAAI,EAAE,IAAI,GACV,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { FunctionComponent, useMemo } from 'react';\n\nimport {\n BaseProps,\n ComboBox,\n ForwardProps,\n hasProp,\n MenuButton,\n menuHelpers,\n MenuProps,\n NoChildrenProp,\n TranslationPack,\n useI18n\n} from '@pega/cosmos-react-core';\nimport { TranslationFunction } from '@pega/cosmos-react-core/lib/i18n/translate';\nimport { Selected } from '@pega/cosmos-react-core/lib/components/ComboBox/ComboBox.types';\n\nimport { Comparator, FieldType, RHSType } from '../core/types';\nimport { DateFunctionsByType, LeafCondition, ParameterValue } from '../ConditionBuilder.types';\n\nenum ItemID {\n LITERAL_VALUE = 'LITERAL_VALUE',\n DATE_PART = 'DATE_PART',\n RELATIVE_DATE = 'RELATIVE_DATE',\n ANOTHER_FIELD = 'ANOTHER_FIELD',\n PARAMETER = 'PARAMETER'\n}\n\nfunction isRangeComparator(comparator: Comparator | undefined): boolean {\n return comparator === 'BTW' || comparator === 'NOT_BTW';\n}\n\n// Label for the `Enter <value>` option on the gear-menu\nfunction getValueOptionLabel(\n fieldType: FieldType,\n t: TranslationFunction<TranslationPack>,\n comparator?: Comparator\n): string {\n switch (fieldType) {\n case 'TEXT':\n return t('condition_builder_compare_with_text_value');\n case 'NUMBER':\n return isRangeComparator(comparator)\n ? t('condition_builder_compare_with_numeric_range_value')\n : t('condition_builder_compare_with_numeric_value');\n case 'DATE_TIME':\n case 'DATE_ONLY':\n return isRangeComparator(comparator)\n ? t('condition_builder_compare_with_date_range_value')\n : t('condition_builder_compare_with_date_value');\n case 'TIME_ONLY':\n return isRangeComparator(comparator)\n ? t('condition_builder_compare_with_time_range_value')\n : t('condition_builder_compare_with_time_value');\n default:\n return t('condition_builder_value_label'); // Not needed (BOOLEAN is not expected to be passed to the function)\n }\n}\n\ninterface RhsMenuButtonProps extends BaseProps, NoChildrenProp {\n /** Passed Parameters array for Rhstype PARAMETER */\n parameters: ParameterValue[];\n\n /** Type of field on the LHS */\n fieldType: FieldType;\n\n /** Comparator for the condition */\n comparator: Comparator;\n\n /** Rhs for the condition */\n rhs: NonNullable<LeafCondition['rhs']>;\n\n /** Callback for any modifications to the Rhs */\n onChange: (rhs: NonNullable<LeafCondition['rhs']>) => void;\n\n /** Display mode */\n mode: 'combo-box' | 'menu-button';\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/** Renders a Gear MenuButton on the RHS (when applicable) */\nconst RhsModeSwitch: FunctionComponent<RhsMenuButtonProps & ForwardProps> = ({\n parameters,\n fieldType,\n comparator,\n rhs,\n onChange,\n mode,\n validRhsTypes,\n dateFunctions\n}: RhsMenuButtonProps) => {\n const t = useI18n();\n\n // Identify current mode\n const currentMode = useMemo(() => {\n if (hasProp(rhs, 'field')) return ItemID.ANOTHER_FIELD;\n if (hasProp(rhs, 'field')) return ItemID.ANOTHER_FIELD;\n if (hasProp(rhs, 'value') && hasProp(rhs, 'dateFunction')) return ItemID.DATE_PART;\n if (hasProp(rhs, 'parameterId')) return ItemID.PARAMETER;\n if (hasProp(rhs, 'relativeDate')) return ItemID.RELATIVE_DATE;\n return ItemID.LITERAL_VALUE;\n }, [rhs]);\n\n // Determine actions for the menu\n const menu = useMemo<MenuProps>(() => {\n const items: MenuProps['items'] = [];\n\n // Boolean conditions either don't use an rhs or always use the field-selector\n // For IN/NOT_IN comparators, only one mode is possible for a given case - CSV Input or a Value-selector\n if (fieldType !== 'BOOLEAN' && !['IN', 'NOT_IN'].includes(comparator)) {\n // Literal value input\n if (validRhsTypes.has('LITERAL')) {\n // Literal Value inputs\n items.push({\n id: ItemID.LITERAL_VALUE,\n primary: getValueOptionLabel(fieldType, t, comparator),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange(isRangeComparator(comparator) ? { start: '', end: '' } : { value: '' }); // Submit a new RHS to re-render with the new mode\n },\n selected: currentMode === ItemID.LITERAL_VALUE\n });\n }\n\n // Field selector\n if (validRhsTypes.has('FIELD')) {\n items.push({\n id: ItemID.ANOTHER_FIELD,\n primary: t('condition_builder_compare_with_another_field'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({ field: '' }); // Submit a new RHS to re-render with the new mode\n },\n selected: currentMode === ItemID.ANOTHER_FIELD\n });\n }\n\n // Rhs of PARAMETER type\n if (\n validRhsTypes.has('PARAMETER') &&\n ['EQ', 'NEQ'].includes(comparator) &&\n parameters.length > 0\n ) {\n items.push({\n id: ItemID.PARAMETER,\n primary: t('condition_builder_compare_with_parameter'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n if (parameters.length === 1) onChange({ parameterId: parameters[0].id });\n else onChange({ parameterId: '' }); // Submit a new RHS to re-render with the new mode\n },\n selected: currentMode === ItemID.PARAMETER\n });\n }\n\n // Relative Date value input\n if (\n validRhsTypes.has('RELATIVE_DATE') &&\n (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY')\n ) {\n items.push({\n id: ItemID.RELATIVE_DATE,\n primary: t('condition_builder_compare_with_relative_date'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({\n relativeDate: {\n timePeriod: 'CURRENT',\n datePart: 'DAYS'\n }\n });\n },\n selected: currentMode === ItemID.RELATIVE_DATE\n });\n }\n\n // Date Part value input\n if (\n validRhsTypes.has('DATE_FUNCTION') &&\n dateFunctions &&\n (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY')\n ) {\n items.push({\n id: ItemID.DATE_PART,\n primary: t('condition_builder_date_part'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({ value: '', dateFunction: dateFunctions[fieldType][0] }); // Submit a new RHS to re-render with the new mode. Initializing with the first available date function\n },\n selected: currentMode === ItemID.DATE_PART\n });\n }\n }\n\n return { items, mode: 'single-select' };\n }, [fieldType, comparator, onChange, validRhsTypes, dateFunctions, currentMode, t]);\n\n // Identify current selection for ComboBox\n const selected = useMemo<Selected | undefined>(() => {\n const selectedItem = menuHelpers.getItem(menu.items, currentMode);\n return selectedItem ? { id: selectedItem.id, text: selectedItem.primary } : undefined;\n }, [menu, currentMode]);\n\n // Render the button only when there are multiple options in the menu\n if (menu.items.length < 2) return null;\n\n if (mode === 'combo-box') {\n return (\n <ComboBox\n label={t('condition_builder_compare_with')}\n labelHidden\n mode='single-select'\n selected={{ items: selected }}\n menu={menu}\n />\n );\n }\n\n return (\n <MenuButton\n text={t('condition_builder_compare_with')}\n icon='gear'\n iconOnly\n variant='simple'\n menu={menu}\n />\n );\n};\n\nexport default RhsModeSwitch;\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FunctionComponent } from 'react';
|
|
2
|
-
import { BaseProps, ForwardProps } from '@pega/cosmos-react-core';
|
|
2
|
+
import { BaseProps, ForwardProps, FormControlProps } from '@pega/cosmos-react-core';
|
|
3
3
|
import { FieldType, Comparator, RHSType } from '../core/types';
|
|
4
4
|
import { LeafCondition, Field, DateFunctionsByType } from '../ConditionBuilder.types';
|
|
5
5
|
/**
|
|
@@ -12,6 +12,7 @@ import { LeafCondition, Field, DateFunctionsByType } from '../ConditionBuilder.t
|
|
|
12
12
|
export declare function isValidRhs(rhs: LeafCondition['rhs'], lhs: LeafCondition['lhs'], fields: Field[], fieldType?: FieldType, trimValues?: boolean): boolean;
|
|
13
13
|
/** For a condition with the given comparator and lhs-field-type, determines an appropriate default value for the Rhs */
|
|
14
14
|
export declare function getDefaultRhs(fieldType: FieldType, comparator: Comparator, validRhsTypes: Set<RHSType>, dateFunctions?: DateFunctionsByType): LeafCondition['rhs'];
|
|
15
|
+
export declare function truncateISODateString(dateString: string, fieldType: FieldType): string;
|
|
15
16
|
/** Type definition for the input props of RhsControls */
|
|
16
17
|
interface RhsControlProps extends BaseProps {
|
|
17
18
|
/** Lhs for the condition */
|
|
@@ -32,6 +33,8 @@ interface RhsControlProps extends BaseProps {
|
|
|
32
33
|
validRhsTypes: Set<RHSType>;
|
|
33
34
|
/** Passed to enable additional date controls on the RHS, when a DATE_TIME/DATE_ONLY field is selected on the LHS */
|
|
34
35
|
dateFunctions?: DateFunctionsByType;
|
|
36
|
+
/** Visually hides the label region. */
|
|
37
|
+
labelHidden?: FormControlProps['labelHidden'];
|
|
35
38
|
}
|
|
36
39
|
/** A controlled component for controls on a Condition's RHS */
|
|
37
40
|
declare const RhsControls: FunctionComponent<RhsControlProps & ForwardProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA6C,MAAM,OAAO,CAAC;AAErF,OAAO,EAML,SAAS,EACT,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA6C,MAAM,OAAO,CAAC;AAErF,OAAO,EAML,SAAS,EACT,YAAY,EAKZ,gBAAgB,EAEjB,MAAM,yBAAyB,CAAC;AAMjC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAwCtF;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,EACzB,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,EACzB,MAAM,EAAE,KAAK,EA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
|
|
2
2
|
import { useState, useEffect, useMemo } from 'react';
|
|
3
|
-
import { DateInput, DateTimeInput, Flex, Input, hasProp, TimeInput, useI18n } from '@pega/cosmos-react-core';
|
|
3
|
+
import { DateInput, DateTimeInput, Flex, Input, hasProp, TimeInput, useI18n, DateRangeInput, TimeRangeInput, NumberRangeInput } from '@pega/cosmos-react-core';
|
|
4
4
|
import { convertTimeValueToMs, convertMsToTimeValue } from '../core/time-utils';
|
|
5
5
|
import { getItem } from '../core/utils';
|
|
6
6
|
import ValueSelector from './ValueSelector';
|
|
@@ -9,6 +9,26 @@ import RhsModeSwitch from './RhsModeSwitch';
|
|
|
9
9
|
import TimePeriodInput from './TimePeriodInput';
|
|
10
10
|
import TimePeriodMenu from './TimePeriodMenu';
|
|
11
11
|
import NumericInput from './NumericInput';
|
|
12
|
+
function isValidLiteralValue(value, fieldType, trimValues = false) {
|
|
13
|
+
// Identify any invalid numbers (e.g. when `-` is entered)
|
|
14
|
+
if (typeof value === 'number') {
|
|
15
|
+
return !Number.isNaN(value);
|
|
16
|
+
}
|
|
17
|
+
// NOTE: Not trimming the value in the change-handler so that users can freely type spaces between words
|
|
18
|
+
if (trimValues) {
|
|
19
|
+
value = value.trim();
|
|
20
|
+
}
|
|
21
|
+
// Can be empty on init and on clearing the value
|
|
22
|
+
if (value.trim() === '') {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
// This check is needed to eliminate invalid dates like `Feb 31` (02/31/2020), which the input allows
|
|
26
|
+
if ((fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY') &&
|
|
27
|
+
Number.isNaN(new Date(value).getTime())) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
12
32
|
/**
|
|
13
33
|
* Verifies if the condition has all valid values.
|
|
14
34
|
* NOTES:
|
|
@@ -75,6 +95,11 @@ export function isValidRhs(rhs, lhs, fields, fieldType, trimValues = false) {
|
|
|
75
95
|
(!rhs.relativeDate.interval || rhs.relativeDate.interval <= 0)))) {
|
|
76
96
|
return false;
|
|
77
97
|
}
|
|
98
|
+
if (hasProp(rhs, 'start') &&
|
|
99
|
+
(!isValidLiteralValue(rhs.start, fieldType, trimValues) ||
|
|
100
|
+
!isValidLiteralValue(rhs.end, fieldType, trimValues))) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
78
103
|
return true;
|
|
79
104
|
}
|
|
80
105
|
/** For a condition with the given comparator and lhs-field-type, determines an appropriate default value for the Rhs */
|
|
@@ -88,6 +113,9 @@ export function getDefaultRhs(fieldType, comparator, validRhsTypes, dateFunction
|
|
|
88
113
|
case 'IN':
|
|
89
114
|
case 'NOT_IN':
|
|
90
115
|
return { values: [] };
|
|
116
|
+
case 'BTW':
|
|
117
|
+
case 'NOT_BTW':
|
|
118
|
+
return { start: '', end: '' };
|
|
91
119
|
default: {
|
|
92
120
|
if (fieldType === 'BOOLEAN' && (comparator === 'EQ' || comparator === 'NEQ')) {
|
|
93
121
|
// For booleans, these comparators can only be used for comparing with other fields
|
|
@@ -116,7 +144,7 @@ export function getDefaultRhs(fieldType, comparator, validRhsTypes, dateFunction
|
|
|
116
144
|
}
|
|
117
145
|
// Truncates output values from DateInput/DateTimeInput to return a wall time on the RHS
|
|
118
146
|
// NOTE: This assumes that the input date is set up on the UTC timezone
|
|
119
|
-
function truncateISODateString(dateString, fieldType) {
|
|
147
|
+
export function truncateISODateString(dateString, fieldType) {
|
|
120
148
|
const date = new Date(dateString);
|
|
121
149
|
const YYYY = date.getUTCFullYear().toString().padStart(4, '0');
|
|
122
150
|
const MM = (date.getUTCMonth() + 1).toString().padStart(2, '0');
|
|
@@ -135,7 +163,7 @@ function truncateISODateString(dateString, fieldType) {
|
|
|
135
163
|
}
|
|
136
164
|
/** A controlled component for controls on a Condition's RHS */
|
|
137
165
|
const RhsControls = (props) => {
|
|
138
|
-
const { lhs, comparator, rhs, fields, onChange, indicateErrors, itemDirection, validRhsTypes, dateFunctions } = props;
|
|
166
|
+
const { lhs, comparator, rhs, fields, onChange, indicateErrors, itemDirection, validRhsTypes, dateFunctions, labelHidden = true } = props;
|
|
139
167
|
const t = useI18n();
|
|
140
168
|
// Find the field corresponding to the LHS
|
|
141
169
|
const matchingField = getItem(fields, lhs.field);
|
|
@@ -206,6 +234,24 @@ const RhsControls = (props) => {
|
|
|
206
234
|
value: fieldType === 'TIME_ONLY' ? convertTimeValueToMs(truncatedValue) : truncatedValue
|
|
207
235
|
});
|
|
208
236
|
};
|
|
237
|
+
const handleDateRangeValueChange = ({ start, end }) => {
|
|
238
|
+
if (start.valueAsISOString === '' || end.valueAsISOString === '')
|
|
239
|
+
return;
|
|
240
|
+
const [truncatedStartValue, truncatedEndValue] = [
|
|
241
|
+
truncateISODateString(start.valueAsISOString, fieldType),
|
|
242
|
+
truncateISODateString(end.valueAsISOString, fieldType)
|
|
243
|
+
];
|
|
244
|
+
onChange({
|
|
245
|
+
start: fieldType === 'TIME_ONLY' ? convertTimeValueToMs(truncatedStartValue) : truncatedStartValue,
|
|
246
|
+
end: fieldType === 'TIME_ONLY' ? convertTimeValueToMs(truncatedEndValue) : truncatedEndValue
|
|
247
|
+
});
|
|
248
|
+
};
|
|
249
|
+
const handleNumberRangeValueChange = ({ start, end }) => {
|
|
250
|
+
onChange({
|
|
251
|
+
start: start.trim() ? Number(start) : '',
|
|
252
|
+
end: end.trim() ? Number(end) : ''
|
|
253
|
+
});
|
|
254
|
+
};
|
|
209
255
|
// Handle changes from a CSV-input
|
|
210
256
|
const handleCSVChange = (e) => {
|
|
211
257
|
// Update the controlled input
|
|
@@ -228,7 +274,7 @@ const RhsControls = (props) => {
|
|
|
228
274
|
justify: 'between',
|
|
229
275
|
gap: 0.5
|
|
230
276
|
}, children: [_jsx(RhsModeSwitch, { parameters: parameters, fieldType: fieldType, comparator: comparator, rhs: rhs, onChange: onChange, mode: itemDirection === 'column' ? 'combo-box' : 'menu-button', validRhsTypes: validRhsTypes, dateFunctions: dateFunctions }), hasProp(rhs, 'field') && (_jsx(Flex, { item: { grow: 1 }, children: _jsx(FieldSelector, { value: rhs.field, onChange: handleFieldChange, fields: fieldOptions, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_no_selection') : undefined }) })), hasProp(rhs, 'parameterId') && (_jsxs(Flex, { item: { grow: 1 }, children: [parameters.length === 1 && (_jsx(Input, { value: parameters[0].primary.toString(), status: showError ? 'error' : undefined, info: showError ? t('condition_builder_empty_value_text') : undefined, name: 'rhs-text-parameter-input', label: t('condition_builder_rhs_with_readOnly_input'), labelHidden: true, readOnly: true })), parameters.length > 1 && (_jsx(ValueSelector, { parameters: parameters, mode: 'single-select', values: rhs.parameterId.toString(), selectedField: matchingField, rhs: rhs, comparator: comparator, onChange: handleValueSelection, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_empty_selection_error_text') : undefined }))] })), hasProp(rhs, 'value') && !hasProp(rhs, 'dateFunction') && (_jsxs(Flex, { item: { grow: 1 }, children: [fieldType === 'TEXT' && useValueSelector && (_jsx(ValueSelector, { parameters: parameters, mode: 'single-select', values: rhs.value.toString(), selectedField: matchingField, comparator: comparator, rhs: rhs, onChange: handleValueSelection, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_no_selection') : undefined })), fieldType === 'TEXT' && !useValueSelector && (_jsx(Input, { value: rhs.value.toString(), onChange: handleValueChange, status: showError ? 'error' : undefined, info: showError ? t('empty_value') : undefined, name: 'rhs-text-literal-input', label: t('condition_builder_rhs_with_input_type'), labelHidden: true })), fieldType === 'NUMBER' && (_jsx(NumericInput, { rhs: rhs, onChange: onChange, status: showError ? 'error' : undefined })), fieldType === 'TIME_ONLY' && (_jsx(TimeInput, { value: rhs.value !== '' ? convertMsToTimeValue(Number(rhs.value)) : undefined, withSeconds: true, onChange: handleDateValueChange, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_invalid_time') : '', label: '-', labelHidden: true })), fieldType === 'DATE_ONLY' && (_jsx(DateInput, { value: rhs.value, onChange: handleDateValueChange, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_invalid_date') : '', label: '-', labelHidden: true })), fieldType === 'DATE_TIME' && (_jsx(DateTimeInput, { value: rhs.value !== '' ? rhs.value : undefined, onChange: handleDateValueChange, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_invalid_date') : '', label: '-', labelHidden: true }))] })), (fieldType === 'DATE_ONLY' || fieldType === 'DATE_TIME') &&
|
|
231
|
-
(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 }) })), hasProp(rhs, 'values') && (_jsxs(Flex, { item: { grow: 1 }, children: [useValueSelector && (_jsx(ValueSelector, { parameters: parameters, mode: 'multi-select', values: rhs.values.map(String), selectedField: matchingField, comparator: comparator, rhs: rhs, onChange: handleValueSelection, status: showError ? 'error' : undefined })), !useValueSelector && (_jsx(Input, { value: csvInput, onChange: handleCSVChange, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_invalid_values') : undefined, label: '-', labelHidden: true, placeholder: t('condition_builder_enter_csv_placeholder') }))] }))] }));
|
|
277
|
+
(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 }) })), hasProp(rhs, 'values') && (_jsxs(Flex, { item: { grow: 1 }, children: [useValueSelector && (_jsx(ValueSelector, { parameters: parameters, mode: 'multi-select', values: rhs.values.map(String), selectedField: matchingField, comparator: comparator, rhs: rhs, onChange: handleValueSelection, status: showError ? 'error' : undefined })), !useValueSelector && (_jsx(Input, { value: csvInput, onChange: handleCSVChange, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_invalid_values') : undefined, label: '-', labelHidden: true, placeholder: t('condition_builder_enter_csv_placeholder') }))] })), hasProp(rhs, 'start') && (_jsxs(Flex, { item: { grow: 1 }, children: [fieldType === 'NUMBER' && (_jsx(NumberRangeInput, { value: { start: rhs.start.toString(), end: rhs.end.toString() }, onChange: handleNumberRangeValueChange, status: showError ? 'error' : undefined, label: matchingField.primary, labelHidden: labelHidden, info: showError ? t('condition_builder_invalid_number_range') : undefined })), fieldType === 'DATE_ONLY' && (_jsx(DateRangeInput, { value: { start: rhs.start || undefined, end: rhs.end || undefined }, onChange: handleDateRangeValueChange, labelHidden: labelHidden, label: matchingField.primary, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_invalid_date_range') : '' })), fieldType === 'TIME_ONLY' && (_jsx(TimeRangeInput, { mode: 'time', value: { start: rhs.start || undefined, end: rhs.end || undefined }, onChange: handleDateRangeValueChange, labelHidden: labelHidden, label: matchingField.primary, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_invalid_time_range') : '' })), fieldType === 'DATE_TIME' && (_jsx(TimeRangeInput, { mode: 'datetime', value: { start: rhs.start || undefined, end: rhs.end || undefined }, onChange: handleDateRangeValueChange, labelHidden: labelHidden, label: matchingField.primary, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_invalid_date_range') : '' }))] }))] }));
|
|
232
278
|
};
|
|
233
279
|
export default RhsControls;
|
|
234
280
|
//# sourceMappingURL=index.js.map
|