@pega/cosmos-react-condition-builder 3.0.0-dev.9.1 → 3.0.0-rc.10

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.
Files changed (110) hide show
  1. package/lib/components/ConditionBuilder/AtomicCondition.d.ts +6 -4
  2. package/lib/components/ConditionBuilder/AtomicCondition.d.ts.map +1 -1
  3. package/lib/components/ConditionBuilder/AtomicCondition.js +31 -21
  4. package/lib/components/ConditionBuilder/AtomicCondition.js.map +1 -1
  5. package/lib/components/ConditionBuilder/ConditionBuilder.d.ts.map +1 -1
  6. package/lib/components/ConditionBuilder/ConditionBuilder.js +15 -41
  7. package/lib/components/ConditionBuilder/ConditionBuilder.js.map +1 -1
  8. package/lib/components/ConditionBuilder/ConditionBuilder.styles.d.ts +5 -0
  9. package/lib/components/ConditionBuilder/ConditionBuilder.styles.d.ts.map +1 -0
  10. package/lib/components/ConditionBuilder/ConditionBuilder.styles.js +44 -0
  11. package/lib/components/ConditionBuilder/ConditionBuilder.styles.js.map +1 -0
  12. package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts +41 -20
  13. package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts.map +1 -1
  14. package/lib/components/ConditionBuilder/ConditionBuilder.types.js.map +1 -1
  15. package/lib/components/ConditionBuilder/FieldCondition.d.ts.map +1 -1
  16. package/lib/components/ConditionBuilder/FieldCondition.js +12 -12
  17. package/lib/components/ConditionBuilder/FieldCondition.js.map +1 -1
  18. package/lib/components/ConditionBuilder/FieldCondition.types.d.ts +11 -4
  19. package/lib/components/ConditionBuilder/FieldCondition.types.d.ts.map +1 -1
  20. package/lib/components/ConditionBuilder/FieldCondition.types.js.map +1 -1
  21. package/lib/components/ConditionBuilder/RhsControls/FieldSelector.d.ts.map +1 -1
  22. package/lib/components/ConditionBuilder/RhsControls/FieldSelector.js +13 -20
  23. package/lib/components/ConditionBuilder/RhsControls/FieldSelector.js.map +1 -1
  24. package/lib/components/ConditionBuilder/RhsControls/NumericInput.d.ts.map +1 -1
  25. package/lib/components/ConditionBuilder/RhsControls/NumericInput.js +4 -1
  26. package/lib/components/ConditionBuilder/RhsControls/NumericInput.js.map +1 -1
  27. package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.d.ts +5 -3
  28. package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.d.ts.map +1 -1
  29. package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.js +48 -14
  30. package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.js.map +1 -1
  31. package/lib/components/ConditionBuilder/RhsControls/ValueSelector.d.ts +41 -0
  32. package/lib/components/ConditionBuilder/RhsControls/ValueSelector.d.ts.map +1 -0
  33. package/lib/components/ConditionBuilder/RhsControls/ValueSelector.js +145 -0
  34. package/lib/components/ConditionBuilder/RhsControls/ValueSelector.js.map +1 -0
  35. package/lib/components/ConditionBuilder/RhsControls/index.d.ts +5 -2
  36. package/lib/components/ConditionBuilder/RhsControls/index.d.ts.map +1 -1
  37. package/lib/components/ConditionBuilder/RhsControls/index.js +90 -28
  38. package/lib/components/ConditionBuilder/RhsControls/index.js.map +1 -1
  39. package/lib/components/ConditionBuilder/core/comparators.d.ts.map +1 -1
  40. package/lib/components/ConditionBuilder/core/comparators.js +4 -0
  41. package/lib/components/ConditionBuilder/core/comparators.js.map +1 -1
  42. package/lib/components/ConditionBuilder/core/evaluator.d.ts.map +1 -1
  43. package/lib/components/ConditionBuilder/core/evaluator.js +10 -3
  44. package/lib/components/ConditionBuilder/core/evaluator.js.map +1 -1
  45. package/lib/components/ConditionBuilder/core/formatter.d.ts +1 -0
  46. package/lib/components/ConditionBuilder/core/formatter.d.ts.map +1 -1
  47. package/lib/components/ConditionBuilder/core/formatter.js +87 -38
  48. package/lib/components/ConditionBuilder/core/formatter.js.map +1 -1
  49. package/lib/components/ConditionBuilder/core/transformer.d.ts.map +1 -1
  50. package/lib/components/ConditionBuilder/core/transformer.js +67 -11
  51. package/lib/components/ConditionBuilder/core/transformer.js.map +1 -1
  52. package/lib/components/ConditionBuilder/core/types.d.ts +2 -2
  53. package/lib/components/ConditionBuilder/core/types.d.ts.map +1 -1
  54. package/lib/components/ConditionBuilder/core/types.js.map +1 -1
  55. package/lib/components/ConditionBuilder/core/utils.d.ts +5 -1
  56. package/lib/components/ConditionBuilder/core/utils.d.ts.map +1 -1
  57. package/lib/components/ConditionBuilder/core/utils.js +18 -0
  58. package/lib/components/ConditionBuilder/core/utils.js.map +1 -1
  59. package/lib/components/ConditionBuilder/index.d.ts +1 -1
  60. package/lib/components/ConditionBuilder/index.d.ts.map +1 -1
  61. package/lib/components/ConditionBuilder/index.js.map +1 -1
  62. package/lib/components/ConditionInput/ConditionInput.d.ts +6 -0
  63. package/lib/components/ConditionInput/ConditionInput.d.ts.map +1 -0
  64. package/lib/components/ConditionInput/ConditionInput.js +215 -0
  65. package/lib/components/ConditionInput/ConditionInput.js.map +1 -0
  66. package/lib/components/ConditionInput/ConditionInput.styles.d.ts +5 -0
  67. package/lib/components/ConditionInput/ConditionInput.styles.d.ts.map +1 -0
  68. package/lib/components/ConditionInput/ConditionInput.styles.js +27 -0
  69. package/lib/components/ConditionInput/ConditionInput.styles.js.map +1 -0
  70. package/lib/components/ConditionInput/ConditionInput.types.d.ts +29 -0
  71. package/lib/components/ConditionInput/ConditionInput.types.d.ts.map +1 -0
  72. package/lib/components/ConditionInput/ConditionInput.types.js +2 -0
  73. package/lib/components/ConditionInput/ConditionInput.types.js.map +1 -0
  74. package/lib/components/ConditionInput/index.d.ts +3 -0
  75. package/lib/components/ConditionInput/index.d.ts.map +1 -0
  76. package/lib/components/ConditionInput/index.js +2 -0
  77. package/lib/components/ConditionInput/index.js.map +1 -0
  78. package/lib/components/ConditionInput/utils.d.ts +13 -0
  79. package/lib/components/ConditionInput/utils.d.ts.map +1 -0
  80. package/lib/components/ConditionInput/utils.js +56 -0
  81. package/lib/components/ConditionInput/utils.js.map +1 -0
  82. package/lib/components/PromotedFilters/ConditionSelector.d.ts +31 -0
  83. package/lib/components/PromotedFilters/ConditionSelector.d.ts.map +1 -0
  84. package/lib/components/PromotedFilters/ConditionSelector.js +72 -0
  85. package/lib/components/PromotedFilters/ConditionSelector.js.map +1 -0
  86. package/lib/components/PromotedFilters/PromotedFilters.d.ts +11 -0
  87. package/lib/components/PromotedFilters/PromotedFilters.d.ts.map +1 -0
  88. package/lib/components/PromotedFilters/PromotedFilters.js +119 -0
  89. package/lib/components/PromotedFilters/PromotedFilters.js.map +1 -0
  90. package/lib/components/PromotedFilters/PromotedFilters.styles.d.ts +4 -0
  91. package/lib/components/PromotedFilters/PromotedFilters.styles.d.ts.map +1 -0
  92. package/lib/components/PromotedFilters/PromotedFilters.styles.js +26 -0
  93. package/lib/components/PromotedFilters/PromotedFilters.styles.js.map +1 -0
  94. package/lib/components/PromotedFilters/PromotedFilters.types.d.ts +31 -0
  95. package/lib/components/PromotedFilters/PromotedFilters.types.d.ts.map +1 -0
  96. package/lib/components/PromotedFilters/PromotedFilters.types.js +2 -0
  97. package/lib/components/PromotedFilters/PromotedFilters.types.js.map +1 -0
  98. package/lib/components/PromotedFilters/index.d.ts +3 -0
  99. package/lib/components/PromotedFilters/index.d.ts.map +1 -0
  100. package/lib/components/PromotedFilters/index.js +2 -0
  101. package/lib/components/PromotedFilters/index.js.map +1 -0
  102. package/lib/index.d.ts +4 -0
  103. package/lib/index.d.ts.map +1 -1
  104. package/lib/index.js +4 -0
  105. package/lib/index.js.map +1 -1
  106. package/package.json +8 -6
  107. package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.d.ts +0 -16
  108. package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.d.ts.map +0 -1
  109. package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.js +0 -43
  110. package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"RhsModeSwitch.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls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AW,EAAE,CAAC,CAAC,CAAC,CAAC;IAEpF,0CAA0C;IAC1C,MAAM,QAAQ,GAAG,OAAO,CAAuB,GAAG,EAAE;QAClD,MAAM,YAAY,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QAClE,OAAO,YAAY,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,YAAY,CAAC,EAAE,EAAE,IAAI,EAAE,YAAY,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IACxF,CAAC,EAAE,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,WAAW,QACX,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,EACzC,IAAI,EAAC,MAAM,EACX,QAAQ,QACR,OAAO,EAAC,QAAQ,EAChB,IAAI,EAAE,IAAI,GACV,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { FunctionComponent, useMemo } from 'react';\n\nimport {\n BaseProps,\n ComboBox,\n ForwardProps,\n hasProp,\n MenuButton,\n menuHelpers,\n MenuProps,\n NoChildrenProp,\n TranslationPack,\n useI18n\n} from '@pega/cosmos-react-core';\nimport { TranslationFunction } from '@pega/cosmos-react-core/lib/i18n/translate';\nimport { Selected } from '@pega/cosmos-react-core/lib/components/ComboBox/ComboBox.types';\n\nimport { Comparator, FieldType, RHSType } from '../core/types';\nimport { DateFunctionsByType, LeafCondition } 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}\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 /** 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: LeafCondition['rhs'];\n\n /** Callback for any modifications to the Rhs */\n onChange: (rhs: 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 props: RhsMenuButtonProps\n) => {\n const { fieldType, comparator, rhs, onChange, mode, validRhsTypes, dateFunctions } = props;\n const t = useI18n();\n\n // Identify current mode\n const currentMode = useMemo(() => {\n // rhs should already be defined if this component is being rendered. Indicating the same to TS using `!`\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!, 'relativeDate')) return ItemID.RELATIVE_DATE;\n return ItemID.LITERAL_VALUE;\n }, [rhs]);\n\n // Determine actions for the menu\n const menu = useMemo<MenuProps>(() => {\n const items: MenuProps['items'] = [];\n\n // Boolean conditions either don't use an rhs or always use the field-selector\n // For IN/NOT_IN comparators, only one mode is possible for a given case - CSV Input or a Value-selector\n if (fieldType !== 'BOOLEAN' && !['IN', 'NOT_IN'].includes(comparator)) {\n // Literal value input\n if (validRhsTypes.has('LITERAL')) {\n // Literal Value inputs\n items.push({\n id: ItemID.LITERAL_VALUE,\n primary: getValueOptionLabel(fieldType, t),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({ value: '' }); // Submit a new RHS to re-render with the new mode\n }\n });\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 });\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 });\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 });\n }\n }\n\n return { items, mode: 'action' };\n }, [fieldType, comparator, onChange, validRhsTypes, dateFunctions, currentMode, t]);\n\n // Identify current selection for ComboBox\n const selected = useMemo<Selected | undefined>(() => {\n const selectedItem = menuHelpers.getItem(menu.items, currentMode);\n return selectedItem ? { id: selectedItem.id, text: selectedItem.primary } : undefined;\n }, [menu, currentMode]);\n\n // Render the button only when there are multiple options in the menu\n if (menu.items.length < 2) return null;\n\n if (mode === 'combo-box') {\n return (\n <ComboBox\n label={t('condition_builder_compare_with')}\n labelHidden\n mode='single-select'\n selected={{ items: selected }}\n menu={menu}\n />\n );\n }\n\n return (\n <MenuButton\n text={t('condition_builder_compare_with')}\n icon='gear'\n iconOnly\n variant='simple'\n menu={menu}\n />\n );\n};\n\nexport default RhsModeSwitch;\n"]}
