@pega/cosmos-react-condition-builder 3.0.0-dev.9.0 → 3.0.0-rc.2

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 +38 -0
  32. package/lib/components/ConditionBuilder/RhsControls/ValueSelector.d.ts.map +1 -0
  33. package/lib/components/ConditionBuilder/RhsControls/ValueSelector.js +133 -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 +89 -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 +84 -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 +55 -2
  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 +118 -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 -4
  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,4 +1,5 @@
1
- import type { BaseProps, NoChildrenProp } from '@pega/cosmos-react-core';
1
+ import { Ref } from 'react';
2
+ import type { BaseProps, NoChildrenProp, MenuItemProps } from '@pega/cosmos-react-core';
2
3
  import { FieldType, Comparator, ComparatorsByType, DateFunction, RHSType, TimePeriod, DatePart } from './core/types';
3
4
  /** RHS object with a Date function */
4
5
  export interface RhsWithDateFunction {
@@ -25,6 +26,10 @@ export interface RhsWithRelativeDate {
25
26
  datePart: DatePart;
26
27
  };
27
28
  }
29
+ /** RHS object with PARAMETER type */
30
+ export interface RhsWithParameter {
31
+ parameterId: string;
32
+ }
28
33
  /** Type definition for the leaf-level nodes in nested conditions */
29
34
  export interface LeafCondition {
30
35
  comparator: Comparator;
@@ -37,7 +42,10 @@ export interface LeafCondition {
37
42
  value: string | number;
38
43
  } | {
39
44
  values: string[] | number[];
40
- } | RhsWithDateFunction | RhsWithRelativeDate;
45
+ } | {
46
+ start: string | number;
47
+ end: string | number;
48
+ } | RhsWithDateFunction | RhsWithRelativeDate | RhsWithParameter;
41
49
  }
42
50
  /** Type definition for objects representing condition-rows in the builder UI */
