@pega/cosmos-react-condition-builder 7.4.7 → 7.5.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.map +1 -1
- package/lib/components/ConditionBuilder/AtomicCondition.js +4 -1
- package/lib/components/ConditionBuilder/AtomicCondition.js.map +1 -1
- package/lib/components/ConditionBuilder/core/comparators.d.ts +1 -1
- package/lib/components/ConditionBuilder/core/comparators.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/comparators.js +37 -41
- package/lib/components/ConditionBuilder/core/comparators.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AtomicCondition.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/AtomicCondition.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAe,GAAG,EAAmB,MAAM,OAAO,CAAC;AAYlF,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAGpF,OAAO,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAI1F,OAAO,KAAK,EAAc,iBAAiB,EAAa,OAAO,EAAE,MAAM,cAAc,CAAC;AAoDtF,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,6DAA6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mB,CAAC;IAEpC,6CAA6C;IAC7C,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;IAC1B,wBAAwB;IACxB,MAAM,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;CAC3B;AAED,mDAAmD;AACnD,QAAA,MAAM,eAAe,EAAE,iBAAiB,CAAC,oBAAoB,GAAG,YAAY,CAwL3E,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -91,7 +91,10 @@ const AtomicCondition = forwardRef(function AtomicCondition({ condition, fields,
|
|
|
91
91
|
const newCondition = useRef(condition);
|
|
92
92
|
const fieldType = getFieldType(condition.lhs.field, fields); // Can be `undefined` if no match or if no previous field
|
|
93
93
|
const comparatorOptions = fieldType
|
|
94
|
-
? getComparatorOptions(fieldType, validComparators)
|
|
94
|
+
? getComparatorOptions(fieldType, validComparators).map(option => ({
|
|
95
|
+
...option,
|
|
96
|
+
label: t(`condition_builder_comparator_${option.label}`)
|
|
97
|
+
}))
|
|
95
98
|
: [{ id: '', label: t('condition_builder_select_placeholder') }];
|
|
96
99
|
useAfterInitialEffect(() => {
|
|
97
100
|
setState(condition);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AtomicCondition.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/AtomicCondition.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AAG1E,OAAO,EACL,IAAI,EACJ,MAAM,EACN,MAAM,EACN,OAAO,EACP,OAAO,EACP,kBAAkB,EAClB,cAAc,EACd,qBAAqB,EACtB,MAAM,yBAAyB,CAAC;AAGjC,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,oB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ent":["import { forwardRef, useRef, useState, useImperativeHandle } from 'react';\nimport type { FunctionComponent, ChangeEvent, Ref, PropsWithoutRef } from 'react';\n\nimport {\n Grid,\n Select,\n Option,\n useI18n,\n hasProp,\n useConsolidatedRef,\n useFocusWithin,\n useAfterInitialEffect\n} from '@pega/cosmos-react-core';\nimport type { BaseProps, HandleValue, ForwardProps } from '@pega/cosmos-react-core';\n\nimport { getItem } from './core/utils';\nimport type { LeafCondition, Field, DateFunctionsByType } from './ConditionBuilder.types';\nimport FieldSelector from './RhsControls/FieldSelector';\nimport RhsControls, { getDefaultRhs, isValidRhs } from './RhsControls';\nimport getComparatorOptions from './core/comparators';\nimport type { 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, status?: 'error') => void;\n\n /** Callback fired when the condition changes. */\n onBlur?: (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 /** Ref forwarded to the wrapping element. */\n ref?: Ref<HTMLDivElement>;\n /** Imperative handle */\n handle?: Ref<HandleValue>;\n}\n\n/** A controlled component for Atomic Conditions */\nconst AtomicCondition: FunctionComponent<AtomicConditionProps & ForwardProps> = forwardRef(\n function AtomicCondition(\n {\n condition,\n fields,\n indicateErrors,\n validComparators,\n onChange,\n onBlur,\n itemDirection,\n lhsMode = 'input',\n validRhsTypes = new Set<RHSType>(['LITERAL', 'FIELD']),\n dateFunctions,\n handle,\n ...restProps\n }: PropsWithoutRef<AtomicConditionProps>,\n ref: AtomicConditionProps['ref']\n ) {\n const t = useI18n();\n\n // stores condition form state\n const [state, setState] = useState<LeafCondition>(condition);\n // ref needed to handle use case of onChange and onBlur being triggered at the same time\n // state is not updated by the time blur is invoked, ref is always set to newest value\n const newCondition = useRef(condition);\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 useAfterInitialEffect(() => {\n setState(condition);\n }, [condition]);\n\n const onFocusChange = (focused: boolean) => {\n if (!focused) {\n // newCondition is returned, as it stores newest value\n onBlur?.(\n newCondition.current && isValidCondition(newCondition.current, fields, true)\n ? newCondition.current\n : undefined\n );\n }\n };\n\n const containerRef = useConsolidatedRef(ref);\n useFocusWithin([containerRef], onFocusChange);\n\n // Handle condition update\n const handleConditionChange = (updatedCondition: LeafCondition, status?: 'error') => {\n newCondition.current = updatedCondition;\n // new condition is returned with status to allow recognizing errors and avoiding clearing wrong values from input\n onChange?.(updatedCondition, status);\n };\n\n // Handle change in the field-selector\n const handleFieldChange = (id: string) => {\n const lhs = { field: id };\n const initCondition = getInitConditionForLhs(\n lhs,\n fields,\n validRhsTypes,\n validComparators,\n dateFunctions\n ); // Determine comparator and rhs for the new lhs\n handleConditionChange(initCondition);\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 conditionRhs = condition.rhs\n ? ({ ...condition.rhs } as LeafCondition['rhs']) // Duplicating rhs to avoid using source object as it can be mutated later.\n : undefined;\n\n const rhs = isRhsValidForComparator(conditionRhs, comparator)\n ? conditionRhs\n : getDefaultRhs(fieldType as FieldType, comparator, validRhsTypes, dateFunctions);\n\n handleConditionChange({ ...condition, comparator, rhs });\n };\n\n // Handle change in the RHS\n const handleRHSChange = (rhs: LeafCondition['rhs'], status?: 'error') => {\n handleConditionChange({ ...condition, rhs }, status);\n };\n\n const rhsHandle = useRef<HandleValue>(null);\n\n const clear = () => {\n rhsHandle.current?.clear();\n if (newCondition.current) {\n handleConditionChange(\n getInitConditionForLhs(state.lhs, fields, validRhsTypes, validComparators, dateFunctions)\n );\n }\n };\n\n useImperativeHandle(\n handle,\n () => ({\n clear\n }),\n [clear]\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={lhsMode === 'hidden' ? lhsLabel : undefined}\n >\n <Grid\n sm={{\n container: {\n cols:\n itemDirection === 'column'\n ? 'minmax(0, 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 ref={containerRef}\n >\n {/* LHS selector */}\n {lhsMode === 'input' && (\n <FieldSelector\n value={state.lhs.field}\n onChange={handleFieldChange}\n fields={fields}\n status={indicateErrors && state.lhs.field === '' ? 'error' : undefined}\n info={\n indicateErrors && state.lhs.field === ''\n ? t('condition_builder_condition_select_info_default')\n : undefined\n }\n />\n )}\n\n {/* Comparator selector */}\n <Select\n value={state.comparator}\n onChange={handleComparatorChange}\n name='comparator'\n label={t('condition_builder_comparator_label')}\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={state.lhs}\n comparator={state.comparator}\n rhs={state.rhs}\n fields={fields}\n onChange={handleRHSChange}\n indicateErrors={indicateErrors}\n validRhsTypes={validRhsTypes}\n dateFunctions={dateFunctions}\n itemDirection={itemDirection || 'row'}\n handle={rhsHandle}\n />\n </Grid>\n </StyledAtomicCondition>\n );\n }\n);\n\nexport default AtomicCondition;\n"]}
|
|
1
|
+
{"version":3,"file":"AtomicCondition.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/AtomicCondition.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,E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AM,IAAiB,KAAK,EAAE,MAAM,CAAC,EAAE,YACrC,MAAM,CAAC,KAAK,IADF,MAAM,CAAC,EAAE,CAEb,CACV,CAAC,GACK,EAGT,KAAC,WAAW,IACV,GAAG,EAAE,KAAK,CAAC,GAAG,EACd,UAAU,EAAE,KAAK,CAAC,UAAU,EAC5B,GAAG,EAAE,KAAK,CAAC,GAAG,EACd,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,MAAM,EAAE,SAAS,GACjB,IACG,GACe,CACzB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { forwardRef, useRef, useState, useImperativeHandle } from 'react';\nimport type { FunctionComponent, ChangeEvent, Ref, PropsWithoutRef } from 'react';\n\nimport {\n Grid,\n Select,\n Option,\n useI18n,\n hasProp,\n useConsolidatedRef,\n useFocusWithin,\n useAfterInitialEffect\n} from '@pega/cosmos-react-core';\nimport type { BaseProps, HandleValue, ForwardProps } from '@pega/cosmos-react-core';\n\nimport { getItem } from './core/utils';\nimport type { LeafCondition, Field, DateFunctionsByType } from './ConditionBuilder.types';\nimport FieldSelector from './RhsControls/FieldSelector';\nimport RhsControls, { getDefaultRhs, isValidRhs } from './RhsControls';\nimport getComparatorOptions from './core/comparators';\nimport type { 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, status?: 'error') => void;\n\n /** Callback fired when the condition changes. */\n onBlur?: (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 /** Ref forwarded to the wrapping element. */\n ref?: Ref<HTMLDivElement>;\n /** Imperative handle */\n handle?: Ref<HandleValue>;\n}\n\n/** A controlled component for Atomic Conditions */\nconst AtomicCondition: FunctionComponent<AtomicConditionProps & ForwardProps> = forwardRef(\n function AtomicCondition(\n {\n condition,\n fields,\n indicateErrors,\n validComparators,\n onChange,\n onBlur,\n itemDirection,\n lhsMode = 'input',\n validRhsTypes = new Set<RHSType>(['LITERAL', 'FIELD']),\n dateFunctions,\n handle,\n ...restProps\n }: PropsWithoutRef<AtomicConditionProps>,\n ref: AtomicConditionProps['ref']\n ) {\n const t = useI18n();\n\n // stores condition form state\n const [state, setState] = useState<LeafCondition>(condition);\n // ref needed to handle use case of onChange and onBlur being triggered at the same time\n // state is not updated by the time blur is invoked, ref is always set to newest value\n const newCondition = useRef(condition);\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).map(option => ({\n ...option,\n label: t(`condition_builder_comparator_${option.label}`)\n }))\n : [{ id: '', label: t('condition_builder_select_placeholder') }];\n\n useAfterInitialEffect(() => {\n setState(condition);\n }, [condition]);\n\n const onFocusChange = (focused: boolean) => {\n if (!focused) {\n // newCondition is returned, as it stores newest value\n onBlur?.(\n newCondition.current && isValidCondition(newCondition.current, fields, true)\n ? newCondition.current\n : undefined\n );\n }\n };\n\n const containerRef = useConsolidatedRef(ref);\n useFocusWithin([containerRef], onFocusChange);\n\n // Handle condition update\n const handleConditionChange = (updatedCondition: LeafCondition, status?: 'error') => {\n newCondition.current = updatedCondition;\n // new condition is returned with status to allow recognizing errors and avoiding clearing wrong values from input\n onChange?.(updatedCondition, status);\n };\n\n // Handle change in the field-selector\n const handleFieldChange = (id: string) => {\n const lhs = { field: id };\n const initCondition = getInitConditionForLhs(\n lhs,\n fields,\n validRhsTypes,\n validComparators,\n dateFunctions\n ); // Determine comparator and rhs for the new lhs\n handleConditionChange(initCondition);\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 conditionRhs = condition.rhs\n ? ({ ...condition.rhs } as LeafCondition['rhs']) // Duplicating rhs to avoid using source object as it can be mutated later.\n : undefined;\n\n const rhs = isRhsValidForComparator(conditionRhs, comparator)\n ? conditionRhs\n : getDefaultRhs(fieldType as FieldType, comparator, validRhsTypes, dateFunctions);\n\n handleConditionChange({ ...condition, comparator, rhs });\n };\n\n // Handle change in the RHS\n const handleRHSChange = (rhs: LeafCondition['rhs'], status?: 'error') => {\n handleConditionChange({ ...condition, rhs }, status);\n };\n\n const rhsHandle = useRef<HandleValue>(null);\n\n const clear = () => {\n rhsHandle.current?.clear();\n if (newCondition.current) {\n handleConditionChange(\n getInitConditionForLhs(state.lhs, fields, validRhsTypes, validComparators, dateFunctions)\n );\n }\n };\n\n useImperativeHandle(\n handle,\n () => ({\n clear\n }),\n [clear]\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={lhsMode === 'hidden' ? lhsLabel : undefined}\n >\n <Grid\n sm={{\n container: {\n cols:\n itemDirection === 'column'\n ? 'minmax(0, 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 ref={containerRef}\n >\n {/* LHS selector */}\n {lhsMode === 'input' && (\n <FieldSelector\n value={state.lhs.field}\n onChange={handleFieldChange}\n fields={fields}\n status={indicateErrors && state.lhs.field === '' ? 'error' : undefined}\n info={\n indicateErrors && state.lhs.field === ''\n ? t('condition_builder_condition_select_info_default')\n : undefined\n }\n />\n )}\n\n {/* Comparator selector */}\n <Select\n value={state.comparator}\n onChange={handleComparatorChange}\n name='comparator'\n label={t('condition_builder_comparator_label')}\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={state.lhs}\n comparator={state.comparator}\n rhs={state.rhs}\n fields={fields}\n onChange={handleRHSChange}\n indicateErrors={indicateErrors}\n validRhsTypes={validRhsTypes}\n dateFunctions={dateFunctions}\n itemDirection={itemDirection || 'row'}\n handle={rhsHandle}\n />\n </Grid>\n </StyledAtomicCondition>\n );\n }\n);\n\nexport default AtomicCondition;\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { FieldType, Comparator, ComparatorsByType } from './types';
|
|
2
2
|
interface ComparatorOption {
|
|
3
3
|
id: Comparator;
|
|
4
|
-
label:
|
|
4
|
+
label: 'is_true' | 'is_false' | 'is_equal_to' | 'is_not_equal_to' | 'is_in_list' | 'is_not_in_list' | 'between' | 'not_between' | 'greater_than' | 'greater_than_or_equals' | 'lower_than' | 'lower_than_or_equals' | 'starts_with' | 'not_starts_with' | 'ends_with' | 'not_ends_with' | 'contains' | 'not_contains' | 'is_null' | 'is_not_null';
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
7
|
* Returns Comparator-options applicable to the input fieldType
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comparators.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/comparators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAExE,UAAU,gBAAgB;IACxB,EAAE,EAAE,UAAU,CAAC;IACf,KAAK,
|
|
1
|
+
{"version":3,"file":"comparators.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/comparators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAExE,UAAU,gBAAgB;IACxB,EAAE,EAAE,UAAU,CAAC;IACf,KAAK,EACD,SAAS,GACT,UAAU,GACV,aAAa,GACb,iBAAiB,GACjB,YAAY,GACZ,gBAAgB,GAChB,SAAS,GACT,aAAa,GACb,cAAc,GACd,wBAAwB,GACxB,YAAY,GACZ,sBAAsB,GACtB,aAAa,GACb,iBAAiB,GACjB,WAAW,GACX,eAAe,GACf,UAAU,GACV,cAAc,GACd,SAAS,GACT,aAAa,CAAC;CACnB;AAgED;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAC1C,SAAS,EAAE,SAAS,EACpB,gBAAgB,CAAC,EAAE,iBAAiB,EAAE,GACrC,gBAAgB,EAAE,CAapB"}
|
|
@@ -1,54 +1,50 @@
|
|
|
1
|
-
// FIXME: TR
|
|
2
1
|
const boolFieldOptions = [
|
|
3
|
-
{ id: 'IS_TRUE', label: '
|
|
4
|
-
{ id: 'IS_FALSE', label: '
|
|
5
|
-
{ id: 'EQ', label: '
|
|
6
|
-
{ id: 'NEQ', label: '
|
|
7
|
-
{ id: 'IS_NULL', label: '
|
|
8
|
-
{ id: 'IS_NOT_NULL', label: '
|
|
2
|
+
{ id: 'IS_TRUE', label: 'is_true' },
|
|
3
|
+
{ id: 'IS_FALSE', label: 'is_false' },
|
|
4
|
+
{ id: 'EQ', label: 'is_equal_to' },
|
|
5
|
+
{ id: 'NEQ', label: 'is_not_equal_to' },
|
|
6
|
+
{ id: 'IS_NULL', label: 'is_null' },
|
|
7
|
+
{ id: 'IS_NOT_NULL', label: 'is_not_null' }
|
|
9
8
|
];
|
|
10
|
-
// FIXME: TR
|
|
11
9
|
const textFieldOptions = [
|
|
12
|
-
{ id: 'EQ', label: '
|
|
13
|
-
{ id: 'NEQ', label: '
|
|
14
|
-
{ id: 'IN', label: '
|
|
15
|
-
{ id: 'NOT_IN', label: '
|
|
16
|
-
{ id: 'STARTS_WITH', label: '
|
|
17
|
-
{ id: 'NOT_STARTS_WITH', label: '
|
|
18
|
-
{ id: 'ENDS_WITH', label: '
|
|
19
|
-
{ id: 'NOT_ENDS_WITH', label: '
|
|
10
|
+
{ id: 'EQ', label: 'is_equal_to' },
|
|
11
|
+
{ id: 'NEQ', label: 'is_not_equal_to' },
|
|
12
|
+
{ id: 'IN', label: 'is_in_list' },
|
|
13
|
+
{ id: 'NOT_IN', label: 'is_not_in_list' },
|
|
14
|
+
{ id: 'STARTS_WITH', label: 'starts_with' },
|
|
15
|
+
{ id: 'NOT_STARTS_WITH', label: 'not_starts_with' },
|
|
16
|
+
{ id: 'ENDS_WITH', label: 'ends_with' },
|
|
17
|
+
{ id: 'NOT_ENDS_WITH', label: 'not_ends_with' },
|
|
20
18
|
{ id: 'CONTAINS', label: 'contains' },
|
|
21
|
-
{ id: 'NOT_CONTAINS', label: '
|
|
22
|
-
{ id: 'IS_NULL', label: '
|
|
23
|
-
{ id: 'IS_NOT_NULL', label: '
|
|
19
|
+
{ id: 'NOT_CONTAINS', label: 'not_contains' },
|
|
20
|
+
{ id: 'IS_NULL', label: 'is_null' },
|
|
21
|
+
{ id: 'IS_NOT_NULL', label: 'is_not_null' }
|
|
24
22
|
];
|
|
25
|
-
// FIXME: TR
|
|
26
23
|
const numericFieldOptions = [
|
|
27
24
|
{ id: 'BTW', label: 'between' },
|
|
28
|
-
{ id: 'NOT_BTW', label: '
|
|
29
|
-
{ id: 'EQ', label: '
|
|
30
|
-
{ id: 'NEQ', label: '
|
|
31
|
-
{ id: 'IN', label: '
|
|
32
|
-
{ id: 'NOT_IN', label: '
|
|
33
|
-
{ id: 'GT', label: '
|
|
34
|
-
{ id: 'GTE', label: '
|
|
35
|
-
{ id: 'LT', label: '
|
|
36
|
-
{ id: 'LTE', label: '
|
|
37
|
-
{ id: 'IS_NULL', label: '
|
|
38
|
-
{ id: 'IS_NOT_NULL', label: '
|
|
25
|
+
{ id: 'NOT_BTW', label: 'not_between' },
|
|
26
|
+
{ id: 'EQ', label: 'is_equal_to' },
|
|
27
|
+
{ id: 'NEQ', label: 'is_not_equal_to' },
|
|
28
|
+
{ id: 'IN', label: 'is_in_list' },
|
|
29
|
+
{ id: 'NOT_IN', label: 'is_not_in_list' },
|
|
30
|
+
{ id: 'GT', label: 'greater_than' },
|
|
31
|
+
{ id: 'GTE', label: 'greater_than_or_equals' },
|
|
32
|
+
{ id: 'LT', label: 'lower_than' },
|
|
33
|
+
{ id: 'LTE', label: 'lower_than_or_equals' },
|
|
34
|
+
{ id: 'IS_NULL', label: 'is_null' },
|
|
35
|
+
{ id: 'IS_NOT_NULL', label: 'is_not_null' }
|
|
39
36
|
];
|
|
40
|
-
// FIXME: TR
|
|
41
37
|
const dateTimeFieldOptions = [
|
|
42
38
|
{ id: 'BTW', label: 'between' },
|
|
43
|
-
{ id: 'NOT_BTW', label: '
|
|
44
|
-
{ id: 'EQ', label: '
|
|
45
|
-
{ id: 'NEQ', label: '
|
|
46
|
-
{ id: 'GT', label: '
|
|
47
|
-
{ id: 'GTE', label: '
|
|
48
|
-
{ id: 'LT', label: '
|
|
49
|
-
{ id: 'LTE', label: '
|
|
50
|
-
{ id: 'IS_NULL', label: '
|
|
51
|
-
{ id: 'IS_NOT_NULL', label: '
|
|
39
|
+
{ id: 'NOT_BTW', label: 'not_between' },
|
|
40
|
+
{ id: 'EQ', label: 'is_equal_to' },
|
|
41
|
+
{ id: 'NEQ', label: 'is_not_equal_to' },
|
|
42
|
+
{ id: 'GT', label: 'greater_than' },
|
|
43
|
+
{ id: 'GTE', label: 'greater_than_or_equals' },
|
|
44
|
+
{ id: 'LT', label: 'lower_than' },
|
|
45
|
+
{ id: 'LTE', label: 'lower_than_or_equals' },
|
|
46
|
+
{ id: 'IS_NULL', label: 'is_null' },
|
|
47
|
+
{ id: 'IS_NOT_NULL', label: 'is_not_null' }
|
|
52
48
|
];
|
|
53
49
|
const typeWiseComparators = {
|
|
54
50
|
BOOLEAN: boolFieldOptions,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comparators.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/comparators.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"comparators.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/comparators.ts"],"names":[],"mappings":"AA2BA,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,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,EAAE,YAAY,EAAE;IACjC,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,gBAAgB,EAAE;IACzC,EAAE,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE;IAC3C,EAAE,EAAE,EAAE,iBAAiB,EAAE,KAAK,EAAE,iBAAiB,EAAE;IACnD,EAAE,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE;IACvC,EAAE,EAAE,EAAE,eAAe,EAAE,KAAK,EAAE,eAAe,EAAE;IAC/C,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE;IACrC,EAAE,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,cAAc,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: Comparator;\n label:\n | 'is_true'\n | 'is_false'\n | 'is_equal_to'\n | 'is_not_equal_to'\n | 'is_in_list'\n | 'is_not_in_list'\n | 'between'\n | 'not_between'\n | 'greater_than'\n | 'greater_than_or_equals'\n | 'lower_than'\n | 'lower_than_or_equals'\n | 'starts_with'\n | 'not_starts_with'\n | 'ends_with'\n | 'not_ends_with'\n | 'contains'\n | 'not_contains'\n | 'is_null'\n | 'is_not_null';\n}\n\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\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\nconst numericFieldOptions: ComparatorOption[] = [\n { id: 'BTW', label: 'between' },\n { id: 'NOT_BTW', label: 'not_between' },\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\nconst dateTimeFieldOptions: ComparatorOption[] = [\n { id: 'BTW', label: 'between' },\n { id: 'NOT_BTW', label: 'not_between' },\n { id: 'EQ', label: 'is_equal_to' },\n { id: 'NEQ', label: 'is_not_equal_to' },\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\nconst typeWiseComparators: Record<FieldType, ComparatorOption[]> = {\n BOOLEAN: boolFieldOptions,\n TEXT: textFieldOptions,\n DECIMAL: numericFieldOptions,\n INTEGER: 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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pega/cosmos-react-condition-builder",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.5.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/pegasystems/cosmos-react.git",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"build": "tsc -b tsconfig.build.json"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@pega/cosmos-react-core": "7.
|
|
25
|
+
"@pega/cosmos-react-core": "7.5.0",
|
|
26
26
|
"@types/react": "^17.0.62",
|
|
27
27
|
"@types/react-dom": "^17.0.20",
|
|
28
28
|
"@types/styled-components": "^5.1.26",
|