1
+ {"version":3,"file":"RhsModeSwitch.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/RhsModeSwitch.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAqB,OAAO,EAAE,MAAM,OAAO,CAAC;AAEnD,OAAO,EAEL,QAAQ,EAER,OAAO,EACP,UAAU,EACV,WAAW,EAIX,OAAO,EACR,MAAM,yBAAyB,CAAC;AAOjC,IAAK,MAMJ;AAND,WAAK,MAAM;IACT,yCAA+B,CAAA;IAC/B,iCAAuB,CAAA;IACvB,yCAA+B,CAAA;IAC/B,yCAA+B,CAAA;IAC/B,iCAAuB,CAAA;AACzB,CAAC,EANI,MAAM,KAAN,MAAM,QAMV;AAED,SAAS,iBAAiB,CAAC,UAAkC;IAC3D,OAAO,UAAU,KAAK,KAAK,IAAI,UAAU,KAAK,SAAS,CAAC;AAC1D,CAAC;AAED,wDAAwD;AACxD,SAAS,mBAAmB,CAC1B,SAAoB,EACpB,CAAuC,EACvC,UAAuB;IAEvB,QAAQ,SAAS,EAAE;QACjB,KAAK,MAAM;YACT,OAAO,CAAC,CAAC,2CAA2C,CAAC,CAAC;QACxD,KAAK,QAAQ;YACX,OAAO,iBAA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AC,EAAE,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,WAAW,QACX,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,EACzC,IAAI,EAAC,MAAM,EACX,QAAQ,QACR,OAAO,EAAC,QAAQ,EAChB,IAAI,EAAE,IAAI,GACV,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { FunctionComponent, useMemo } from 'react';\n\nimport {\n BaseProps,\n ComboBox,\n ForwardProps,\n hasProp,\n MenuButton,\n menuHelpers,\n MenuProps,\n NoChildrenProp,\n TranslationPack,\n useI18n\n} from '@pega/cosmos-react-core';\nimport { TranslationFunction } from '@pega/cosmos-react-core/lib/i18n/translate';\nimport { Selected } from '@pega/cosmos-react-core/lib/components/ComboBox/ComboBox.types';\n\nimport { Comparator, FieldType, RHSType } from '../core/types';\nimport { DateFunctionsByType, LeafCondition, ParameterValue } from '../ConditionBuilder.types';\n\nenum ItemID {\n LITERAL_VALUE = 'LITERAL_VALUE',\n DATE_PART = 'DATE_PART',\n RELATIVE_DATE = 'RELATIVE_DATE',\n ANOTHER_FIELD = 'ANOTHER_FIELD',\n PARAMETER = 'PARAMETER'\n}\n\nfunction isRangeComparator(comparator: Comparator | undefined): boolean {\n return comparator === 'BTW' || comparator === 'NOT_BTW';\n}\n\n// Label for the `Enter <value>` option on the gear-menu\nfunction getValueOptionLabel(\n fieldType: FieldType,\n t: TranslationFunction<TranslationPack>,\n comparator?: Comparator\n): string {\n switch (fieldType) {\n case 'TEXT':\n return t('condition_builder_compare_with_text_value');\n case 'NUMBER':\n return isRangeComparator(comparator)\n ? t('condition_builder_compare_with_numeric_range_value')\n : t('condition_builder_compare_with_numeric_value');\n case 'DATE_TIME':\n case 'DATE_ONLY':\n return isRangeComparator(comparator)\n ? t('condition_builder_compare_with_date_range_value')\n : t('condition_builder_compare_with_date_value');\n case 'TIME_ONLY':\n return isRangeComparator(comparator)\n ? t('condition_builder_compare_with_time_range_value')\n : t('condition_builder_compare_with_time_value');\n default:\n return t('condition_builder_value_label'); // Not needed (BOOLEAN is not expected to be passed to the function)\n }\n}\n\ninterface RhsMenuButtonProps extends BaseProps, NoChildrenProp {\n /** Passed Parameters array for Rhstype PARAMETER */\n parameters: ParameterValue[];\n\n /** Type of field on the LHS */\n fieldType: FieldType;\n\n /** Comparator for the condition */\n comparator: Comparator;\n\n /** Rhs for the condition */\n rhs: NonNullable<LeafCondition['rhs']>;\n\n /** Callback for any modifications to the Rhs */\n onChange: (rhs: NonNullable<LeafCondition['rhs']>) => void;\n\n /** Display mode */\n mode: 'combo-box' | 'menu-button';\n\n /** Restricts RHS values to only specified RHS types */\n validRhsTypes: Set<RHSType>;\n\n /** Passed to enable additional date controls on the RHS, when a DATE_TIME/DATE_ONLY field is selected on the LHS */\n dateFunctions?: DateFunctionsByType;\n}\n\n/** Renders a Gear MenuButton on the RHS (when applicable) */\nconst RhsModeSwitch: FunctionComponent<RhsMenuButtonProps & ForwardProps> = ({\n parameters,\n fieldType,\n comparator,\n rhs,\n onChange,\n mode,\n validRhsTypes,\n dateFunctions\n}: RhsMenuButtonProps) => {\n const t = useI18n();\n\n // Identify current mode\n const currentMode = useMemo(() => {\n if (hasProp(rhs, 'field')) return ItemID.ANOTHER_FIELD;\n if (hasProp(rhs, 'field')) return ItemID.ANOTHER_FIELD;\n if (hasProp(rhs, 'value') && hasProp(rhs, 'dateFunction')) return ItemID.DATE_PART;\n if (hasProp(rhs, 'parameterId')) return ItemID.PARAMETER;\n if (hasProp(rhs, 'relativeDate')) return ItemID.RELATIVE_DATE;\n return ItemID.LITERAL_VALUE;\n }, [rhs]);\n\n // Determine actions for the menu\n const menu = useMemo<MenuProps>(() => {\n const items: MenuProps['items'] = [];\n\n // Boolean conditions either don't use an rhs or always use the field-selector\n // For IN/NOT_IN comparators, only one mode is possible for a given case - CSV Input or a Value-selector\n if (fieldType !== 'BOOLEAN' && !['IN', 'NOT_IN'].includes(comparator)) {\n // Literal value input\n if (validRhsTypes.has('LITERAL')) {\n // Literal Value inputs\n items.push({\n id: ItemID.LITERAL_VALUE,\n primary: getValueOptionLabel(fieldType, t, comparator),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange(isRangeComparator(comparator) ? { start: '', end: '' } : { value: '' }); // Submit a new RHS to re-render with the new mode\n },\n selected: currentMode === ItemID.LITERAL_VALUE\n });\n }\n\n // Field selector\n if (validRhsTypes.has('FIELD')) {\n items.push({\n id: ItemID.ANOTHER_FIELD,\n primary: t('condition_builder_compare_with_another_field'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({ field: '' }); // Submit a new RHS to re-render with the new mode\n },\n selected: currentMode === ItemID.ANOTHER_FIELD\n });\n }\n\n // Rhs of PARAMETER type\n if (\n validRhsTypes.has('PARAMETER') &&\n ['EQ', 'NEQ'].includes(comparator) &&\n parameters.length > 0\n ) {\n items.push({\n id: ItemID.PARAMETER,\n primary: t('condition_builder_compare_with_parameter'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n if (parameters.length === 1) onChange({ parameterId: parameters[0].id });\n else onChange({ parameterId: '' }); // Submit a new RHS to re-render with the new mode\n },\n selected: currentMode === ItemID.PARAMETER\n });\n }\n\n // Relative Date value input\n if (\n validRhsTypes.has('RELATIVE_DATE') &&\n (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY')\n ) {\n items.push({\n id: ItemID.RELATIVE_DATE,\n primary: t('condition_builder_compare_with_relative_date'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({\n relativeDate: {\n timePeriod: 'CURRENT',\n datePart: 'DAYS'\n }\n });\n },\n selected: currentMode === ItemID.RELATIVE_DATE\n });\n }\n\n // Date Part value input\n if (\n validRhsTypes.has('DATE_FUNCTION') &&\n dateFunctions &&\n (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY')\n ) {\n items.push({\n id: ItemID.DATE_PART,\n primary: t('condition_builder_date_part'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({ value: '', dateFunction: dateFunctions[fieldType][0] }); // Submit a new RHS to re-render with the new mode. Initializing with the first available date function\n },\n selected: currentMode === ItemID.DATE_PART\n });\n }\n }\n\n return { items, mode: 'single-select' };\n }, [fieldType, comparator, onChange, validRhsTypes, dateFunctions, currentMode, t]);\n\n // Identify current selection for ComboBox\n const selected = useMemo<Selected | undefined>(() => {\n const selectedItem = menuHelpers.getItem(menu.items, currentMode);\n return selectedItem ? { id: selectedItem.id, text: selectedItem.primary } : undefined;\n }, [menu, currentMode]);\n\n // Render the button only when there are multiple options in the menu\n if (menu.items.length < 2) return null;\n\n if (mode === 'combo-box') {\n return (\n <ComboBox\n label={t('condition_builder_compare_with')}\n labelHidden\n mode='single-select'\n selected={{ items: selected }}\n menu={menu}\n />\n );\n }\n\n return (\n <MenuButton\n text={t('condition_builder_compare_with')}\n icon='gear'\n iconOnly\n variant='simple'\n menu={menu}\n />\n );\n};\n\nexport default RhsModeSwitch;\n"]}
@@ -0,0 +1,41 @@
1
+ import { Dispatch, SetStateAction } from 'react';
2
+ import { BaseProps, NoChildrenProp, ComboBoxProps } from '@pega/cosmos-react-core';
3
+ import { LeafCondition, ParameterValue, ValueSelection } from '../ConditionBuilder.types';
4
+ import { Comparator } from '../core/types';
5
+ interface ValueSelectorProps<T extends {
6
+ possibleValues?: ValueSelection<T>;
7
+ }> extends BaseProps, NoChildrenProp {
8
+ mode: ComboBoxProps['mode'];
9
+ /** Previous selection */
10
+ values: string[] | string;
11
+ /** Current selected LHS */
12
+ selectedField: T;
13
+ /** Current selected comparator */
14
+ comparator: Comparator;
15
+ /** Rhs for the condition */
16
+ rhs: NonNullable<LeafCondition['rhs']>;
17
+ /** Passed Parameters array for Rhstype PARAMETER */
18
+ parameters: ParameterValue[];
19
+ /** Callback for changes */
20
+ onChange: (selection: string[] | string) => void;
21
+ /** Callback for blur */
22
+ onBlur?: (selection?: string[] | string) => void;
23
+ /** Callback for clear */
24
+ onClear?: () => void;
25
+ /** Used to indicate any errors on the control */
26
+ status?: 'error';
27
+ /** Placeholder text to display in empty control */
28
+ placeholder?: ComboBoxProps['placeholder'];
29
+ /** Custom label for input. Makes label visible if provided. */
30
+ label?: ComboBoxProps['label'];
31
+ /** Guidance text that apppears below the input. */
32
+ info?: ComboBoxProps['info'];
33
+ /** sets status and info */
34
+ setApiError?: Dispatch<SetStateAction<string | null>>;
35
+ }
36
+ /** A control for selecting multiple values using checkboxes in an overlay */
37
+ declare const ValueSelector: <F extends object & {
38
+ possibleValues?: ValueSelection<F> | undefined;
39
+ }>({ values, selectedField, comparator, rhs, onChange, onBlur, onClear, status, mode, parameters, placeholder, label, info, setApiError }: ValueSelectorProps<F>) => JSX.Element;
40
+ export default ValueSelector;
41
+ //# sourceMappingURL=ValueSelector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValueSelector.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/ValueSelector.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAwC,QAAQ,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAEvF,OAAO,EAEL,SAAS,EAIT,cAAc,EACd,aAAa,EAId,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,aAAa,EACb,cAAc,EAEd,cAAc,EACf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAA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sx-runtime";
2
+ import { useState, useMemo, useEffect, useRef } from 'react';
3
+ import { useI18n, ComboBox, createStringMatcher, useAfterInitialEffect, hasProp, Button, Icon } from '@pega/cosmos-react-core';
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 }) => {
6
+ const t = useI18n();
7
+ const inputRef = useRef(null);
8
+ const [selections, setSelections] = useState(values);
9
+ const [filterValue, setFilterValue] = useState('');
10
+ const [options, setOptions] = useState([]);
11
+ const [loading, setLoading] = useState(false);
12
+ const itemsToRender = useMemo(() => {
13
+ let opts = options;
14
+ if (filterValue) {
15
+ const matcher = createStringMatcher(filterValue, 'boundary');
16
+ opts = opts.filter(option => {
17
+ if (typeof option === 'object')
18
+ return matcher.test(option.primary);
19
+ return matcher.test(option);
20
+ });
21
+ }
22
+ return opts.map(option => {
23
+ if (typeof option === 'object') {
24
+ return {
25
+ ...option,
26
+ selected: selections.includes(option.id)
27
+ };
28
+ }
29
+ return {
30
+ id: option,
31
+ primary: option,
32
+ selected: selections.includes(option)
33
+ };
34
+ });
35
+ }, [options, filterValue, selections]);
36
+ useAfterInitialEffect(() => {
37
+ onChange(selections);
38
+ }, [selections]);
39
+ useEffect(() => {
40
+ if (!selectedField) {
41
+ return;
42
+ }
43
+ let subscribed = true;
44
+ if (hasProp(rhs, 'parameterId')) {
45
+ setOptions(parameters);
46
+ }
47
+ else if (hasProp(selectedField, 'possibleValues')) {
48
+ const { possibleValues } = selectedField;
49
+ if (typeof possibleValues === 'function') {
50
+ setLoading(true);
51
+ setOptions([]);
52
+ possibleValues({ searchString: filterValue, comparator, lhs: selectedField })
53
+ .then(response => {
54
+ if (!subscribed)
55
+ return;
56
+ setOptions(response);
57
+ setLoading(false);
58
+ })
59
+ .catch(err => {
60
+ if (err && subscribed) {
61
+ setApiError?.(t('condition_builder_possible_values_error'));
62
+ setOptions([]);
63
+ setLoading(false);
64
+ }
65
+ });
66
+ }
67
+ else if (Array.isArray(possibleValues)) {
68
+ setOptions(possibleValues);
69
+ }
70
+ else {
71
+ setOptions([]);
72
+ }
73
+ }
74
+ return () => {
75
+ subscribed = false;
76
+ setApiError?.(null);
77
+ };
78
+ }, [filterValue, selectedField, comparator]);
79
+ useEffect(() => setFilterValue(''), [selectedField, comparator]);
80
+ const getSelections = () => {
81
+ if (typeof selections === 'string') {
82
+ let itemLabel;
83
+ if (hasProp(rhs, 'parameterId')) {
84
+ const selectedItem = parameters.find(item => item.id === selections);
85
+ itemLabel = selectedItem !== undefined ? selectedItem.primary : selections;
86
+ }
87
+ else
88
+ itemLabel = selections;
89
+ return {
90
+ items: { id: selections, text: itemLabel }
91
+ };
92
+ }
93
+ if (selections.length > 0) {
94
+ return {
95
+ items: selections.map(s => {
96
+ const optionLabel = options.find(opt => typeof opt === 'object' && opt.id === s);
97
+ return { id: s, text: optionLabel?.primary ?? s };
98
+ }),
99
+ onRemove: (value) => {
100
+ setSelections(cur => {
101
+ const current = cur;
102
+ return current.filter(selection => selection !== value);
103
+ });
104
+ }
105
+ };
106
+ }
107
+ return undefined;
108
+ };
109
+ return (_jsx(ComboBox, { ref: inputRef, mode: mode, label: label ?? t('condition_builder_possible_values_label'), labelHidden: !label, placeholder: placeholder ??
110
+ (mode === 'single-select'
111
+ ? t('condition_builder_single_selection_text_default')
112
+ : t('condition_builder_multi_selection_text_default')), value: filterValue, onChange: e => {
113
+ setFilterValue(e.target.value);
114
+ }, onBlur: () => {
115
+ onBlur?.(selections);
116
+ setFilterValue('');
117
+ }, menu: {
118
+ items: itemsToRender,
119
+ onItemClick: id => {
120
+ setFilterValue('');
121
+ if (mode === 'single-select') {
122
+ setSelections(id);
123
+ }
124
+ else {
125
+ setSelections(cur => {
126
+ const current = cur;
127
+ return current.includes(id)
128
+ ? current.filter(selection => selection !== id)
129
+ : [...cur, id];
130
+ });
131
+ }
132
+ },
133
+ loading
134
+ }, selected: getSelections(), status: status, info: info, actions: onClear &&
135
+ selections.length > 0 && (_jsx(Button, { icon: true, variant: 'simple', label: t('clear'), onClick: () => {
136
+ setSelections([]);
137
+ onClear();
138
+ if (inputRef.current) {
139
+ const inputEl = inputRef.current.querySelector('input');
140
+ inputEl?.focus();
141
+ }
142
+ }, children: _jsx(Icon, { name: 'times' }) })) }));
143
+ };
144
+ export default ValueSelector;
145
+ //# sourceMappingURL=ValueSelector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValueSelector.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/ValueSelector.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAA4B,MAAM,OAAO,CAAC;AAEvF,OAAO,EACL,OAAO,EAEP,QAAQ,EACR,mBAAmB,EACnB,qBAAqB,EAGrB,OAAO,EACP,MAAM,EACN,IAAI,EACL,MAAM,yBAAyB,CAAC;AA0CjC,6EAA6E;AAC7E,MAAM,aAAa,GAAG,CAA4D,EAChF,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,EACW,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;IACxE,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IACnD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAA+C,EAAE,CAAC,CAAC;IACzF,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAA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AAC,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, useMemo, useEffect, useRef, Dispatch, SetStateAction } from 'react';\n\nimport {\n useI18n,\n BaseProps,\n ComboBox,\n createStringMatcher,\n useAfterInitialEffect,\n NoChildrenProp,\n ComboBoxProps,\n hasProp,\n Button,\n Icon\n} from '@pega/cosmos-react-core';\n\nimport {\n LeafCondition,\n ParameterValue,\n ReferenceValue,\n ValueSelection\n} from '../ConditionBuilder.types';\nimport { Comparator } from '../core/types';\n\ninterface ValueSelectorProps<T extends { 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 & { 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 [selections, setSelections] = useState<string[] | string>(values);\n const [filterValue, setFilterValue] = useState('');\n const [options, setOptions] = useState<(string | ParameterValue | ReferenceValue)[]>([]);\n const [loading, setLoading] = useState(false);\n\n const itemsToRender = useMemo(() => {\n let opts = options;\n\n if (filterValue) {\n const matcher = createStringMatcher(filterValue, 'boundary');\n opts = opts.filter(option => {\n if (typeof option === 'object') return matcher.test(option.primary);\n return matcher.test(option);\n });\n }\n\n return opts.map(option => {\n if (typeof option === 'object') {\n return {\n ...option,\n selected: selections.includes(option.id)\n };\n }\n return {\n id: option,\n primary: option,\n selected: selections.includes(option)\n };\n });\n }, [options, filterValue, selections]);\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, 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 return (\n <ComboBox\n ref={inputRef}\n mode={mode}\n label={label ?? t('condition_builder_possible_values_label')}\n labelHidden={!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 }}\n onBlur={() => {\n onBlur?.(selections);\n setFilterValue('');\n }}\n menu={{\n items: itemsToRender,\n onItemClick: id => {\n setFilterValue('');\n if (mode === 'single-select') {\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 }}\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,5 +1,5 @@
1
1
  import { FunctionComponent } from 'react';
