@pega/cosmos-react-condition-builder 3.0.0-dev.11.0 → 3.0.0-dev.14.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 +1 -1
- package/lib/components/ConditionBuilder/AtomicCondition.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/AtomicCondition.js.map +1 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.js.map +1 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts +4 -3
- 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/FieldCondition.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/FieldCondition.js +12 -12
- package/lib/components/ConditionBuilder/FieldCondition.js.map +1 -1
- package/lib/components/ConditionBuilder/FieldCondition.types.d.ts +9 -2
- package/lib/components/ConditionBuilder/FieldCondition.types.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/FieldCondition.types.js.map +1 -1
- package/lib/components/ConditionBuilder/core/formatter.js +2 -2
- package/lib/components/ConditionBuilder/core/formatter.js.map +1 -1
- package/lib/components/ConditionInput/ConditionInput.d.ts +6 -0
- package/lib/components/ConditionInput/ConditionInput.d.ts.map +1 -0
- package/lib/components/ConditionInput/ConditionInput.js +124 -0
- package/lib/components/ConditionInput/ConditionInput.js.map +1 -0
- package/lib/components/ConditionInput/ConditionInput.types.d.ts +21 -0
- package/lib/components/ConditionInput/ConditionInput.types.d.ts.map +1 -0
- package/lib/components/ConditionInput/ConditionInput.types.js +2 -0
- package/lib/components/ConditionInput/ConditionInput.types.js.map +1 -0
- package/lib/components/ConditionInput/index.d.ts +3 -0
- package/lib/components/ConditionInput/index.d.ts.map +1 -0
- package/lib/components/ConditionInput/index.js +2 -0
- package/lib/components/ConditionInput/index.js.map +1 -0
- package/lib/components/PromotedFilters/PromotedFilters.d.ts +6 -0
- package/lib/components/PromotedFilters/PromotedFilters.d.ts.map +1 -0
- package/lib/components/PromotedFilters/PromotedFilters.js +50 -0
- package/lib/components/PromotedFilters/PromotedFilters.js.map +1 -0
- package/lib/components/PromotedFilters/PromotedFilters.types.d.ts +25 -0
- package/lib/components/PromotedFilters/PromotedFilters.types.d.ts.map +1 -0
- package/lib/components/PromotedFilters/PromotedFilters.types.js +2 -0
- package/lib/components/PromotedFilters/PromotedFilters.types.js.map +1 -0
- package/lib/components/PromotedFilters/index.d.ts +3 -0
- package/lib/components/PromotedFilters/index.d.ts.map +1 -0
- package/lib/components/PromotedFilters/index.js +2 -0
- package/lib/components/PromotedFilters/index.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -0
- package/lib/index.js.map +1 -1
- package/package.json +7 -3
|
@@ -12,7 +12,7 @@ export declare function getInitConditionForLhs(lhs: LeafCondition['lhs'], fields
|
|
|
12
12
|
*/
|
|
13
13
|
export declare function isValidCondition(condition: LeafCondition, fields: Field[], trimValues?: boolean): boolean;
|
|
14
14
|
/** Type definition for the input props of AtomicCondition */
|
|
15
|
-
interface AtomicConditionProps extends BaseProps {
|
|
15
|
+
export interface AtomicConditionProps extends BaseProps {
|
|
16
16
|
/** Condition to use in the component */
|
|
17
17
|
condition: LeafCondition;
|
|
18
18
|
/** Metadata (data-model) for the Fields to use in the Condition */
|
|
@@ -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,EAOL,SAAS,EACT,YAAY,EACb,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAIrF,OAAO,EAAc,iBAAiB,EAAa,OAAO,EAAE,MAAM,cAAc,CAAC;AA2CjF,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,
|
|
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,EAOL,SAAS,EACT,YAAY,EACb,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAIrF,OAAO,EAAc,iBAAiB,EAAa,OAAO,EAAE,MAAM,cAAc,CAAC;AA2CjF,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;IACr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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,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { FunctionComponent, ChangeEvent } from 'react';\n\nimport {\n Grid,\n Select,\n Option,\n Text,\n useI18n,\n hasProp,\n BaseProps,\n ForwardProps\n} from '@pega/cosmos-react-core';\n\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';\n\n// Returns field-type for a given field-name\nfunction getFieldType(fieldName: string, fields: Field[]): FieldType | undefined {\n const matchingField = fields.find(f => f.name === fieldName);\n return matchingField?.type;\n}\n\n// Returns display label for a given field-name\nfunction getFieldLabel(fieldName: string, fields: Field[]): string | undefined {\n const matchingField = fields.find(f => f.name === fieldName);\n return matchingField?.label || matchingField?.name;\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 // `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, fieldType, trimValues);\n}\n\n/** Type definition for the input props of AtomicCondition */\ninterface 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 showing the LHS as a readonly label.\n * NOTE: Make sure that a valid LHS is passed in the 'condition'\n */\n showLhsAsLabel?: boolean;\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 props: AtomicConditionProps\n) => {\n const {\n condition,\n fields,\n indicateErrors,\n validComparators,\n onChange,\n itemDirection,\n showLhsAsLabel,\n validRhsTypes = new Set<RHSType>(['LITERAL', 'FIELD']),\n dateFunctions\n } = props;\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: 'Select…' }]; // FIXME: TR\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 t = useI18n();\n\n return (\n // Using minmax() to get equal widths: https://stackoverflow.com/a/61240964/4247448\n <Grid\n sm={{\n container: { cols: itemDirection === 'column' ? '1fr' : 'repeat(3, minmax(5rem,1fr))' }\n }}\n md={{\n container: { cols: itemDirection === 'column' ? '1fr' : 'repeat(3, minmax(10rem,1fr))' }\n }}\n container={{\n justifyItems: 'stretch',\n colGap: 0.5,\n rowGap: 0.5\n }}\n >\n {/* LHS label */}\n {showLhsAsLabel && (\n <Text variant='secondary'>{getFieldLabel(condition.lhs.field, fields)}</Text>\n )}\n {/* LHS selector */}\n {!showLhsAsLabel && (\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='-'\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 );\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,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AC,UAAU,EAC3B,QAAQ,EAAE,sBAAsB,EAChC,IAAI,EAAC,YAAY,EACjB,KAAK,EAAC,GAAG,EACT,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,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { FunctionComponent, ChangeEvent } from 'react';\n\nimport {\n Grid,\n Select,\n Option,\n Text,\n useI18n,\n hasProp,\n BaseProps,\n ForwardProps\n} from '@pega/cosmos-react-core';\n\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';\n\n// Returns field-type for a given field-name\nfunction getFieldType(fieldName: string, fields: Field[]): FieldType | undefined {\n const matchingField = fields.find(f => f.name === fieldName);\n return matchingField?.type;\n}\n\n// Returns display label for a given field-name\nfunction getFieldLabel(fieldName: string, fields: Field[]): string | undefined {\n const matchingField = fields.find(f => f.name === fieldName);\n return matchingField?.label || matchingField?.name;\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 // `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, 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 showing the LHS as a readonly label.\n * NOTE: Make sure that a valid LHS is passed in the 'condition'\n */\n showLhsAsLabel?: boolean;\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 props: AtomicConditionProps\n) => {\n const {\n condition,\n fields,\n indicateErrors,\n validComparators,\n onChange,\n itemDirection,\n showLhsAsLabel,\n validRhsTypes = new Set<RHSType>(['LITERAL', 'FIELD']),\n dateFunctions\n } = props;\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: 'Select…' }]; // FIXME: TR\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 t = useI18n();\n\n return (\n // Using minmax() to get equal widths: https://stackoverflow.com/a/61240964/4247448\n <Grid\n sm={{\n container: { cols: itemDirection === 'column' ? '1fr' : 'repeat(3, minmax(5rem,1fr))' }\n }}\n md={{\n container: { cols: itemDirection === 'column' ? '1fr' : 'repeat(3, minmax(10rem,1fr))' }\n }}\n container={{\n justifyItems: 'stretch',\n colGap: 0.5,\n rowGap: 0.5\n }}\n >\n {/* LHS label */}\n {showLhsAsLabel && (\n <Text variant='secondary'>{getFieldLabel(condition.lhs.field, fields)}</Text>\n )}\n {/* LHS selector */}\n {!showLhsAsLabel && (\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='-'\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 );\n};\n\nexport default AtomicCondition;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConditionBuilder.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.tsx"],"names":[],"mappings":";AAAA,OAAO,EAEL,QAAQ,EAER,QAAQ,EACR,UAAU,EACV,mBAAmB,EACpB,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EACL,MAAM,EACN,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,UAAU,EAEV,SAAS,EACT,OAAO,EACP,gBAAgB,EAChB,OAAO,EACR,MAAM,yBAAyB,CAAC;AAEjC,OAAO,eAAe,EAAE,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,UAAU,MAAM,cAAc,CAAC;AAMtC,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,cAAc,CAAC;AACtB,OAAO,WAAW,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGtF,wCAAwC;AACxC,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;;gBAEd,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,aAAa,CAAC;CAC9E,CAAC;AACF,SAAS,CAAC,YAAY,GAAG,gBAAgB,CAAC;A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,IAAI,EAAE,UAAU,GAChB,GACE,CACP,EAGD,MAAC,IAAI,IAAC,SAAS,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,EAAE,aAE7C,eAAe,IAAI,CAClB,KAAC,MAAM,IACL,EAAE,EAAE,SAAS,EAAE,EACf,OAAO,EAAC,SAAS,EACjB,QAAQ,EAAE,CAAC,CAAC,CAAC,sCAAsC,CAAC,CAAC,EACrD,MAAM,EACJ,KAAC,MAAM,IAAC,IAAI,EAAC,mBAAmB,EAAC,OAAO,EAAC,WAAW,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,YACjF,CAAC,CAAC,wCAAwC,CAAC,GACrC,EAEX,SAAS,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,GACtC,CACH,EAGD,KAAC,IAAI,IAAC,SAAS,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,YACrC,KAAC,MAAM,IAAC,IAAI,EAAC,aAAa,EAAC,OAAO,EAAC,QAAQ,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,YACzE,WAAW;gCACV,CAAC,CAAC,CAAC,CAAC,8CAA8C,CAAC;gCACnD,CAAC,CAAC,CAAC,CAAC,2CAA2C,CAAC,GAC3C,GACJ,IACF,IACF,CACR,CAAC;AACJ,CAAC,CAAC;AACF,gBAAgB,CAAC,YAAY,GAAG,YAAY,CAAC;AAE7C,eAAe,gBAAgB,CAAC","sourcesContent":["import {\n FunctionComponent,\n Fragment,\n ChangeEvent,\n useState,\n useReducer,\n useImperativeHandle\n} from 'react';\nimport styled from 'styled-components';\n\nimport {\n Banner,\n Button,\n Flex,\n Icon,\n Input,\n MenuButton,\n ForwardProps,\n createUID,\n hasProp,\n defaultThemeProp,\n useI18n\n} from '@pega/cosmos-react-core';\n\nimport AtomicCondition, { isValidCondition } from './AtomicCondition';\nimport HelpButton from './HelpButton';\nimport ConditionBuilderProps, {\n Condition,\n HandleProps,\n LeafCondition\n} from './ConditionBuilder.types';\nimport {\n splitConditionForBuilder,\n parseLogicString,\n disambiguateLogic,\n isBasicModeApplicable,\n getBasicModeOperators,\n getLogicFromBasicMode\n} from './core/utils';\nimport rowsReducer, { INSERT_ROW, UPDATE_ROW, REMOVE_ROW } from './core/rows-reducer';\nimport { RHSType } from './core/types';\n\n// Styled wrapper for each Condition row\nconst StyledRow = styled(Flex)`\n padding: 0.25rem;\n background: ${props => (props.shaded ? 'rgba(0, 0, 0, 0.05)' : 'transparent')};\n`;\nStyledRow.defaultProps = defaultThemeProp;\n\n// Styled row-separators for Basic-mode\nconst StyledRowWithSeparator = styled(StyledRow)`\n padding: 0 0.25rem;\n &::after {\n content: '';\n flex-grow: 1;\n background-image: linear-gradient(to right, rgba(0, 0, 0, 0.2) 60%, rgba(0, 0, 0, 0) 0%);\n background-position: left center;\n background-size: 1.75rem 0.0625rem;\n background-repeat: repeat-x;\n }\n`;\n\n// Styled label for the rows in Advanced-mode\nconst StyledLabel = styled.div`\n line-height: 2rem;\n height: 2rem;\n width: 2rem;\n min-width: 2rem;\n text-align: center;\n background: rgba(0, 0, 0, 0.04);\n`;\nStyledLabel.defaultProps = defaultThemeProp;\n\n// Default props for the builder\nconst defaultProps: Partial<ConditionBuilderProps> = {\n condition: {\n condition: {\n comparator: 'IS_NOT_NULL',\n lhs: { field: '' }\n }\n }\n};\n\n// Component for the builder\nconst ConditionBuilder: FunctionComponent<ConditionBuilderProps & ForwardProps> = (\n props: ConditionBuilderProps\n) => {\n const {\n fields,\n condition: seedCondition,\n validComparators,\n validRhsTypes = new Set<RHSType>(['LITERAL', 'FIELD']),\n dateFunctions,\n disallowNOT,\n handle\n } = props;\n\n // Split the condition tree into a logic-string and a list of condition-rows.\n const clonedCondition: Condition = JSON.parse(JSON.stringify(seedCondition)); // Cloning to avoid modifying the original\n const { logic: seedLogic, rows: seedRows } = splitConditionForBuilder(clonedCondition);\n\n // On load, look to use the Basic-mode if the seed-condition is simple enough\n const [isBasicMode, setBasicMode] = useState(() => isBasicModeApplicable(clonedCondition));\n const [operatorsList, setOperatorsList] = useState(() => getBasicModeOperators(seedLogic)); // Operators-list used in Basic-mode to render dropdowns between the rows. NOTE: When in Advanced-mode, this can contain stale values.\n const [logicString, setLogicString] = useState(seedLogic); // Logic-string used in Advanced-mode. NOTE: When in Basic-mode, this can contain stale values.\n const [conditionRows, dispatch] = useReducer(rowsReducer, seedRows); // Conditions-rows\n const [logicError, setLogicError] = useState<string | null>(null); // Used to indicate errors in the logic string\n const [showModeWarning, setModeWarning] = useState(false); // Used to warn user about losing information when moving away from Advanced mode\n const [showErrorIndicators, setErrorIndicators] = useState(false); // Used to enable inline error indicators in the condition rows\n const enableShading =\n isBasicMode && operatorsList.includes('AND') && operatorsList.includes('OR'); // In Basic mode, enable shading to indicate grouping only when both operators are present\n\n // Upon adding/removing rows in Advanced mode, update the logic string to reflect the change in labels\n // NOTE: The input is updated only if the previous logicString was simple enough\n const updateLogicString = (actionType: string): void => {\n const numNewRows =\n actionType === INSERT_ROW ? conditionRows.length + 1 : conditionRows.length - 1;\n\n // If only one row left after the action, simply use its label as logicString\n // NOTE: If none left, the rowsReducer adds a new empty row\n if (numNewRows <= 1) {\n setLogicString('1');\n return;\n }\n\n // If the previous string was a simple AND/OR between all the rows, update the logicString to follow the same for the new list of rows.\n // If the previous string was a single token like `1` and a new row is inserted, do an AND between the new rows, i.e. `1 AND 2`\n // For all other complex cases, skip automatically updating the string and wait for the user to change it\n // To check this, split the previous string by `OR/AND` and check if each of the resultant token is a simple numeric token\n const splitter = logicString.includes('OR') ? 'OR' : 'AND';\n const tokens = logicString.split(splitter);\n const isEveryTokenInteger = tokens.every(w => /^\\d+$/.test(w.trim()));\n if (isEveryTokenInteger) {\n setLogicString(\n new Array(numNewRows)\n .fill(0)\n .map((w, i) => i + 1)\n .join(` ${splitter} `)\n );\n }\n };\n\n // Insert a new row at the given index\n const insertRow = (insertAt: number): void => {\n dispatch({ type: INSERT_ROW, payload: { insertAt } }); // Insert an entry in conditionRows\n if (isBasicMode) {\n // Set up a new AND/OR selector\n const insertOpAt = insertAt - 1; // Using `insertAt-1` since the operatorsList has one less entry compared to the conditionRows\n setOperatorsList([\n ...operatorsList.slice(0, insertOpAt),\n 'AND',\n ...operatorsList.slice(insertOpAt)\n ]);\n } else {\n updateLogicString(INSERT_ROW); // Update the logicString input to reflect the insertion\n }\n };\n\n // Remove the row at the given index\n const removeRow = (removeAt: number): void => {\n dispatch({ type: REMOVE_ROW, payload: { removeAt } }); // Remove an entry in conditionRows\n if (isBasicMode) {\n // Remove an AND/OR selector\n if (removeAt === 0) {\n // If removing the first of the condition rows, remove the extraneous operator\n setOperatorsList(operatorsList.slice(1));\n } else {\n let removeOpAt = removeAt - 1; // Using `removeAt-1` since the operatorsList has one less entry compared to the conditionRows\n if (operatorsList[removeOpAt] === 'OR' && operatorsList[removeOpAt + 1] === 'AND') {\n // If removing a condition at the start of a nested group, remove the first operator from that group. e.g. Take `(1 AND 2) OR (3 AND 4 AND 5)`. If `3` is being deleted, it should become `(1 AND 2) OR (4 AND 5)` instead of `1 AND 2 AND 4 AND 5`\n removeOpAt += 1;\n }\n setOperatorsList([\n ...operatorsList.slice(0, removeOpAt),\n ...operatorsList.slice(removeOpAt + 1)\n ]);\n }\n } else {\n updateLogicString(REMOVE_ROW); // Update the logicString input to reflect the removal\n }\n };\n\n // Update a Basic-mode operator at the given index\n const updateOperator = (updateAt: number, newValue: 'AND' | 'OR'): void => {\n setOperatorsList([\n ...operatorsList.slice(0, updateAt),\n newValue,\n ...operatorsList.slice(updateAt + 1)\n ]);\n };\n\n // Validate the logic input. Called upon clicking outside the textBox or upon submission.\n // If the expression is invalid, shows appropriate feedback and returns null.\n // If the expression is valid, formats it by setting up brackets at necessary places (to clear any ambiguities e.g. `1 AND 2 OR 3` is formatted as `(1 AND 2) OR 3` ). Returns a save-ready condition\n const validateLogicString = (logicToUse: string): Condition | null => {\n // Set up a lookup with row-labels as keys and rows as values\n const conditionLookup: { [label: string]: LeafCondition } = {};\n conditionRows.forEach(row => {\n const { id, label, ...leaf } = row; // Discard the extra properties added by ConditionRow to the LeafCondition interface\n conditionLookup[row.label] = leaf;\n });\n\n // Convert the logic string into a condition tree\n const parseResult = parseLogicString(logicToUse, conditionLookup, disallowNOT);\n\n // Indicate any parse error\n if (hasProp(parseResult, 'error')) {\n setLogicError(parseResult.error);\n return null;\n }\n\n // If no errors\n setLogicError(null); // Clear any previous error\n setLogicString(disambiguateLogic(logicToUse)); // Disambiguating the logic string by placing parentheses at appropriate places\n return parseResult.condition;\n };\n\n // Toggle between the Basic and Advanced modes\n // `forceToggle:true` is passed when switching from Advanced to Basic mode despite a loss of information\n const toggleMode = (forceToggle?: boolean): void => {\n setModeWarning(false); // Clear any previous warning\n if (isBasicMode) {\n // Update the logicString to match the operatorsList before switching the mode\n setLogicString(getLogicFromBasicMode(operatorsList));\n setBasicMode(false);\n } else if (forceToggle) {\n // If forcibly toggling from Advanced to Basic despite a loss of operators\n // Set up the default `AND` operator between all rows before switching to Basic mode\n setOperatorsList(new Array(conditionRows.length - 1).fill('AND'));\n setBasicMode(true);\n } else {\n // If switching from Advanced mode\n const condition = validateLogicString(logicString); // Validate the logicString. If it is an invalid, an appropriate error is shown for the user to act on\n if (condition !== null) {\n // If it's a valid condition, check if it's simple enough to be shown in Basic mode without any loss of information\n if (isBasicModeApplicable(condition)) {\n // If the logic is simple enough, identify the new set of operators before switching to Basic mode\n setOperatorsList(getBasicModeOperators(logicString));\n setBasicMode(true);\n } else {\n // If the logic is too complex show a warning for the user to act on\n setModeWarning(true);\n }\n }\n }\n };\n\n const getCondition: HandleProps['getCondition'] = () => {\n setErrorIndicators(false); // Reset any previous flag\n setLogicError(null); // Clear any previous error\n\n // If there's a single empty condition, submit with an `undefined` value (useful for clearing a previous condition)\n if (conditionRows.length === 1 && conditionRows[0].lhs.field === '') {\n return [true, undefined];\n }\n\n // Identify and indicate any invalid values in the condition rows\n const hasInvalidRows = conditionRows.some(row => !isValidCondition(row, fields, true));\n if (hasInvalidRows) {\n setErrorIndicators(true); // Enable inline error indications\n return [false];\n }\n\n // Validate the Logic string\n const logicToUse = isBasicMode ? getLogicFromBasicMode(operatorsList) : logicString; // If in Basic-mode, construct a different logicString based on the operatorsList\n const condition = validateLogicString(logicToUse); // This also takes care of showing an appropriate error feedback as needed\n if (condition !== null) {\n // Can be null when the logic string has errors\n return [true, condition];\n }\n\n return [false];\n };\n\n useImperativeHandle<HandleProps, HandleProps>(\n handle,\n () => ({\n getCondition\n }),\n [getCondition]\n );\n\n const t = useI18n();\n\n return (\n <Flex container={{ direction: 'column', gap: 4 }}>\n {/* Condition Rows */}\n <div>\n {conditionRows.map(({ id, label, ...leaf }, index) => (\n <Fragment key={id}>\n {/* Row with the operator dropdown in Basic mode */}\n {isBasicMode && index > 0 && (\n <StyledRowWithSeparator\n container\n shaded={enableShading && operatorsList[index - 1] === 'AND'}\n >\n <MenuButton\n text={operatorsList[index - 1].toLowerCase()}\n variant='simple'\n menu={{\n items: [\n {\n id: 'AND',\n primary: 'and',\n onClick: () => updateOperator(index - 1, 'AND')\n },\n {\n id: 'OR',\n primary: 'or',\n onClick: () => updateOperator(index - 1, 'OR')\n }\n ]\n }}\n />\n </StyledRowWithSeparator>\n )}\n\n {/* Row with the AtomicCondition */}\n <StyledRow\n container={{ gap: 0.5, alignItems: 'start' }}\n shaded={isBasicMode && enableShading}\n >\n {/* Label */}\n {!isBasicMode && <StyledLabel>{label}</StyledLabel>}\n\n {/* Condition controls */}\n <Flex item={{ grow: 1 }}>\n <AtomicCondition\n condition={leaf}\n fields={fields}\n indicateErrors={showErrorIndicators}\n validComparators={validComparators}\n dateFunctions={dateFunctions}\n onChange={(newCondition: LeafCondition) => {\n const newRow = { id, label, ...newCondition };\n dispatch({ type: UPDATE_ROW, payload: { updateAt: index, newRow } });\n }}\n validRhsTypes={validRhsTypes}\n />\n </Flex>\n\n {/* Row actions */}\n <Button\n icon\n variant='simple'\n onClick={() => insertRow(index + 1)}\n aria-label={t('condition_builder_add_button_label')}\n >\n <Icon name='plus' />\n </Button>\n <Button\n icon\n variant='simple'\n onClick={() => removeRow(index)}\n aria-label={t('condition_builder_remove_button_label')}\n >\n <Icon name='trash' />\n </Button>\n </StyledRow>\n </Fragment>\n ))}\n </div>\n\n {/* LogicString input */}\n {!isBasicMode && (\n <div>\n <Input\n type='text'\n placeholder={t('condition_builder_advanced_condition_placeholder')}\n label={\n <>\n {t('condition_builder_advanced_condition_label')} \n {/* FIXME: TR */}\n <HelpButton>\n {`A logical expression representing an advanced condition.\\nUse numbers like 1,2,3,… to represent different condition rows.\\nUse ${\n disallowNOT ? 'AND/OR' : 'AND/OR/NOT'\n } operators and parentheses to construct advanced conditions.\\n\\nExample: ${\n disallowNOT ? '(1 OR 2) AND (3 OR 4 OR 5)' : '(1 AND 2) OR (3 AND NOT 4)'\n }`}\n </HelpButton>\n </>\n }\n value={logicString}\n onChange={(e: ChangeEvent<HTMLInputElement>) => setLogicString(e.target.value)}\n onBlur={() => validateLogicString(logicString)}\n status={logicError !== null ? 'error' : undefined}\n info={logicError}\n />\n </div>\n )}\n\n {/* Submit block */}\n <Flex container={{ direction: 'column', gap: 2 }}>\n {/* Banner to show a warning when switching from Advanced to Basic mode */}\n {showModeWarning && (\n <Banner\n id={createUID()}\n variant='warning'\n messages={[t('condition_builder_switch_banner_text')]}\n action={\n <Button name='force-mode-switch' variant='secondary' onClick={() => toggleMode(true)}>\n {t('condition_builder_confirm_button_label')}\n </Button>\n }\n onDismiss={() => setModeWarning(false)}\n />\n )}\n\n {/* Footer buttons */}\n <Flex container={{ justify: 'between' }}>\n <Button name='mode-switch' variant='simple' onClick={() => toggleMode(false)}>\n {isBasicMode\n ? t('condition_builder_advanced_mode_button_label')\n : t('condition_builder_basic_mode_button_label')}\n </Button>\n </Flex>\n </Flex>\n </Flex>\n );\n};\nConditionBuilder.defaultProps = defaultProps;\n\nexport default ConditionBuilder;\n"]}
|
|
1
|
+
{"version":3,"file":"ConditionBuilder.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.tsx"],"names":[],"mappings":";AAAA,OAAO,EAEL,QAAQ,EAER,QAAQ,EACR,UAAU,EACV,mBAAmB,EACpB,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EACL,MAAM,EACN,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,UAAU,EAEV,SAAS,EACT,OAAO,EACP,gBAAgB,EAChB,OAAO,EACR,MAAM,yBAAyB,CAAC;AAEjC,OAAO,eAAe,EAAE,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,UAAU,MAAM,cAAc,CAAC;AAMtC,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,cAAc,CAAC;AACtB,OAAO,WAAW,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGtF,wCAAwC;AACxC,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;;gBAEd,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,aAAa,CAAC;CAC9E,CAAC;AACF,SAAS,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAE1C,uCAAuC;AACvC,MAAM,sBAAsB,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;;;;;;;;;;CAU/C,CAAC;AAEF,6CAA6C;AAC7C,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;CAO7B,CAAC;AACF,WAAW,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAE5C,gCAAgC;AAChC,MAAM,YAAY,GAAmC;IACnD,SAAS,EAAE;QACT,SAAS,EAAE;YAC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M,IAAC,IAAI,EAAC,mBAAmB,EAAC,OAAO,EAAC,WAAW,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,YACjF,CAAC,CAAC,wCAAwC,CAAC,GACrC,EAEX,SAAS,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,GACtC,CACH,EAGD,KAAC,IAAI,IAAC,SAAS,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,YACrC,KAAC,MAAM,IAAC,IAAI,EAAC,aAAa,EAAC,OAAO,EAAC,QAAQ,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,YACzE,WAAW;gCACV,CAAC,CAAC,CAAC,CAAC,8CAA8C,CAAC;gCACnD,CAAC,CAAC,CAAC,CAAC,2CAA2C,CAAC,GAC3C,GACJ,IACF,IACF,CACR,CAAC;AACJ,CAAC,CAAC;AACF,gBAAgB,CAAC,YAAY,GAAG,YAAY,CAAC;AAE7C,eAAe,gBAAgB,CAAC","sourcesContent":["import {\n FunctionComponent,\n Fragment,\n ChangeEvent,\n useState,\n useReducer,\n useImperativeHandle\n} from 'react';\nimport styled from 'styled-components';\n\nimport {\n Banner,\n Button,\n Flex,\n Icon,\n Input,\n MenuButton,\n ForwardProps,\n createUID,\n hasProp,\n defaultThemeProp,\n useI18n\n} from '@pega/cosmos-react-core';\n\nimport AtomicCondition, { isValidCondition } from './AtomicCondition';\nimport HelpButton from './HelpButton';\nimport ConditionBuilderProps, {\n Condition,\n HandleValue,\n LeafCondition\n} from './ConditionBuilder.types';\nimport {\n splitConditionForBuilder,\n parseLogicString,\n disambiguateLogic,\n isBasicModeApplicable,\n getBasicModeOperators,\n getLogicFromBasicMode\n} from './core/utils';\nimport rowsReducer, { INSERT_ROW, UPDATE_ROW, REMOVE_ROW } from './core/rows-reducer';\nimport { RHSType } from './core/types';\n\n// Styled wrapper for each Condition row\nconst StyledRow = styled(Flex)`\n padding: 0.25rem;\n background: ${props => (props.shaded ? 'rgba(0, 0, 0, 0.05)' : 'transparent')};\n`;\nStyledRow.defaultProps = defaultThemeProp;\n\n// Styled row-separators for Basic-mode\nconst StyledRowWithSeparator = styled(StyledRow)`\n padding: 0 0.25rem;\n &::after {\n content: '';\n flex-grow: 1;\n background-image: linear-gradient(to right, rgba(0, 0, 0, 0.2) 60%, rgba(0, 0, 0, 0) 0%);\n background-position: left center;\n background-size: 1.75rem 0.0625rem;\n background-repeat: repeat-x;\n }\n`;\n\n// Styled label for the rows in Advanced-mode\nconst StyledLabel = styled.div`\n line-height: 2rem;\n height: 2rem;\n width: 2rem;\n min-width: 2rem;\n text-align: center;\n background: rgba(0, 0, 0, 0.04);\n`;\nStyledLabel.defaultProps = defaultThemeProp;\n\n// Default props for the builder\nconst defaultProps: Partial<ConditionBuilderProps> = {\n condition: {\n condition: {\n comparator: 'IS_NOT_NULL',\n lhs: { field: '' }\n }\n }\n};\n\n// Component for the builder\nconst ConditionBuilder: FunctionComponent<ConditionBuilderProps & ForwardProps> = (\n props: ConditionBuilderProps\n) => {\n const {\n fields,\n condition: seedCondition,\n validComparators,\n validRhsTypes = new Set<RHSType>(['LITERAL', 'FIELD']),\n dateFunctions,\n disallowNOT,\n handle\n } = props;\n\n // Split the condition tree into a logic-string and a list of condition-rows.\n const clonedCondition: Condition = JSON.parse(JSON.stringify(seedCondition)); // Cloning to avoid modifying the original\n const { logic: seedLogic, rows: seedRows } = splitConditionForBuilder(clonedCondition);\n\n // On load, look to use the Basic-mode if the seed-condition is simple enough\n const [isBasicMode, setBasicMode] = useState(() => isBasicModeApplicable(clonedCondition));\n const [operatorsList, setOperatorsList] = useState(() => getBasicModeOperators(seedLogic)); // Operators-list used in Basic-mode to render dropdowns between the rows. NOTE: When in Advanced-mode, this can contain stale values.\n const [logicString, setLogicString] = useState(seedLogic); // Logic-string used in Advanced-mode. NOTE: When in Basic-mode, this can contain stale values.\n const [conditionRows, dispatch] = useReducer(rowsReducer, seedRows); // Conditions-rows\n const [logicError, setLogicError] = useState<string | null>(null); // Used to indicate errors in the logic string\n const [showModeWarning, setModeWarning] = useState(false); // Used to warn user about losing information when moving away from Advanced mode\n const [showErrorIndicators, setErrorIndicators] = useState(false); // Used to enable inline error indicators in the condition rows\n const enableShading =\n isBasicMode && operatorsList.includes('AND') && operatorsList.includes('OR'); // In Basic mode, enable shading to indicate grouping only when both operators are present\n\n // Upon adding/removing rows in Advanced mode, update the logic string to reflect the change in labels\n // NOTE: The input is updated only if the previous logicString was simple enough\n const updateLogicString = (actionType: string): void => {\n const numNewRows =\n actionType === INSERT_ROW ? conditionRows.length + 1 : conditionRows.length - 1;\n\n // If only one row left after the action, simply use its label as logicString\n // NOTE: If none left, the rowsReducer adds a new empty row\n if (numNewRows <= 1) {\n setLogicString('1');\n return;\n }\n\n // If the previous string was a simple AND/OR between all the rows, update the logicString to follow the same for the new list of rows.\n // If the previous string was a single token like `1` and a new row is inserted, do an AND between the new rows, i.e. `1 AND 2`\n // For all other complex cases, skip automatically updating the string and wait for the user to change it\n // To check this, split the previous string by `OR/AND` and check if each of the resultant token is a simple numeric token\n const splitter = logicString.includes('OR') ? 'OR' : 'AND';\n const tokens = logicString.split(splitter);\n const isEveryTokenInteger = tokens.every(w => /^\\d+$/.test(w.trim()));\n if (isEveryTokenInteger) {\n setLogicString(\n new Array(numNewRows)\n .fill(0)\n .map((w, i) => i + 1)\n .join(` ${splitter} `)\n );\n }\n };\n\n // Insert a new row at the given index\n const insertRow = (insertAt: number): void => {\n dispatch({ type: INSERT_ROW, payload: { insertAt } }); // Insert an entry in conditionRows\n if (isBasicMode) {\n // Set up a new AND/OR selector\n const insertOpAt = insertAt - 1; // Using `insertAt-1` since the operatorsList has one less entry compared to the conditionRows\n setOperatorsList([\n ...operatorsList.slice(0, insertOpAt),\n 'AND',\n ...operatorsList.slice(insertOpAt)\n ]);\n } else {\n updateLogicString(INSERT_ROW); // Update the logicString input to reflect the insertion\n }\n };\n\n // Remove the row at the given index\n const removeRow = (removeAt: number): void => {\n dispatch({ type: REMOVE_ROW, payload: { removeAt } }); // Remove an entry in conditionRows\n if (isBasicMode) {\n // Remove an AND/OR selector\n if (removeAt === 0) {\n // If removing the first of the condition rows, remove the extraneous operator\n setOperatorsList(operatorsList.slice(1));\n } else {\n let removeOpAt = removeAt - 1; // Using `removeAt-1` since the operatorsList has one less entry compared to the conditionRows\n if (operatorsList[removeOpAt] === 'OR' && operatorsList[removeOpAt + 1] === 'AND') {\n // If removing a condition at the start of a nested group, remove the first operator from that group. e.g. Take `(1 AND 2) OR (3 AND 4 AND 5)`. If `3` is being deleted, it should become `(1 AND 2) OR (4 AND 5)` instead of `1 AND 2 AND 4 AND 5`\n removeOpAt += 1;\n }\n setOperatorsList([\n ...operatorsList.slice(0, removeOpAt),\n ...operatorsList.slice(removeOpAt + 1)\n ]);\n }\n } else {\n updateLogicString(REMOVE_ROW); // Update the logicString input to reflect the removal\n }\n };\n\n // Update a Basic-mode operator at the given index\n const updateOperator = (updateAt: number, newValue: 'AND' | 'OR'): void => {\n setOperatorsList([\n ...operatorsList.slice(0, updateAt),\n newValue,\n ...operatorsList.slice(updateAt + 1)\n ]);\n };\n\n // Validate the logic input. Called upon clicking outside the textBox or upon submission.\n // If the expression is invalid, shows appropriate feedback and returns null.\n // If the expression is valid, formats it by setting up brackets at necessary places (to clear any ambiguities e.g. `1 AND 2 OR 3` is formatted as `(1 AND 2) OR 3` ). Returns a save-ready condition\n const validateLogicString = (logicToUse: string): Condition | null => {\n // Set up a lookup with row-labels as keys and rows as values\n const conditionLookup: { [label: string]: LeafCondition } = {};\n conditionRows.forEach(row => {\n const { id, label, ...leaf } = row; // Discard the extra properties added by ConditionRow to the LeafCondition interface\n conditionLookup[row.label] = leaf;\n });\n\n // Convert the logic string into a condition tree\n const parseResult = parseLogicString(logicToUse, conditionLookup, disallowNOT);\n\n // Indicate any parse error\n if (hasProp(parseResult, 'error')) {\n setLogicError(parseResult.error);\n return null;\n }\n\n // If no errors\n setLogicError(null); // Clear any previous error\n setLogicString(disambiguateLogic(logicToUse)); // Disambiguating the logic string by placing parentheses at appropriate places\n return parseResult.condition;\n };\n\n // Toggle between the Basic and Advanced modes\n // `forceToggle:true` is passed when switching from Advanced to Basic mode despite a loss of information\n const toggleMode = (forceToggle?: boolean): void => {\n setModeWarning(false); // Clear any previous warning\n if (isBasicMode) {\n // Update the logicString to match the operatorsList before switching the mode\n setLogicString(getLogicFromBasicMode(operatorsList));\n setBasicMode(false);\n } else if (forceToggle) {\n // If forcibly toggling from Advanced to Basic despite a loss of operators\n // Set up the default `AND` operator between all rows before switching to Basic mode\n setOperatorsList(new Array(conditionRows.length - 1).fill('AND'));\n setBasicMode(true);\n } else {\n // If switching from Advanced mode\n const condition = validateLogicString(logicString); // Validate the logicString. If it is an invalid, an appropriate error is shown for the user to act on\n if (condition !== null) {\n // If it's a valid condition, check if it's simple enough to be shown in Basic mode without any loss of information\n if (isBasicModeApplicable(condition)) {\n // If the logic is simple enough, identify the new set of operators before switching to Basic mode\n setOperatorsList(getBasicModeOperators(logicString));\n setBasicMode(true);\n } else {\n // If the logic is too complex show a warning for the user to act on\n setModeWarning(true);\n }\n }\n }\n };\n\n const getCondition: HandleValue['getCondition'] = () => {\n setErrorIndicators(false); // Reset any previous flag\n setLogicError(null); // Clear any previous error\n\n // If there's a single empty condition, submit with an `undefined` value (useful for clearing a previous condition)\n if (conditionRows.length === 1 && conditionRows[0].lhs.field === '') {\n return [true, undefined];\n }\n\n // Identify and indicate any invalid values in the condition rows\n const hasInvalidRows = conditionRows.some(row => !isValidCondition(row, fields, true));\n if (hasInvalidRows) {\n setErrorIndicators(true); // Enable inline error indications\n return [false];\n }\n\n // Validate the Logic string\n const logicToUse = isBasicMode ? getLogicFromBasicMode(operatorsList) : logicString; // If in Basic-mode, construct a different logicString based on the operatorsList\n const condition = validateLogicString(logicToUse); // This also takes care of showing an appropriate error feedback as needed\n if (condition !== null) {\n // Can be null when the logic string has errors\n return [true, condition];\n }\n\n return [false];\n };\n\n useImperativeHandle(\n handle,\n () => ({\n getCondition\n }),\n [getCondition]\n );\n\n const t = useI18n();\n\n return (\n <Flex container={{ direction: 'column', gap: 4 }}>\n {/* Condition Rows */}\n <div>\n {conditionRows.map(({ id, label, ...leaf }, index) => (\n <Fragment key={id}>\n {/* Row with the operator dropdown in Basic mode */}\n {isBasicMode && index > 0 && (\n <StyledRowWithSeparator\n container\n shaded={enableShading && operatorsList[index - 1] === 'AND'}\n >\n <MenuButton\n text={operatorsList[index - 1].toLowerCase()}\n variant='simple'\n menu={{\n items: [\n {\n id: 'AND',\n primary: 'and',\n onClick: () => updateOperator(index - 1, 'AND')\n },\n {\n id: 'OR',\n primary: 'or',\n onClick: () => updateOperator(index - 1, 'OR')\n }\n ]\n }}\n />\n </StyledRowWithSeparator>\n )}\n\n {/* Row with the AtomicCondition */}\n <StyledRow\n container={{ gap: 0.5, alignItems: 'start' }}\n shaded={isBasicMode && enableShading}\n >\n {/* Label */}\n {!isBasicMode && <StyledLabel>{label}</StyledLabel>}\n\n {/* Condition controls */}\n <Flex item={{ grow: 1 }}>\n <AtomicCondition\n condition={leaf}\n fields={fields}\n indicateErrors={showErrorIndicators}\n validComparators={validComparators}\n dateFunctions={dateFunctions}\n onChange={(newCondition: LeafCondition) => {\n const newRow = { id, label, ...newCondition };\n dispatch({ type: UPDATE_ROW, payload: { updateAt: index, newRow } });\n }}\n validRhsTypes={validRhsTypes}\n />\n </Flex>\n\n {/* Row actions */}\n <Button\n icon\n variant='simple'\n onClick={() => insertRow(index + 1)}\n aria-label={t('condition_builder_add_button_label')}\n >\n <Icon name='plus' />\n </Button>\n <Button\n icon\n variant='simple'\n onClick={() => removeRow(index)}\n aria-label={t('condition_builder_remove_button_label')}\n >\n <Icon name='trash' />\n </Button>\n </StyledRow>\n </Fragment>\n ))}\n </div>\n\n {/* LogicString input */}\n {!isBasicMode && (\n <div>\n <Input\n type='text'\n placeholder={t('condition_builder_advanced_condition_placeholder')}\n label={\n <>\n {t('condition_builder_advanced_condition_label')} \n {/* FIXME: TR */}\n <HelpButton>\n {`A logical expression representing an advanced condition.\\nUse numbers like 1,2,3,… to represent different condition rows.\\nUse ${\n disallowNOT ? 'AND/OR' : 'AND/OR/NOT'\n } operators and parentheses to construct advanced conditions.\\n\\nExample: ${\n disallowNOT ? '(1 OR 2) AND (3 OR 4 OR 5)' : '(1 AND 2) OR (3 AND NOT 4)'\n }`}\n </HelpButton>\n </>\n }\n value={logicString}\n onChange={(e: ChangeEvent<HTMLInputElement>) => setLogicString(e.target.value)}\n onBlur={() => validateLogicString(logicString)}\n status={logicError !== null ? 'error' : undefined}\n info={logicError}\n />\n </div>\n )}\n\n {/* Submit block */}\n <Flex container={{ direction: 'column', gap: 2 }}>\n {/* Banner to show a warning when switching from Advanced to Basic mode */}\n {showModeWarning && (\n <Banner\n id={createUID()}\n variant='warning'\n messages={[t('condition_builder_switch_banner_text')]}\n action={\n <Button name='force-mode-switch' variant='secondary' onClick={() => toggleMode(true)}>\n {t('condition_builder_confirm_button_label')}\n </Button>\n }\n onDismiss={() => setModeWarning(false)}\n />\n )}\n\n {/* Footer buttons */}\n <Flex container={{ justify: 'between' }}>\n <Button name='mode-switch' variant='simple' onClick={() => toggleMode(false)}>\n {isBasicMode\n ? t('condition_builder_advanced_mode_button_label')\n : t('condition_builder_basic_mode_button_label')}\n </Button>\n </Flex>\n </Flex>\n </Flex>\n );\n};\nConditionBuilder.defaultProps = defaultProps;\n\nexport default ConditionBuilder;\n"]}
|
|
@@ -91,9 +91,10 @@ export interface DateFunctionsByType {
|
|
|
91
91
|
/** Date functions to enable for DATE_ONLY fields */
|
|
92
92
|
DATE_ONLY: DateFunction[];
|
|
93
93
|
}
|
|
94
|
-
export interface
|
|
94
|
+
export interface HandleValue {
|
|
95
95
|
/**
|
|
96
|
-
* Returns
|
|
96
|
+
* Returns condition validity and condition or undefined if valid.
|
|
97
|
+
* Undefined indicates no condition.
|
|
97
98
|
*/
|
|
98
99
|
getCondition: () => [valid: false] | [valid: true, condition: Condition | undefined];
|
|
99
100
|
}
|
|
@@ -116,6 +117,6 @@ export default interface ConditionBuilderProps extends BaseProps, NoChildrenProp
|
|
|
116
117
|
/** (Optional) Pass this if the `NOT` operator should be considered as invalid */
|
|
117
118
|
disallowNOT?: boolean;
|
|
118
119
|
/** Imperative handle for the component. */
|
|
119
|
-
handle?: Ref<
|
|
120
|
+
handle?: Ref<HandleValue>;
|
|
120
121
|
}
|
|
121
122
|
//# sourceMappingURL=ConditionBuilder.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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,MAAM,yBAAyB,CAAC;AAEzE,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,oEAAoE;AACpE,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,UAAU,CAAC;IAEvB,GAAG,EAAE;QACH,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IAGF,GAAG,CAAC,EACA;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GACjB;QAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAC1B;QAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAA;KAAE,GAC/B,mBAAmB,GACnB,mBAAmB,CAAC;CACzB;AAED,gFAAgF;AAChF,MAAM,WAAW,YAAa,SAAQ,aAAa;IACjD,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,oBAAY,SAAS,GACjB;IAAE,GAAG,EAAE,SAAS,EAAE,CAAA;CAAE,GACpB;IAAE,EAAE,EAAE,SAAS,EAAE,CAAA;CAAE,GACnB;IAAE,GAAG,EAAE,SAAS,CAAA;CAAE,GAClB;IAAE,SAAS,EAAE,aAAa,CAAA;CAAE,CAAC;AAEjC,2EAA2E;AAC3E,MAAM,WAAW,KAAK;IACpB,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC;IAEb,6FAA6F;IAC7F,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;;OAKG;IACH,IAAI,EAAE,SAAS,CAAC;IAEhB,yEAAyE;IACzE,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,cAAc,CAAC,EACX,MAAM,EAAE,GACR,CAAC,CAAC,iCAAiC,EAAE;QACnC,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,GAAG,CAAC,EAAE,KAAK,CAAC;KACb,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;CAC9B;AAED,yCAAyC;AACzC,MAAM,WAAW,mBAAmB;IAClC,oDAAoD;IACpD,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,oDAAoD;IACpD,SAAS,EAAE,YAAY,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,WAAW;IAC1B
|
|
1
|
+
{"version":3,"file":"ConditionBuilder.types.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.types.ts"],"names":[],"mappings":"AACA,OA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AEtB,2CAA2C;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 } 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/** 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}\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 */\nexport interface Field {\n /** Name of the Field. Saved as part of the output condition */\n name: string;\n\n /** (Optional) Display label for the Field. If none passed, the `name` itself will be used */\n label?: string;\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 /** (Optional) Used to add the field to a group during field-selection */\n groupLabel?: string;\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?:\n | string[]\n | ((fetchPossibleValuesApiInputParams: {\n searchString?: string;\n comparator?: string;\n lhs?: Field;\n }) => Promise<string[]>);\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
|
|
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 } 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/** 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}\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 */\nexport interface Field {\n /** Name of the Field. Saved as part of the output condition */\n name: string;\n\n /** (Optional) Display label for the Field. If none passed, the `name` itself will be used */\n label?: string;\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 /** (Optional) Used to add the field to a group during field-selection */\n groupLabel?: string;\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?:\n | string[]\n | ((fetchPossibleValuesApiInputParams: {\n searchString?: string;\n comparator?: string;\n lhs?: Field;\n }) => Promise<string[]>);\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":"FieldCondition.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/FieldCondition.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"FieldCondition.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/FieldCondition.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAiC,MAAM,OAAO,CAAC;AAEzE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,mBAAoC,MAAM,wBAAwB,CAAC;AAI1E,kEAAkE;AAClE,QAAA,MAAM,cAAc,EAAE,iBAAiB,CAAC,mBAAmB,GAAG,YAAY,CA0DzE,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
import { Flex, Button, useI18n } from '@pega/cosmos-react-core';
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useImperativeHandle, useState } from 'react';
|
|
4
3
|
import AtomicCondition, { getInitConditionForLhs, isValidCondition } from './AtomicCondition';
|
|
5
4
|
/** Component for building an atomic condition on a given field */
|
|
6
5
|
const FieldCondition = (props) => {
|
|
7
|
-
const { targetField, fields,
|
|
6
|
+
const { targetField, fields, condition: seedCondition, validComparators, validRhsTypes = new Set(['LITERAL', 'FIELD']), dateFunctions, handle } = props;
|
|
8
7
|
const [condition, setCondition] = useState(
|
|
9
8
|
// If editing use the seedCondition, otherwise, determine an initial condition based on the targetField
|
|
10
9
|
() => seedCondition ||
|
|
11
10
|
getInitConditionForLhs({ field: targetField }, fields, validRhsTypes, validComparators, dateFunctions));
|
|
12
11
|
const [showErrorIndicators, setErrorIndicators] = useState(false); // Used to enable inline error indicators on the controls
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
setErrorIndicators(false); // Reset any previous flag
|
|
12
|
+
const getCondition = () => {
|
|
13
|
+
setErrorIndicators(false);
|
|
16
14
|
if (isValidCondition(condition, fields, true)) {
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
setErrorIndicators(true); // Otherwise, indicate errors
|
|
15
|
+
return [true, condition];
|
|
21
16
|
}
|
|
17
|
+
setErrorIndicators(true);
|
|
18
|
+
return [false];
|
|
22
19
|
};
|
|
23
|
-
|
|
20
|
+
useImperativeHandle(handle, () => ({
|
|
21
|
+
getCondition
|
|
22
|
+
}), [getCondition]);
|
|
23
|
+
return (_jsx(AtomicCondition, { condition: condition, fields: fields, indicateErrors: showErrorIndicators, validComparators: validComparators, dateFunctions: dateFunctions, onChange: c => setCondition(c), itemDirection: 'column', validRhsTypes: validRhsTypes, showLhsAsLabel: true }));
|
|
24
24
|
};
|
|
25
25
|
export default FieldCondition;
|
|
26
26
|
//# sourceMappingURL=FieldCondition.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldCondition.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/FieldCondition.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAqB,
|
|
1
|
+
{"version":3,"file":"FieldCondition.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/FieldCondition.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAqB,mBAAmB,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAKzE,OAAO,eAAe,EAAE,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAG9F,kEAAkE;AAClE,MAAM,cAAc,GAA0D,CAC5E,KAA0B,EAC1B,EAAE;IACF,MAAM,EACJ,WAAW,EACX,MAAM,EACN,SAAS,EAAE,aAAa,EACxB,gBAAgB,EAChB,aAAa,GAAG,IAAI,GAAG,CAAU,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,EACtD,aAAa,EACb,MAAM,EACP,GAAG,KAAK,CAAC;IACV,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ;IACxC,uGAAuG;IACvG,GAAG,EAAE,CACH,aAAa;QACb,sBAAsB,CACpB,EAAE,KAAK,EAAE,WAAW,EAAE,EACtB,MAAM,EACN,aAAa,EACb,gBAAgB,EAChB,aAAa,CACd,CACJ,CAAC;IACF,MAAM,CAAC,mBAAmB,EAAE,kBAAkB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,yDAAyD;IAE5H,MAAM,YAAY,GAAgC,GAAG,EAAE;QACrD,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAE1B,IAAI,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;YAC7C,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;SAC1B;QAED,kBAAkB,CAAC,IAAI,CAAC,CAAC;QACzB,OAAO,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC,CAAC;IAEF,mBAAmB,CACjB,MAAM,EACN,GAAG,EAAE,CAAC,CAAC;QACL,YAAY;KACb,CAAC,EACF,CAAC,YAAY,CAAC,CACf,CAAC;IAEF,OAAO,CACL,KAAC,eAAe,IACd,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,mBAAmB,EACnC,gBAAgB,EAAE,gBAAgB,EAClC,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,EAC9B,aAAa,EAAC,QAAQ,EACtB,aAAa,EAAE,aAAa,EAC5B,cAAc,SACd,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["import { FunctionComponent, useImperativeHandle, useState } from 'react';\n\nimport { ForwardProps } from '@pega/cosmos-react-core';\n\nimport FieldConditionProps, { HandleValue } from './FieldCondition.types';\nimport AtomicCondition, { getInitConditionForLhs, isValidCondition } from './AtomicCondition';\nimport { RHSType } from './core/types';\n\n/** Component for building an atomic condition on a given field */\nconst FieldCondition: FunctionComponent<FieldConditionProps & ForwardProps> = (\n props: FieldConditionProps\n) => {\n const {\n targetField,\n fields,\n condition: seedCondition,\n validComparators,\n validRhsTypes = new Set<RHSType>(['LITERAL', 'FIELD']),\n dateFunctions,\n handle\n } = props;\n const [condition, setCondition] = useState(\n // If editing use the seedCondition, otherwise, determine an initial condition based on the targetField\n () =>\n seedCondition ||\n getInitConditionForLhs(\n { field: targetField },\n fields,\n validRhsTypes,\n validComparators,\n dateFunctions\n )\n );\n const [showErrorIndicators, setErrorIndicators] = useState(false); // Used to enable inline error indicators on the controls\n\n const getCondition: HandleValue['getCondition'] = () => {\n setErrorIndicators(false);\n\n if (isValidCondition(condition, fields, true)) {\n return [true, condition];\n }\n\n setErrorIndicators(true);\n return [false];\n };\n\n useImperativeHandle(\n handle,\n () => ({\n getCondition\n }),\n [getCondition]\n );\n\n return (\n <AtomicCondition\n condition={condition}\n fields={fields}\n indicateErrors={showErrorIndicators}\n validComparators={validComparators}\n dateFunctions={dateFunctions}\n onChange={c => setCondition(c)}\n itemDirection='column'\n validRhsTypes={validRhsTypes}\n showLhsAsLabel\n />\n );\n};\n\nexport default FieldCondition;\n"]}
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
+
import { Ref } from 'react';
|
|
1
2
|
import { BaseProps } from '@pega/cosmos-react-core';
|
|
2
3
|
import { ComparatorsByType, RHSType } from './core/types';
|
|
3
4
|
import { Field, LeafCondition, DateFunctionsByType } from './ConditionBuilder.types';
|
|
5
|
+
export interface HandleValue {
|
|
6
|
+
/**
|
|
7
|
+
* Returns condition validity and condition if valid.
|
|
8
|
+
*/
|
|
9
|
+
getCondition: () => [valid: false] | [valid: true, condition: LeafCondition];
|
|
10
|
+
}
|
|
4
11
|
/** Type definition for the input props of FieldCondition */
|
|
5
12
|
export default interface FieldConditionProps extends BaseProps {
|
|
6
13
|
/** Name of the field on which the condition should be constructed */
|
|
7
14
|
targetField: Field['name'];
|
|
8
15
|
/** Metadata (data-model) for the Fields to use in the RHS field-selector etc. */
|
|
9
16
|
fields: Field[];
|
|
10
|
-
/** Callback used from the component's `Submit` button */
|
|
11
|
-
onSubmit: (condition: LeafCondition) => void;
|
|
12
17
|
/** (Optional) Passed when editing an existing condition */
|
|
13
18
|
condition?: LeafCondition;
|
|
14
19
|
/** (Optional) Used to limit the Comparators allowed in the component. */
|
|
@@ -21,5 +26,7 @@ export default interface FieldConditionProps extends BaseProps {
|
|
|
21
26
|
validRhsTypes?: Set<RHSType>;
|
|
22
27
|
/** (Optional) When enabling 'DATE_FUNCTION's via `validRhsTypes`, pass this to specify which all date functions are applicable per field type */
|
|
23
28
|
dateFunctions?: DateFunctionsByType;
|
|
29
|
+
/** Imperative handle for the component. */
|
|
30
|
+
handle?: Ref<HandleValue>;
|
|
24
31
|
}
|
|
25
32
|
//# sourceMappingURL=FieldCondition.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldCondition.types.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/FieldCondition.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAErF,4DAA4D;AAC5D,MAAM,CAAC,OAAO,WAAW,mBAAoB,SAAQ,SAAS;IAC5D,qEAAqE;IACrE,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAE3B,iFAAiF;IACjF,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB,
|
|
1
|
+
{"version":3,"file":"FieldCondition.types.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/FieldCondition.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAErF,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;CAC9E;AAED,4DAA4D;AAC5D,MAAM,CAAC,OAAO,WAAW,mBAAoB,SAAQ,SAAS;IAC5D,qEAAqE;IACrE,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAE3B,iFAAiF;IACjF,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,aAAa,CAAC;IAE1B,yEAAyE;IACzE,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,2CAA2C;IAC3C,MAAM,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;CAC3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldCondition.types.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/FieldCondition.types.ts"],"names":[],"mappings":"","sourcesContent":["import { BaseProps } from '@pega/cosmos-react-core';\n\nimport { ComparatorsByType, RHSType } from './core/types';\nimport { Field, LeafCondition, DateFunctionsByType } from './ConditionBuilder.types';\n\n/** Type definition for the input props of FieldCondition */\nexport default interface FieldConditionProps extends BaseProps {\n /** Name of the field on which the condition should be constructed */\n targetField: Field['name'];\n\n /** Metadata (data-model) for the Fields to use in the RHS field-selector etc. */\n fields: Field[];\n\n /**
|
|
1
|
+
{"version":3,"file":"FieldCondition.types.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/FieldCondition.types.ts"],"names":[],"mappings":"","sourcesContent":["import { Ref } from 'react';\n\nimport { BaseProps } from '@pega/cosmos-react-core';\n\nimport { ComparatorsByType, RHSType } from './core/types';\nimport { Field, LeafCondition, DateFunctionsByType } from './ConditionBuilder.types';\n\nexport interface HandleValue {\n /**\n * Returns condition validity and condition if valid.\n */\n getCondition: () => [valid: false] | [valid: true, condition: LeafCondition];\n}\n\n/** Type definition for the input props of FieldCondition */\nexport default interface FieldConditionProps extends BaseProps {\n /** Name of the field on which the condition should be constructed */\n targetField: Field['name'];\n\n /** Metadata (data-model) for the Fields to use in the RHS field-selector etc. */\n fields: Field[];\n\n /** (Optional) Passed when editing an existing condition */\n condition?: LeafCondition;\n\n /** (Optional) Used to limit the Comparators allowed in the component. */\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 /** Imperative handle for the component. */\n handle?: Ref<HandleValue>;\n}\n"]}
|
|
@@ -99,8 +99,8 @@ function formatLeafCondition(leaf, fields, translate, { locale = 'en-US' } = {})
|
|
|
99
99
|
break;
|
|
100
100
|
case 'NUMBER':
|
|
101
101
|
rhsText = getFormattedValue(rhs.value.toString(), locale, undefined, {
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
useGrouping: true,
|
|
103
|
+
maximumFractionDigits: 4
|
|
104
104
|
});
|
|
105
105
|
break;
|
|
106
106
|
default:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/formatter.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,mEAAmE;AACnE,OAAO,EAAE,OAAO,EAAm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AY,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,mBAAmB,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;QAC1F,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;KACzC;IAED,IAAI,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE;QACxB,MAAM,WAAW,GAAG,mBAAmB,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QAC9E,IAAI,WAAW,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YAClE,8DAA8D;YAC9D,OAAO,OAAO,WAAW,EAAE,CAAC;SAC7B;QACD,OAAO,QAAQ,WAAW,GAAG,CAAC;KAC/B;IAED,OAAO,mBAAmB,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,2BAA2B;AACrG,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,SAAoB,EACpB,MAAe,EACf,SAA+C,EAC/C,OAAgC;IAEhC,yDAAyD;IACzD,IAAI,IAAI,GAAG,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IAEtE,2EAA2E;IAC3E,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QACpD,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;KAC1B;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["// cSpell:words LPAREN RPAREN\n// FIXME: TR (Several constructs in this file need to be localized)\nimport { hasProp, TranslationPack } from '@pega/cosmos-react-core';\nimport { getFormattedValue } from '@pega/cosmos-react-core/lib/components/Number/utils';\nimport { TranslationFunction } from '@pega/cosmos-react-core/lib/i18n/translate';\nimport { getQuarter } from '@pega/cosmos-react-core/lib/components/DateTime/Input/utils';\n\nimport { Condition, LeafCondition, Field } from '../ConditionBuilder.types';\n\nimport { DatePart, TimePeriod } from './types';\nimport { convertMsToTimeValue } from './time-utils';\n\nconst LPAREN = '(';\nconst RPAREN = ')';\n\n/** Options object optionally passed to formatCondition method. */\ninterface ConditionFormatOptions {\n locale?: string;\n}\n\nexport function formatRelativeDate(\n translate: TranslationFunction<TranslationPack>,\n timePeriod: TimePeriod,\n datePart: DatePart,\n interval?: number\n): string {\n const translationKey =\n timePeriod === 'CURRENT'\n ? `condition_builder_current_${datePart.toLowerCase().slice(0, -1)}`\n : `condition_builder_${timePeriod.toLowerCase()}_X_${datePart.toLowerCase()}`;\n return translate(translationKey as keyof TranslationPack, [interval ?? 0], {\n count: interval ?? 0\n });\n}\n\n/** Returns a user-friendly text representation of a given leaf condition */\nfunction formatLeafCondition(\n leaf: LeafCondition,\n fields: Field[],\n translate: TranslationFunction<TranslationPack>,\n { locale = 'en-US' }: ConditionFormatOptions = {}\n): string {\n const { lhs, comparator, rhs } = leaf;\n\n // Determine texts for LHS and RHS\n const lhsField = fields.find(f => f.name === lhs.field) as Field; // Expecting valid inputs\n const lhsText = lhsField.label || lhsField.name; // label is optional\n let rhsText = '';\n if (rhs) {\n if (hasProp(rhs, 'field')) {\n // If RHS is another field\n const rhsField = fields.find(f => f.name === rhs.field) as Field; // Expecting valid inputs\n rhsText = rhsField.label || rhsField.name; // label is optional\n } else if (hasProp(rhs, 'value')) {\n if (hasProp(rhs, 'dateFunction')) {\n // If RHS is a date function value\n switch (rhs.dateFunction) {\n case 'YEARS':\n rhsText = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric'\n });\n break;\n case 'QUARTERS': {\n const formattedYear = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric'\n });\n const quarterNumber = getQuarter(rhs.value);\n rhsText = `${translate(`date_quarter_q${quarterNumber}`, [formattedYear])}`;\n break;\n }\n case 'MONTHS':\n rhsText = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric',\n month: 'short'\n });\n break;\n case 'WEEKS':\n rhsText = `Week of ${new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric',\n month: 'short',\n day: 'numeric'\n })}`;\n break;\n case 'DAYS':\n rhsText = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric',\n month: 'short',\n day: 'numeric'\n });\n break;\n case 'HOURS':\n rhsText = new Date(rhs.value).toLocaleString(locale, {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n hour: 'numeric',\n hour12: true\n });\n break;\n case 'MONTHS_OF_YEAR':\n rhsText = new Date(2021, (rhs.value as number) - 1, 1).toLocaleString(locale, {\n month: 'long'\n });\n break;\n case 'DAYS_OF_MONTH':\n rhsText = `Day ${rhs.value} of month`;\n break;\n case 'DAYS_OF_WEEK':\n // Choosing Feb-2021 as it starts on a Monday\n rhsText = new Date(2021, 1, rhs.value as number).toLocaleString(locale, {\n weekday: 'long'\n });\n break;\n default: // Not needed\n }\n } else {\n // If RHS is a single literal value\n switch (lhsField.type) {\n case 'TIME_ONLY':\n // For these cases, rhs.value is stored as # of milliseconds since day-start\n rhsText = convertMsToTimeValue(rhs.value as number);\n break;\n case 'NUMBER':\n rhsText = getFormattedValue(rhs.value.toString(), locale, undefined, {\n showGroupSeparators: true,\n numberOfDecimals: 4\n });\n break;\n default:\n rhsText = rhs.value as string;\n }\n }\n } else if (hasProp(rhs, 'relativeDate')) {\n const {\n relativeDate: { timePeriod, interval, datePart }\n } = rhs;\n rhsText = formatRelativeDate(translate, timePeriod, datePart, interval);\n } else {\n rhsText = rhs.values.join(', '); // If RHS is a list of values\n }\n }\n\n switch (comparator) {\n case 'IS_NULL':\n return `${lhsText} is null`;\n case 'IS_NOT_NULL':\n return `${lhsText} is not null`;\n case 'IS_TRUE':\n return `${lhsText} is true`;\n case 'IS_FALSE':\n return `${lhsText} is false`;\n case 'EQ':\n return `${lhsText} is ${rhsText}`;\n case 'NEQ':\n return `${lhsText} isn't ${rhsText}`;\n case 'IN':\n return `${lhsText} is among ${rhsText}`;\n case 'NOT_IN':\n return `${lhsText} is not among ${rhsText}`;\n case 'GT':\n return `${lhsText} > ${rhsText}`;\n case 'GTE':\n return `${lhsText} >= ${rhsText}`;\n case 'LT':\n return `${lhsText} < ${rhsText}`;\n case 'LTE':\n return `${lhsText} <= ${rhsText}`;\n case 'STARTS_WITH':\n return `${lhsText} starts with ${rhsText}`;\n case 'NOT_STARTS_WITH':\n return `${lhsText} doesn't start with ${rhsText}`;\n case 'ENDS_WITH':\n return `${lhsText} ends with ${rhsText}`;\n case 'NOT_ENDS_WITH':\n return `${lhsText} doesn't end with ${rhsText}`;\n case 'CONTAINS':\n return `${lhsText} contains ${rhsText}`;\n case 'NOT_CONTAINS':\n return `${lhsText} doesn't contain ${rhsText}`;\n default:\n return ''; // Not needed\n }\n}\n\n/** Returns a user-friendly text representation of the given node in a condition */\nfunction formatConditionNode(\n node: Condition,\n fields: Field[],\n translate: TranslationFunction<TranslationPack>,\n options?: ConditionFormatOptions\n): string {\n if (hasProp(node, 'AND')) {\n const childStrings = node.AND.map(n => formatConditionNode(n, fields, translate, options));\n return `(${childStrings.join(' AND ')})`;\n }\n\n if (hasProp(node, 'OR')) {\n const childStrings = node.OR.map(n => formatConditionNode(n, fields, translate, options));\n return `(${childStrings.join(' OR ')})`;\n }\n\n if (hasProp(node, 'NOT')) {\n const childString = formatConditionNode(node.NOT, fields, translate, options);\n if (childString.startsWith(LPAREN) && childString.endsWith(RPAREN)) {\n // Avoid double brackets when the child node is an AND/OR node\n return `NOT ${childString}`;\n }\n return `NOT (${childString})`;\n }\n\n return formatLeafCondition(node.condition, fields, translate, options); // If leaf-level is reached\n}\n\n/**\n * Returns a user-friendly text representation of a given complex condition\n * The input `fields` are used to look up display labels for the fields\n */\nexport default function formatCondition(\n condition: Condition,\n fields: Field[],\n translate: TranslationFunction<TranslationPack>,\n options?: ConditionFormatOptions\n): string {\n // Recursively format the tree, starting at the root node\n let text = formatConditionNode(condition, fields, translate, options);\n\n // If the root node is AND/OR, there will be extra parentheses. Remove them\n if (text.startsWith(LPAREN) && text.endsWith(RPAREN)) {\n text = text.slice(1, -1);\n }\n\n return text;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/formatter.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,mEAAmE;AACnE,OAAO,EAAE,OAAO,EAAmB,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qDAAqD,CAAC;AAExF,OAAO,EAAE,UAAU,EAAE,MAAM,6DAA6D,CAAC;AAKzF,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD,MAAM,MAAM,GAAG,GAAG,CAAC;AACnB,MAAM,MAAM,GAAG,GAAG,CAAC;AAOnB,MAAM,UAAU,kBAAkB,CAChC,SAA+C,EAC/C,UAAsB,EACtB,QAAkB,EAClB,QAAiB;IAEjB,MAAM,cAAc,GAClB,UAAU,KAAK,SAAS;QACtB,CAAC,CAAC,6BAA6B,QAAQ,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;QACpE,CAAC,CAAC,qBAAqB,UAAU,CAAC,WAAW,EAAE,MAAM,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC;IAClF,OAAO,SAAS,CAAC,cAAuC,EAAE,CAAC,QAAQ,IAAI,CAAC,CAAC,EAAE;QACzE,KAAK,EAAE,QAAQ,IAAI,CAAC;KACrB,CAAC,CAAC;AACL,CAAC;AAED,4EAA4E;AAC5E,SAAS,mBAAmB,CAC1B,IAAmB,EACnB,MAAe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EAC/C,OAAgC;IAEhC,yDAAyD;IACzD,IAAI,IAAI,GAAG,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IAEtE,2EAA2E;IAC3E,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QACpD,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;KAC1B;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["// cSpell:words LPAREN RPAREN\n// FIXME: TR (Several constructs in this file need to be localized)\nimport { hasProp, TranslationPack } from '@pega/cosmos-react-core';\nimport { getFormattedValue } from '@pega/cosmos-react-core/lib/components/Number/utils';\nimport { TranslationFunction } from '@pega/cosmos-react-core/lib/i18n/translate';\nimport { getQuarter } from '@pega/cosmos-react-core/lib/components/DateTime/Input/utils';\n\nimport { Condition, LeafCondition, Field } from '../ConditionBuilder.types';\n\nimport { DatePart, TimePeriod } from './types';\nimport { convertMsToTimeValue } from './time-utils';\n\nconst LPAREN = '(';\nconst RPAREN = ')';\n\n/** Options object optionally passed to formatCondition method. */\ninterface ConditionFormatOptions {\n locale?: string;\n}\n\nexport function formatRelativeDate(\n translate: TranslationFunction<TranslationPack>,\n timePeriod: TimePeriod,\n datePart: DatePart,\n interval?: number\n): string {\n const translationKey =\n timePeriod === 'CURRENT'\n ? `condition_builder_current_${datePart.toLowerCase().slice(0, -1)}`\n : `condition_builder_${timePeriod.toLowerCase()}_X_${datePart.toLowerCase()}`;\n return translate(translationKey as keyof TranslationPack, [interval ?? 0], {\n count: interval ?? 0\n });\n}\n\n/** Returns a user-friendly text representation of a given leaf condition */\nfunction formatLeafCondition(\n leaf: LeafCondition,\n fields: Field[],\n translate: TranslationFunction<TranslationPack>,\n { locale = 'en-US' }: ConditionFormatOptions = {}\n): string {\n const { lhs, comparator, rhs } = leaf;\n\n // Determine texts for LHS and RHS\n const lhsField = fields.find(f => f.name === lhs.field) as Field; // Expecting valid inputs\n const lhsText = lhsField.label || lhsField.name; // label is optional\n let rhsText = '';\n if (rhs) {\n if (hasProp(rhs, 'field')) {\n // If RHS is another field\n const rhsField = fields.find(f => f.name === rhs.field) as Field; // Expecting valid inputs\n rhsText = rhsField.label || rhsField.name; // label is optional\n } else if (hasProp(rhs, 'value')) {\n if (hasProp(rhs, 'dateFunction')) {\n // If RHS is a date function value\n switch (rhs.dateFunction) {\n case 'YEARS':\n rhsText = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric'\n });\n break;\n case 'QUARTERS': {\n const formattedYear = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric'\n });\n const quarterNumber = getQuarter(rhs.value);\n rhsText = `${translate(`date_quarter_q${quarterNumber}`, [formattedYear])}`;\n break;\n }\n case 'MONTHS':\n rhsText = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric',\n month: 'short'\n });\n break;\n case 'WEEKS':\n rhsText = `Week of ${new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric',\n month: 'short',\n day: 'numeric'\n })}`;\n break;\n case 'DAYS':\n rhsText = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric',\n month: 'short',\n day: 'numeric'\n });\n break;\n case 'HOURS':\n rhsText = new Date(rhs.value).toLocaleString(locale, {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n hour: 'numeric',\n hour12: true\n });\n break;\n case 'MONTHS_OF_YEAR':\n rhsText = new Date(2021, (rhs.value as number) - 1, 1).toLocaleString(locale, {\n month: 'long'\n });\n break;\n case 'DAYS_OF_MONTH':\n rhsText = `Day ${rhs.value} of month`;\n break;\n case 'DAYS_OF_WEEK':\n // Choosing Feb-2021 as it starts on a Monday\n rhsText = new Date(2021, 1, rhs.value as number).toLocaleString(locale, {\n weekday: 'long'\n });\n break;\n default: // Not needed\n }\n } else {\n // If RHS is a single literal value\n switch (lhsField.type) {\n case 'TIME_ONLY':\n // For these cases, rhs.value is stored as # of milliseconds since day-start\n rhsText = convertMsToTimeValue(rhs.value as number);\n break;\n case 'NUMBER':\n rhsText = getFormattedValue(rhs.value.toString(), locale, undefined, {\n useGrouping: true,\n maximumFractionDigits: 4\n });\n break;\n default:\n rhsText = rhs.value as string;\n }\n }\n } else if (hasProp(rhs, 'relativeDate')) {\n const {\n relativeDate: { timePeriod, interval, datePart }\n } = rhs;\n rhsText = formatRelativeDate(translate, timePeriod, datePart, interval);\n } else {\n rhsText = rhs.values.join(', '); // If RHS is a list of values\n }\n }\n\n switch (comparator) {\n case 'IS_NULL':\n return `${lhsText} is null`;\n case 'IS_NOT_NULL':\n return `${lhsText} is not null`;\n case 'IS_TRUE':\n return `${lhsText} is true`;\n case 'IS_FALSE':\n return `${lhsText} is false`;\n case 'EQ':\n return `${lhsText} is ${rhsText}`;\n case 'NEQ':\n return `${lhsText} isn't ${rhsText}`;\n case 'IN':\n return `${lhsText} is among ${rhsText}`;\n case 'NOT_IN':\n return `${lhsText} is not among ${rhsText}`;\n case 'GT':\n return `${lhsText} > ${rhsText}`;\n case 'GTE':\n return `${lhsText} >= ${rhsText}`;\n case 'LT':\n return `${lhsText} < ${rhsText}`;\n case 'LTE':\n return `${lhsText} <= ${rhsText}`;\n case 'STARTS_WITH':\n return `${lhsText} starts with ${rhsText}`;\n case 'NOT_STARTS_WITH':\n return `${lhsText} doesn't start with ${rhsText}`;\n case 'ENDS_WITH':\n return `${lhsText} ends with ${rhsText}`;\n case 'NOT_ENDS_WITH':\n return `${lhsText} doesn't end with ${rhsText}`;\n case 'CONTAINS':\n return `${lhsText} contains ${rhsText}`;\n case 'NOT_CONTAINS':\n return `${lhsText} doesn't contain ${rhsText}`;\n default:\n return ''; // Not needed\n }\n}\n\n/** Returns a user-friendly text representation of the given node in a condition */\nfunction formatConditionNode(\n node: Condition,\n fields: Field[],\n translate: TranslationFunction<TranslationPack>,\n options?: ConditionFormatOptions\n): string {\n if (hasProp(node, 'AND')) {\n const childStrings = node.AND.map(n => formatConditionNode(n, fields, translate, options));\n return `(${childStrings.join(' AND ')})`;\n }\n\n if (hasProp(node, 'OR')) {\n const childStrings = node.OR.map(n => formatConditionNode(n, fields, translate, options));\n return `(${childStrings.join(' OR ')})`;\n }\n\n if (hasProp(node, 'NOT')) {\n const childString = formatConditionNode(node.NOT, fields, translate, options);\n if (childString.startsWith(LPAREN) && childString.endsWith(RPAREN)) {\n // Avoid double brackets when the child node is an AND/OR node\n return `NOT ${childString}`;\n }\n return `NOT (${childString})`;\n }\n\n return formatLeafCondition(node.condition, fields, translate, options); // If leaf-level is reached\n}\n\n/**\n * Returns a user-friendly text representation of a given complex condition\n * The input `fields` are used to look up display labels for the fields\n */\nexport default function formatCondition(\n condition: Condition,\n fields: Field[],\n translate: TranslationFunction<TranslationPack>,\n options?: ConditionFormatOptions\n): string {\n // Recursively format the tree, starting at the root node\n let text = formatConditionNode(condition, fields, translate, options);\n\n // If the root node is AND/OR, there will be extra parentheses. Remove them\n if (text.startsWith(LPAREN) && text.endsWith(RPAREN)) {\n text = text.slice(1, -1);\n }\n\n return text;\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FunctionComponent } from 'react';
|
|
2
|
+
import { ForwardProps } from '@pega/cosmos-react-core';
|
|
3
|
+
import { ConditionInputProps } from './ConditionInput.types';
|
|
4
|
+
declare const ConditionInput: FunctionComponent<ConditionInputProps & ForwardProps>;
|
|
5
|
+
export default ConditionInput;
|
|
6
|
+
//# sourceMappingURL=ConditionInput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConditionInput.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionInput/ConditionInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAKlB,MAAM,OAAO,CAAC;AAGf,OAAO,EAIL,YAAY,EAQb,MAAM,yBAAyB,CAAC;AAUjC,OAAO,EAAsB,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAkCjF,QAAA,MAAM,cAAc,EAAE,iBAAiB,CAAC,mBAAmB,GAAG,YAAY,CA6KzE,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useState, useEffect } from 'react';
|
|
3
|
+
import styled from 'styled-components';
|
|
4
|
+
import { CompositeInput, defaultThemeProp, hasProp, Input, NumberInput, RadioButton, RadioButtonGroup, StyledGrid, useI18n } from '@pega/cosmos-react-core';
|
|
5
|
+
import AtomicCondition, { getInitConditionForLhs } from '../ConditionBuilder/AtomicCondition';
|
|
6
|
+
import formatCondition from '../ConditionBuilder/core/formatter';
|
|
7
|
+
const defaultComparators = {
|
|
8
|
+
TEXT: 'CONTAINS',
|
|
9
|
+
EMAIL: 'CONTAINS',
|
|
10
|
+
URL: 'CONTAINS',
|
|
11
|
+
PHONE: 'CONTAINS',
|
|
12
|
+
INTEGER: 'EQ',
|
|
13
|
+
DECIMAL: 'EQ',
|
|
14
|
+
PERCENTAGE: 'EQ',
|
|
15
|
+
CURRENCY: 'EQ',
|
|
16
|
+
BOOLEAN: 'IS_TRUE'
|
|
17
|
+
};
|
|
18
|
+
const basicFieldMap = {
|
|
19
|
+
EMAIL: 'TEXT',
|
|
20
|
+
URL: 'TEXT',
|
|
21
|
+
PHONE: 'TEXT',
|
|
22
|
+
INTEGER: 'NUMBER',
|
|
23
|
+
DECIMAL: 'NUMBER',
|
|
24
|
+
PERCENTAGE: 'NUMBER',
|
|
25
|
+
CURRENCY: 'NUMBER',
|
|
26
|
+
TEXT: 'TEXT',
|
|
27
|
+
BOOLEAN: 'BOOLEAN'
|
|
28
|
+
};
|
|
29
|
+
const StyledConditionRadioGroup = styled(RadioButtonGroup) `
|
|
30
|
+
${StyledGrid} {
|
|
31
|
+
display: inline-flex;
|
|
32
|
+
} ;
|
|
33
|
+
`;
|
|
34
|
+
StyledConditionRadioGroup.defaultProps = defaultThemeProp;
|
|
35
|
+
const ConditionInput = forwardRef(({ fieldName, fieldType, condition: conditionProp, fieldLabel, mode, onChange }, ref) => {
|
|
36
|
+
const t = useI18n();
|
|
37
|
+
const basicType = basicFieldMap[fieldType] ?? fieldType;
|
|
38
|
+
const fields = [
|
|
39
|
+
{ name: fieldName, type: basicType, label: fieldLabel }
|
|
40
|
+
];
|
|
41
|
+
const condition = conditionProp ??
|
|
42
|
+
(fieldType === 'BOOLEAN'
|
|
43
|
+
? undefined
|
|
44
|
+
: getInitConditionForLhs({ field: fieldName }, fields, new Set(['LITERAL'])));
|
|
45
|
+
const onRadioButtonChange = (value) => {
|
|
46
|
+
const updatedCondition = value === undefined
|
|
47
|
+
? undefined
|
|
48
|
+
: {
|
|
49
|
+
lhs: { field: fieldName },
|
|
50
|
+
comparator: value ? 'IS_TRUE' : 'IS_FALSE'
|
|
51
|
+
};
|
|
52
|
+
onChange(updatedCondition);
|
|
53
|
+
};
|
|
54
|
+
const createConditionForDefaultMode = (value) => {
|
|
55
|
+
return {
|
|
56
|
+
lhs: { field: fieldName },
|
|
57
|
+
comparator: defaultComparators[fieldType],
|
|
58
|
+
rhs: { value: basicType === 'NUMBER' ? Number(value) : value }
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
const rhsValue = condition?.rhs && hasProp(condition.rhs, 'value')
|
|
62
|
+
? condition.rhs.value.toString()
|
|
63
|
+
: undefined;
|
|
64
|
+
const [inputValue, setInputValue] = useState(rhsValue);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
setInputValue(rhsValue);
|
|
67
|
+
}, [conditionProp]);
|
|
68
|
+
const showAdvanced = mode === 'advanced' && fieldType !== 'BOOLEAN';
|
|
69
|
+
let defaultControl = null;
|
|
70
|
+
if (!showAdvanced) {
|
|
71
|
+
switch (fieldType) {
|
|
72
|
+
case 'INTEGER':
|
|
73
|
+
case 'DECIMAL':
|
|
74
|
+
case 'PERCENTAGE':
|
|
75
|
+
case 'CURRENCY':
|
|
76
|
+
defaultControl = (_jsx(NumberInput, { label: fieldLabel, ref: ref, value: inputValue, onChange: setInputValue, onBlur: value => {
|
|
77
|
+
onChange(createConditionForDefaultMode(value));
|
|
78
|
+
}, numberOfDecimals: fieldType === 'INTEGER' ? 0 : undefined }));
|
|
79
|
+
break;
|
|
80
|
+
case 'BOOLEAN':
|
|
81
|
+
defaultControl = (_jsxs(StyledConditionRadioGroup, { ref: ref, label: fieldLabel, name: fieldName, inline: true, children: [_jsx(RadioButton, { label: t('show_all'), checked: condition === undefined, onChange: () => onRadioButtonChange() }), _jsx(RadioButton, { label: t('boolean_display_true_label'), checked: condition?.comparator === 'IS_TRUE', onChange: () => onRadioButtonChange(true) }), _jsx(RadioButton, { label: t('boolean_display_false_label'), checked: condition?.comparator === 'IS_FALSE', onChange: () => onRadioButtonChange(false) })] }));
|
|
82
|
+
break;
|
|
83
|
+
case 'TEXT':
|
|
84
|
+
case 'EMAIL':
|
|
85
|
+
case 'URL':
|
|
86
|
+
case 'PHONE':
|
|
87
|
+
default:
|
|
88
|
+
defaultControl = (_jsx(Input, { label: fieldLabel, ref: ref, value: inputValue, onChange: (e) => setInputValue(e.target.value), onBlur: (e) => onChange(createConditionForDefaultMode(e.target.value)) }));
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const [newCondition, setNewCondition] = useState(condition);
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
setNewCondition(condition);
|
|
95
|
+
}, [conditionProp]);
|
|
96
|
+
const dialog = {
|
|
97
|
+
renderer: AtomicCondition,
|
|
98
|
+
rendererProps: {
|
|
99
|
+
condition: newCondition ??
|
|
100
|
+
getInitConditionForLhs({ field: fieldName }, fields, new Set(['LITERAL'])),
|
|
101
|
+
fields,
|
|
102
|
+
onChange: setNewCondition,
|
|
103
|
+
itemDirection: 'column',
|
|
104
|
+
showLhsAsLabel: true,
|
|
105
|
+
validRhsTypes: new Set(['LITERAL']),
|
|
106
|
+
indicateErrors: false
|
|
107
|
+
},
|
|
108
|
+
onCancel: ({ close }) => {
|
|
109
|
+
setNewCondition(condition);
|
|
110
|
+
close();
|
|
111
|
+
},
|
|
112
|
+
onApply: ({ close }) => {
|
|
113
|
+
onChange(newCondition);
|
|
114
|
+
close();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const onClear = () => {
|
|
118
|
+
onChange(undefined);
|
|
119
|
+
setNewCondition(condition);
|
|
120
|
+
};
|
|
121
|
+
return (_jsx(_Fragment, { children: showAdvanced ? (_jsx(CompositeInput, { dialog: dialog, label: fieldLabel, onClear: onClear, value: conditionProp ? formatCondition({ condition: conditionProp }, fields, t) : undefined, placeholder: t('all'), ref: ref })) : (defaultControl) }));
|
|
122
|
+
});
|
|
123
|
+
export default ConditionInput;
|
|
124
|
+
//# sourceMappingURL=ConditionInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConditionInput.js","sourceRoot":"","sources":["../../../src/components/ConditionInput/ConditionInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAGV,QAAQ,EAER,SAAS,EACV,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EACL,cAAc,EAEd,gBAAgB,EAEhB,OAAO,EACP,KAAK,EACL,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,OAAO,EACR,MAAM,yBAAyB,CAAC;AAGjC,OAAO,eAAe,EAAE,EAEtB,sBAAsB,EACvB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,eAAe,MAAM,oCAAoC,CAAC;AAKjE,MAAM,kBAAkB,GAA2C;IACjE,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE,UAAU;IACjB,GAAG,EAAE,UAAU;IACf,KAAK,EAAE,UAAU;IACjB,OAAO,EAAE,IAAI;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AAc,IACb,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,OAAO,EAChB,KAAK,EACH,aAAa,CAAC,CAAC,CAAC,eAAe,CAAC,EAAE,SAAS,EAAE,aAAa,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,EAEtF,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,EACrB,GAAG,EAAE,GAAG,GACR,CACH,CAAC,CAAC,CAAC,CACF,cAAc,CACf,GACA,CACJ,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n PropsWithoutRef,\n useState,\n ChangeEvent,\n useEffect\n} from 'react';\nimport styled from 'styled-components';\n\nimport {\n CompositeInput,\n CompositeInputProps,\n defaultThemeProp,\n ForwardProps,\n hasProp,\n Input,\n NumberInput,\n RadioButton,\n RadioButtonGroup,\n StyledGrid,\n useI18n\n} from '@pega/cosmos-react-core';\n\nimport type { Comparator, FieldType } from '../ConditionBuilder/core/types';\nimport AtomicCondition, {\n AtomicConditionProps,\n getInitConditionForLhs\n} from '../ConditionBuilder/AtomicCondition';\nimport formatCondition from '../ConditionBuilder/core/formatter';\nimport type { LeafCondition } from '../ConditionBuilder/ConditionBuilder.types';\n\nimport { ConditionFieldType, ConditionInputProps } from './ConditionInput.types';\n\nconst defaultComparators: Record<ConditionFieldType, Comparator> = {\n TEXT: 'CONTAINS',\n EMAIL: 'CONTAINS',\n URL: 'CONTAINS',\n PHONE: 'CONTAINS',\n INTEGER: 'EQ',\n DECIMAL: 'EQ',\n PERCENTAGE: 'EQ',\n CURRENCY: 'EQ',\n BOOLEAN: 'IS_TRUE'\n} as const;\n\nconst basicFieldMap: Record<ConditionFieldType, FieldType> = {\n EMAIL: 'TEXT',\n URL: 'TEXT',\n PHONE: 'TEXT',\n INTEGER: 'NUMBER',\n DECIMAL: 'NUMBER',\n PERCENTAGE: 'NUMBER',\n CURRENCY: 'NUMBER',\n TEXT: 'TEXT',\n BOOLEAN: 'BOOLEAN'\n} as const;\n\nconst StyledConditionRadioGroup = styled(RadioButtonGroup)`\n ${StyledGrid} {\n display: inline-flex;\n } ;\n`;\n\nStyledConditionRadioGroup.defaultProps = defaultThemeProp;\n\nconst ConditionInput: FunctionComponent<ConditionInputProps & ForwardProps> = forwardRef(\n (\n {\n fieldName,\n fieldType,\n condition: conditionProp,\n fieldLabel,\n mode,\n onChange\n }: PropsWithoutRef<ConditionInputProps>,\n ref: ConditionInputProps['ref']\n ) => {\n const t = useI18n();\n\n const basicType = basicFieldMap[fieldType] ?? fieldType;\n\n const fields: AtomicConditionProps['fields'] = [\n { name: fieldName, type: basicType, label: fieldLabel }\n ];\n\n const condition =\n conditionProp ??\n (fieldType === 'BOOLEAN'\n ? undefined\n : getInitConditionForLhs({ field: fieldName }, fields, new Set(['LITERAL'])));\n\n const onRadioButtonChange = (value?: boolean) => {\n const updatedCondition: LeafCondition | undefined =\n value === undefined\n ? undefined\n : {\n lhs: { field: fieldName },\n comparator: value ? 'IS_TRUE' : 'IS_FALSE'\n };\n onChange(updatedCondition);\n };\n\n const createConditionForDefaultMode = (value: string) => {\n return {\n lhs: { field: fieldName },\n comparator: defaultComparators[fieldType],\n rhs: { value: basicType === 'NUMBER' ? Number(value) : value }\n };\n };\n\n const rhsValue =\n condition?.rhs && hasProp(condition.rhs, 'value')\n ? condition.rhs.value.toString()\n : undefined;\n\n const [inputValue, setInputValue] = useState(rhsValue);\n\n useEffect(() => {\n setInputValue(rhsValue);\n }, [conditionProp]);\n\n const showAdvanced = mode === 'advanced' && fieldType !== 'BOOLEAN';\n\n let defaultControl: JSX.Element | null = null;\n\n if (!showAdvanced) {\n switch (fieldType) {\n case 'INTEGER':\n case 'DECIMAL':\n case 'PERCENTAGE':\n case 'CURRENCY':\n defaultControl = (\n <NumberInput\n label={fieldLabel}\n ref={ref}\n value={inputValue}\n onChange={setInputValue}\n onBlur={value => {\n onChange(createConditionForDefaultMode(value));\n }}\n numberOfDecimals={fieldType === 'INTEGER' ? 0 : undefined}\n />\n );\n break;\n case 'BOOLEAN':\n defaultControl = (\n <StyledConditionRadioGroup ref={ref} label={fieldLabel} name={fieldName} inline>\n <RadioButton\n label={t('show_all')}\n checked={condition === undefined}\n onChange={() => onRadioButtonChange()}\n />\n <RadioButton\n label={t('boolean_display_true_label')}\n checked={condition?.comparator === 'IS_TRUE'}\n onChange={() => onRadioButtonChange(true)}\n />\n <RadioButton\n label={t('boolean_display_false_label')}\n checked={condition?.comparator === 'IS_FALSE'}\n onChange={() => onRadioButtonChange(false)}\n />\n </StyledConditionRadioGroup>\n );\n break;\n case 'TEXT':\n case 'EMAIL':\n case 'URL':\n case 'PHONE':\n default:\n defaultControl = (\n <Input\n label={fieldLabel}\n ref={ref}\n value={inputValue}\n onChange={(e: ChangeEvent<HTMLInputElement>) => setInputValue(e.target.value)}\n onBlur={(e: ChangeEvent<HTMLInputElement>) =>\n onChange(createConditionForDefaultMode(e.target.value))\n }\n />\n );\n break;\n }\n }\n\n const [newCondition, setNewCondition] = useState<LeafCondition | undefined>(condition);\n\n useEffect(() => {\n setNewCondition(condition);\n }, [conditionProp]);\n\n const dialog: CompositeInputProps<AtomicConditionProps & ForwardProps>['dialog'] = {\n renderer: AtomicCondition,\n rendererProps: {\n condition:\n newCondition ??\n getInitConditionForLhs({ field: fieldName }, fields, new Set(['LITERAL'])),\n fields,\n onChange: setNewCondition,\n itemDirection: 'column',\n showLhsAsLabel: true,\n validRhsTypes: new Set(['LITERAL']),\n indicateErrors: false\n },\n onCancel: ({ close }) => {\n setNewCondition(condition);\n close();\n },\n onApply: ({ close }) => {\n onChange(newCondition);\n close();\n }\n };\n\n const onClear = () => {\n onChange(undefined);\n setNewCondition(condition);\n };\n\n return (\n <>\n {showAdvanced ? (\n <CompositeInput\n dialog={dialog}\n label={fieldLabel}\n onClear={onClear}\n value={\n conditionProp ? formatCondition({ condition: conditionProp }, fields, t) : undefined\n }\n placeholder={t('all')}\n ref={ref}\n />\n ) : (\n defaultControl\n )}\n </>\n );\n }\n);\n\nexport default ConditionInput;\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Ref } from 'react';
|
|
2
|
+
import { LeafCondition } from '../ConditionBuilder';
|
|
3
|
+
export declare type ConditionFieldType = 'TEXT' | 'EMAIL' | 'URL' | 'PHONE' | 'INTEGER' | 'DECIMAL' | 'PERCENTAGE' | 'BOOLEAN' | 'CURRENCY';
|
|
4
|
+
export declare type ConditionInputMode = 'default' | 'advanced';
|
|
5
|
+
export interface ConditionInputProps {
|
|
6
|
+
/** Name of the field the condition is created for. */
|
|
7
|
+
fieldName: string;
|
|
8
|
+
/** Type of the field the condition is created for. */
|
|
9
|
+
fieldType: ConditionFieldType;
|
|
10
|
+
/** Display mode. Either with default comparator or the full-fledged. */
|
|
11
|
+
mode: ConditionInputMode;
|
|
12
|
+
/** Label for the input. */
|
|
13
|
+
fieldLabel?: string;
|
|
14
|
+
/** Condition value. */
|
|
15
|
+
condition?: LeafCondition;
|
|
16
|
+
/** Callback invoked when user changes the condition. */
|
|
17
|
+
onChange: (condition?: LeafCondition) => void;
|
|
18
|
+
/** Reference to the input element. */
|
|
19
|
+
ref?: Ref<HTMLInputElement>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=ConditionInput.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConditionInput.types.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionInput/ConditionInput.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,oBAAY,kBAAkB,GAC1B,MAAM,GACN,OAAO,GACP,KAAK,GACL,OAAO,GACP,SAAS,GACT,SAAS,GACT,YAAY,GACZ,SAAS,GACT,UAAU,CAAC;AAEf,oBAAY,kBAAkB,GAAG,SAAS,GAAG,UAAU,CAAC;AAExD,MAAM,WAAW,mBAAmB;IAClC,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,SAAS,EAAE,kBAAkB,CAAC;IAC9B,wEAAwE;IACxE,IAAI,EAAE,kBAAkB,CAAC;IACzB,2BAA2B;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uBAAuB;IACvB,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,wDAAwD;IACxD,QAAQ,EAAE,CAAC,SAAS,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IAC9C,sCAAsC;IACtC,GAAG,CAAC,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;CAC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConditionInput.types.js","sourceRoot":"","sources":["../../../src/components/ConditionInput/ConditionInput.types.ts"],"names":[],"mappings":"","sourcesContent":["import { Ref } from 'react';\n\nimport { LeafCondition } from '../ConditionBuilder';\n\nexport type ConditionFieldType =\n | 'TEXT'\n | 'EMAIL'\n | 'URL'\n | 'PHONE'\n | 'INTEGER'\n | 'DECIMAL'\n | 'PERCENTAGE'\n | 'BOOLEAN'\n | 'CURRENCY';\n\nexport type ConditionInputMode = 'default' | 'advanced';\n\nexport interface ConditionInputProps {\n /** Name of the field the condition is created for. */\n fieldName: string;\n /** Type of the field the condition is created for. */\n fieldType: ConditionFieldType;\n /** Display mode. Either with default comparator or the full-fledged. */\n mode: ConditionInputMode;\n /** Label for the input. */\n fieldLabel?: string;\n /** Condition value. */\n condition?: LeafCondition;\n /** Callback invoked when user changes the condition. */\n onChange: (condition?: LeafCondition) => void;\n /** Reference to the input element. */\n ref?: Ref<HTMLInputElement>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionInput/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/ConditionInput/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC","sourcesContent":["export { default } from './ConditionInput';\nexport {\n ConditionInputProps,\n ConditionInputMode,\n ConditionFieldType\n} from './ConditionInput.types';\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FunctionComponent } from 'react';
|
|
2
|
+
import { ForwardProps } from '@pega/cosmos-react-core';
|
|
3
|
+
import { PromotedFiltersProps } from './PromotedFilters.types';
|
|
4
|
+
declare const PromotedFilters: FunctionComponent<PromotedFiltersProps & ForwardProps>;
|
|
5
|
+
export default PromotedFilters;
|
|
6
|
+
//# sourceMappingURL=PromotedFilters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PromotedFilters.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,iBAAiB,EAAmB,MAAM,OAAO,CAAC;AAGvE,OAAO,EAAkC,YAAY,EAAW,MAAM,yBAAyB,CAAC;AAMhG,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAkB/D,QAAA,MAAM,eAAe,EAAE,iBAAiB,CAAC,oBAAoB,GAAG,YAAY,CAqE3E,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import styled, { css } from 'styled-components';
|
|
4
|
+
import { Button, defaultThemeProp, Flex, useI18n } from '@pega/cosmos-react-core';
|
|
5
|
+
import { splitConditionForBuilder } from '../ConditionBuilder/core/utils';
|
|
6
|
+
import ConditionInput from '../ConditionInput';
|
|
7
|
+
const StyledPromotedFilters = styled.div(({ theme }) => {
|
|
8
|
+
return css `
|
|
9
|
+
border-radius: ${theme.components.card['border-radius']};
|
|
10
|
+
background-color: ${theme.base.palette['secondary-background']};
|
|
11
|
+
`;
|
|
12
|
+
});
|
|
13
|
+
StyledPromotedFilters.defaultProps = defaultThemeProp;
|
|
14
|
+
const StyledClearAllButton = styled(Button) `
|
|
15
|
+
margin-top: 0.625rem;
|
|
16
|
+
white-space: nowrap;
|
|
17
|
+
`;
|
|
18
|
+
StyledClearAllButton.defaultProps = defaultThemeProp;
|
|
19
|
+
const PromotedFilters = forwardRef(({ filters, condition, onChange }, ref) => {
|
|
20
|
+
const t = useI18n();
|
|
21
|
+
// map of Conditions indexed by field name
|
|
22
|
+
const conditionsMap = condition
|
|
23
|
+
? splitConditionForBuilder(condition).rows.reduce((result, item) => {
|
|
24
|
+
result[item.lhs.field] = item;
|
|
25
|
+
return result;
|
|
26
|
+
}, {})
|
|
27
|
+
: {};
|
|
28
|
+
const createUpdatedCondition = (key, newCondition) => {
|
|
29
|
+
if (newCondition) {
|
|
30
|
+
conditionsMap[key] = newCondition;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
delete conditionsMap[key];
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
AND: Object.values(conditionsMap).map(c => {
|
|
37
|
+
return { condition: c };
|
|
38
|
+
})
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
return (_jsxs(Flex, { as: StyledPromotedFilters, container: { alignItems: 'start', justify: 'between', pad: 2, gap: 2 }, ref: ref, children: [_jsx(Flex, { container: { wrap: 'wrap', gap: 2 }, children: filters.map(filter => {
|
|
42
|
+
return (_jsx(ConditionInput, { fieldName: filter.fieldName, fieldType: filter.fieldType, mode: filter.mode, fieldLabel: filter.fieldLabel ?? filter.fieldName, condition: conditionsMap[filter.fieldName], onChange: (newCondition) => {
|
|
43
|
+
onChange(createUpdatedCondition(filter.fieldName, newCondition));
|
|
44
|
+
} }, filter.fieldName));
|
|
45
|
+
}) }), _jsx("div", { children: _jsx(StyledClearAllButton, { variant: 'simple', onClick: () => {
|
|
46
|
+
onChange();
|
|
47
|
+
}, children: t('promoted_filters_clear_all_button_label') }) })] }));
|
|
48
|
+
});
|
|
49
|
+
export default PromotedFilters;
|
|
50
|
+
//# sourceMappingURL=PromotedFilters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PromotedFilters.js","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAsC,MAAM,OAAO,CAAC;AACvE,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,IAAI,EAAgB,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAGhG,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAI/C,MAAM,qBAAqB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IACrD,OAAO,GAAG,CAAA;qBACS,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC;wBACnC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC;GAC/D,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,qBAAqB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAEtD,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;;;CAG1C,CAAC;AAEF,oBAAoB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAErD,MAAM,eAAe,GAA2D,UAAU,CACxF,CACE,EAAE,OAAO,EAAE,SAAS,EA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EAC3B,IAAI,EAAE,MAAM,CAAC,IAAI,EACjB,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,SAAS,EACjD,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,EAC1C,QAAQ,EAAE,CAAC,YAA4B,EAAE,EAAE;4BACzC,QAAQ,CAAC,sBAAsB,CAAC,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC;wBACnE,CAAC,IARI,MAAM,CAAC,SAAS,CASrB,CACH,CAAC;gBACJ,CAAC,CAAC,GACG,EAEP,wBACE,KAAC,oBAAoB,IACnB,OAAO,EAAC,QAAQ,EAChB,OAAO,EAAE,GAAG,EAAE;wBACZ,QAAQ,EAAE,CAAC;oBACb,CAAC,YAEA,CAAC,CAAC,yCAAyC,CAAC,GACxB,GACnB,IACD,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { forwardRef, FunctionComponent, PropsWithoutRef } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport { Button, defaultThemeProp, Flex, ForwardProps, useI18n } from '@pega/cosmos-react-core';\n\nimport { Condition, LeafCondition } from '../ConditionBuilder/ConditionBuilder.types';\nimport { splitConditionForBuilder } from '../ConditionBuilder/core/utils';\nimport ConditionInput from '../ConditionInput';\n\nimport { PromotedFiltersProps } from './PromotedFilters.types';\n\nconst StyledPromotedFilters = styled.div(({ theme }) => {\n return css`\n border-radius: ${theme.components.card['border-radius']};\n background-color: ${theme.base.palette['secondary-background']};\n `;\n});\n\nStyledPromotedFilters.defaultProps = defaultThemeProp;\n\nconst StyledClearAllButton = styled(Button)`\n margin-top: 0.625rem;\n white-space: nowrap;\n`;\n\nStyledClearAllButton.defaultProps = defaultThemeProp;\n\nconst PromotedFilters: FunctionComponent<PromotedFiltersProps & ForwardProps> = forwardRef(\n (\n { filters, condition, onChange }: PropsWithoutRef<PromotedFiltersProps>,\n ref: PromotedFiltersProps['ref']\n ) => {\n const t = useI18n();\n\n // map of Conditions indexed by field name\n const conditionsMap = condition\n ? splitConditionForBuilder(condition).rows.reduce(\n (result: { [key: string]: LeafCondition }, item) => {\n result[item.lhs.field] = item;\n return result;\n },\n {}\n )\n : {};\n\n const createUpdatedCondition = (key: string, newCondition?: LeafCondition) => {\n if (newCondition) {\n conditionsMap[key] = newCondition;\n } else {\n delete conditionsMap[key];\n }\n\n return {\n AND: Object.values(conditionsMap).map(c => {\n return { condition: c } as Condition;\n })\n };\n };\n\n return (\n <Flex\n as={StyledPromotedFilters}\n container={{ alignItems: 'start', justify: 'between', pad: 2, gap: 2 }}\n ref={ref}\n >\n <Flex container={{ wrap: 'wrap', gap: 2 }}>\n {filters.map(filter => {\n return (\n <ConditionInput\n key={filter.fieldName}\n fieldName={filter.fieldName}\n fieldType={filter.fieldType}\n mode={filter.mode}\n fieldLabel={filter.fieldLabel ?? filter.fieldName}\n condition={conditionsMap[filter.fieldName]}\n onChange={(newCondition?: LeafCondition) => {\n onChange(createUpdatedCondition(filter.fieldName, newCondition));\n }}\n />\n );\n })}\n </Flex>\n\n <div>\n <StyledClearAllButton\n variant='simple'\n onClick={() => {\n onChange();\n }}\n >\n {t('promoted_filters_clear_all_button_label')}\n </StyledClearAllButton>\n </div>\n </Flex>\n );\n }\n);\n\nexport default PromotedFilters;\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Ref } from 'react';
|
|
2
|
+
import { BaseProps } from '@pega/cosmos-react-core';
|
|
3
|
+
import type { Condition } from '../ConditionBuilder/ConditionBuilder.types';
|
|
4
|
+
import type { ConditionInputMode, ConditionFieldType } from '../ConditionInput/ConditionInput.types';
|
|
5
|
+
export interface PromotedFilter {
|
|
6
|
+
/** Unique field identifier. */
|
|
7
|
+
fieldName: string;
|
|
8
|
+
/** Type of the field. */
|
|
9
|
+
fieldType: ConditionFieldType;
|
|
10
|
+
/** Display mode. */
|
|
11
|
+
mode: ConditionInputMode;
|
|
12
|
+
/** Label for the filter. */
|
|
13
|
+
fieldLabel?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface PromotedFiltersProps extends BaseProps {
|
|
16
|
+
/** Configuration of filters for every field that has been defined as promoted. */
|
|
17
|
+
filters: PromotedFilter[];
|
|
18
|
+
/** A value representing the current condition state. */
|
|
19
|
+
condition?: Condition;
|
|
20
|
+
/** Callback fired on change of any of the filters. */
|
|
21
|
+
onChange: (condition?: Condition) => void;
|
|
22
|
+
/** Ref for the wrapping element. */
|
|
23
|
+
ref?: Ref<HTMLDivElement>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=PromotedFilters.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PromotedFilters.types.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4CAA4C,CAAC;AAC5E,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,wCAAwC,CAAC;AAEhD,MAAM,WAAW,cAAc;IAC7B,+BAA+B;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,yBAAyB;IACzB,SAAS,EAAE,kBAAkB,CAAC;IAC9B,oBAAoB;IACpB,IAAI,EAAE,kBAAkB,CAAC;IACzB,4BAA4B;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,oBAAqB,SAAQ,SAAS;IACrD,kFAAkF;IAClF,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,wDAAwD;IACxD,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,sDAAsD;IACtD,QAAQ,EAAE,CAAC,SAAS,CAAC,EAAE,SAAS,KAAK,IAAI,CAAC;IAC1C,oCAAoC;IACpC,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PromotedFilters.types.js","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.types.ts"],"names":[],"mappings":"","sourcesContent":["import { Ref } from 'react';\n\nimport { BaseProps } from '@pega/cosmos-react-core';\n\nimport type { Condition } from '../ConditionBuilder/ConditionBuilder.types';\nimport type {\n ConditionInputMode,\n ConditionFieldType\n} from '../ConditionInput/ConditionInput.types';\n\nexport interface PromotedFilter {\n /** Unique field identifier. */\n fieldName: string;\n /** Type of the field. */\n fieldType: ConditionFieldType;\n /** Display mode. */\n mode: ConditionInputMode;\n /** Label for the filter. */\n fieldLabel?: string;\n}\n\nexport interface PromotedFiltersProps extends BaseProps {\n /** Configuration of filters for every field that has been defined as promoted. */\n filters: PromotedFilter[];\n /** A value representing the current condition state. */\n condition?: Condition;\n /** Callback fired on change of any of the filters. */\n onChange: (condition?: Condition) => void;\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLDivElement>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/PromotedFilters/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC","sourcesContent":["export { default } from './PromotedFilters';\nexport { PromotedFiltersProps, PromotedFilter } from './PromotedFilters.types';\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
export { default as ConditionBuilder } from './components/ConditionBuilder';
|
|
2
2
|
export * from './components/ConditionBuilder';
|
|
3
|
+
export { default as ConditionInput } from './components/ConditionInput';
|
|
4
|
+
export * from './components/ConditionInput';
|
|
5
|
+
export { default as PromotedFilters } from './components/PromotedFilters';
|
|
6
|
+
export * from './components/PromotedFilters';
|
|
3
7
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,cAAc,+BAA+B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,cAAc,+BAA+B,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,6BAA6B,CAAC;AACxE,cAAc,6BAA6B,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC1E,cAAc,8BAA8B,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
// This file is autogenerated. Any changes will be overwritten.
|
|
2
2
|
export { default as ConditionBuilder } from './components/ConditionBuilder';
|
|
3
3
|
export * from './components/ConditionBuilder';
|
|
4
|
+
export { default as ConditionInput } from './components/ConditionInput';
|
|
5
|
+
export * from './components/ConditionInput';
|
|
6
|
+
export { default as PromotedFilters } from './components/PromotedFilters';
|
|
7
|
+
export * from './components/PromotedFilters';
|
|
4
8
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,cAAc,+BAA+B,CAAC","sourcesContent":["// This file is autogenerated. Any changes will be overwritten.\nexport { default as ConditionBuilder } from './components/ConditionBuilder';\nexport * from './components/ConditionBuilder';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,cAAc,+BAA+B,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,6BAA6B,CAAC;AACxE,cAAc,6BAA6B,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC1E,cAAc,8BAA8B,CAAC","sourcesContent":["// This file is autogenerated. Any changes will be overwritten.\nexport { default as ConditionBuilder } from './components/ConditionBuilder';\nexport * from './components/ConditionBuilder';\nexport { default as ConditionInput } from './components/ConditionInput';\nexport * from './components/ConditionInput';\nexport { default as PromotedFilters } from './components/PromotedFilters';\nexport * from './components/PromotedFilters';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pega/cosmos-react-condition-builder",
|
|
3
|
-
"version": "3.0.0-dev.
|
|
3
|
+
"version": "3.0.0-dev.14.0",
|
|
4
4
|
"author": "Pegasystems",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"repository": {
|
|
@@ -16,17 +16,18 @@
|
|
|
16
16
|
"lib"
|
|
17
17
|
],
|
|
18
18
|
"sideEffects": [
|
|
19
|
+
"./src/components/ConditionBuilder/core/extendDayJs.ts",
|
|
19
20
|
"./lib/components/ConditionBuilder/core/extendDayJs.js"
|
|
20
21
|
],
|
|
21
22
|
"scripts": {
|
|
22
23
|
"build": "tsc -b"
|
|
23
24
|
},
|
|
24
25
|
"dependencies": {
|
|
25
|
-
"@pega/cosmos-react-core": "3.0.0-dev.
|
|
26
|
+
"@pega/cosmos-react-core": "3.0.0-dev.14.0",
|
|
26
27
|
"@types/react": "^16.14.24 || ^17.0.38",
|
|
27
28
|
"@types/react-dom": "^16.9.14 || ^17.0.11",
|
|
28
29
|
"@types/styled-components": "^5.1.7",
|
|
29
|
-
"dayjs": "1.
|
|
30
|
+
"dayjs": "^1.10.7",
|
|
30
31
|
"polished": "^4.1.0",
|
|
31
32
|
"react": "^16.14.0 || ^17.0.0",
|
|
32
33
|
"react-dom": "^16.14.0 || ^17.0.0",
|
|
@@ -40,6 +41,9 @@
|
|
|
40
41
|
"@storybook/addons": "^6.4.19",
|
|
41
42
|
"@storybook/react": "^6.4.19",
|
|
42
43
|
"@storybook/theming": "^6.4.19",
|
|
44
|
+
"@testing-library/jest-dom": "^5.16.2",
|
|
45
|
+
"@testing-library/react": "^12.1.3",
|
|
46
|
+
"@testing-library/user-event": "^13.5.0",
|
|
43
47
|
"enzyme": "^3.11.0",
|
|
44
48
|
"typescript": "~4.6.2"
|
|
45
49
|
}
|