@pega/cosmos-react-condition-builder 7.0.0-build.2.1 → 7.0.0-build.20.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/ConditionBuilder.styles.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.styles.js +10 -10
- package/lib/components/ConditionBuilder/ConditionBuilder.styles.js.map +1 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts +1 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.types.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/NumericInput.d.ts +2 -0
- package/lib/components/ConditionBuilder/RhsControls/NumericInput.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/NumericInput.js +2 -2
- package/lib/components/ConditionBuilder/RhsControls/NumericInput.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.js +1 -0
- package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.d.ts +3 -5
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.js +26 -40
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/index.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/index.js +5 -4
- package/lib/components/ConditionBuilder/RhsControls/index.js.map +1 -1
- package/lib/components/ConditionBuilder/core/comparators.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/comparators.js +1 -0
- package/lib/components/ConditionBuilder/core/comparators.js.map +1 -1
- package/lib/components/ConditionBuilder/core/evaluator.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/evaluator.js +1 -0
- package/lib/components/ConditionBuilder/core/evaluator.js.map +1 -1
- package/lib/components/ConditionBuilder/core/formatter.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/formatter.js +1 -0
- package/lib/components/ConditionBuilder/core/formatter.js.map +1 -1
- package/lib/components/ConditionBuilder/core/transformer.js +1 -1
- package/lib/components/ConditionBuilder/core/transformer.js.map +1 -1
- package/lib/components/ConditionBuilder/core/types.d.ts +4 -1
- package/lib/components/ConditionBuilder/core/types.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/types.js.map +1 -1
- package/lib/components/ConditionInput/ConditionInput.d.ts.map +1 -1
- package/lib/components/ConditionInput/ConditionInput.js +26 -14
- package/lib/components/ConditionInput/ConditionInput.js.map +1 -1
- package/lib/components/ConditionInput/utils.js +1 -1
- package/lib/components/ConditionInput/utils.js.map +1 -1
- package/lib/components/PromotedFilters/PromotedFilters.d.ts.map +1 -1
- package/lib/components/PromotedFilters/PromotedFilters.js +17 -47
- package/lib/components/PromotedFilters/PromotedFilters.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConditionBuilder.styles.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.styles.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,sBAAsB,
|
|
1
|
+
{"version":3,"file":"ConditionBuilder.styles.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.styles.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,sBAAsB,mOAUjC,CAAC;AAKH,eAAO,MAAM,SAAS,mOAGrB,CAAC;AAIF,eAAO,MAAM,yBAAyB,yGAIpC,CAAC;AAKH,eAAO,MAAM,sBAAsB,mOAUlC,CAAC;AAKF,eAAO,MAAM,WAAW,yGAOvB,CAAC;AAIF,eAAO,MAAM,qBAAqB,yOAkBhC,CAAC"}
|
|
@@ -3,10 +3,10 @@ import { calculateFontSize, defaultThemeProp, FieldGroup, Flex, StyledFieldGroup
|
|
|
3
3
|
import { StyledDialog } from '@pega/cosmos-react-core/lib/components/Dialog/Dialog.styles';
|
|
4
4
|
export const StyledConditionBuilder = styled(Flex)(({ theme: { base: { 'content-width': contentWidth, spacing } } }) => {
|
|
5
5
|
return css `
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
${StyledPopover}:not(${StyledDialog}) & {
|
|
7
|
+
min-width: min(${contentWidth.lg}, calc(100vw - 4 * ${spacing}));
|
|
8
|
+
}
|
|
9
|
+
`;
|
|
10
10
|
});
|
|
11
11
|
StyledConditionBuilder.defaultProps = defaultThemeProp;
|
|
12
12
|
// Styled wrapper for each Condition row
|
|
@@ -48,12 +48,12 @@ export const StyledAtomicCondition = styled(FieldGroup)(({ theme: { base: { 'fon
|
|
|
48
48
|
const fontSizes = calculateFontSize(fontSize, fontScale);
|
|
49
49
|
return (!collapsed &&
|
|
50
50
|
css `
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
${StyledFieldGroupLegend} {
|
|
52
|
+
font-size: ${fontSizes[text.secondary['font-size']]};
|
|
53
|
+
font-weight: ${text.secondary['font-weight']};
|
|
54
|
+
margin-block-end: calc(0.5 * ${spacing});
|
|
55
|
+
}
|
|
56
|
+
`);
|
|
57
57
|
});
|
|
58
58
|
StyledAtomicCondition.defaultProps = defaultThemeProp;
|
|
59
59
|
//# sourceMappingURL=ConditionBuilder.styles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConditionBuilder.styles.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.styles.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACV,IAAI,EACJ,sBAAsB,EACtB,aAAa,EACd,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,YAAY,EAAE,MAAM,6DAA6D,CAAC;AAE3F,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"ConditionBuilder.styles.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.styles.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACV,IAAI,EACJ,sBAAsB,EACtB,aAAa,EACd,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,YAAY,EAAE,MAAM,6DAA6D,CAAC;AAE3F,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAClD,KAAK,EAAE,EACL,IAAI,EAAE,EAAE,eAAe,EAAE,YAAY,EAAE,OAAO,EAAE,EACjD,EACF,EAAE,EAAE;IACH,OAAO,GAAG,CAAA;MACN,aAAa,QAAQ,YAAY;uBAChB,YAAY,CAAC,EAAE,sBAAsB,OAAO;;GAEhE,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,sBAAsB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAEvD,wCAAwC;AACxC,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;;gBAErB,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,aAAa,CAAC;CAC9E,CAAC;AAEF,SAAS,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAE1C,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IAChE,OAAO,GAAG,CAAA;aACC,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,EAAE;GACxC,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,yBAAyB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAE1D,uCAAuC;AACvC,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;;;;;;;;;;CAUtD,CAAC;AAEF,sBAAsB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAEvD,6CAA6C;AAC7C,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;CAOpC,CAAC;AAEF,WAAW,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAE5C,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,EACvD,KAAK,EAAE,EACL,IAAI,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,EACjE,UAAU,EAAE,EAAE,IAAI,EAAE,EACrB,EACD,SAAS,EACV,EAAE,EAAE;IACH,MAAM,SAAS,GAAG,iBAAiB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IACzD,OAAO,CACL,CAAC,SAAS;QACV,GAAG,CAAA;QACC,sBAAsB;qBACT,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAa,CAAC;uBAChD,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC;uCACb,OAAO;;KAEzC,CACF,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,qBAAqB,CAAC,YAAY,GAAG,gBAAgB,CAAC","sourcesContent":["import styled, { css } from 'styled-components';\n\nimport {\n calculateFontSize,\n defaultThemeProp,\n FieldGroup,\n Flex,\n StyledFieldGroupLegend,\n StyledPopover\n} from '@pega/cosmos-react-core';\nimport type { FontSize } from '@pega/cosmos-react-core';\nimport { StyledDialog } from '@pega/cosmos-react-core/lib/components/Dialog/Dialog.styles';\n\nexport const StyledConditionBuilder = styled(Flex)(({\n theme: {\n base: { 'content-width': contentWidth, spacing }\n }\n}) => {\n return css`\n ${StyledPopover}:not(${StyledDialog}) & {\n min-width: min(${contentWidth.lg}, calc(100vw - 4 * ${spacing}));\n }\n `;\n});\n\nStyledConditionBuilder.defaultProps = defaultThemeProp;\n\n// Styled wrapper for each Condition row\nexport const StyledRow = styled(Flex)`\n padding: 0.25rem;\n background: ${props => (props.shaded ? 'rgba(0, 0, 0, 0.05)' : 'transparent')};\n`;\n\nStyledRow.defaultProps = defaultThemeProp;\n\nexport const StyledTimePeriodContainer = styled.div(({ theme }) => {\n return css`\n width: ${theme.base['content-width'].sm};\n `;\n});\n\nStyledTimePeriodContainer.defaultProps = defaultThemeProp;\n\n// Styled row-separators for Basic-mode\nexport const 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\nStyledRowWithSeparator.defaultProps = defaultThemeProp;\n\n// Styled label for the rows in Advanced-mode\nexport const 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`;\n\nStyledLabel.defaultProps = defaultThemeProp;\n\nexport const StyledAtomicCondition = styled(FieldGroup)(({\n theme: {\n base: { 'font-size': fontSize, 'font-scale': fontScale, spacing },\n components: { text }\n },\n collapsed\n}) => {\n const fontSizes = calculateFontSize(fontSize, fontScale);\n return (\n !collapsed &&\n css`\n ${StyledFieldGroupLegend} {\n font-size: ${fontSizes[text.secondary['font-size'] as FontSize]};\n font-weight: ${text.secondary['font-weight']};\n margin-block-end: calc(0.5 * ${spacing});\n }\n `\n );\n});\n\nStyledAtomicCondition.defaultProps = defaultThemeProp;\n"]}
|
|
@@ -89,7 +89,7 @@ export type Field = BasicField & ({
|
|
|
89
89
|
/**
|
|
90
90
|
* Data-type for the field.
|
|
91
91
|
* Has to be one of these values. Convert where necessary
|
|
92
|
-
* e.g.
|
|
92
|
+
* e.g. Decimal/Currency... should be used as `NUMBER`
|
|
93
93
|
* e.g. Text(single value)/Picklist/... should be used as `TEXT`
|
|
94
94
|
*/
|
|
95
95
|
type: FieldType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConditionBuilder.types.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.types.ts"],"names":[],"mappings":"","sourcesContent":["// cspell:words DDTHH\nimport type { Ref } from 'react';\n\nimport type { BaseProps, NoChildrenProp, MenuItemProps } from '@pega/cosmos-react-core';\n\nimport type {\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 * MINUTES: YYYY-MM-DDTHH:mm:ss\n * SECONDS: YYYY-MM-DDTHH:mm:ss\n * HOURS_OF_DAY: 0-23\n * MONTHS_OF_YEAR: 1-12\n * DAYS_OF_MONTH: 1-31\n * DAYS_OF_WEEK: 1-7\n */\n value: string | number;\n dateFunction: DateFunction;\n}\n\n/** RHS object with a Relative Date */\nexport interface RhsWithRelativeDate {\n relativeDate: {\n timePeriod: TimePeriod;\n interval?: number;\n datePart: DatePart;\n };\n}\n\n/** RHS object with PARAMETER type */\nexport interface RhsWithParameter {\n parameterId: string;\n}\n\n/** Type definition for the leaf-level nodes in nested conditions */\nexport interface LeafCondition {\n comparator: Comparator;\n\n lhs: {\n field: string;\n };\n\n // Optional for some of the comparators like IS_TRUE, IS_NULL, etc.\n rhs?:\n | { field: string } // When comparing the LHS with another field\n | { value: string | number } // When comparing the LHS with a single literal value (for comparators like EQ, GTE etc.)\n | { values: string[] | number[] } // When comparing the LHS with a list of literal values (for comparators like IN, NOT_IN etc.)\n | { start: string | number; end: string | number } // When comparing numeric or date field with two values that determine range\n | RhsWithDateFunction // When comparing a date field with a date function on RHS\n | RhsWithRelativeDate // When comparing a date field with a symbolic date on RHS\n | RhsWithParameter; // When comparing the LHS with PARAMETER type\n}\n\n/** Type definition for objects representing condition-rows in the builder UI */\nexport interface ConditionRow extends LeafCondition {\n id: string; // To use as `key` prop when rendering a list of rows\n label: string; // Used to refer the row from a logic-string\n}\n\n/**\n * Type definition for simple/complex conditions\n * At a given node in the condition tree, it can have exactly one of the keys AND/OR/NOT/condition\n */\nexport type Condition =\n | { AND: Condition[] }\n | { OR: Condition[] }\n | { NOT: Condition }\n | { condition: LeafCondition };\n\n/** Type definition for the input Field objects for the ConditionBuilder */\n\nexport type ParameterValue = Pick<MenuItemProps, 'id' | 'primary'>;\n\nexport type ReferenceValue = Pick<MenuItemProps, 'id' | 'primary'>;\n\nexport type ValueSelection<F> =\n | string[]\n | ReferenceValue[]\n | (({\n searchString,\n comparator,\n lhs\n }: {\n searchString?: string;\n comparator?: string;\n lhs?: F;\n }) => Promise<string[] | ReferenceValue[]>);\n\ninterface BasicField extends Pick<MenuItemProps, 'id' | 'primary'> {}\n\nexport type Field = BasicField &\n (\n | {\n parameters?: ParameterValue[];\n\n /**\n * For TEXT fields, if a list of possible values is known ahead of time, they can be passed.\n * Otherwise we fetch data from api and pass a promise which returns list of values\n * This enables users to select from those values instead of manually typing them\n */\n possibleValues?: ValueSelection<Field>;\n\n /**\n * Data-type for the field.\n * Has to be one of these values. Convert where necessary\n * e.g.
|
|
1
|
+
{"version":3,"file":"ConditionBuilder.types.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.types.ts"],"names":[],"mappings":"","sourcesContent":["// cspell:words DDTHH\nimport type { Ref } from 'react';\n\nimport type { BaseProps, NoChildrenProp, MenuItemProps } from '@pega/cosmos-react-core';\n\nimport type {\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 * MINUTES: YYYY-MM-DDTHH:mm:ss\n * SECONDS: YYYY-MM-DDTHH:mm:ss\n * HOURS_OF_DAY: 0-23\n * MONTHS_OF_YEAR: 1-12\n * DAYS_OF_MONTH: 1-31\n * DAYS_OF_WEEK: 1-7\n */\n value: string | number;\n dateFunction: DateFunction;\n}\n\n/** RHS object with a Relative Date */\nexport interface RhsWithRelativeDate {\n relativeDate: {\n timePeriod: TimePeriod;\n interval?: number;\n datePart: DatePart;\n };\n}\n\n/** RHS object with PARAMETER type */\nexport interface RhsWithParameter {\n parameterId: string;\n}\n\n/** Type definition for the leaf-level nodes in nested conditions */\nexport interface LeafCondition {\n comparator: Comparator;\n\n lhs: {\n field: string;\n };\n\n // Optional for some of the comparators like IS_TRUE, IS_NULL, etc.\n rhs?:\n | { field: string } // When comparing the LHS with another field\n | { value: string | number } // When comparing the LHS with a single literal value (for comparators like EQ, GTE etc.)\n | { values: string[] | number[] } // When comparing the LHS with a list of literal values (for comparators like IN, NOT_IN etc.)\n | { start: string | number; end: string | number } // When comparing numeric or date field with two values that determine range\n | RhsWithDateFunction // When comparing a date field with a date function on RHS\n | RhsWithRelativeDate // When comparing a date field with a symbolic date on RHS\n | RhsWithParameter; // When comparing the LHS with PARAMETER type\n}\n\n/** Type definition for objects representing condition-rows in the builder UI */\nexport interface ConditionRow extends LeafCondition {\n id: string; // To use as `key` prop when rendering a list of rows\n label: string; // Used to refer the row from a logic-string\n}\n\n/**\n * Type definition for simple/complex conditions\n * At a given node in the condition tree, it can have exactly one of the keys AND/OR/NOT/condition\n */\nexport type Condition =\n | { AND: Condition[] }\n | { OR: Condition[] }\n | { NOT: Condition }\n | { condition: LeafCondition };\n\n/** Type definition for the input Field objects for the ConditionBuilder */\n\nexport type ParameterValue = Pick<MenuItemProps, 'id' | 'primary'>;\n\nexport type ReferenceValue = Pick<MenuItemProps, 'id' | 'primary'>;\n\nexport type ValueSelection<F> =\n | string[]\n | ReferenceValue[]\n | (({\n searchString,\n comparator,\n lhs\n }: {\n searchString?: string;\n comparator?: string;\n lhs?: F;\n }) => Promise<string[] | ReferenceValue[]>);\n\ninterface BasicField extends Pick<MenuItemProps, 'id' | 'primary'> {}\n\nexport type Field = BasicField &\n (\n | {\n parameters?: ParameterValue[];\n\n /**\n * For TEXT fields, if a list of possible values is known ahead of time, they can be passed.\n * Otherwise we fetch data from api and pass a promise which returns list of values\n * This enables users to select from those values instead of manually typing them\n */\n possibleValues?: ValueSelection<Field>;\n\n /**\n * Data-type for the field.\n * Has to be one of these values. Convert where necessary\n * e.g. Decimal/Currency... should be used as `NUMBER`\n * e.g. Text(single value)/Picklist/... should be used as `TEXT`\n */\n type: FieldType;\n }\n | {\n /** An array of type Field to represent the child items. */\n items: Field[];\n }\n );\n\n/** Valid date functions by field type */\nexport interface DateFunctionsByType {\n /** Date functions to enable for DATE_TIME fields */\n DATE_TIME: DateFunction[];\n /** Date functions to enable for DATE_ONLY fields */\n DATE_ONLY: DateFunction[];\n}\n\nexport interface HandleValue {\n /**\n * Returns condition validity and condition or undefined if valid.\n * Undefined indicates no condition.\n */\n getCondition: () => [valid: false] | [valid: true, condition: Condition | undefined];\n}\n\n/** Type definition for the input props of ConditionBuilder */\nexport default interface ConditionBuilderProps extends BaseProps, NoChildrenProp {\n /** Metadata (data-model) for the Fields to use in the builder */\n fields: Field[];\n\n /** (Optional) A seed condition for the builder. To use when editing an existing condition */\n condition?: Condition;\n\n /** (Optional) Used to limit the Comparators allowed in the builder. */\n validComparators?: ComparatorsByType[];\n\n /**\n * (Optional) Pass this to control which all types of RHS are enabled in the component\n * DEFAULT: Set(['LITERAL', 'FIELD'])\n * NOTE: If enabling `DATE_FUNCTION`s, additionally pass a `dateFunctions` prop to specify which functions are enabled\n */\n validRhsTypes?: Set<RHSType>;\n\n /** (Optional) When enabling 'DATE_FUNCTION's via `validRhsTypes`, pass this to specify which all date functions are applicable per field type */\n dateFunctions?: DateFunctionsByType;\n\n /** (Optional) Pass this if the `NOT` operator should be considered as invalid */\n disallowNOT?: boolean;\n\n /** Imperative handle for the component. */\n handle?: Ref<HandleValue>;\n}\n"]}
|
|
@@ -11,6 +11,8 @@ interface NumericInputProps extends BaseProps, NoChildrenProp {
|
|
|
11
11
|
}) => void;
|
|
12
12
|
/** Used to indicate any errors on the control */
|
|
13
13
|
status?: 'error';
|
|
14
|
+
/** Determines whether decimals can be entered */
|
|
15
|
+
allowDecimal?: boolean;
|
|
14
16
|
}
|
|
15
17
|
/** Wrapper over the NumberInput to parse values as Numbers, while still allowing the user to type partial values like `12.`, `12.0`, ... */
|
|
16
18
|
declare const NumericInput: FunctionComponent<NumericInputProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumericInput.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/NumericInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAG/C,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzE,UAAU,iBAAkB,SAAQ,SAAS,EAAE,cAAc;IAC3D,4BAA4B;IAC5B,GAAG,EAAE;QAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAEhC,gDAAgD;IAChD,QAAQ,EAAE,CAAC,GAAG,EAAE;QAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAEpD,iDAAiD;IACjD,MAAM,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"NumericInput.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/NumericInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAG/C,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzE,UAAU,iBAAkB,SAAQ,SAAS,EAAE,cAAc;IAC3D,4BAA4B;IAC5B,GAAG,EAAE;QAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAEhC,gDAAgD;IAChD,QAAQ,EAAE,CAAC,GAAG,EAAE;QAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAEpD,iDAAiD;IACjD,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB,iDAAiD;IACjD,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,4IAA4I;AAC5I,QAAA,MAAM,YAAY,EAAE,iBAAiB,CAAC,iBAAiB,CA4BtD,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -3,7 +3,7 @@ import { useState } from 'react';
|
|
|
3
3
|
import { NumberInput, useAfterInitialEffect, useI18n } from '@pega/cosmos-react-core';
|
|
4
4
|
/** Wrapper over the NumberInput to parse values as Numbers, while still allowing the user to type partial values like `12.`, `12.0`, ... */
|
|
5
5
|
const NumericInput = (props) => {
|
|
6
|
-
const { rhs, onChange, status } = props;
|
|
6
|
+
const { rhs, onChange, status, allowDecimal = true } = props;
|
|
7
7
|
const t = useI18n();
|
|
8
8
|
// Since we want to always call onChange with parsed Numbers,
|
|
9
9
|
// if we parse values like `12.`, `12.0`, etc., the decimals will be lost leading to bad UX
|
|
@@ -16,7 +16,7 @@ const NumericInput = (props) => {
|
|
|
16
16
|
setLocalValue(newValue);
|
|
17
17
|
onChange({ value: newValue.trim() ? Number(newValue) : '' }); // Save as a number unless the input is empty
|
|
18
18
|
};
|
|
19
|
-
return (_jsx(NumberInput, { value: localValue, onChange: handleInputChange, status: status, info: status === 'error' ? t('condition_builder_invalid_number') : undefined, label: t('condition_builder_value_label') }));
|
|
19
|
+
return (_jsx(NumberInput, { value: localValue, onChange: handleInputChange, status: status, info: status === 'error' ? t('condition_builder_invalid_number') : undefined, label: t('condition_builder_value_label'), numberOfDecimals: allowDecimal ? undefined : 0 }));
|
|
20
20
|
};
|
|
21
21
|
export default NumericInput;
|
|
22
22
|
//# sourceMappingURL=NumericInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumericInput.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/NumericInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGjC,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"NumericInput.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/NumericInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGjC,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAiBtF,4IAA4I;AAC5I,MAAM,YAAY,GAAyC,CAAC,KAAwB,EAAE,EAAE;IACtF,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IAC7D,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IAEpB,6DAA6D;IAC7D,2FAA2F;IAC3F,oCAAoC;IACpC,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;IAEnE,qBAAqB,CAAC,GAAG,EAAE;QACzB,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;IACtC,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;IAEhB,MAAM,iBAAiB,GAAG,CAAC,QAAgB,EAAE,EAAE;QAC7C,aAAa,CAAC,QAAQ,CAAC,CAAC;QACxB,QAAQ,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,6CAA6C;IAC7G,CAAC,CAAC;IAEF,OAAO,CACL,KAAC,WAAW,IACV,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,iBAAiB,EAC3B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,kCAAkC,CAAC,CAAC,CAAC,CAAC,SAAS,EAC5E,KAAK,EAAE,CAAC,CAAC,+BAA+B,CAAC,EACzC,gBAAgB,EAAE,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAC9C,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import { useState } from 'react';\nimport type { FunctionComponent } from 'react';\n\nimport { NumberInput, useAfterInitialEffect, useI18n } from '@pega/cosmos-react-core';\nimport type { BaseProps, NoChildrenProp } from '@pega/cosmos-react-core';\n\ninterface NumericInputProps extends BaseProps, NoChildrenProp {\n /** Rhs for the condition */\n rhs: { value: string | number };\n\n /** Callback for any modifications to the Rhs */\n onChange: (rhs: { value: string | number }) => void;\n\n /** Used to indicate any errors on the control */\n status?: 'error';\n\n /** Determines whether decimals can be entered */\n allowDecimal?: boolean;\n}\n\n/** Wrapper over the NumberInput to parse values as Numbers, while still allowing the user to type partial values like `12.`, `12.0`, ... */\nconst NumericInput: FunctionComponent<NumericInputProps> = (props: NumericInputProps) => {\n const { rhs, onChange, status, allowDecimal = true } = props;\n const t = useI18n();\n\n // Since we want to always call onChange with parsed Numbers,\n // if we parse values like `12.`, `12.0`, etc., the decimals will be lost leading to bad UX\n // Using a local state to avoid that\n const [localValue, setLocalValue] = useState(rhs.value.toString());\n\n useAfterInitialEffect(() => {\n setLocalValue(rhs.value.toString());\n }, [rhs.value]);\n\n const handleInputChange = (newValue: string) => {\n setLocalValue(newValue);\n onChange({ value: newValue.trim() ? Number(newValue) : '' }); // Save as a number unless the input is empty\n };\n\n return (\n <NumberInput\n value={localValue}\n onChange={handleInputChange}\n status={status}\n info={status === 'error' ? t('condition_builder_invalid_number') : undefined}\n label={t('condition_builder_value_label')}\n numberOfDecimals={allowDecimal ? undefined : 0}\n />\n );\n};\n\nexport default NumericInput;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RhsModeSwitch.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/RhsModeSwitch.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAG/C,OAAO,KAAK,EACV,SAAS,EACT,YAAY,EAEZ,cAAc,EAEf,MAAM,yBAAyB,CAAC;AAIjC,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"RhsModeSwitch.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/RhsModeSwitch.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAG/C,OAAO,KAAK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WAAW,CAAC,CAAC,CAAC;IAExB,qEAAqE;IACrE,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAEvC,IAAI,IAAI,KAAK,WAAW,EAAE;QACxB,OAAO,CACL,KAAC,QAAQ,IACP,KAAK,EAAE,CAAC,CAAC,gCAAgC,CAAC,EAC1C,IAAI,EAAC,eAAe,EACpB,QAAQ,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,EAC7B,IAAI,EAAE,IAAI,GACV,CACH,CAAC;KACH;IAED,OAAO,CACL,KAAC,UAAU,IACT,IAAI,EAAE,CAAC,CAAC,gCAAgC,CAAC,gBAC7B,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,gCAAgC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,EACvF,IAAI,EAAC,MAAM,EACX,QAAQ,QACR,OAAO,EAAC,QAAQ,EAChB,IAAI,EAAE,IAAI,GACV,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { useMemo } from 'react';\nimport type { FunctionComponent } from 'react';\n\nimport { ComboBox, hasProp, MenuButton, menuHelpers, useI18n } from '@pega/cosmos-react-core';\nimport type {\n BaseProps,\n ForwardProps,\n MenuProps,\n NoChildrenProp,\n TranslationPack\n} from '@pega/cosmos-react-core';\nimport type { TranslationFunction } from '@pega/cosmos-react-core/lib/i18n/translate';\nimport type { Selected } from '@pega/cosmos-react-core/lib/components/ComboBox/ComboBox.types';\n\nimport type { Comparator, FieldType, RHSType } from '../core/types';\nimport type { DateFunctionsByType, LeafCondition, ParameterValue } from '../ConditionBuilder.types';\n\nenum ItemID {\n LITERAL_VALUE = 'LITERAL_VALUE',\n DATE_PART = 'DATE_PART',\n RELATIVE_DATE = 'RELATIVE_DATE',\n ANOTHER_FIELD = 'ANOTHER_FIELD',\n PARAMETER = 'PARAMETER'\n}\n\n// Label for the `Enter <value>` option on the gear-menu\nfunction getValueOptionLabel(\n fieldType: FieldType,\n t: TranslationFunction<TranslationPack>\n): string {\n switch (fieldType) {\n case 'TEXT':\n return t('condition_builder_compare_with_text_value');\n case 'NUMBER':\n return t('condition_builder_compare_with_numeric_value');\n case 'DATE_TIME':\n case 'DATE_ONLY':\n return t('condition_builder_compare_with_date_value');\n case 'TIME_ONLY':\n return t('condition_builder_compare_with_time_value');\n default:\n return t('condition_builder_value_label'); // Not needed (BOOLEAN is not expected to be passed to the function)\n }\n}\n\ninterface RhsMenuButtonProps extends BaseProps, NoChildrenProp {\n /** Passed Parameters array for Rhstype PARAMETER */\n parameters: ParameterValue[];\n\n /** Type of field on the LHS */\n fieldType: FieldType;\n\n /** Comparator for the condition */\n comparator: Comparator;\n\n /** Rhs for the condition */\n rhs: NonNullable<LeafCondition['rhs']>;\n\n /** Callback for any modifications to the Rhs */\n onChange: (rhs: NonNullable<LeafCondition['rhs']>) => void;\n\n /** Display mode */\n mode: 'combo-box' | 'menu-button';\n\n /** Restricts RHS values to only specified RHS types */\n validRhsTypes: Set<RHSType>;\n\n /** Passed to enable additional date controls on the RHS, when a DATE_TIME/DATE_ONLY field is selected on the LHS */\n dateFunctions?: DateFunctionsByType;\n}\n\n/** Renders a Gear MenuButton on the RHS (when applicable) */\nconst RhsModeSwitch: FunctionComponent<RhsMenuButtonProps & ForwardProps> = ({\n parameters,\n fieldType,\n comparator,\n rhs,\n onChange,\n mode,\n validRhsTypes,\n dateFunctions\n}: RhsMenuButtonProps) => {\n const t = useI18n();\n\n // Identify current mode\n const currentMode = useMemo(() => {\n if (hasProp(rhs, 'field')) return ItemID.ANOTHER_FIELD;\n if (hasProp(rhs, 'field')) return ItemID.ANOTHER_FIELD;\n if (hasProp(rhs, 'value') && hasProp(rhs, 'dateFunction')) return ItemID.DATE_PART;\n if (hasProp(rhs, 'parameterId')) return ItemID.PARAMETER;\n if (hasProp(rhs, 'relativeDate')) return ItemID.RELATIVE_DATE;\n return ItemID.LITERAL_VALUE;\n }, [rhs]);\n\n // Determine actions for the menu\n const menu = useMemo<MenuProps>(() => {\n const items: MenuProps['items'] = [];\n\n // Boolean conditions either don't use an rhs or always use the field-selector\n // For IN/NOT_IN comparators, only one mode is possible for a given case - CSV Input or a Value-selector\n // For BTW/NOT_BTW comparator, only range rhs values are possible\n\n if (fieldType !== 'BOOLEAN' && !['IN', 'NOT_IN', 'BTW', 'NOT_BTW'].includes(comparator)) {\n // Literal value input\n if (validRhsTypes.has('LITERAL')) {\n // Literal Value inputs\n items.push({\n id: ItemID.LITERAL_VALUE,\n primary: getValueOptionLabel(fieldType, t),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({ value: '' }); // Submit a new RHS to re-render with the new mode\n },\n selected: currentMode === ItemID.LITERAL_VALUE\n });\n }\n\n // Field selector\n if (validRhsTypes.has('FIELD')) {\n items.push({\n id: ItemID.ANOTHER_FIELD,\n primary: t('condition_builder_compare_with_another_field'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({ field: '' }); // Submit a new RHS to re-render with the new mode\n },\n selected: currentMode === ItemID.ANOTHER_FIELD\n });\n }\n\n // Rhs of PARAMETER type\n if (\n validRhsTypes.has('PARAMETER') &&\n ['EQ', 'NEQ'].includes(comparator) &&\n parameters.length > 0\n ) {\n items.push({\n id: ItemID.PARAMETER,\n primary: t('condition_builder_compare_with_parameter'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n if (parameters.length === 1) onChange({ parameterId: parameters[0].id });\n else onChange({ parameterId: '' }); // Submit a new RHS to re-render with the new mode\n },\n selected: currentMode === ItemID.PARAMETER\n });\n }\n\n // Relative Date value input\n if (\n validRhsTypes.has('RELATIVE_DATE') &&\n (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY')\n ) {\n items.push({\n id: ItemID.RELATIVE_DATE,\n primary: t('condition_builder_compare_with_relative_date'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({\n relativeDate: {\n timePeriod: 'CURRENT',\n datePart: 'DAYS'\n }\n });\n },\n selected: currentMode === ItemID.RELATIVE_DATE\n });\n }\n\n // Date Part value input\n if (\n validRhsTypes.has('DATE_FUNCTION') &&\n dateFunctions &&\n (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY')\n ) {\n items.push({\n id: ItemID.DATE_PART,\n primary: t('condition_builder_date_part'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({ value: '', dateFunction: dateFunctions[fieldType][0] }); // Submit a new RHS to re-render with the new mode. Initializing with the first available date function\n },\n selected: currentMode === ItemID.DATE_PART\n });\n }\n }\n\n return { items, mode: 'single-select' };\n }, [fieldType, comparator, onChange, validRhsTypes, dateFunctions, currentMode, t]);\n\n // Identify current selection for ComboBox\n const selected = useMemo<Selected | undefined>(() => {\n const selectedItem = menuHelpers.getItem(menu.items, currentMode);\n return selectedItem ? { id: selectedItem.id, text: selectedItem.primary } : undefined;\n }, [menu, currentMode]);\n\n // Render the button only when there are multiple options in the menu\n if (menu.items.length < 2) return null;\n\n if (mode === 'combo-box') {\n return (\n <ComboBox\n label={t('condition_builder_compare_with')}\n mode='single-select'\n selected={{ items: selected }}\n menu={menu}\n />\n );\n }\n\n return (\n <MenuButton\n text={t('condition_builder_compare_with')}\n aria-label={selected ? t('condition_builder_compare_with', [selected.text]) : undefined}\n icon='gear'\n iconOnly\n variant='simple'\n menu={menu}\n />\n );\n};\n\nexport default RhsModeSwitch;\n"]}
|
|
1
|
+
{"version":3,"file":"RhsModeSwitch.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/RhsModeSwitch.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAGhC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAc9F,IAAK,MAMJ;AAND,WAAK,MAAM;IAC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,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC;IAExB,qEAAqE;IACrE,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAEvC,IAAI,IAAI,KAAK,WAAW,EAAE;QACxB,OAAO,CACL,KAAC,QAAQ,IACP,KAAK,EAAE,CAAC,CAAC,gCAAgC,CAAC,EAC1C,IAAI,EAAC,eAAe,EACpB,QAAQ,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,EAC7B,IAAI,EAAE,IAAI,GACV,CACH,CAAC;KACH;IAED,OAAO,CACL,KAAC,UAAU,IACT,IAAI,EAAE,CAAC,CAAC,gCAAgC,CAAC,gBAC7B,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,gCAAgC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,EACvF,IAAI,EAAC,MAAM,EACX,QAAQ,QACR,OAAO,EAAC,QAAQ,EAChB,IAAI,EAAE,IAAI,GACV,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { useMemo } from 'react';\nimport type { FunctionComponent } from 'react';\n\nimport { ComboBox, hasProp, MenuButton, menuHelpers, useI18n } from '@pega/cosmos-react-core';\nimport type {\n BaseProps,\n ForwardProps,\n MenuProps,\n NoChildrenProp,\n TranslationPack\n} from '@pega/cosmos-react-core';\nimport type { TranslationFunction } from '@pega/cosmos-react-core/lib/i18n/translate';\nimport type { Selected } from '@pega/cosmos-react-core/lib/components/ComboBox/ComboBox.types';\n\nimport type { Comparator, FieldType, RHSType } from '../core/types';\nimport type { DateFunctionsByType, LeafCondition, ParameterValue } from '../ConditionBuilder.types';\n\nenum ItemID {\n LITERAL_VALUE = 'LITERAL_VALUE',\n DATE_PART = 'DATE_PART',\n RELATIVE_DATE = 'RELATIVE_DATE',\n ANOTHER_FIELD = 'ANOTHER_FIELD',\n PARAMETER = 'PARAMETER'\n}\n\n// Label for the `Enter <value>` option on the gear-menu\nfunction getValueOptionLabel(\n fieldType: FieldType,\n t: TranslationFunction<TranslationPack>\n): string {\n switch (fieldType) {\n case 'TEXT':\n return t('condition_builder_compare_with_text_value');\n case 'NUMBER':\n case 'INTEGER':\n return t('condition_builder_compare_with_numeric_value');\n case 'DATE_TIME':\n case 'DATE_ONLY':\n return t('condition_builder_compare_with_date_value');\n case 'TIME_ONLY':\n return t('condition_builder_compare_with_time_value');\n default:\n return t('condition_builder_value_label'); // Not needed (BOOLEAN is not expected to be passed to the function)\n }\n}\n\ninterface RhsMenuButtonProps extends BaseProps, NoChildrenProp {\n /** Passed Parameters array for Rhstype PARAMETER */\n parameters: ParameterValue[];\n\n /** Type of field on the LHS */\n fieldType: FieldType;\n\n /** Comparator for the condition */\n comparator: Comparator;\n\n /** Rhs for the condition */\n rhs: NonNullable<LeafCondition['rhs']>;\n\n /** Callback for any modifications to the Rhs */\n onChange: (rhs: NonNullable<LeafCondition['rhs']>) => void;\n\n /** Display mode */\n mode: 'combo-box' | 'menu-button';\n\n /** Restricts RHS values to only specified RHS types */\n validRhsTypes: Set<RHSType>;\n\n /** Passed to enable additional date controls on the RHS, when a DATE_TIME/DATE_ONLY field is selected on the LHS */\n dateFunctions?: DateFunctionsByType;\n}\n\n/** Renders a Gear MenuButton on the RHS (when applicable) */\nconst RhsModeSwitch: FunctionComponent<RhsMenuButtonProps & ForwardProps> = ({\n parameters,\n fieldType,\n comparator,\n rhs,\n onChange,\n mode,\n validRhsTypes,\n dateFunctions\n}: RhsMenuButtonProps) => {\n const t = useI18n();\n\n // Identify current mode\n const currentMode = useMemo(() => {\n if (hasProp(rhs, 'field')) return ItemID.ANOTHER_FIELD;\n if (hasProp(rhs, 'field')) return ItemID.ANOTHER_FIELD;\n if (hasProp(rhs, 'value') && hasProp(rhs, 'dateFunction')) return ItemID.DATE_PART;\n if (hasProp(rhs, 'parameterId')) return ItemID.PARAMETER;\n if (hasProp(rhs, 'relativeDate')) return ItemID.RELATIVE_DATE;\n return ItemID.LITERAL_VALUE;\n }, [rhs]);\n\n // Determine actions for the menu\n const menu = useMemo<MenuProps>(() => {\n const items: MenuProps['items'] = [];\n\n // Boolean conditions either don't use an rhs or always use the field-selector\n // For IN/NOT_IN comparators, only one mode is possible for a given case - CSV Input or a Value-selector\n // For BTW/NOT_BTW comparator, only range rhs values are possible\n\n if (fieldType !== 'BOOLEAN' && !['IN', 'NOT_IN', 'BTW', 'NOT_BTW'].includes(comparator)) {\n // Literal value input\n if (validRhsTypes.has('LITERAL')) {\n // Literal Value inputs\n items.push({\n id: ItemID.LITERAL_VALUE,\n primary: getValueOptionLabel(fieldType, t),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({ value: '' }); // Submit a new RHS to re-render with the new mode\n },\n selected: currentMode === ItemID.LITERAL_VALUE\n });\n }\n\n // Field selector\n if (validRhsTypes.has('FIELD')) {\n items.push({\n id: ItemID.ANOTHER_FIELD,\n primary: t('condition_builder_compare_with_another_field'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({ field: '' }); // Submit a new RHS to re-render with the new mode\n },\n selected: currentMode === ItemID.ANOTHER_FIELD\n });\n }\n\n // Rhs of PARAMETER type\n if (\n validRhsTypes.has('PARAMETER') &&\n ['EQ', 'NEQ'].includes(comparator) &&\n parameters.length > 0\n ) {\n items.push({\n id: ItemID.PARAMETER,\n primary: t('condition_builder_compare_with_parameter'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n if (parameters.length === 1) onChange({ parameterId: parameters[0].id });\n else onChange({ parameterId: '' }); // Submit a new RHS to re-render with the new mode\n },\n selected: currentMode === ItemID.PARAMETER\n });\n }\n\n // Relative Date value input\n if (\n validRhsTypes.has('RELATIVE_DATE') &&\n (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY')\n ) {\n items.push({\n id: ItemID.RELATIVE_DATE,\n primary: t('condition_builder_compare_with_relative_date'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({\n relativeDate: {\n timePeriod: 'CURRENT',\n datePart: 'DAYS'\n }\n });\n },\n selected: currentMode === ItemID.RELATIVE_DATE\n });\n }\n\n // Date Part value input\n if (\n validRhsTypes.has('DATE_FUNCTION') &&\n dateFunctions &&\n (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY')\n ) {\n items.push({\n id: ItemID.DATE_PART,\n primary: t('condition_builder_date_part'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({ value: '', dateFunction: dateFunctions[fieldType][0] }); // Submit a new RHS to re-render with the new mode. Initializing with the first available date function\n },\n selected: currentMode === ItemID.DATE_PART\n });\n }\n }\n\n return { items, mode: 'single-select' };\n }, [fieldType, comparator, onChange, validRhsTypes, dateFunctions, currentMode, t]);\n\n // Identify current selection for ComboBox\n const selected = useMemo<Selected | undefined>(() => {\n const selectedItem = menuHelpers.getItem(menu.items, currentMode);\n return selectedItem ? { id: selectedItem.id, text: selectedItem.primary } : undefined;\n }, [menu, currentMode]);\n\n // Render the button only when there are multiple options in the menu\n if (menu.items.length < 2) return null;\n\n if (mode === 'combo-box') {\n return (\n <ComboBox\n label={t('condition_builder_compare_with')}\n mode='single-select'\n selected={{ items: selected }}\n menu={menu}\n />\n );\n }\n\n return (\n <MenuButton\n text={t('condition_builder_compare_with')}\n aria-label={selected ? t('condition_builder_compare_with', [selected.text]) : undefined}\n icon='gear'\n iconOnly\n variant='simple'\n menu={menu}\n />\n );\n};\n\nexport default RhsModeSwitch;\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Dispatch, SetStateAction
|
|
2
|
-
import type { BaseProps, NoChildrenProp, ComboBoxProps
|
|
1
|
+
import type { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import type { BaseProps, NoChildrenProp, ComboBoxProps } from '@pega/cosmos-react-core';
|
|
3
3
|
import type { LeafCondition, ParameterValue, ValueSelection } from '../ConditionBuilder.types';
|
|
4
4
|
import type { Comparator } from '../core/types';
|
|
5
5
|
interface ValueSelectorProps<T extends {
|
|
@@ -33,13 +33,11 @@ interface ValueSelectorProps<T extends {
|
|
|
33
33
|
info?: ComboBoxProps['info'];
|
|
34
34
|
/** sets status and info */
|
|
35
35
|
setApiError?: Dispatch<SetStateAction<string | null>>;
|
|
36
|
-
/** Imperative handle */
|
|
37
|
-
handle?: Ref<HandleValue>;
|
|
38
36
|
}
|
|
39
37
|
/** A control for selecting multiple values using checkboxes in an overlay */
|
|
40
38
|
declare const ValueSelector: <F extends object & {
|
|
41
39
|
id: string;
|
|
42
40
|
possibleValues?: ValueSelection<F> | undefined;
|
|
43
|
-
}>({ values, selectedField, comparator, rhs, onChange, onBlur, onClear, status, mode, parameters, placeholder, label, info, setApiError
|
|
41
|
+
}>({ values, selectedField, comparator, rhs, onChange, onBlur, onClear, status, mode, parameters, placeholder, label, info, setApiError }: ValueSelectorProps<F>) => JSX.Element;
|
|
44
42
|
export default ValueSelector;
|
|
45
43
|
//# sourceMappingURL=ValueSelector.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValueSelector.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/ValueSelector.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"ValueSelector.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/ValueSelector.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAUtD,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,aAAa,EAAa,MAAM,yBAAyB,CAAC;AAEnG,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EAEd,cAAc,EACf,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,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
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useState, useEffect, useRef, useCallback
|
|
3
|
-
import { useI18n, ComboBox, createStringMatcher,
|
|
2
|
+
import { useState, useEffect, useRef, useCallback } from 'react';
|
|
3
|
+
import { useI18n, ComboBox, createStringMatcher, hasProp, Button, Icon } from '@pega/cosmos-react-core';
|
|
4
4
|
/** A control for selecting multiple values using checkboxes in an overlay */
|
|
5
|
-
const ValueSelector = ({ values, selectedField, comparator, rhs, onChange, onBlur, onClear, status, mode, parameters, placeholder, label, info, setApiError
|
|
5
|
+
const ValueSelector = ({ values, selectedField, comparator, rhs, onChange, onBlur, onClear, status, mode, parameters, placeholder, label, info, setApiError }) => {
|
|
6
6
|
const t = useI18n();
|
|
7
7
|
const inputRef = useRef(null);
|
|
8
|
-
const [selections, setSelections] = useState(values);
|
|
9
8
|
const [filterValue, setFilterValue] = useState('');
|
|
10
9
|
const [options, setOptions] = useState([]);
|
|
11
10
|
const [filterOptions, setFilterOptions] = useState([]);
|
|
@@ -17,27 +16,23 @@ const ValueSelector = ({ values, selectedField, comparator, rhs, onChange, onBlu
|
|
|
17
16
|
if (typeof option === 'object') {
|
|
18
17
|
return {
|
|
19
18
|
...option,
|
|
20
|
-
selected: Array.isArray(
|
|
21
|
-
? selections.includes(option.id)
|
|
22
|
-
: selections === option.id
|
|
19
|
+
selected: Array.isArray(values) ? values.includes(option.id) : values === option.id
|
|
23
20
|
};
|
|
24
21
|
}
|
|
25
22
|
return {
|
|
26
23
|
id: option,
|
|
27
24
|
primary: option,
|
|
28
|
-
selected: Array.isArray(
|
|
25
|
+
selected: Array.isArray(values) ? values.includes(option) : values === option
|
|
29
26
|
};
|
|
30
27
|
});
|
|
31
28
|
};
|
|
32
29
|
useEffect(() => {
|
|
33
30
|
const updatedItems = items.map(item => {
|
|
34
|
-
const result = Array.isArray(
|
|
35
|
-
? selections.includes(item.id)
|
|
36
|
-
: selections === item.id;
|
|
31
|
+
const result = Array.isArray(values) ? values.includes(item.id) : values === item.id;
|
|
37
32
|
return { ...item, selected: result };
|
|
38
33
|
});
|
|
39
34
|
setItems(updatedItems);
|
|
40
|
-
}, [
|
|
35
|
+
}, [values]);
|
|
41
36
|
useEffect(() => {
|
|
42
37
|
const matcher = createStringMatcher(filterValue);
|
|
43
38
|
setFilterOptions(options.filter(option => {
|
|
@@ -46,13 +41,9 @@ const ValueSelector = ({ values, selectedField, comparator, rhs, onChange, onBlu
|
|
|
46
41
|
return matcher.test(option);
|
|
47
42
|
}));
|
|
48
43
|
}, [filterValue, options]);
|
|
49
|
-
useAfterInitialEffect(() => {
|
|
50
|
-
onChange(selections);
|
|
51
|
-
}, [selections]);
|
|
52
44
|
useEffect(() => {
|
|
53
|
-
if (!selectedField)
|
|
45
|
+
if (!selectedField)
|
|
54
46
|
return;
|
|
55
|
-
}
|
|
56
47
|
let subscribed = true;
|
|
57
48
|
if (hasProp(rhs, 'parameterId')) {
|
|
58
49
|
setOptions(parameters);
|
|
@@ -91,29 +82,29 @@ const ValueSelector = ({ values, selectedField, comparator, rhs, onChange, onBlu
|
|
|
91
82
|
}, [filterValue, selectedField.id, comparator]);
|
|
92
83
|
useEffect(() => setFilterValue(''), [selectedField, comparator]);
|
|
93
84
|
const getSelections = () => {
|
|
94
|
-
if (typeof
|
|
85
|
+
if (typeof values === 'string') {
|
|
95
86
|
let itemLabel;
|
|
96
87
|
if (hasProp(rhs, 'parameterId')) {
|
|
97
|
-
const selectedItem = parameters.find(item => item.id ===
|
|
98
|
-
itemLabel = selectedItem !== undefined ? selectedItem.primary :
|
|
88
|
+
const selectedItem = parameters.find(item => item.id === values);
|
|
89
|
+
itemLabel = selectedItem !== undefined ? selectedItem.primary : values;
|
|
99
90
|
}
|
|
100
91
|
else
|
|
101
|
-
itemLabel =
|
|
92
|
+
itemLabel = values;
|
|
102
93
|
return {
|
|
103
|
-
items: { id:
|
|
94
|
+
items: { id: values, text: itemLabel }
|
|
104
95
|
};
|
|
105
96
|
}
|
|
106
|
-
if (
|
|
97
|
+
if (values.length > 0) {
|
|
107
98
|
return {
|
|
108
|
-
items:
|
|
99
|
+
items: values.map(s => {
|
|
109
100
|
const optionLabel = options.find(opt => typeof opt === 'object' && opt.id === s);
|
|
110
101
|
return { id: s, text: optionLabel?.primary ?? s };
|
|
111
102
|
}),
|
|
112
103
|
onRemove: (value) => {
|
|
113
|
-
|
|
114
|
-
const current =
|
|
104
|
+
onChange((() => {
|
|
105
|
+
const current = values;
|
|
115
106
|
return current.filter(selection => selection !== value);
|
|
116
|
-
});
|
|
107
|
+
})());
|
|
117
108
|
}
|
|
118
109
|
};
|
|
119
110
|
}
|
|
@@ -150,11 +141,6 @@ const ValueSelector = ({ values, selectedField, comparator, rhs, onChange, onBlu
|
|
|
150
141
|
});
|
|
151
142
|
}
|
|
152
143
|
}, [options, loading, filterOptions, items, hasMore]);
|
|
153
|
-
useImperativeHandle(handle, () => ({
|
|
154
|
-
clear: () => {
|
|
155
|
-
setSelections([]);
|
|
156
|
-
}
|
|
157
|
-
}), []);
|
|
158
144
|
return (_jsx(ComboBox, { ref: inputRef, mode: mode, label: label ?? t('condition_builder_possible_values_label'), placeholder: placeholder ??
|
|
159
145
|
(mode === 'single-select'
|
|
160
146
|
? t('condition_builder_single_selection_text_default')
|
|
@@ -162,29 +148,29 @@ const ValueSelector = ({ values, selectedField, comparator, rhs, onChange, onBlu
|
|
|
162
148
|
setFilterValue(e.target.value);
|
|
163
149
|
setHasMore(true);
|
|
164
150
|
}, onBlur: () => {
|
|
165
|
-
onBlur?.(
|
|
151
|
+
onBlur?.(values);
|
|
166
152
|
setFilterValue('');
|
|
167
153
|
}, menu: {
|
|
168
154
|
items,
|
|
169
155
|
onItemClick: id => {
|
|
170
156
|
if (mode === 'single-select') {
|
|
171
157
|
setFilterValue('');
|
|
172
|
-
|
|
158
|
+
onChange(id);
|
|
173
159
|
}
|
|
174
160
|
else {
|
|
175
|
-
|
|
176
|
-
const current =
|
|
161
|
+
onChange((() => {
|
|
162
|
+
const current = values;
|
|
177
163
|
return current.includes(id)
|
|
178
164
|
? current.filter(selection => selection !== id)
|
|
179
|
-
: [...
|
|
180
|
-
});
|
|
165
|
+
: [...values, id];
|
|
166
|
+
})());
|
|
181
167
|
}
|
|
182
168
|
},
|
|
183
169
|
loading,
|
|
184
170
|
loadMore: hasMore ? loadMore : undefined
|
|
185
171
|
}, selected: getSelections(), status: status, info: info, actions: onClear &&
|
|
186
|
-
|
|
187
|
-
|
|
172
|
+
values.length > 0 && (_jsx(Button, { icon: true, variant: 'simple', label: t('clear'), onClick: () => {
|
|
173
|
+
onChange([]);
|
|
188
174
|
onClear();
|
|
189
175
|
if (inputRef.current) {
|
|
190
176
|
const inputEl = inputRef.current.querySelector('input');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValueSelector.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/ValueSelector.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AAGtF,OAAO,EACL,OAAO,EACP,QAAQ,EACR,mBAAmB,EACnB,qBAAqB,EACrB,OAAO,EACP,MAAM,EACN,IAAI,EACL,MAAM,yBAAyB,CAAC;AAmDjC,6EAA6E;AAC7E,MAAM,aAAa,GAAG,CAAwE,EAC5F,MAAM,EACN,aAAa,EACb,UAAU,EACV,GAAG,EACH,QAAQ,EACR,MAAM,EACN,OAAO,EACP,MAAM,EACN,IAAI,EACJ,UAAU,EACV,WAAW,EACX,KAAK,EACL,IAAI,EACJ,WAAW,EACX,MAAM,EACgB,EAAE,EAAE;IAC1B,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IAEpB,MAAM,QAAQ,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAE9C,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAoB,MAAM,CAAC,CAAC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AAC,QAAQ,EAChB,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,EACjB,OAAO,EAAE,GAAG,EAAE;gBACZ,aAAa,CAAC,EAAE,CAAC,CAAC;gBAClB,OAAO,EAAE,CAAC;gBACV,IAAI,QAAQ,CAAC,OAAO,EAAE;oBACpB,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;oBACxD,OAAO,EAAE,KAAK,EAAE,CAAC;iBAClB;YACH,CAAC,YAED,KAAC,IAAI,IAAC,IAAI,EAAC,OAAO,GAAG,GACd,CACV,GAEH,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { useState, useEffect, useRef, useCallback, useImperativeHandle } from 'react';\nimport type { Dispatch, SetStateAction, Ref } from 'react';\n\nimport {\n useI18n,\n ComboBox,\n createStringMatcher,\n useAfterInitialEffect,\n hasProp,\n Button,\n Icon\n} from '@pega/cosmos-react-core';\nimport type {\n BaseProps,\n NoChildrenProp,\n ComboBoxProps,\n MenuProps,\n HandleValue\n} from '@pega/cosmos-react-core';\n\nimport type {\n LeafCondition,\n ParameterValue,\n ReferenceValue,\n ValueSelection\n} from '../ConditionBuilder.types';\nimport type { Comparator } from '../core/types';\n\ninterface ValueSelectorProps<T extends { id: string; possibleValues?: ValueSelection<T> }>\n extends BaseProps,\n NoChildrenProp {\n mode: ComboBoxProps['mode'];\n /** Previous selection */\n values: string[] | string;\n /** Current selected LHS */\n selectedField: T;\n /** Current selected comparator */\n comparator: Comparator;\n /** Rhs for the condition */\n rhs: NonNullable<LeafCondition['rhs']>;\n /** Passed Parameters array for Rhstype PARAMETER */\n parameters: ParameterValue[];\n /** Callback for changes */\n onChange: (selection: string[] | string) => void;\n /** Callback for blur */\n onBlur?: (selection?: string[] | string) => void;\n /** Callback for clear */\n onClear?: () => void;\n /** Used to indicate any errors on the control */\n status?: 'error';\n /** Placeholder text to display in empty control */\n placeholder?: ComboBoxProps['placeholder'];\n /** Custom label for input. Makes label visible if provided. */\n label?: ComboBoxProps['label'];\n /** Guidance text that apppears below the input. */\n info?: ComboBoxProps['info'];\n /** sets status and info */\n setApiError?: Dispatch<SetStateAction<string | null>>;\n /** Imperative handle */\n handle?: Ref<HandleValue>;\n}\n\n/** A control for selecting multiple values using checkboxes in an overlay */\nconst ValueSelector = <F extends object & { id: string; possibleValues?: ValueSelection<F> }>({\n values,\n selectedField,\n comparator,\n rhs,\n onChange,\n onBlur,\n onClear,\n status,\n mode,\n parameters,\n placeholder,\n label,\n info,\n setApiError,\n handle\n}: ValueSelectorProps<F>) => {\n const t = useI18n();\n\n const inputRef = useRef<HTMLDivElement>(null);\n\n const [selections, setSelections] = useState<string[] | string>(values);\n const [filterValue, setFilterValue] = useState('');\n const [options, setOptions] = useState<(string | ParameterValue | ReferenceValue)[]>([]);\n const [filterOptions, setFilterOptions] = useState<(string | ParameterValue | ReferenceValue)[]>(\n []\n );\n const [loading, setLoading] = useState(false);\n const [hasMore, setHasMore] = useState(true);\n const [items, setItems] = useState<MenuProps['items']>([]);\n\n const itemsToRender = (item: (string | ParameterValue | ReferenceValue)[]) => {\n return item.map(option => {\n if (typeof option === 'object') {\n return {\n ...option,\n selected: Array.isArray(selections)\n ? selections.includes(option.id)\n : selections === option.id\n };\n }\n return {\n id: option,\n primary: option,\n selected: Array.isArray(selections) ? selections.includes(option) : selections === option\n };\n });\n };\n\n useEffect(() => {\n const updatedItems = items.map(item => {\n const result = Array.isArray(selections)\n ? selections.includes(item.id)\n : selections === item.id;\n return { ...item, selected: result };\n });\n setItems(updatedItems);\n }, [selections]);\n\n useEffect(() => {\n const matcher = createStringMatcher(filterValue);\n setFilterOptions(\n options.filter(option => {\n if (typeof option === 'object') return matcher.test(option.primary);\n return matcher.test(option);\n })\n );\n }, [filterValue, options]);\n\n useAfterInitialEffect(() => {\n onChange(selections);\n }, [selections]);\n\n useEffect(() => {\n if (!selectedField) {\n return;\n }\n let subscribed = true;\n\n if (hasProp(rhs, 'parameterId')) {\n setOptions(parameters);\n } else if (hasProp(selectedField, 'possibleValues')) {\n const { possibleValues } = selectedField;\n if (typeof possibleValues === 'function') {\n setLoading(true);\n setOptions([]);\n possibleValues({ searchString: filterValue, comparator, lhs: selectedField })\n .then(response => {\n if (!subscribed) return;\n setOptions(response);\n setLoading(false);\n })\n .catch(err => {\n if (err && subscribed) {\n setApiError?.(t('condition_builder_possible_values_error'));\n setOptions([]);\n setLoading(false);\n }\n });\n } else if (Array.isArray(possibleValues)) {\n setOptions(possibleValues);\n } else {\n setOptions([]);\n }\n }\n\n return () => {\n subscribed = false;\n setApiError?.(null);\n };\n }, [filterValue, selectedField.id, comparator]);\n\n useEffect(() => setFilterValue(''), [selectedField, comparator]);\n\n const getSelections = () => {\n if (typeof selections === 'string') {\n let itemLabel;\n if (hasProp(rhs, 'parameterId')) {\n const selectedItem = parameters.find(item => item.id === selections);\n itemLabel = selectedItem !== undefined ? selectedItem.primary : selections;\n } else itemLabel = selections;\n\n return {\n items: { id: selections, text: itemLabel }\n };\n }\n if (selections.length > 0) {\n return {\n items: selections.map(s => {\n const optionLabel = options.find(opt => typeof opt === 'object' && opt.id === s) as\n | ParameterValue\n | ReferenceValue\n | undefined;\n return { id: s, text: optionLabel?.primary ?? s };\n }),\n onRemove: (value: string) => {\n setSelections(cur => {\n const current = cur as string[];\n return current.filter(selection => selection !== value);\n });\n }\n };\n }\n\n return undefined;\n };\n\n useEffect(() => {\n if (filterValue !== '') {\n setItems(itemsToRender(filterOptions.slice(0, 10)));\n } else {\n setItems(itemsToRender(options.slice(0, 10)));\n }\n }, [options, filterOptions]);\n\n const loadMore = useCallback(() => {\n if (!loading) {\n setLoading(true);\n\n let totalItem: (string | ParameterValue | ReferenceValue)[];\n if (filterOptions.length > 0) totalItem = filterOptions;\n else totalItem = options;\n\n const remItems = totalItem.length - items.length;\n let newItemsLength = 10;\n if (remItems <= newItemsLength) {\n setHasMore(false);\n newItemsLength = remItems;\n }\n\n setLoading(false);\n setItems(prev => {\n return [\n ...prev,\n ...itemsToRender(totalItem.slice(items.length, items.length + newItemsLength))\n ];\n });\n }\n }, [options, loading, filterOptions, items, hasMore]);\n\n useImperativeHandle(\n handle,\n () => ({\n clear: () => {\n setSelections([]);\n }\n }),\n []\n );\n\n return (\n <ComboBox\n ref={inputRef}\n mode={mode}\n label={label ?? t('condition_builder_possible_values_label')}\n placeholder={\n placeholder ??\n (mode === 'single-select'\n ? t('condition_builder_single_selection_text_default')\n : t('condition_builder_multi_selection_text_default'))\n }\n value={filterValue}\n onChange={e => {\n setFilterValue(e.target.value);\n setHasMore(true);\n }}\n onBlur={() => {\n onBlur?.(selections);\n setFilterValue('');\n }}\n menu={{\n items,\n onItemClick: id => {\n if (mode === 'single-select') {\n setFilterValue('');\n setSelections(id);\n } else {\n setSelections(cur => {\n const current = cur as string[];\n return current.includes(id)\n ? current.filter(selection => selection !== id)\n : [...cur, id];\n });\n }\n },\n loading,\n loadMore: hasMore ? loadMore : undefined\n }}\n selected={getSelections()}\n status={status}\n info={info}\n actions={\n onClear &&\n selections.length > 0 && (\n <Button\n icon\n variant='simple'\n label={t('clear')}\n onClick={() => {\n setSelections([]);\n onClear();\n if (inputRef.current) {\n const inputEl = inputRef.current.querySelector('input');\n inputEl?.focus();\n }\n }}\n >\n <Icon name='times' />\n </Button>\n )\n }\n />\n );\n};\n\nexport default ValueSelector;\n"]}
|
|
1
|
+
{"version":3,"file":"ValueSelector.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/ValueSelector.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAGjE,OAAO,EACL,OAAO,EACP,QAAQ,EACR,mBAAmB,EACnB,OAAO,EACP,MAAM,EACN,IAAI,EACL,MAAM,yBAAyB,CAAC;AA2CjC,6EAA6E;AAC7E,MAAM,aAAa,GAAG,CAAwE,EAC5F,MAAM,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ChB,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,EACjB,OAAO,EAAE,GAAG,EAAE;gBACZ,QAAQ,CAAC,EAAE,CAAC,CAAC;gBACb,OAAO,EAAE,CAAC;gBACV,IAAI,QAAQ,CAAC,OAAO,EAAE;oBACpB,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;oBACxD,OAAO,EAAE,KAAK,EAAE,CAAC;iBAClB;YACH,CAAC,YAED,KAAC,IAAI,IAAC,IAAI,EAAC,OAAO,GAAG,GACd,CACV,GAEH,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { useState, useEffect, useRef, useCallback } from 'react';\nimport type { Dispatch, SetStateAction } from 'react';\n\nimport {\n useI18n,\n ComboBox,\n createStringMatcher,\n hasProp,\n Button,\n Icon\n} from '@pega/cosmos-react-core';\nimport type { BaseProps, NoChildrenProp, ComboBoxProps, MenuProps } from '@pega/cosmos-react-core';\n\nimport type {\n LeafCondition,\n ParameterValue,\n ReferenceValue,\n ValueSelection\n} from '../ConditionBuilder.types';\nimport type { Comparator } from '../core/types';\n\ninterface ValueSelectorProps<T extends { id: string; possibleValues?: ValueSelection<T> }>\n extends BaseProps,\n NoChildrenProp {\n mode: ComboBoxProps['mode'];\n /** Previous selection */\n values: string[] | string;\n /** Current selected LHS */\n selectedField: T;\n /** Current selected comparator */\n comparator: Comparator;\n /** Rhs for the condition */\n rhs: NonNullable<LeafCondition['rhs']>;\n /** Passed Parameters array for Rhstype PARAMETER */\n parameters: ParameterValue[];\n /** Callback for changes */\n onChange: (selection: string[] | string) => void;\n /** Callback for blur */\n onBlur?: (selection?: string[] | string) => void;\n /** Callback for clear */\n onClear?: () => void;\n /** Used to indicate any errors on the control */\n status?: 'error';\n /** Placeholder text to display in empty control */\n placeholder?: ComboBoxProps['placeholder'];\n /** Custom label for input. Makes label visible if provided. */\n label?: ComboBoxProps['label'];\n /** Guidance text that apppears below the input. */\n info?: ComboBoxProps['info'];\n /** sets status and info */\n setApiError?: Dispatch<SetStateAction<string | null>>;\n}\n\n/** A control for selecting multiple values using checkboxes in an overlay */\nconst ValueSelector = <F extends object & { id: string; possibleValues?: ValueSelection<F> }>({\n values,\n selectedField,\n comparator,\n rhs,\n onChange,\n onBlur,\n onClear,\n status,\n mode,\n parameters,\n placeholder,\n label,\n info,\n setApiError\n}: ValueSelectorProps<F>) => {\n const t = useI18n();\n\n const inputRef = useRef<HTMLDivElement>(null);\n\n const [filterValue, setFilterValue] = useState('');\n const [options, setOptions] = useState<(string | ParameterValue | ReferenceValue)[]>([]);\n const [filterOptions, setFilterOptions] = useState<(string | ParameterValue | ReferenceValue)[]>(\n []\n );\n const [loading, setLoading] = useState(false);\n const [hasMore, setHasMore] = useState(true);\n const [items, setItems] = useState<MenuProps['items']>([]);\n\n const itemsToRender = (item: (string | ParameterValue | ReferenceValue)[]) => {\n return item.map(option => {\n if (typeof option === 'object') {\n return {\n ...option,\n selected: Array.isArray(values) ? values.includes(option.id) : values === option.id\n };\n }\n return {\n id: option,\n primary: option,\n selected: Array.isArray(values) ? values.includes(option) : values === option\n };\n });\n };\n\n useEffect(() => {\n const updatedItems = items.map(item => {\n const result = Array.isArray(values) ? values.includes(item.id) : values === item.id;\n return { ...item, selected: result };\n });\n setItems(updatedItems);\n }, [values]);\n\n useEffect(() => {\n const matcher = createStringMatcher(filterValue);\n setFilterOptions(\n options.filter(option => {\n if (typeof option === 'object') return matcher.test(option.primary);\n return matcher.test(option);\n })\n );\n }, [filterValue, options]);\n\n useEffect(() => {\n if (!selectedField) return;\n let subscribed = true;\n\n if (hasProp(rhs, 'parameterId')) {\n setOptions(parameters);\n } else if (hasProp(selectedField, 'possibleValues')) {\n const { possibleValues } = selectedField;\n if (typeof possibleValues === 'function') {\n setLoading(true);\n setOptions([]);\n possibleValues({ searchString: filterValue, comparator, lhs: selectedField })\n .then(response => {\n if (!subscribed) return;\n setOptions(response);\n setLoading(false);\n })\n .catch(err => {\n if (err && subscribed) {\n setApiError?.(t('condition_builder_possible_values_error'));\n setOptions([]);\n setLoading(false);\n }\n });\n } else if (Array.isArray(possibleValues)) {\n setOptions(possibleValues);\n } else {\n setOptions([]);\n }\n }\n\n return () => {\n subscribed = false;\n setApiError?.(null);\n };\n }, [filterValue, selectedField.id, comparator]);\n\n useEffect(() => setFilterValue(''), [selectedField, comparator]);\n\n const getSelections = () => {\n if (typeof values === 'string') {\n let itemLabel;\n if (hasProp(rhs, 'parameterId')) {\n const selectedItem = parameters.find(item => item.id === values);\n itemLabel = selectedItem !== undefined ? selectedItem.primary : values;\n } else itemLabel = values;\n\n return {\n items: { id: values, text: itemLabel }\n };\n }\n if (values.length > 0) {\n return {\n items: values.map(s => {\n const optionLabel = options.find(opt => typeof opt === 'object' && opt.id === s) as\n | ParameterValue\n | ReferenceValue\n | undefined;\n return { id: s, text: optionLabel?.primary ?? s };\n }),\n onRemove: (value: string) => {\n onChange(\n (() => {\n const current = values as string[];\n return current.filter(selection => selection !== value) as string | string[];\n })()\n );\n }\n };\n }\n\n return undefined;\n };\n\n useEffect(() => {\n if (filterValue !== '') {\n setItems(itemsToRender(filterOptions.slice(0, 10)));\n } else {\n setItems(itemsToRender(options.slice(0, 10)));\n }\n }, [options, filterOptions]);\n\n const loadMore = useCallback(() => {\n if (!loading) {\n setLoading(true);\n\n let totalItem: (string | ParameterValue | ReferenceValue)[];\n if (filterOptions.length > 0) totalItem = filterOptions;\n else totalItem = options;\n\n const remItems = totalItem.length - items.length;\n let newItemsLength = 10;\n if (remItems <= newItemsLength) {\n setHasMore(false);\n newItemsLength = remItems;\n }\n\n setLoading(false);\n setItems(prev => {\n return [\n ...prev,\n ...itemsToRender(totalItem.slice(items.length, items.length + newItemsLength))\n ];\n });\n }\n }, [options, loading, filterOptions, items, hasMore]);\n\n return (\n <ComboBox\n ref={inputRef}\n mode={mode}\n label={label ?? t('condition_builder_possible_values_label')}\n placeholder={\n placeholder ??\n (mode === 'single-select'\n ? t('condition_builder_single_selection_text_default')\n : t('condition_builder_multi_selection_text_default'))\n }\n value={filterValue}\n onChange={e => {\n setFilterValue(e.target.value);\n setHasMore(true);\n }}\n onBlur={() => {\n onBlur?.(values);\n setFilterValue('');\n }}\n menu={{\n items,\n onItemClick: id => {\n if (mode === 'single-select') {\n setFilterValue('');\n onChange(id);\n } else {\n onChange(\n (() => {\n const current = values as string[];\n return current.includes(id)\n ? current.filter(selection => selection !== id)\n : [...values, id];\n })()\n );\n }\n },\n loading,\n loadMore: hasMore ? loadMore : undefined\n }}\n selected={getSelections()}\n status={status}\n info={info}\n actions={\n onClear &&\n values.length > 0 && (\n <Button\n icon\n variant='simple'\n label={t('clear')}\n onClick={() => {\n onChange([]);\n onClear();\n if (inputRef.current) {\n const inputEl = inputRef.current.querySelector('input');\n inputEl?.focus();\n }\n }}\n >\n <Icon name='times' />\n </Button>\n )\n }\n />\n );\n};\n\nexport default ValueSelector;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAe,GAAG,EAAE,MAAM,OAAO,CAAC;AAcjE,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAMpF,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAyC3F;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,EACzB,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,EACzB,MAAM,EAAE,KAAK,EAAE,EACf,SAAS,CAAC,EAAE,SAAS,EACrB,UAAU,GAAE,OA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AChD,QAAQ,EAAE,CAAC,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAEhE,+DAA+D;IAC/D,cAAc,EAAE,OAAO,CAAC;IAExB,0BAA0B;IAC1B,aAAa,EAAE,KAAK,GAAG,QAAQ,CAAC;IAEhC,uDAAuD;IACvD,aAAa,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAE5B,oHAAoH;IACpH,aAAa,CAAC,EAAE,mBAAmB,CAAC;IAEpC,wBAAwB;IACxB,MAAM,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;CAC3B;AAED,+DAA+D;AAC/D,QAAA,MAAM,WAAW,EAAE,iBAAiB,CAAC,eAAe,GAAG,YAAY,CAwalE,CAAC;AACF,eAAe,WAAW,CAAC"}
|
|
@@ -67,7 +67,8 @@ export function isValidRhs(rhs, lhs, fields, fieldType, trimValues = false) {
|
|
|
67
67
|
return false;
|
|
68
68
|
}
|
|
69
69
|
// For numeric fields, RHS is invalid if any NaN values are present in the list
|
|
70
|
-
if (fieldType === 'NUMBER'
|
|
70
|
+
if ((fieldType === 'NUMBER' || fieldType === 'INTEGER') &&
|
|
71
|
+
rhs.values.some(v => Number.isNaN(v))) {
|
|
71
72
|
return false;
|
|
72
73
|
}
|
|
73
74
|
}
|
|
@@ -304,7 +305,7 @@ const RhsControls = (props) => {
|
|
|
304
305
|
.split(',')
|
|
305
306
|
.map(v => v.trim())
|
|
306
307
|
.filter(v => v.length > 0); // Ignore empty strings
|
|
307
|
-
if (fieldType === 'NUMBER') {
|
|
308
|
+
if (fieldType === 'NUMBER' || fieldType === 'INTEGER') {
|
|
308
309
|
newValues = newValues.map(v => Number(v)); // This can set up some NaN values. Those are used to show an appropriate feedback when the submit button is hit
|
|
309
310
|
}
|
|
310
311
|
onChange({ values: newValues });
|
|
@@ -317,8 +318,8 @@ const RhsControls = (props) => {
|
|
|
317
318
|
alignItems: itemDirection === 'column' ? 'stretch' : alignItems,
|
|
318
319
|
justify: 'between',
|
|
319
320
|
gap: 0.5
|
|
320
|
-
}, children: [_jsx(RhsModeSwitch, { parameters: parameters, fieldType: fieldType, comparator: comparator, rhs: rhs, onChange: onChange, mode: itemDirection === 'column' ? 'combo-box' : 'menu-button', validRhsTypes: validRhsTypes, dateFunctions: dateFunctions }), hasProp(rhs, 'field') && (_jsx(Flex, { item: { grow: 1 }, children: _jsx(FieldSelector, { value: rhs.field, onChange: handleFieldChange, fields: fieldOptions, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_no_selection') : undefined, label: t('condition_builder_value_label') }) })), hasProp(rhs, 'parameterId') && (_jsxs(Flex, { item: { grow: 1 }, children: [parameters.length === 1 && (_jsx(Input, { value: parameters[0].primary.toString(), status: showError ? 'error' : undefined, info: showError ? t('condition_builder_empty_value_text') : undefined, name: 'rhs-text-parameter-input', label: t('condition_builder_value_label'), readOnly: true })), parameters.length > 1 && (_jsx(ValueSelector, { parameters: parameters, mode: 'single-select', values: rhs.parameterId.toString(), selectedField: matchingField, rhs: rhs, comparator: comparator, onChange: handleValueSelection, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_empty_selection_error_text') : undefined,
|
|
321
|
-
(hasProp(rhs, 'relativeDate') || hasProp(rhs, 'dateFunction')) && (_jsx(Flex, { item: { grow: 1 }, children: _jsx(TimePeriodComp, { rhs: rhs, fieldType: fieldType, onChange: onChange, dateFunctionsList: dateFunctions ? dateFunctions[fieldType] : [], status: showError ? 'error' : undefined }) })), hasProp(rhs, 'values') && (_jsxs(Flex, { item: { grow: 1 }, children: [useValueSelector && (_jsx(ValueSelector, { parameters: parameters, mode: 'multi-select', values: rhs.values.map(String), selectedField: matchingField, comparator: comparator, rhs: rhs, onChange: handleValueSelection, status: showError || apiError ? 'error' : undefined, info: showError ? t('condition_builder_no_selection') : apiError, setApiError: setApiError,
|
|
321
|
+
}, children: [_jsx(RhsModeSwitch, { parameters: parameters, fieldType: fieldType, comparator: comparator, rhs: rhs, onChange: onChange, mode: itemDirection === 'column' ? 'combo-box' : 'menu-button', validRhsTypes: validRhsTypes, dateFunctions: dateFunctions }), hasProp(rhs, 'field') && (_jsx(Flex, { item: { grow: 1 }, children: _jsx(FieldSelector, { value: rhs.field, onChange: handleFieldChange, fields: fieldOptions, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_no_selection') : undefined, label: t('condition_builder_value_label') }) })), hasProp(rhs, 'parameterId') && (_jsxs(Flex, { item: { grow: 1 }, children: [parameters.length === 1 && (_jsx(Input, { value: parameters[0].primary.toString(), status: showError ? 'error' : undefined, info: showError ? t('condition_builder_empty_value_text') : undefined, name: 'rhs-text-parameter-input', label: t('condition_builder_value_label'), readOnly: true })), parameters.length > 1 && (_jsx(ValueSelector, { parameters: parameters, mode: 'single-select', values: rhs.parameterId.toString(), selectedField: matchingField, rhs: rhs, comparator: comparator, onChange: handleValueSelection, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_empty_selection_error_text') : undefined, label: t('condition_builder_value_label') }))] })), hasProp(rhs, 'value') && !hasProp(rhs, 'dateFunction') && (_jsxs(Flex, { item: { grow: 1 }, children: [fieldType === 'TEXT' && useValueSelector && (_jsx(ValueSelector, { parameters: parameters, mode: 'single-select', values: rhs.value.toString(), selectedField: matchingField, comparator: comparator, rhs: rhs, onChange: handleValueSelection, status: showError || apiError ? 'error' : undefined, info: showError ? t('condition_builder_no_selection') : apiError, setApiError: setApiError, label: t('condition_builder_value_label') })), fieldType === 'TEXT' && !useValueSelector && (_jsx(Input, { value: rhs.value.toString(), onChange: handleValueChange, status: showError ? 'error' : undefined, info: showError ? t('empty_value') : undefined, name: 'rhs-text-literal-input', label: t('condition_builder_value_label') })), (fieldType === 'NUMBER' || fieldType === 'INTEGER') && (_jsx(NumericInput, { rhs: rhs, onChange: onChange, allowDecimal: fieldType !== 'INTEGER', status: showError ? 'error' : undefined })), fieldType === 'TIME_ONLY' && (_jsx(TimeInput, { value: rhs.value !== '' ? convertMsToTimeValue(Number(rhs.value)) : undefined, withSeconds: true, onChange: handleDateValueChange, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_invalid_time') : '', label: t('condition_builder_value_label') })), fieldType === 'DATE_ONLY' && (_jsx(DateInput, { value: rhs.value, onChange: handleDateValueChange, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_invalid_date') : '', label: t('condition_builder_value_label') })), fieldType === 'DATE_TIME' && (_jsx(DateTimeInput, { value: rhs.value !== '' ? rhs.value : undefined, onChange: handleDateValueChange, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_invalid_date') : '', label: t('condition_builder_value_label') }))] })), (fieldType === 'DATE_ONLY' || fieldType === 'DATE_TIME') &&
|
|
322
|
+
(hasProp(rhs, 'relativeDate') || hasProp(rhs, 'dateFunction')) && (_jsx(Flex, { item: { grow: 1 }, children: _jsx(TimePeriodComp, { rhs: rhs, fieldType: fieldType, onChange: onChange, dateFunctionsList: dateFunctions ? dateFunctions[fieldType] : [], status: showError ? 'error' : undefined }) })), hasProp(rhs, 'values') && (_jsxs(Flex, { item: { grow: 1 }, children: [useValueSelector && (_jsx(ValueSelector, { parameters: parameters, mode: 'multi-select', values: rhs.values.map(String), selectedField: matchingField, comparator: comparator, rhs: rhs, onChange: handleValueSelection, status: showError || apiError ? 'error' : undefined, info: showError ? t('condition_builder_no_selection') : apiError, setApiError: setApiError, label: t('condition_builder_value_label') })), !useValueSelector && (_jsx(Input, { value: csvInput, onChange: handleCSVChange, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_invalid_values') : undefined, label: t('condition_builder_value_label'), placeholder: t('condition_builder_enter_csv_placeholder') }))] })), hasProp(rhs, 'start') && (_jsxs(Flex, { item: { grow: 1 }, children: [(fieldType === 'NUMBER' || fieldType === 'INTEGER') && (_jsx(NumberRangeInput, { value: { start: rhs.start.toString(), end: rhs.end.toString() }, onChange: handleNumberRangeValueChange, status: showError ? 'error' : undefined, label: t('condition_builder_value_label'), info: showError ? t('condition_builder_invalid_number_range') : undefined, handle: handle, numberOfDecimals: fieldType === 'INTEGER' ? 0 : undefined })), fieldType === 'DATE_ONLY' && (_jsx(DateRangeInput, { value: { start: rhs.start, end: rhs.end }, onChange: handleDateRangeValueChange, label: t('condition_builder_value_label'), status: showError ? 'error' : undefined, info: showError ? t('condition_builder_invalid_date_range') : '' })), fieldType === 'TIME_ONLY' && (_jsx(TimeRangeInput, { mode: 'time', value: {
|
|
322
323
|
start: rhs.start === '' ? undefined : rhs.start,
|
|
323
324
|
end: rhs.end === '' ? undefined : rhs.end
|
|
324
325
|
}, onChange: handleDateRangeValueChange, label: t('condition_builder_value_label'), status: showError ? 'error' : undefined, info: showError ? t('condition_builder_invalid_time_range') : '' })), fieldType === 'DATE_TIME' && (_jsx(TimeRangeInput, { mode: 'datetime', value: { start: rhs.start, end: rhs.end }, onChange: handleDateRangeValueChange, label: t('condition_builder_value_label'), status: showError ? 'error' : undefined, info: showError ? t('condition_builder_invalid_date_range') : '' }))] }))] }));
|