2
- import { BaseProps, ForwardProps } from '@pega/cosmos-react-core';
2
+ import { BaseProps, ForwardProps, FormControlProps } from '@pega/cosmos-react-core';
3
3
  import { FieldType, Comparator, RHSType } from '../core/types';
4
4
  import { LeafCondition, Field, DateFunctionsByType } from '../ConditionBuilder.types';
5
5
  /**
@@ -9,9 +9,10 @@ import { LeafCondition, Field, DateFunctionsByType } from '../ConditionBuilder.t
9
9
  * - If a condition is manually constructed outside these components, this utility could miss some malformed conditions.
10
10
  * - Also, this does not try to validate if the given `rhs` matches the `lhs`/`comparator`/`validRhsTypes`. Instead, it assumes that the appropriate LHS/Comparator/validRhsTypes must have been already in place for this rhs to be generated.
11
11
  */
12
- export declare function isValidRhs(rhs: LeafCondition['rhs'], fieldType?: FieldType, trimValues?: boolean): boolean;
12
+ export declare function isValidRhs(rhs: LeafCondition['rhs'], lhs: LeafCondition['lhs'], fields: Field[], fieldType?: FieldType, trimValues?: boolean): boolean;
13
13
  /** For a condition with the given comparator and lhs-field-type, determines an appropriate default value for the Rhs */