43
51
  export interface ConditionRow extends LeafCondition {
@@ -58,11 +66,23 @@ export declare type Condition = {
58
66
  condition: LeafCondition;
59
67
  };
60
68
  /** Type definition for the input Field objects for the ConditionBuilder */
61
- export interface Field {
62
- /** Name of the Field. Saved as part of the output condition */
63
- name: string;
64
- /** (Optional) Display label for the Field. If none passed, the `name` itself will be used */
65
- label?: string;
69
+ export declare type ParameterValue = Pick<MenuItemProps, 'id' | 'primary'>;
70
+ export declare type ReferenceValue = Pick<MenuItemProps, 'id' | 'primary'>;
71
+ export declare type ValueSelection<F> = string[] | ReferenceValue[] | (({ searchString, comparator, lhs }: {
72
+ searchString?: string;
73
+ comparator?: string;
74
+ lhs?: F;
75
+ }) => Promise<string[] | ReferenceValue[]>);
76
+ interface BasicField extends Pick<MenuItemProps, 'id' | 'primary'> {
77
+ }
78
+ export declare type Field = BasicField & ({
79
+ parameters?: ParameterValue[];
80
+ /**
81
+ * For TEXT fields, if a list of possible values is known ahead of time, they can be passed.
82
+ * Otherwise we fetch data from api and pass a promise which returns list of values
83
+ * This enables users to select from those values instead of manually typing them
84
+ */
85
+ possibleValues?: ValueSelection<Field>;
66
86
  /**
67
87
  * Data-type for the field.
68
88
  * Has to be one of these values. Convert where necessary
@@ -70,14 +90,10 @@ export interface Field {
70
90
  * e.g. Text(single value)/Picklist/... should be used as `TEXT`
71
91
  */
72
92
  type: FieldType;
73
- /** (Optional) Used to add the field to a group during field-selection */
74
- groupLabel?: string;
75
- /**
76
- * For TEXT fields, if a list of possible values is known ahead of time, they can be passed.
77
- * This enables users to select from those values instead of manually typing them
78
- */
79
- possibleValues?: string[];
80
- }
93
+ } | {
94
+ /** An array of type Field to represent the child items. */
95
+ items: Field[];
96
+ });
81
97
  /** Valid date functions by field type */
82
98
  export interface DateFunctionsByType {
83
99
  /** Date functions to enable for DATE_TIME fields */
@@ -85,15 +101,17 @@ export interface DateFunctionsByType {
85
101
  /** Date functions to enable for DATE_ONLY fields */
86
102
  DATE_ONLY: DateFunction[];
87
103
  }
104
+ export interface HandleValue {
105
+ /**
106
+ * Returns condition validity and condition or undefined if valid.
107
+ * Undefined indicates no condition.
108
+ */
109
+ getCondition: () => [valid: false] | [valid: true, condition: Condition | undefined];
110
+ }
88
111
  /** Type definition for the input props of ConditionBuilder */
89
112
  export default interface ConditionBuilderProps extends BaseProps, NoChildrenProp {
90
113
  /** Metadata (data-model) for the Fields to use in the builder */
91
114
  fields: Field[];
92
- /**
93
- * Callback used from the builder's `Submit` button
94
- * Called with undefined when an empty condition is submitted (useful for clearing a previous condition)
95
- */
96
- onConditionSubmit: (condition: Condition | undefined) => void;
97
115
  /** (Optional) A seed condition for the builder. To use when editing an existing condition */
98
116
  condition?: Condition;
99
117
  /** (Optional) Used to limit the Comparators allowed in the builder. */
@@ -108,5 +126,8 @@ export default interface ConditionBuilderProps extends BaseProps, NoChildrenProp
108
126
  dateFunctions?: DateFunctionsByType;
109
127
  /** (Optional) Pass this if the `NOT` operator should be considered as invalid */
110
128
  disallowNOT?: boolean;
129
+ /** Imperative handle for the component. */
130
+ handle?: Ref<HandleValue>;
111
131
  }
132
+ export {};
112
133
  //# sourceMappingURL=ConditionBuilder.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionBuilder.types.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzE,OAAO,EACL,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,YAAY,EACZ,OAAO,EACP,UAAU,EACV,QAAQ,EACT,MAAM,cAAc,CAAC;AAEtB,sCAAsC;AACtC,MAAM,WAAW,mBAAmB;IAClC;;;;;;;;;;;OAWG;IACH,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED,sCAAsC;AACtC,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE;QACZ,UAAU,EAAE,UAAU,CAAC;QACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,QAAQ,CAAC;KACpB,CAAC;CACH;AAED,oEAAoE;AACpE,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,UAAU,CAAC;IAEvB,GAAG,EAAE;QACH,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IAGF,GAAG,CAAC,EACA;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GACjB;QAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAC1B;QAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAA;KAAE,GAC/B,mBAAmB,GACnB,mBAAmB,CAAC;CACzB;AAED,gFAAgF;AAChF,MAAM,WAAW,YAAa,SAAQ,aAAa;IACjD,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,oBAAY,SAAS,GACjB;IA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AW,WAAW;IAC1B;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,GAAG,SAAS,CAAC,CAAC;CACtF;AAED,8DAA8D;AAC9D,MAAM,CAAC,OAAO,WAAW,qBAAsB,SAAQ,SAAS,EAAE,cAAc;IAC9E,iEAAiE;IACjE,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB,6FAA6F;IAC7F,SAAS,CAAC,EAAE,SAAS,CAAC;IAEtB,uEAAuE;IACvE,gBAAgB,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAEvC;;;;OAIG;IACH,aAAa,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAE7B,iJAAiJ;IACjJ,aAAa,CAAC,EAAE,mBAAmB,CAAC;IAEpC,iFAAiF;IACjF,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,2CAA2C;IAC3C,MAAM,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;CAC3B"}
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionBuilder.types.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.types.ts"],"names":[],"mappings":"","sourcesContent":["// cspell:ignore words DDTHH\nimport type { BaseProps, NoChildrenProp } from '@pega/cosmos-react-core';\n\nimport {\n FieldType,\n Comparator,\n ComparatorsByType,\n DateFunction,\n RHSType,\n TimePeriod,\n DatePart\n} from './core/types';\n\n/** RHS object with a Date function */\nexport interface RhsWithDateFunction {\n /**\n * Output format for the value varies based on the dateFunction:\n * YEARS: First day of year as YYYY-MM-DD\n * QUARTERS: First day of quarter as YYYY-MM-DD\n * MONTHS: First day of month as YYYY-MM-DD\n * WEEKS: First day of week as YYYY-MM-DD\n * DAYS: Date as YYYY-MM-DD\n * HOURS: YYYY-MM-DDTHH:mm:ss\n * MONTHS_OF_YEAR: 1-12\n * DAYS_OF_MONTH: 1-31\n * DAYS_OF_WEEK: 1-7\n */\n value: string | number;\n dateFunction: DateFunction;\n}\n\n/** RHS object with a Relative Date */\nexport interface RhsWithRelativeDate {\n relativeDate: {\n timePeriod: TimePeriod;\n interval?: number;\n datePart: DatePart;\n };\n}\n\n/** Type definition for the leaf-level nodes in nested conditions */\nexport interface LeafCondition {\n comparator: Comparator;\n\n lhs: {\n field: string;\n };\n\n // Optional for some of the comparators like IS_TRUE, IS_NULL, etc.\n rhs?:\n | { field: string } // When comparing the LHS with another field\n | { value: string | number } // When comparing the LHS with a single literal value (for comparators like EQ, GTE etc.)\n | { values: string[] | number[] } // When comparing the LHS with a list of literal values (for comparators like IN, NOT_IN etc.)\n | RhsWithDateFunction // When comparing a date field with a date function on RHS\n | RhsWithRelativeDate; // When comparing a date field with a symbolic date on RHS\n}\n\n/** Type definition for objects representing condition-rows in the builder UI */\nexport interface ConditionRow extends LeafCondition {\n id: string; // To use as `key` prop when rendering a list of rows\n label: string; // Used to refer the row from a logic-string\n}\n\n/**\n * Type definition for simple/complex conditions\n * At a given node in the condition tree, it can have exactly one of the keys AND/OR/NOT/condition\n */\nexport type Condition =\n | { AND: Condition[] }\n | { OR: Condition[] }\n | { NOT: Condition }\n | { condition: LeafCondition };\n\n/** Type definition for the input Field objects for the ConditionBuilder */\nexport interface Field {\n /** Name of the Field. Saved as part of the output condition */\n name: string;\n\n /** (Optional) Display label for the Field. If none passed, the `name` itself will be used */\n label?: string;\n\n /**\n * Data-type for the field.\n * Has to be one of these values. Convert where necessary\n * e.g. Integer/Decimal/... should be used as `NUMBER`\n * e.g. Text(single value)/Picklist/... should be used as `TEXT`\n */\n type: FieldType;\n\n /** (Optional) Used to add the field to a group during field-selection */\n groupLabel?: string;\n\n /**\n * For TEXT fields, if a list of possible values is known ahead of time, they can be passed.\n * This enables users to select from those values instead of manually typing them\n */\n possibleValues?: string[];\n}\n\n/** Valid date functions by field type */\nexport interface DateFunctionsByType {\n /** Date functions to enable for DATE_TIME fields */\n DATE_TIME: DateFunction[];\n /** Date functions to enable for DATE_ONLY fields */\n DATE_ONLY: DateFunction[];\n}\n\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 /**\n * Callback used from the builder's `Submit` button\n * Called with undefined when an empty condition is submitted (useful for clearing a previous condition)\n */\n onConditionSubmit: (condition: Condition | undefined) => void;\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"]}
1
+ {"version":3,"file":"ConditionBuilder.types.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.types.ts"],"names":[],"mappings":"","sourcesContent":["// cspell:ignore words DDTHH\nimport { Ref } from 'react';\n\nimport type { BaseProps, NoChildrenProp, MenuItemProps } from '@pega/cosmos-react-core';\n\nimport {\n FieldType,\n Comparator,\n ComparatorsByType,\n DateFunction,\n RHSType,\n TimePeriod,\n DatePart\n} from './core/types';\n\n/** RHS object with a Date function */\nexport interface RhsWithDateFunction {\n /**\n * Output format for the value varies based on the dateFunction:\n * YEARS: First day of year as YYYY-MM-DD\n * QUARTERS: First day of quarter as YYYY-MM-DD\n * MONTHS: First day of month as YYYY-MM-DD\n * WEEKS: First day of week as YYYY-MM-DD\n * DAYS: Date as YYYY-MM-DD\n * HOURS: YYYY-MM-DDTHH:mm:ss\n * MONTHS_OF_YEAR: 1-12\n * DAYS_OF_MONTH: 1-31\n * DAYS_OF_WEEK: 1-7\n */\n value: string | number;\n dateFunction: DateFunction;\n}\n\n/** RHS object with a Relative Date */\nexport interface RhsWithRelativeDate {\n relativeDate: {\n timePeriod: TimePeriod;\n interval?: number;\n datePart: DatePart;\n };\n}\n\n/** RHS object with PARAMETER type */\nexport interface RhsWithParameter {\n parameterId: string;\n}\n\n/** Type definition for the leaf-level nodes in nested conditions */\nexport interface LeafCondition {\n comparator: Comparator;\n\n lhs: {\n field: string;\n };\n\n // Optional for some of the comparators like IS_TRUE, IS_NULL, etc.\n rhs?:\n | { field: string } // When comparing the LHS with another field\n | { value: string | number } // When comparing the LHS with a single literal value (for comparators like EQ, GTE etc.)\n | { values: string[] | number[] } // When comparing the LHS with a list of literal values (for comparators like IN, NOT_IN etc.)\n | { start: string | number; end: string | number } // When comparing numeric or date field with two values that determine range\n | RhsWithDateFunction // When comparing a date field with a date function on RHS\n | RhsWithRelativeDate // When comparing a date field with a symbolic date on RHS\n | RhsWithParameter; // When comparing the LHS with PARAMETER type\n}\n\n/** Type definition for objects representing condition-rows in the builder UI */\nexport interface ConditionRow extends LeafCondition {\n id: string; // To use as `key` prop when rendering a list of rows\n label: string; // Used to refer the row from a logic-string\n}\n\n/**\n * Type definition for simple/complex conditions\n * At a given node in the condition tree, it can have exactly one of the keys AND/OR/NOT/condition\n */\nexport type Condition =\n | { AND: Condition[] }\n | { OR: Condition[] }\n | { NOT: Condition }\n | { condition: LeafCondition };\n\n/** Type definition for the input Field objects for the ConditionBuilder */\n\nexport type ParameterValue = Pick<MenuItemProps, 'id' | 'primary'>;\n\nexport type ReferenceValue = Pick<MenuItemProps, 'id' | 'primary'>;\n\nexport type ValueSelection<F> =\n | string[]\n | ReferenceValue[]\n | (({\n searchString,\n comparator,\n lhs\n }: {\n searchString?: string;\n comparator?: string;\n lhs?: F;\n }) => Promise<string[] | ReferenceValue[]>);\n\ninterface BasicField extends Pick<MenuItemProps, 'id' | 'primary'> {}\n\nexport type Field = BasicField &\n (\n | {\n parameters?: ParameterValue[];\n\n /**\n * For TEXT fields, if a list of possible values is known ahead of time, they can be passed.\n * Otherwise we fetch data from api and pass a promise which returns list of values\n * This enables users to select from those values instead of manually typing them\n */\n possibleValues?: ValueSelection<Field>;\n\n /**\n * Data-type for the field.\n * Has to be one of these values. Convert where necessary\n * e.g. Integer/Decimal/... should be used as `NUMBER`\n * e.g. Text(single value)/Picklist/... should be used as `TEXT`\n */\n type: FieldType;\n }\n | {\n /** An array of type Field to represent the child items. */\n items: Field[];\n }\n );\n\n/** Valid date functions by field type */\nexport interface DateFunctionsByType {\n /** Date functions to enable for DATE_TIME fields */\n DATE_TIME: DateFunction[];\n /** Date functions to enable for DATE_ONLY fields */\n DATE_ONLY: DateFunction[];\n}\n\nexport interface HandleValue {\n /**\n * Returns condition validity and condition or undefined if valid.\n * Undefined indicates no condition.\n */\n getCondition: () => [valid: false] | [valid: true, condition: Condition | undefined];\n}\n\n/** Type definition for the input props of ConditionBuilder */\nexport default interface ConditionBuilderProps extends BaseProps, NoChildrenProp {\n /** Metadata (data-model) for the Fields to use in the builder */\n fields: Field[];\n\n /** (Optional) A seed condition for the builder. To use when editing an existing condition */\n condition?: Condition;\n\n /** (Optional) Used to limit the Comparators allowed in the builder. */\n validComparators?: ComparatorsByType[];\n\n /**\n * (Optional) Pass this to control which all types of RHS are enabled in the component\n * DEFAULT: Set(['LITERAL', 'FIELD'])\n * NOTE: If enabling `DATE_FUNCTION`s, additionally pass a `dateFunctions` prop to specify which functions are enabled\n */\n validRhsTypes?: Set<RHSType>;\n\n /** (Optional) When enabling 'DATE_FUNCTION's via `validRhsTypes`, pass this to specify which all date functions are applicable per field type */\n dateFunctions?: DateFunctionsByType;\n\n /** (Optional) Pass this if the `NOT` operator should be considered as invalid */\n disallowNOT?: boolean;\n\n /** Imperative handle for the component. */\n handle?: Ref<HandleValue>;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"FieldCondition.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/FieldCondition.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAY,MAAM,OAAO,CAAC;AAEpD,OAAO,EAAyB,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE9E,OAAO,mBAAmB,MAAM,wBAAwB,CAAC;AAIzD,kEAAkE;AAClE,QAAA,MAAM,cAAc,EAAE,iBAAiB,CAAC,mBAAmB,GAAG,YAAY,CA2DzE,CAAC;AAEF,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"FieldCondition.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/FieldCondition.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAiC,MAAM,OAAO,CAAC;AAEzE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,mBAAoC,MAAM,wBAAwB,CAAC;AAI1E,kEAAkE;AAClE,QAAA,MAAM,cAAc,EAAE,iBAAiB,CAAC,mBAAmB,GAAG,YAAY,CA0DzE,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -1,26 +1,26 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useState } from 'react';
3
- import { Flex, Button, useI18n } from '@pega/cosmos-react-core';
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useImperativeHandle, useState } from 'react';
4
3
  import AtomicCondition, { getInitConditionForLhs, isValidCondition } from './AtomicCondition';
5
4
  /** Component for building an atomic condition on a given field */
6
5
  const FieldCondition = (props) => {
7
- const { targetField, fields, onSubmit, condition: seedCondition, validComparators, validRhsTypes = new Set(['LITERAL', 'FIELD']), dateFunctions } = props;
6
+ const { targetField, fields, condition: seedCondition, validComparators, validRhsTypes = new Set(['LITERAL', 'FIELD']), dateFunctions, handle } = props;
8
7
  const [condition, setCondition] = useState(
9
8
  // If editing use the seedCondition, otherwise, determine an initial condition based on the targetField
10
9
  () => seedCondition ||
11
10
  getInitConditionForLhs({ field: targetField }, fields, validRhsTypes, validComparators, dateFunctions));
12
11
  const [showErrorIndicators, setErrorIndicators] = useState(false); // Used to enable inline error indicators on the controls
13
- const t = useI18n();
14
- const handleSubmission = () => {
15
- setErrorIndicators(false); // Reset any previous flag
12
+ const getCondition = () => {
13
+ setErrorIndicators(false);
16
14
  if (isValidCondition(condition, fields, true)) {
17
- onSubmit(condition); // If it's a valid condition, submit it
18
- }
19
- else {
20
- setErrorIndicators(true); // Otherwise, indicate errors
15
+ return [true, condition];
21
16
  }
17
+ setErrorIndicators(true);
18
+ return [false];
22
19
  };
23
- return (_jsxs(Flex, { container: { direction: 'column', gap: 2 }, children: [_jsx(AtomicCondition, { condition: condition, fields: fields, indicateErrors: showErrorIndicators, validComparators: validComparators, dateFunctions: dateFunctions, onChange: c => setCondition(c), itemDirection: 'column', validRhsTypes: validRhsTypes, showLhsAsLabel: true }), _jsx(Flex, { container: { justify: 'end' }, children: _jsx(Button, { name: 'field-condition-submit', variant: 'primary', onClick: handleSubmission, children: t('condition_builder_submit_button_label') }) })] }));
20
+ useImperativeHandle(handle, () => ({
21
+ getCondition
22
+ }), [getCondition]);
23
+ return (_jsx(AtomicCondition, { condition: condition, fields: fields, indicateErrors: showErrorIndicators, validComparators: validComparators, dateFunctions: dateFunctions, onChange: c => setCondition(c), itemDirection: 'column', validRhsTypes: validRhsTypes, lhsMode: 'label' }));
24
24
  };
25
25
  export default FieldCondition;
26
26
  //# sourceMappingURL=FieldCondition.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FieldCondition.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/FieldCondition.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAqB,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAgB,MAAM,yBAAyB,CAAC;AAG9E,OAAO,eAAe,EAAE,EAAE,sBAAsB,EAAE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AE,CAAC,YAAY,CAAC,CAAC,CAAC,EAC9B,aAAa,EAAC,QAAQ,EACtB,aAAa,EAAE,aAAa,EAC5B,cAAc,SACd,EAGF,KAAC,IAAI,IAAC,SAAS,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,YACjC,KAAC,MAAM,IAAC,IAAI,EAAC,wBAAwB,EAAC,OAAO,EAAC,SAAS,EAAC,OAAO,EAAE,gBAAgB,YAC9E,CAAC,CAAC,uCAAuC,CAAC,GACpC,GACJ,IACF,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["import { FunctionComponent, useState } from 'react';\n\nimport { Flex, Button, useI18n, ForwardProps } from '@pega/cosmos-react-core';\n\nimport FieldConditionProps from './FieldCondition.types';\nimport AtomicCondition, { getInitConditionForLhs, isValidCondition } from './AtomicCondition';\nimport { RHSType } from './core/types';\n\n/** Component for building an atomic condition on a given field */\nconst FieldCondition: FunctionComponent<FieldConditionProps & ForwardProps> = (\n props: FieldConditionProps\n) => {\n const {\n targetField,\n fields,\n onSubmit,\n condition: seedCondition,\n validComparators,\n validRhsTypes = new Set<RHSType>(['LITERAL', 'FIELD']),\n dateFunctions\n } = props;\n const [condition, setCondition] = useState(\n // If editing use the seedCondition, otherwise, determine an initial condition based on the targetField\n () =>\n seedCondition ||\n getInitConditionForLhs(\n { field: targetField },\n fields,\n validRhsTypes,\n validComparators,\n dateFunctions\n )\n );\n const [showErrorIndicators, setErrorIndicators] = useState(false); // Used to enable inline error indicators on the controls\n const t = useI18n();\n\n const handleSubmission = () => {\n setErrorIndicators(false); // Reset any previous flag\n\n if (isValidCondition(condition, fields, true)) {\n onSubmit(condition); // If it's a valid condition, submit it\n } else {\n setErrorIndicators(true); // Otherwise, indicate errors\n }\n };\n\n return (\n <Flex container={{ direction: 'column', gap: 2 }}>\n <AtomicCondition\n condition={condition}\n fields={fields}\n indicateErrors={showErrorIndicators}\n validComparators={validComparators}\n dateFunctions={dateFunctions}\n onChange={c => setCondition(c)}\n itemDirection='column'\n validRhsTypes={validRhsTypes}\n showLhsAsLabel\n />\n\n {/* Submit block */}\n <Flex container={{ justify: 'end' }}>\n <Button name='field-condition-submit' variant='primary' onClick={handleSubmission}>\n {t('condition_builder_submit_button_label')}\n </Button>\n </Flex>\n </Flex>\n );\n};\n\nexport default FieldCondition;\n"]}
1
+ {"version":3,"file":"FieldCondition.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/FieldCondition.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAqB,mBAAmB,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAKzE,OAAO,eAAe,EAAE,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAG9F,kEAAkE;AAClE,MAAM,cAAc,GAA0D,CAC5E,KAA0B,EAC1B,EAAE;IACF,MAAM,EACJ,WAAW,EACX,MAAM,EACN,SAAS,EAAE,aAAa,EACxB,gBAAgB,EAChB,aAAa,GAAG,IAAI,GAAG,CAAU,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,EACtD,aAAa,EACb,MAAM,EACP,GAAG,KAAK,CAAC;IACV,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ;IACxC,uGAAuG;IACvG,GAAG,EAAE,CACH,aAAa;QACb,sBAAsB,CACpB,EAAE,KAAK,EAAE,WAAW,EAAE,EACtB,MAAM,EACN,aAAa,EACb,gBAAgB,EAChB,aAAa,CACd,CACJ,CAAC;IACF,MAAM,CAAC,mBAAmB,EAAE,kBAAkB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,yDAAyD;IAE5H,MAAM,YAAY,GAAgC,GAAG,EAAE;QACrD,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAE1B,IAAI,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;YAC7C,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;SAC1B;QAED,kBAAkB,CAAC,IAAI,CAAC,CAAC;QACzB,OAAO,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC,CAAC;IAEF,mBAAmB,CACjB,MAAM,EACN,GAAG,EAAE,CAAC,CAAC;QACL,YAAY;KACb,CAAC,EACF,CAAC,YAAY,CAAC,CACf,CAAC;IAEF,OAAO,CACL,KAAC,eAAe,IACd,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,mBAAmB,EACnC,gBAAgB,EAAE,gBAAgB,EAClC,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,EAC9B,aAAa,EAAC,QAAQ,EACtB,aAAa,EAAE,aAAa,EAC5B,OAAO,EAAC,OAAO,GACf,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["import { FunctionComponent, useImperativeHandle, useState } from 'react';\n\nimport { ForwardProps } from '@pega/cosmos-react-core';\n\nimport FieldConditionProps, { HandleValue } from './FieldCondition.types';\nimport AtomicCondition, { getInitConditionForLhs, isValidCondition } from './AtomicCondition';\nimport { RHSType } from './core/types';\n\n/** Component for building an atomic condition on a given field */\nconst FieldCondition: FunctionComponent<FieldConditionProps & ForwardProps> = (\n props: FieldConditionProps\n) => {\n const {\n targetField,\n fields,\n condition: seedCondition,\n validComparators,\n validRhsTypes = new Set<RHSType>(['LITERAL', 'FIELD']),\n dateFunctions,\n handle\n } = props;\n const [condition, setCondition] = useState(\n // If editing use the seedCondition, otherwise, determine an initial condition based on the targetField\n () =>\n seedCondition ||\n getInitConditionForLhs(\n { field: targetField },\n fields,\n validRhsTypes,\n validComparators,\n dateFunctions\n )\n );\n const [showErrorIndicators, setErrorIndicators] = useState(false); // Used to enable inline error indicators on the controls\n\n const getCondition: HandleValue['getCondition'] = () => {\n setErrorIndicators(false);\n\n if (isValidCondition(condition, fields, true)) {\n return [true, condition];\n }\n\n setErrorIndicators(true);\n return [false];\n };\n\n useImperativeHandle(\n handle,\n () => ({\n getCondition\n }),\n [getCondition]\n );\n\n return (\n <AtomicCondition\n condition={condition}\n fields={fields}\n indicateErrors={showErrorIndicators}\n validComparators={validComparators}\n dateFunctions={dateFunctions}\n onChange={c => setCondition(c)}\n itemDirection='column'\n validRhsTypes={validRhsTypes}\n lhsMode='label'\n />\n );\n};\n\nexport default FieldCondition;\n"]}
@@ -1,14 +1,19 @@
1
+ import { Ref } from 'react';
1
2
  import { BaseProps } from '@pega/cosmos-react-core';
2
3
  import { ComparatorsByType, RHSType } from './core/types';
3
4
  import { Field, LeafCondition, DateFunctionsByType } from './ConditionBuilder.types';
5
+ export interface HandleValue {
6
+ /**
7
+ * Returns condition validity and condition if valid.
8
+ */
9
+ getCondition: () => [valid: false] | [valid: true, condition: LeafCondition];
10
+ }
4
11
  /** Type definition for the input props of FieldCondition */
5
12
  export default interface FieldConditionProps extends BaseProps {
6
- /** Name of the field on which the condition should be constructed */
7
- targetField: Field['name'];
13
+ /** Id of the field on which the condition should be constructed */
14
+ targetField: Field['id'];
8
15
  /** Metadata (data-model) for the Fields to use in the RHS field-selector etc. */
9
16
  fields: Field[];
10
- /** Callback used from the component's `Submit` button */
11
- onSubmit: (condition: LeafCondition) => void;
12
17
  /** (Optional) Passed when editing an existing condition */
13
18
  condition?: LeafCondition;
14
19
  /** (Optional) Used to limit the Comparators allowed in the component. */
@@ -21,5 +26,7 @@ export default interface FieldConditionProps extends BaseProps {
21
26
  validRhsTypes?: Set<RHSType>;
22
27
  /** (Optional) When enabling 'DATE_FUNCTION's via `validRhsTypes`, pass this to specify which all date functions are applicable per field type */
23
28
  dateFunctions?: DateFunctionsByType;
29
+ /** Imperative handle for the component. */
30
+ handle?: Ref<HandleValue>;
24
31
  }
25
32
  //# sourceMappingURL=FieldCondition.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FieldCondition.types.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/FieldCondition.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAErF,4DAA4D;AAC5D,MAAM,CAAC,OAAO,WAAW,mBAAoB,SAAQ,SAAS;IAC5D,qEAAqE;IACrE,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAE3B,iFAAiF;IACjF,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB,yDAAyD;IACzD,QAAQ,EAAE,CAAC,SAAS,EAAE,aAAa,KAAK,IAAI,CAAC;IAE7C,2DAA2D;IAC3D,SAAS,CAAC,EAAE,aAAa,CAAC;IAE1B,yEAAyE;IACzE,gBAAgB,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAEvC;;;;OAIG;IACH,aAAa,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAE7B,iJAAiJ;IACjJ,aAAa,CAAC,EAAE,mBAAmB,CAAC;CACrC"}
1
+ {"version":3,"file":"FieldCondition.types.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/FieldCondition.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAErF,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;CAC9E;AAED,4DAA4D;AAC5D,MAAM,CAAC,OAAO,WAAW,mBAAoB,SAAQ,SAAS;IAC5D,mEAAmE;IACnE,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IAEzB,iFAAiF;IACjF,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,aAAa,CAAC;IAE1B,yEAAyE;IACzE,gBAAgB,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAEvC;;;;OAIG;IACH,aAAa,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAE7B,iJAAiJ;IACjJ,aAAa,CAAC,EAAE,mBAAmB,CAAC;IAEpC,2CAA2C;IAC3C,MAAM,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;CAC3B"}
@@ -1 +1 @@
1
- {"version":3,"file":"FieldCondition.types.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/FieldCondition.types.ts"],"names":[],"mappings":"","sourcesContent":["import { BaseProps } from '@pega/cosmos-react-core';\n\nimport { ComparatorsByType, RHSType } from './core/types';\nimport { Field, LeafCondition, DateFunctionsByType } from './ConditionBuilder.types';\n\n/** Type definition for the input props of FieldCondition */\nexport default interface FieldConditionProps extends BaseProps {\n /** Name of the field on which the condition should be constructed */\n targetField: Field['name'];\n\n /** Metadata (data-model) for the Fields to use in the RHS field-selector etc. */\n fields: Field[];\n\n /** Callback used from the component's `Submit` button */\n onSubmit: (condition: LeafCondition) => void;\n\n /** (Optional) Passed when editing an existing condition */\n condition?: LeafCondition;\n\n /** (Optional) Used to limit the Comparators allowed in the component. */\n validComparators?: ComparatorsByType[];\n\n /**\n * (Optional) Pass this to control which all types of RHS are enabled in the component\n * DEFAULT: Set(['LITERAL', 'FIELD'])\n * NOTE: If enabling `DATE_FUNCTION`s, additionally pass a `dateFunctions` prop to specify which functions are enabled\n */\n validRhsTypes?: Set<RHSType>;\n\n /** (Optional) When enabling 'DATE_FUNCTION's via `validRhsTypes`, pass this to specify which all date functions are applicable per field type */\n dateFunctions?: DateFunctionsByType;\n}\n"]}
1
+ {"version":3,"file":"FieldCondition.types.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/FieldCondition.types.ts"],"names":[],"mappings":"","sourcesContent":["import { Ref } from 'react';\n\nimport { BaseProps } from '@pega/cosmos-react-core';\n\nimport { ComparatorsByType, RHSType } from './core/types';\nimport { Field, LeafCondition, DateFunctionsByType } from './ConditionBuilder.types';\n\nexport interface HandleValue {\n /**\n * Returns condition validity and condition if valid.\n */\n getCondition: () => [valid: false] | [valid: true, condition: LeafCondition];\n}\n\n/** Type definition for the input props of FieldCondition */\nexport default interface FieldConditionProps extends BaseProps {\n /** Id of the field on which the condition should be constructed */\n targetField: Field['id'];\n\n /** Metadata (data-model) for the Fields to use in the RHS field-selector etc. */\n fields: Field[];\n\n /** (Optional) Passed when editing an existing condition */\n condition?: LeafCondition;\n\n /** (Optional) Used to limit the Comparators allowed in the component. */\n validComparators?: ComparatorsByType[];\n\n /**\n * (Optional) Pass this to control which all types of RHS are enabled in the component\n * DEFAULT: Set(['LITERAL', 'FIELD'])\n * NOTE: If enabling `DATE_FUNCTION`s, additionally pass a `dateFunctions` prop to specify which functions are enabled\n */\n validRhsTypes?: Set<RHSType>;\n\n /** (Optional) When enabling 'DATE_FUNCTION's via `validRhsTypes`, pass this to specify which all date functions are applicable per field type */\n dateFunctions?: DateFunctionsByType;\n\n /** Imperative handle for the component. */\n handle?: Ref<HandleValue>;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"FieldSelector.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/FieldSelector.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAe,iBAAiB,EAAqB,MAAM,OAAO,CAAC;AAE1E,OAAO,EAIL,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACf,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B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kBAAkB,GAAG,YAAY,CA0DvE,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -1,32 +1,25 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useMemo, useState } from 'react';
3
- import { ComboBox, menuHelpers } from '@pega/cosmos-react-core';
3
+ import { ComboBox, menuHelpers, hasProp, useI18n } from '@pega/cosmos-react-core';
4
4
  /** Convert input Fields to use as ComboBox options */
5
5
  function getMenuItemsFromFields(fields, selection) {
6
- const items = [];
7
- const itemsByGroupLabel = {};
8
- fields.forEach(field => {
9
- const item = {
10
- id: field.name,
11
- primary: field.label ?? field.name,
12
- selected: field.name === selection // set Selected field to selection
6
+ return fields.map(field => {
7
+ const { id, primary } = field;
8
+ let childitems;
9
+ if (hasProp(field, 'items'))
10
+ childitems = getMenuItemsFromFields(field.items, selection);
11
+ return {
12
+ id,
13
+ primary,
14
+ selected: childitems ? undefined : id === selection,
15
+ items: childitems
13
16
  };
14
- if (field.groupLabel) {
15
- itemsByGroupLabel[field.groupLabel] = itemsByGroupLabel[field.groupLabel] || [];
16
- itemsByGroupLabel[field.groupLabel].push(item);
17
- }
18
- else {
19
- items.push(item);
20
- }
21
17
  });
22
- Object.entries(itemsByGroupLabel).forEach(([label, childItems]) => {
23
- items.push({ id: label, primary: label, items: childItems });
24
- });
25
- return items;
26
18
  }
27
19
  /** Sets up a ComboBox to select a Field. Handles grouping and autocomplete. */
28
20
  const FieldSelector = (props) => {
29
21
  const { value, onChange, fields, status, info } = props;
22
+ const t = useI18n();
30
23
  // Determine ComboBox menu items from the fields
31
24
  const items = useMemo(() => getMenuItemsFromFields(fields, value), [fields, value]);
32
25
  const selected = useMemo(() => {
@@ -47,7 +40,7 @@ const FieldSelector = (props) => {
47
40
  ? menuHelpers.flatten(items).filter(({ primary }) => filterRegex.test(primary))
48
41
  : items;
49
42
  }, [filterRegex, items]);
50
- return (_jsx(ComboBox, { label: 'field', labelHidden: true, status: status, info: info, placeholder: 'Select\u2026', mode: 'single-select', value: filterValue, onChange: (ev) => {
43
+ return (_jsx(ComboBox, { label: t('condition_builder_field_label'), labelHidden: true, status: status, info: info, placeholder: t('select_placeholder_default'), mode: 'single-select', value: filterValue, onChange: (ev) => {
51
44
  setFilterValue(ev.target.value);
52
45
  if (!ev.target.value)
53
46
  onChange('');
@@ -1 +1 @@
1
- {"version":3,"file":"FieldSelector.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/FieldSelector.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAkC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE1E,OAAO,EACL,QAAQ,EAER,WAAW,EAKZ,MAAM,yBAAyB,CAAC;AAKjC,sDAAsD;AACtD,SAAS,sBAAsB,CAAC,MAAe,EAAE,SAAiB;IAChE,MAAM,KAAK,GAAuB,EAAE,CAAC;IACrC,MAAM,iBAAiB,GAA4C,EAAE,CAAC;IAEtE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACrB,MAAM,IAAI,GAAG;YACX,EAAE,EAAE,KAAK,CAAC,IAAI;YACd,OAAO,EAAE,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI;YAClC,QAAQ,EAAE,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,kCAAkC;SACtE,CAAC;QACF,IAAI,KAAK,CAAC,UAAU,EAAE;YACpB,iBAAiB,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,iBAAiB,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;YAChF,iBAAiB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SAChD;aAAM;YACL,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SAClB;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,UAAU,CAAC,EAAE,EAAE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GAAG,OAAO,CAAC,GAAG,EAAE;QACjC,OAAO,WAAW;YAChB,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC/E,CAAC,CAAC,KAAK,CAAC;IACZ,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;IAEzB,OAAO,CACL,KAAC,QAAQ,IACP,KAAK,EAAC,OAAO,EACb,WAAW,QACX,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,EACV,WAAW,EAAC,cAAS,EACrB,IAAI,EAAC,eAAe,EACpB,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,CAAC,EAAiC,EAAE,EAAE;YAC9C,cAAc,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAChC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK;gBAAE,QAAQ,CAAC,EAAE,CAAC,CAAC;QACrC,CAAC,EACD,MAAM,EAAE,GAAG,EAAE;YACX,cAAc,CAAC,EAAE,CAAC,CAAC;QACrB,CAAC,EACD,QAAQ,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,EAC7B,IAAI,EAAE;YACJ,KAAK,EAAE,aAAa;YACpB,IAAI,EAAE,eAAe;YACrB,MAAM,EAAE,WAAW;YACnB,WAAW,EAAE,EAAE,CAAC,EAAE;gBAChB,QAAQ,CAAC,EAAE,CAAC,CAAC;gBACb,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC,0CAA0C;YAChE,CAAC;SACF,GACD,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { ChangeEvent, FunctionComponent, useMemo, useState } from 'react';\n\nimport {\n ComboBox,\n MenuProps,\n menuHelpers,\n BaseProps,\n ForwardProps,\n FormControlProps,\n NoChildrenProp\n} from '@pega/cosmos-react-core';\nimport { Selected } from '@pega/cosmos-react-core/lib/components/ComboBox/ComboBox.types';\n\nimport { Field } from '../ConditionBuilder.types';\n\n/** Convert input Fields to use as ComboBox options */\nfunction getMenuItemsFromFields(fields: Field[], selection: string): MenuProps['items'] {\n const items: MenuProps['items'] = [];\n const itemsByGroupLabel: { [label: string]: MenuProps['items'] } = {};\n\n fields.forEach(field => {\n const item = {\n id: field.name,\n primary: field.label ?? field.name, // field.label is optional\n selected: field.name === selection // set Selected field to selection\n };\n if (field.groupLabel) {\n itemsByGroupLabel[field.groupLabel] = itemsByGroupLabel[field.groupLabel] || [];\n itemsByGroupLabel[field.groupLabel].push(item);\n } else {\n items.push(item);\n }\n });\n\n Object.entries(itemsByGroupLabel).forEach(([label, childItems]) => {\n items.push({ id: label, primary: label, items: childItems });\n });\n\n return items;\n}\n\ninterface FieldSelectorProps extends BaseProps, NoChildrenProp {\n /** Current selection */\n value: string;\n\n /** Change handler */\n onChange: (selection: string) => void;\n\n /** Metadata (data-model) for the Fields to use in the selector */\n fields: Field[];\n\n /** Status for the ComboBox */\n status?: FormControlProps['status'];\n\n /** Info for the ComboBox */\n info?: FormControlProps['info'];\n}\n\n/** Sets up a ComboBox to select a Field. Handles grouping and autocomplete. */\nconst FieldSelector: FunctionComponent<FieldSelectorProps & ForwardProps> = (\n props: FieldSelectorProps\n) => {\n const { value, onChange, fields, status, info } = props;\n\n // Determine ComboBox menu items from the fields\n const items = useMemo(() => getMenuItemsFromFields(fields, value), [fields, value]);\n const selected: Selected | undefined = useMemo(() => {\n const selectedItem = menuHelpers.getItem(items, value);\n return selectedItem ? { id: selectedItem.id, text: selectedItem.primary } : undefined;\n }, [items]);\n\n // Set up autocomplete input\n const [filterValue, setFilterValue] = useState<string>(''); // NOTE: `''` is needed to show the current selection\n const filterRegex = useMemo(() => {\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping\n // Literal string match from input, not user regex input.\n return filterValue\n ? new RegExp(filterValue.replace(/[.*+\\-?^${}()|[\\]\\\\]/g, '\\\\$&'), 'i')\n : undefined;\n }, [filterValue]);\n\n const filteredItems = useMemo(() => {\n return filterRegex\n ? menuHelpers.flatten(items).filter(({ primary }) => filterRegex.test(primary))\n : items;\n }, [filterRegex, items]);\n\n return (\n <ComboBox\n label='field'\n labelHidden\n status={status}\n info={info}\n placeholder='Select…'\n mode='single-select'\n value={filterValue}\n onChange={(ev: ChangeEvent<HTMLInputElement>) => {\n setFilterValue(ev.target.value);\n if (!ev.target.value) onChange('');\n }}\n onBlur={() => {\n setFilterValue('');\n }}\n selected={{ items: selected }}\n menu={{\n items: filteredItems,\n mode: 'single-select',\n accent: filterRegex,\n onItemClick: id => {\n onChange(id);\n setFilterValue(''); // To show the selected value in the input\n }\n }}\n />\n );\n};\n\nexport default FieldSelector;\n"]}
1
+ {"version":3,"file":"FieldSelector.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/FieldSelector.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAkC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE1E,OAAO,EACL,QAAQ,EAER,WAAW,EAKX,OAAO,EACP,OAAO,EACR,MAAM,yBAAyB,CAAC;AAKjC,sDAAsD;AACtD,SAAS,sBAAsB,CAAC,MAAe,EAAE,SAAiB;IAChE,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;QACxB,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;QAC9B,IAAI,UAAU,CAAC;QACf,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC;YAAE,UAAU,GAAG,sBAAsB,CAAC,KAAK,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QACzF,OAAO;YACL,EAAE;YACF,OAAO;YACP,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,SAAS;YACnD,KAAK,EAAE,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AAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC/E,CAAC,CAAC,KAAK,CAAC;IACZ,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;IAEzB,OAAO,CACL,KAAC,QAAQ,IACP,KAAK,EAAE,CAAC,CAAC,+BAA+B,CAAC,EACzC,WAAW,QACX,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,CAAC,CAAC,4BAA4B,CAAC,EAC5C,IAAI,EAAC,eAAe,EACpB,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,CAAC,EAAiC,EAAE,EAAE;YAC9C,cAAc,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAChC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK;gBAAE,QAAQ,CAAC,EAAE,CAAC,CAAC;QACrC,CAAC,EACD,MAAM,EAAE,GAAG,EAAE;YACX,cAAc,CAAC,EAAE,CAAC,CAAC;QACrB,CAAC,EACD,QAAQ,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,EAC7B,IAAI,EAAE;YACJ,KAAK,EAAE,aAAa;YACpB,IAAI,EAAE,eAAe;YACrB,MAAM,EAAE,WAAW;YACnB,WAAW,EAAE,EAAE,CAAC,EAAE;gBAChB,QAAQ,CAAC,EAAE,CAAC,CAAC;gBACb,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC,0CAA0C;YAChE,CAAC;SACF,GACD,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { ChangeEvent, FunctionComponent, useMemo, useState } from 'react';\n\nimport {\n ComboBox,\n MenuProps,\n menuHelpers,\n BaseProps,\n ForwardProps,\n FormControlProps,\n NoChildrenProp,\n hasProp,\n useI18n\n} from '@pega/cosmos-react-core';\nimport { Selected } from '@pega/cosmos-react-core/lib/components/ComboBox/ComboBox.types';\n\nimport { Field } from '../ConditionBuilder.types';\n\n/** Convert input Fields to use as ComboBox options */\nfunction getMenuItemsFromFields(fields: Field[], selection: string): MenuProps['items'] {\n return fields.map(field => {\n const { id, primary } = field;\n let childitems;\n if (hasProp(field, 'items')) childitems = getMenuItemsFromFields(field.items, selection);\n return {\n id,\n primary,\n selected: childitems ? undefined : id === selection, // set Selected field to selection\n items: childitems\n };\n });\n}\n\ninterface FieldSelectorProps extends BaseProps, NoChildrenProp {\n /** Current selection */\n value: string;\n\n /** Change handler */\n onChange: (selection: string) => void;\n\n /** Metadata (data-model) for the Fields to use in the selector */\n fields: Field[];\n\n /** Status for the ComboBox */\n status?: FormControlProps['status'];\n\n /** Info for the ComboBox */\n info?: FormControlProps['info'];\n}\n\n/** Sets up a ComboBox to select a Field. Handles grouping and autocomplete. */\nconst FieldSelector: FunctionComponent<FieldSelectorProps & ForwardProps> = (\n props: FieldSelectorProps\n) => {\n const { value, onChange, fields, status, info } = props;\n\n const t = useI18n();\n\n // Determine ComboBox menu items from the fields\n const items = useMemo(() => getMenuItemsFromFields(fields, value), [fields, value]);\n const selected: Selected | undefined = useMemo(() => {\n const selectedItem = menuHelpers.getItem(items, value);\n return selectedItem ? { id: selectedItem.id, text: selectedItem.primary } : undefined;\n }, [items]);\n\n // Set up autocomplete input\n const [filterValue, setFilterValue] = useState<string>(''); // NOTE: `''` is needed to show the current selection\n const filterRegex = useMemo(() => {\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping\n // Literal string match from input, not user regex input.\n return filterValue\n ? new RegExp(filterValue.replace(/[.*+\\-?^${}()|[\\]\\\\]/g, '\\\\$&'), 'i')\n : undefined;\n }, [filterValue]);\n\n const filteredItems = useMemo(() => {\n return filterRegex\n ? menuHelpers.flatten(items).filter(({ primary }) => filterRegex.test(primary))\n : items;\n }, [filterRegex, items]);\n\n return (\n <ComboBox\n label={t('condition_builder_field_label')}\n labelHidden\n status={status}\n info={info}\n placeholder={t('select_placeholder_default')}\n mode='single-select'\n value={filterValue}\n onChange={(ev: ChangeEvent<HTMLInputElement>) => {\n setFilterValue(ev.target.value);\n if (!ev.target.value) onChange('');\n }}\n onBlur={() => {\n setFilterValue('');\n }}\n selected={{ items: selected }}\n menu={{\n items: filteredItems,\n mode: 'single-select',\n accent: filterRegex,\n onItemClick: id => {\n onChange(id);\n setFilterValue(''); // To show the selected value in the input\n }\n }}\n />\n );\n};\n\nexport default FieldSelector;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"NumericInput.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/NumericInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAY,MAAM,OAAO,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAwB,MAAM,yBAAyB,CAAC;AAE1F,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;CAClB;AAED,4IAA4I;AAC5I,QAAA,MAAM,YAAY,EAAE,iBAAiB,CAAC,iBAAiB,CAwBtD,CAAC;AAEF,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"NumericInput.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/NumericInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAY,MAAM,OAAO,CAAC;AAEpD,OAAO,EACL,SAAS,EACT,cAAc,EAIf,MAAM,yBAAyB,CAAC;AAEjC,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;CAClB;AAED,4IAA4I;AAC5I,QAAA,MAAM,YAAY,EAAE,iBAAiB,CAAC,iBAAiB,CA4BtD,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useState } from 'react';
3
- import { NumberInput, useI18n } from '@pega/cosmos-react-core';
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
6
  const { rhs, onChange, status } = props;
@@ -9,6 +9,9 @@ const NumericInput = (props) => {
9
9
  // if we parse values like `12.`, `12.0`, etc., the decimals will be lost leading to bad UX
10
10
  // Using a local state to avoid that
11
11
  const [localValue, setLocalValue] = useState(rhs.value.toString());
12
+ useAfterInitialEffect(() => {
13
+ setLocalValue(rhs.value.toString());
14
+ }, [rhs.value]);
12
15
  const handleInputChange = (newValue) => {
13
16
  setLocalValue(newValue);
14
17
  onChange({ value: newValue.trim() ? Number(newValue) : '' }); // Save as a number unless the input is empty
@@ -1 +1 @@
1
- {"version":3,"file":"NumericInput.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/NumericInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAqB,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,EAA6B,WAAW,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAa1F,4IAA4I;AAC5I,MAAM,YAAY,GAAyC,CAAC,KAAwB,EAAE,EAAE;IACtF,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IACxC,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,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,8CAA8C,CAAC,EACxD,WAAW,SACX,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import { FunctionComponent, useState } from 'react';\n\nimport { BaseProps, NoChildrenProp, NumberInput, useI18n } 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\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 } = 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 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_compare_with_numeric_value')}\n labelHidden\n />\n );\n};\n\nexport default NumericInput;\n"]}
1
+ {"version":3,"file":"NumericInput.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/NumericInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAqB,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,EAGL,WAAW,EACX,qBAAqB,EACrB,OAAO,EACR,MAAM,yBAAyB,CAAC;AAajC,4IAA4I;AAC5I,MAAM,YAAY,GAAyC,CAAC,KAAwB,EAAE,EAAE;IACtF,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IACxC,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,8CAA8C,CAAC,EACxD,WAAW,SACX,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import { FunctionComponent, useState } from 'react';\n\nimport {\n BaseProps,\n NoChildrenProp,\n NumberInput,\n useAfterInitialEffect,\n useI18n\n} 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\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 } = 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_compare_with_numeric_value')}\n labelHidden\n />\n );\n};\n\nexport default NumericInput;\n"]}
@@ -1,16 +1,18 @@
1
1
  import { FunctionComponent } from 'react';
2
2
  import { BaseProps, ForwardProps, NoChildrenProp } from '@pega/cosmos-react-core';
3
3
  import { Comparator, FieldType, RHSType } from '../core/types';
4
- import { DateFunctionsByType, LeafCondition } from '../ConditionBuilder.types';
4
+ import { DateFunctionsByType, LeafCondition, ParameterValue } from '../ConditionBuilder.types';
5
5
  interface RhsMenuButtonProps extends BaseProps, NoChildrenProp {
6
+ /** Passed Parameters array for Rhstype PARAMETER */
7
+ parameters: ParameterValue[];
6
8
  /** Type of field on the LHS */
7
9
  fieldType: FieldType;
8
10
  /** Comparator for the condition */
9
11
  comparator: Comparator;
10
12
  /** Rhs for the condition */
11
- rhs: LeafCondition['rhs'];
13
+ rhs: NonNullable<LeafCondition['rhs']>;
12
14
  /** Callback for any modifications to the Rhs */
13
- onChange: (rhs: LeafCondition['rhs']) => void;
15
+ onChange: (rhs: NonNullable<LeafCondition['rhs']>) => void;
14
16
  /** Display mode */
15
17
  mode: 'combo-box' | 'menu-button';
16
18
  /** Restricts RHS values to only specified RHS types */
@@ -1 +1 @@
1
- {"version":3,"file":"RhsModeSwitch.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/RhsModeSwitch.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAW,MAAM,OAAO,CAAC;AAEnD,OAAO,EACL,SAAS,EAET,YAAY,EAKZ,cAAc,EAGf,MAAM,yBAAyB,CAAC;AAIjC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AA6B/E,UAAU,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C,CAAC,CAAC;IAEvC,gDAAgD;IAChD,QAAQ,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,CAAC;IAE3D,mBAAmB;IACnB,IAAI,EAAE,WAAW,GAAG,aAAa,CAAC;IAElC,uDAAuD;IACvD,aAAa,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAE5B,oHAAoH;IACpH,aAAa,CAAC,EAAE,mBAAmB,CAAC;CACrC;AAED,6DAA6D;AAC7D,QAAA,MAAM,aAAa,EAAE,iBAAiB,CAAC,kBAAkB,GAAG,YAAY,CAkJvE,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -7,34 +7,46 @@ var ItemID;
7
7
  ItemID["DATE_PART"] = "DATE_PART";
8
8
  ItemID["RELATIVE_DATE"] = "RELATIVE_DATE";
9
9
  ItemID["ANOTHER_FIELD"] = "ANOTHER_FIELD";
10
+ ItemID["PARAMETER"] = "PARAMETER";
10
11
  })(ItemID || (ItemID = {}));
12
+ function isRangeComparator(comparator) {
13
+ return comparator === 'BTW' || comparator === 'NOT_BTW';
14
+ }
11
15
  // Label for the `Enter <value>` option on the gear-menu
12
- function getValueOptionLabel(fieldType, t) {
16
+ function getValueOptionLabel(fieldType, t, comparator) {
13
17
  switch (fieldType) {
14
18
  case 'TEXT':
15
19
  return t('condition_builder_compare_with_text_value');
16
20
  case 'NUMBER':
17
- return t('condition_builder_compare_with_numeric_value');
21
+ return isRangeComparator(comparator)
22
+ ? t('condition_builder_compare_with_numeric_range_value')
23
+ : t('condition_builder_compare_with_numeric_value');
18
24
  case 'DATE_TIME':
19
25
  case 'DATE_ONLY':
20
- return t('condition_builder_compare_with_date_value');
26
+ return isRangeComparator(comparator)
27
+ ? t('condition_builder_compare_with_date_range_value')
28
+ : t('condition_builder_compare_with_date_value');
21
29
  case 'TIME_ONLY':
22
- return t('condition_builder_compare_with_time_value');
30
+ return isRangeComparator(comparator)
31
+ ? t('condition_builder_compare_with_time_range_value')
32
+ : t('condition_builder_compare_with_time_value');
23
33
  default:
24
34
  return t('condition_builder_value_label'); // Not needed (BOOLEAN is not expected to be passed to the function)
25
35
  }
26
36
  }
27
37
  /** Renders a Gear MenuButton on the RHS (when applicable) */
28
- const RhsModeSwitch = (props) => {
29
- const { fieldType, comparator, rhs, onChange, mode, validRhsTypes, dateFunctions } = props;
38
+ const RhsModeSwitch = ({ parameters, fieldType, comparator, rhs, onChange, mode, validRhsTypes, dateFunctions }) => {
30
39
  const t = useI18n();
31
40
  // Identify current mode
32
41
  const currentMode = useMemo(() => {
33
- // rhs should already be defined if this component is being rendered. Indicating the same to TS using `!`
42
+ if (hasProp(rhs, 'field'))
43
+ return ItemID.ANOTHER_FIELD;
34
44
  if (hasProp(rhs, 'field'))
35
45
  return ItemID.ANOTHER_FIELD;
36
46
  if (hasProp(rhs, 'value') && hasProp(rhs, 'dateFunction'))
37
47
  return ItemID.DATE_PART;
48
+ if (hasProp(rhs, 'parameterId'))
49
+ return ItemID.PARAMETER;
38
50
  if (hasProp(rhs, 'relativeDate'))
39
51
  return ItemID.RELATIVE_DATE;
40
52
  return ItemID.LITERAL_VALUE;
@@ -50,12 +62,13 @@ const RhsModeSwitch = (props) => {
50
62
  // Literal Value inputs
51
63
  items.push({
52
64
  id: ItemID.LITERAL_VALUE,
53
- primary: getValueOptionLabel(fieldType, t),
65
+ primary: getValueOptionLabel(fieldType, t, comparator),
54
66
  onClick: id => {
55
67
  if (id === currentMode)
56
68
  return; // Ignore if already in that mode
57
- onChange({ value: '' }); // Submit a new RHS to re-render with the new mode
58
- }
69
+ onChange(isRangeComparator(comparator) ? { start: '', end: '' } : { value: '' }); // Submit a new RHS to re-render with the new mode
70
+ },
71
+ selected: currentMode === ItemID.LITERAL_VALUE
59
72
  });
60
73
  }
61
74
  // Field selector
@@ -67,7 +80,26 @@ const RhsModeSwitch = (props) => {
67
80
  if (id === currentMode)
68
81
  return; // Ignore if already in that mode
69
82
  onChange({ field: '' }); // Submit a new RHS to re-render with the new mode
70
- }
83
+ },
84
+ selected: currentMode === ItemID.ANOTHER_FIELD
85
+ });
86
+ }
87
+ // Rhs of PARAMETER type
88
+ if (validRhsTypes.has('PARAMETER') &&
89
+ ['EQ', 'NEQ'].includes(comparator) &&
90
+ parameters.length > 0) {
91
+ items.push({
92
+ id: ItemID.PARAMETER,
93
+ primary: t('condition_builder_compare_with_parameter'),
94
+ onClick: id => {
95
+ if (id === currentMode)
96
+ return; // Ignore if already in that mode
97
+ if (parameters.length === 1)
98
+ onChange({ parameterId: parameters[0].id });
99
+ else
100
+ onChange({ parameterId: '' }); // Submit a new RHS to re-render with the new mode
101
+ },
102
+ selected: currentMode === ItemID.PARAMETER
71
103
  });
72
104
  }
73
105
  // Relative Date value input
@@ -85,7 +117,8 @@ const RhsModeSwitch = (props) => {
85
117
  datePart: 'DAYS'
86
118
  }
87
119
  });
88
- }
120
+ },
121
+ selected: currentMode === ItemID.RELATIVE_DATE
89
122
  });
90
123
  }
91
124
  // Date Part value input
@@ -99,11 +132,12 @@ const RhsModeSwitch = (props) => {
99
132
  if (id === currentMode)
100
133
  return; // Ignore if already in that mode
101
134
  onChange({ value: '', dateFunction: dateFunctions[fieldType][0] }); // Submit a new RHS to re-render with the new mode. Initializing with the first available date function
102
- }
135
+ },
136
+ selected: currentMode === ItemID.DATE_PART
103
137
  });
104
138
  }
105
139
  }
106
- return { items, mode: 'action' };
140
+ return { items, mode: 'single-select' };
107
141
  }, [fieldType, comparator, onChange, validRhsTypes, dateFunctions, currentMode, t]);
108
142
  // Identify current selection for ComboBox
109
143
  const selected = useMemo(() => {