14
14
  export declare function getDefaultRhs(fieldType: FieldType, comparator: Comparator, validRhsTypes: Set<RHSType>, dateFunctions?: DateFunctionsByType): LeafCondition['rhs'];
15
+ export declare function truncateISODateString(dateString: string, fieldType: FieldType): string;
15
16
  /** Type definition for the input props of RhsControls */
16
17
  interface RhsControlProps extends BaseProps {
17
18
  /** Lhs for the condition */
@@ -32,6 +33,8 @@ interface RhsControlProps extends BaseProps {
32
33
  validRhsTypes: Set<RHSType>;
33
34
  /** Passed to enable additional date controls on the RHS, when a DATE_TIME/DATE_ONLY field is selected on the LHS */
34
35
  dateFunctions?: DateFunctionsByType;
36
+ /** Visually hides the label region. */
37
+ labelHidden?: FormControlProps['labelHidden'];
35
38
  }
36
39
  /** A controlled component for controls on a Condition's RHS */
37
40
  declare const RhsControls: FunctionComponent<RhsControlProps & ForwardProps>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA6C,MAAM,OAAO,CAAC;AAErF,OAAO,EAQL,SA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G,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;IAE9C,+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,uCAAuC;IACvC,WAAW,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC;CAC/C;AAED,+DAA+D;AAC/D,QAAA,MAAM,WAAW,EAAE,iBAAiB,CAAC,eAAe,GAAG,YAAY,CAoXlE,CAAC;AACF,eAAe,WAAW,CAAC"}
@@ -1,13 +1,34 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useState, useEffect, useMemo } from 'react';
3
- import { DateInput, DateTimeInput, Flex, Input, Select, Option, hasProp } from '@pega/cosmos-react-core';
3
+ import { DateInput, DateTimeInput, Flex, Input, hasProp, TimeInput, useI18n, DateRangeInput, TimeRangeInput, NumberRangeInput } from '@pega/cosmos-react-core';
4
4
  import { convertTimeValueToMs, convertMsToTimeValue } from '../core/time-utils';
5
- import MultiValueSelector from './MultiValueSelector';
5
+ import { getItem } from '../core/utils';
6
+ import ValueSelector from './ValueSelector';
6
7
  import FieldSelector from './FieldSelector';
7
8
  import RhsModeSwitch from './RhsModeSwitch';
8
9
  import TimePeriodInput from './TimePeriodInput';
9
10
  import TimePeriodMenu from './TimePeriodMenu';
10
11
  import NumericInput from './NumericInput';
12
+ function isValidLiteralValue(value, fieldType, trimValues = false) {
13
+ // Identify any invalid numbers (e.g. when `-` is entered)
14
+ if (typeof value === 'number') {
15
+ return !Number.isNaN(value);
16
+ }
17
+ // NOTE: Not trimming the value in the change-handler so that users can freely type spaces between words
18
+ if (trimValues) {
19
+ value = value.trim();
20
+ }
21
+ // Can be empty on init and on clearing the value
22
+ if (value.trim() === '') {
23
+ return false;
24
+ }
25
+ // This check is needed to eliminate invalid dates like `Feb 31` (02/31/2020), which the input allows
26
+ if ((fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY') &&
27
+ Number.isNaN(new Date(value).getTime())) {
28
+ return false;
29
+ }
30
+ return true;
31
+ }
11
32
  /**
12
33
  * Verifies if the condition has all valid values.
13
34
  * NOTES:
@@ -15,7 +36,15 @@ import NumericInput from './NumericInput';
15
36
  * - If a condition is manually constructed outside these components, this utility could miss some malformed conditions.
16
37
  * - Also, this does not try to validate if the given `rhs` matches the `lhs`/`comparator`/`validRhsTypes`. Instead, it assumes that the appropriate LHS/Comparator/validRhsTypes must have been already in place for this rhs to be generated.
17
38
  */
18
- export function isValidRhs(rhs, fieldType, trimValues = false) {
39
+ export function isValidRhs(rhs, lhs, fields, fieldType, trimValues = false) {
40
+ // Find the field corresponding to the LHS
41
+ const matchingField = getItem(fields, lhs.field);
42
+ if (matchingField === undefined || !hasProp(matchingField, 'type')) {
43
+ // Check if the RHS has no defined values to select
44
+ return false;
45
+ }
46
+ // A ValueSelector in single/multiple mode is possible when these criteria are met
47
+ const isValueSelectorPossible = fieldType === 'TEXT' && matchingField.possibleValues !== undefined;
19
48
  // RHS would be `undefined` when no RHS is needed. Treat it as a valid value
20
49
  if (rhs === undefined) {
21
50
  return true;
@@ -25,6 +54,11 @@ export function isValidRhs(rhs, fieldType, trimValues = false) {
25
54
  // RHS is invalid if no field is selected
26
55
  return rhs.field !== '';
27
56
  }
57
+ // rhs of Parameter type
58
+ if (hasProp(rhs, 'parameterId')) {
59
+ // RHS is invalid if no id is returned
60
+ return !!rhs.parameterId;
61
+ }
28
62
  // List-input cases
29
63
  if (hasProp(rhs, 'values')) {
30
64
  // RHS is invalid if the list is empty
@@ -42,7 +76,7 @@ export function isValidRhs(rhs, fieldType, trimValues = false) {
42
76
  return !Number.isNaN(rhs.value);
43
77
  }
44
78
  // NOTE: Not trimming the value in the change-handler so that users can freely type spaces between words
45
- if (trimValues) {
79
+ if (trimValues && !isValueSelectorPossible) {
46
80
  rhs.value = rhs.value.trim();
47
81
  }
48
82
  // Can be empty on init and on clearing the value
@@ -61,6 +95,11 @@ export function isValidRhs(rhs, fieldType, trimValues = false) {
61
95
  (!rhs.relativeDate.interval || rhs.relativeDate.interval <= 0)))) {
62
96
  return false;
63
97
  }
98
+ if (hasProp(rhs, 'start') &&
99
+ (!isValidLiteralValue(rhs.start, fieldType, trimValues) ||
100
+ !isValidLiteralValue(rhs.end, fieldType, trimValues))) {
101
+ return false;
102
+ }
64
103
  return true;
65
104
  }
66
105
  /** For a condition with the given comparator and lhs-field-type, determines an appropriate default value for the Rhs */
@@ -74,6 +113,9 @@ export function getDefaultRhs(fieldType, comparator, validRhsTypes, dateFunction
74
113
  case 'IN':
75
114
  case 'NOT_IN':
76
115
  return { values: [] };
116
+ case 'BTW':
117
+ case 'NOT_BTW':
118
+ return { start: '', end: '' };
77
119
  default: {
78
120
  if (fieldType === 'BOOLEAN' && (comparator === 'EQ' || comparator === 'NEQ')) {
79
121
  // For booleans, these comparators can only be used for comparing with other fields
@@ -81,6 +123,8 @@ export function getDefaultRhs(fieldType, comparator, validRhsTypes, dateFunction
81
123
  }
82
124
  if (validRhsTypes.has('LITERAL'))
83
125
  return { value: '' };
126
+ if (validRhsTypes.has('PARAMETER'))
127
+ return { parameterId: '' };
84
128
  if (validRhsTypes.has('DATE_FUNCTION') &&
85
129
  dateFunctions &&
86
130
  (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY'))
@@ -100,7 +144,7 @@ export function getDefaultRhs(fieldType, comparator, validRhsTypes, dateFunction
100
144
  }
101
145
  // Truncates output values from DateInput/DateTimeInput to return a wall time on the RHS
102
146
  // NOTE: This assumes that the input date is set up on the UTC timezone
103
- function truncateISODateString(dateString, fieldType) {
147
+ export function truncateISODateString(dateString, fieldType) {
104
148
  const date = new Date(dateString);
105
149
  const YYYY = date.getUTCFullYear().toString().padStart(4, '0');
106
150
  const MM = (date.getUTCMonth() + 1).toString().padStart(2, '0');
@@ -110,21 +154,26 @@ function truncateISODateString(dateString, fieldType) {
110
154
  return `${YYYY}-${MM}-${DD}`;
111
155
  const hh = date.getUTCHours().toString().padStart(2, '0');
112
156
  const mm = date.getUTCMinutes().toString().padStart(2, '0');
157
+ const ss = date.getUTCSeconds().toString().padStart(2, '0');
158
+ if (fieldType === 'TIME_ONLY')
159
+ return `${hh}:${mm}:${ss}`;
113
160
  // cspell:disable-next-line
114
161
  // For DATE_TIME fields, returning a YYYY-MM-DDTHH:mm format and discarding the time-zone etc. to be consistent with the previous spec which was returning a wall time
115
162
  return `${YYYY}-${MM}-${DD}T${hh}:${mm}`;
116
163
  }
117
164
  /** A controlled component for controls on a Condition's RHS */
118
165
  const RhsControls = (props) => {
119
- const { lhs, comparator, rhs, fields, onChange, indicateErrors, itemDirection, validRhsTypes, dateFunctions } = props;
166
+ const { lhs, comparator, rhs, fields, onChange, indicateErrors, itemDirection, validRhsTypes, dateFunctions, labelHidden = true } = props;
167
+ const t = useI18n();
168
+ const [apiError, setApiError] = useState(null);
120
169
  // Find the field corresponding to the LHS
121
- const matchingField = fields.find(f => f.name === lhs.field);
170
+ const matchingField = getItem(fields, lhs.field);
122
171
  // Options for the Field-selector (if applicable)
123
172
  const fieldOptions = useMemo(() => {
124
- if (!matchingField)
173
+ if (!matchingField || !hasProp(matchingField, 'type'))
125
174
  return [];
126
175
  // Show all other fields of the same data type as the LHS
127
- return fields.filter(f => f.type === matchingField.type && f.name !== lhs.field);
176
+ return fields.filter(f => hasProp(f, 'type') && f.type === matchingField.type && f.id !== lhs.field);
128
177
  }, [fields, lhs]);
129
178
  // Set up a CSV input for IN/NOT_IN comparators
130
179
  const [csvInput, setCsvInput] = useState(rhs && hasProp(rhs, 'values') ? rhs.values.join(', ') : '');
@@ -139,27 +188,29 @@ const RhsControls = (props) => {
139
188
  if (rhs === undefined) {
140
189
  return _jsx("div", {}); // Rendering a placeholder div to keep the layout consistent
141
190
  }
142
- if (matchingField === undefined) {
191
+ if (matchingField === undefined || !hasProp(matchingField, 'type')) {
143
192
  // For safety against any rare cases where the LHS from an input condition is not present in the input fields to the ConditionBuilder
144
193
  // In those cases, don't render an RHS and wait for a valid value to be picked on LHS
145
194
  return _jsx("div", {}); // Rendering a placeholder div to keep the layout consistent
146
195
  }
147
196
  const fieldType = matchingField.type;
197
+ const parameters = matchingField.parameters !== undefined ? matchingField.parameters : [];
148
198
  // If errors should be indicated inline, validate the current rhs
149
199
  let showError = false;
150
200
  if (indicateErrors) {
151
- showError = !isValidRhs(rhs, fieldType, false);
201
+ showError = !isValidRhs(rhs, lhs, fields, fieldType, false);
152
202
  }
153
- // Set up Value-selector (if applicable)
154
- const { possibleValues } = matchingField; // These are passed when possible values are known ahead of time
155
203
  const isValueSelectorPossible = fieldType === 'TEXT' &&
156
- possibleValues !== undefined &&
204
+ matchingField.possibleValues !== undefined &&
157
205
  ['EQ', 'NEQ', 'IN', 'NOT_IN'].includes(comparator); // A ValueSelector in single/multiple mode is possible when these criteria are met
158
- const useValueSelector = isValueSelectorPossible && !hasProp(rhs, 'field'); // Use the ValueSelector component if it is applicable and if not in ANOTHER_FIELD mode
206
+ const useValueSelector = isValueSelectorPossible && !hasProp(rhs, 'field'); // Use the ValueSelector component if it is applicable and if not in ANOTHER_FIELD mode and if RHS is not PARAMETER type
159
207
  // Handle changes from the Value-selector
160
208
  const handleValueSelection = (selection) => {
161
209
  if (typeof selection === 'string') {
162
- onChange({ value: selection }); // Submit a new RHS
210
+ if (hasProp(rhs, 'parameterId'))
211
+ onChange({ parameterId: selection });
212
+ else
213
+ onChange({ value: selection }); // Submit a new RHS
163
214
  }
164
215
  else {
165
216
  onChange({ values: selection }); // Submit a new RHS
@@ -174,21 +225,33 @@ const RhsControls = (props) => {
174
225
  // NOTE: Not trimming the value here so that users can freely type spaces between words. Trimming is done on Submit, via the isValidRhs call
175
226
  onChange({ value: e.target.value }); // Submit a new RHS
176
227
  };
177
- // Handle changes from a Time-input
178
- const handleTimeValueChange = (e) => {
179
- let newValue = e.target.value;
180
- if (newValue.length === 5) {
181
- newValue += ':00'; // Enforce a fixed hh:mm:ss format
182
- }
183
- onChange({ value: convertTimeValueToMs(newValue) }); // Submit a new RHS
184
- };
185
228
  // Handle changes from a DateInput
186
229
  const handleDateValueChange = ({ valueAsISOString, valueAsTimestamp, state }) => {
187
230
  // NOTE: Not relying fully on `state` since in some cases state and valueAsTimestamp as both undefined
188
231
  if (valueAsTimestamp === undefined || state === 'incomplete' || state === 'invalid')
189
232
  return;
190
233
  const truncatedValue = truncateISODateString(valueAsISOString, fieldType); // Truncate to return a wall time as per spec
191
- onChange({ value: truncatedValue });
234
+ onChange({
235
+ value: fieldType === 'TIME_ONLY' ? convertTimeValueToMs(truncatedValue) : truncatedValue
236
+ });
237
+ };
238
+ const handleDateRangeValueChange = ({ start, end }) => {
239
+ if (start.valueAsISOString === '' || end.valueAsISOString === '')
240
+ return;
241
+ const [truncatedStartValue, truncatedEndValue] = [
242
+ truncateISODateString(start.valueAsISOString, fieldType),
243
+ truncateISODateString(end.valueAsISOString, fieldType)
244
+ ];
245
+ onChange({
246
+ start: fieldType === 'TIME_ONLY' ? convertTimeValueToMs(truncatedStartValue) : truncatedStartValue,
247
+ end: fieldType === 'TIME_ONLY' ? convertTimeValueToMs(truncatedEndValue) : truncatedEndValue
248
+ });
249
+ };
250
+ const handleNumberRangeValueChange = ({ start, end }) => {
251
+ onChange({
252
+ start: start.trim() ? Number(start) : '',
253
+ end: end.trim() ? Number(end) : ''
254
+ });
192
255
  };
193
256
  // Handle changes from a CSV-input
194
257
  const handleCSVChange = (e) => {
@@ -211,9 +274,8 @@ const RhsControls = (props) => {
211
274
  alignItems: itemDirection === 'column' ? 'stretch' : 'start',
212
275
  justify: 'between',
213
276
  gap: 0.5
214
- }, children: [_jsx(RhsModeSwitch, { fieldType: fieldType, comparator: comparator, rhs: rhs, onChange: onChange, mode: itemDirection === 'column' ? 'combo-box' : 'menu-button', validRhsTypes: validRhsTypes, dateFunctions: dateFunctions }), hasProp(rhs, 'field') && (_jsx(Flex, { item: { grow: 1 }, children: _jsx(FieldSelector, { value: rhs.field, onChange: handleFieldChange, fields: fieldOptions, status: showError ? 'error' : undefined, info: showError ? 'No selection' : undefined }) })), hasProp(rhs, 'value') && !hasProp(rhs, 'dateFunction') && (_jsxs(Flex, { item: { grow: 1 }, children: [fieldType === 'TEXT' && useValueSelector && (_jsxs(Select, { value: rhs.value, onChange: (e) => handleValueSelection(e.target.value), status: showError ? 'error' : undefined, info: showError ? 'No selection' : undefined, label: '-', labelHidden: true, children: [_jsx(Option, { value: '', children: "Select value" }), possibleValues.map(value => (_jsx(Option, { value: value, children: value }, value)))] })), fieldType === 'TEXT' && !useValueSelector && (_jsx(Input, { value: rhs.value, onChange: handleValueChange, status: showError ? 'error' : undefined, info: showError ? 'Empty value' : undefined, name: 'rhs-text-literal-input', label: '-', labelHidden: true })), fieldType === 'NUMBER' && (_jsx(NumericInput, { rhs: rhs, onChange: onChange, status: showError ? 'error' : undefined })), fieldType === 'TIME_ONLY' && (_jsx(Input, { type: 'time', step: '1', value: typeof rhs.value === 'string' ? rhs.value : convertMsToTimeValue(rhs.value), onChange: handleTimeValueChange, status: showError ? 'error' : undefined, info: showError ? 'Invalid time' : undefined, label: '-', labelHidden: true })), fieldType === 'DATE_ONLY' && (_jsx(DateInput, { value: rhs.value, onChange: handleDateValueChange, status: showError ? 'error' : undefined, info: showError ? 'Invalid date' : '', label: '-', labelHidden: true })), fieldType === 'DATE_TIME' && (_jsx(DateTimeInput, { value: rhs.value !== '' ? rhs.value : undefined, onChange: handleDateValueChange, status: showError ? 'error' : undefined, info: showError ? 'Invalid date' : '', label: '-', labelHidden: true }))] })), (fieldType === 'DATE_ONLY' || fieldType === 'DATE_TIME') &&
215
- (hasProp(rhs, 'relativeDate') || hasProp(rhs, 'dateFunction')) && (_jsx(Flex, { item: { grow: 1 }, children: _jsx(TimePeriodComp, { rhs: rhs, fieldType: fieldType, onChange: onChange, dateFunctionsList: dateFunctions ? dateFunctions[fieldType] : [], status: showError ? 'error' : undefined }) })), hasProp(rhs, 'values') && (_jsxs(Flex, { item: { grow: 1 }, children: [useValueSelector && (_jsx(MultiValueSelector, { values: rhs.values, options: possibleValues, onChange: handleValueSelection, status: showError ? 'error' : undefined })), !useValueSelector && (_jsx(Input, { value: csvInput, onChange: handleCSVChange, status: showError ? 'error' : undefined, info: showError ? 'Invalid values' : undefined, label: '-', labelHidden: true, placeholder: 'Enter comma separated values' // FIXME: TR
216
- }))] }))] }));
277
+ }, children: [_jsx(RhsModeSwitch, { parameters: parameters, fieldType: fieldType, comparator: comparator, rhs: rhs, onChange: onChange, mode: itemDirection === 'column' ? 'combo-box' : 'menu-button', validRhsTypes: validRhsTypes, dateFunctions: dateFunctions }), hasProp(rhs, 'field') && (_jsx(Flex, { item: { grow: 1 }, children: _jsx(FieldSelector, { value: rhs.field, onChange: handleFieldChange, fields: fieldOptions, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_no_selection') : undefined }) })), hasProp(rhs, 'parameterId') && (_jsxs(Flex, { item: { grow: 1 }, children: [parameters.length === 1 && (_jsx(Input, { value: parameters[0].primary.toString(), status: showError ? 'error' : undefined, info: showError ? t('condition_builder_empty_value_text') : undefined, name: 'rhs-text-parameter-input', label: t('condition_builder_rhs_with_readOnly_input'), labelHidden: true, readOnly: true })), parameters.length > 1 && (_jsx(ValueSelector, { parameters: parameters, mode: 'single-select', values: rhs.parameterId.toString(), selectedField: matchingField, rhs: rhs, comparator: comparator, onChange: handleValueSelection, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_empty_selection_error_text') : undefined }))] })), hasProp(rhs, 'value') && !hasProp(rhs, 'dateFunction') && (_jsxs(Flex, { item: { grow: 1 }, children: [fieldType === 'TEXT' && useValueSelector && (_jsx(ValueSelector, { parameters: parameters, mode: 'single-select', values: rhs.value.toString(), selectedField: matchingField, comparator: comparator, rhs: rhs, onChange: handleValueSelection, status: showError || apiError ? 'error' : undefined, info: showError ? t('condition_builder_no_selection') : apiError, setApiError: setApiError })), fieldType === 'TEXT' && !useValueSelector && (_jsx(Input, { value: rhs.value.toString(), onChange: handleValueChange, status: showError ? 'error' : undefined, info: showError ? t('empty_value') : undefined, name: 'rhs-text-literal-input', label: t('condition_builder_rhs_with_input_type'), labelHidden: true })), fieldType === 'NUMBER' && (_jsx(NumericInput, { rhs: rhs, onChange: onChange, status: showError ? 'error' : undefined })), fieldType === 'TIME_ONLY' && (_jsx(TimeInput, { value: rhs.value !== '' ? convertMsToTimeValue(Number(rhs.value)) : undefined, withSeconds: true, onChange: handleDateValueChange, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_invalid_time') : '', label: '-', labelHidden: true })), fieldType === 'DATE_ONLY' && (_jsx(DateInput, { value: rhs.value, onChange: handleDateValueChange, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_invalid_date') : '', label: '-', labelHidden: true })), fieldType === 'DATE_TIME' && (_jsx(DateTimeInput, { value: rhs.value !== '' ? rhs.value : undefined, onChange: handleDateValueChange, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_invalid_date') : '', label: '-', labelHidden: true }))] })), (fieldType === 'DATE_ONLY' || fieldType === 'DATE_TIME') &&
278
+ (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 })), !useValueSelector && (_jsx(Input, { value: csvInput, onChange: handleCSVChange, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_invalid_values') : undefined, label: '-', labelHidden: true, placeholder: t('condition_builder_enter_csv_placeholder') }))] })), hasProp(rhs, 'start') && (_jsxs(Flex, { item: { grow: 1 }, children: [fieldType === 'NUMBER' && (_jsx(NumberRangeInput, { value: { start: rhs.start.toString(), end: rhs.end.toString() }, onChange: handleNumberRangeValueChange, status: showError ? 'error' : undefined, label: matchingField.primary, labelHidden: labelHidden, info: showError ? t('condition_builder_invalid_number_range') : undefined })), fieldType === 'DATE_ONLY' && (_jsx(DateRangeInput, { value: { start: rhs.start || undefined, end: rhs.end || undefined }, onChange: handleDateRangeValueChange, labelHidden: labelHidden, label: matchingField.primary, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_invalid_date_range') : '' })), fieldType === 'TIME_ONLY' && (_jsx(TimeRangeInput, { mode: 'time', value: { start: rhs.start || undefined, end: rhs.end || undefined }, onChange: handleDateRangeValueChange, labelHidden: labelHidden, label: matchingField.primary, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_invalid_time_range') : '' })), fieldType === 'DATE_TIME' && (_jsx(TimeRangeInput, { mode: 'datetime', value: { start: rhs.start || undefined, end: rhs.end || undefined }, onChange: handleDateRangeValueChange, labelHidden: labelHidden, label: matchingField.primary, status: showError ? 'error' : undefined, info: showError ? t('condition_builder_invalid_date_range') : '' }))] }))] }));
217
279
  };
218
280
  export default RhsControls;
219
281
  //# sourceMappingURL=index.js.map