@pega/cosmos-react-condition-builder 3.0.0-dev.3.0 → 3.0.0-dev.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) 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 +16 -42
  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/HelpButton.js +1 -1
  22. package/lib/components/ConditionBuilder/HelpButton.js.map +1 -1
  23. package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.js +1 -1
  24. package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.js.map +1 -1
  25. package/lib/components/ConditionBuilder/RhsControls/FieldSelector.d.ts.map +1 -1
  26. package/lib/components/ConditionBuilder/RhsControls/FieldSelector.js +14 -21
  27. package/lib/components/ConditionBuilder/RhsControls/FieldSelector.js.map +1 -1
  28. package/lib/components/ConditionBuilder/RhsControls/NumericInput.d.ts.map +1 -1
  29. package/lib/components/ConditionBuilder/RhsControls/NumericInput.js +5 -2
  30. package/lib/components/ConditionBuilder/RhsControls/NumericInput.js.map +1 -1
  31. package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.js +1 -1
  32. package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.js.map +1 -1
  33. package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.d.ts +5 -3
  34. package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.d.ts.map +1 -1
  35. package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.js +50 -16
  36. package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.js.map +1 -1
  37. package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.d.ts.map +1 -1
  38. package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.js +8 -8
  39. package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.js.map +1 -1
  40. package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.js +1 -1
  41. package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.js.map +1 -1
  42. package/lib/components/ConditionBuilder/RhsControls/ValueSelector.d.ts +38 -0
  43. package/lib/components/ConditionBuilder/RhsControls/ValueSelector.d.ts.map +1 -0
  44. package/lib/components/ConditionBuilder/RhsControls/ValueSelector.js +133 -0
  45. package/lib/components/ConditionBuilder/RhsControls/ValueSelector.js.map +1 -0
  46. package/lib/components/ConditionBuilder/RhsControls/index.d.ts +5 -2
  47. package/lib/components/ConditionBuilder/RhsControls/index.d.ts.map +1 -1
  48. package/lib/components/ConditionBuilder/RhsControls/index.js +91 -30
  49. package/lib/components/ConditionBuilder/RhsControls/index.js.map +1 -1
  50. package/lib/components/ConditionBuilder/core/comparators.d.ts.map +1 -1
  51. package/lib/components/ConditionBuilder/core/comparators.js +4 -0
  52. package/lib/components/ConditionBuilder/core/comparators.js.map +1 -1
  53. package/lib/components/ConditionBuilder/core/evaluator.d.ts.map +1 -1
  54. package/lib/components/ConditionBuilder/core/evaluator.js +10 -3
  55. package/lib/components/ConditionBuilder/core/evaluator.js.map +1 -1
  56. package/lib/components/ConditionBuilder/core/formatter.d.ts +1 -0
  57. package/lib/components/ConditionBuilder/core/formatter.d.ts.map +1 -1
  58. package/lib/components/ConditionBuilder/core/formatter.js +84 -38
  59. package/lib/components/ConditionBuilder/core/formatter.js.map +1 -1
  60. package/lib/components/ConditionBuilder/core/transformer.d.ts.map +1 -1
  61. package/lib/components/ConditionBuilder/core/transformer.js +37 -2
  62. package/lib/components/ConditionBuilder/core/transformer.js.map +1 -1
  63. package/lib/components/ConditionBuilder/core/types.d.ts +2 -2
  64. package/lib/components/ConditionBuilder/core/types.d.ts.map +1 -1
  65. package/lib/components/ConditionBuilder/core/types.js.map +1 -1
  66. package/lib/components/ConditionBuilder/core/utils.d.ts +5 -1
  67. package/lib/components/ConditionBuilder/core/utils.d.ts.map +1 -1
  68. package/lib/components/ConditionBuilder/core/utils.js +18 -0
  69. package/lib/components/ConditionBuilder/core/utils.js.map +1 -1
  70. package/lib/components/ConditionBuilder/index.d.ts +1 -1
  71. package/lib/components/ConditionBuilder/index.d.ts.map +1 -1
  72. package/lib/components/ConditionBuilder/index.js.map +1 -1
  73. package/lib/components/ConditionInput/ConditionInput.d.ts +6 -0
  74. package/lib/components/ConditionInput/ConditionInput.d.ts.map +1 -0
  75. package/lib/components/ConditionInput/ConditionInput.js +215 -0
  76. package/lib/components/ConditionInput/ConditionInput.js.map +1 -0
  77. package/lib/components/ConditionInput/ConditionInput.styles.d.ts +5 -0
  78. package/lib/components/ConditionInput/ConditionInput.styles.d.ts.map +1 -0
  79. package/lib/components/ConditionInput/ConditionInput.styles.js +27 -0
  80. package/lib/components/ConditionInput/ConditionInput.styles.js.map +1 -0
  81. package/lib/components/ConditionInput/ConditionInput.types.d.ts +29 -0
  82. package/lib/components/ConditionInput/ConditionInput.types.d.ts.map +1 -0
  83. package/lib/components/ConditionInput/ConditionInput.types.js +2 -0
  84. package/lib/components/ConditionInput/ConditionInput.types.js.map +1 -0
  85. package/lib/components/ConditionInput/index.d.ts +3 -0
  86. package/lib/components/ConditionInput/index.d.ts.map +1 -0
  87. package/lib/components/ConditionInput/index.js +2 -0
  88. package/lib/components/ConditionInput/index.js.map +1 -0
  89. package/lib/components/ConditionInput/utils.d.ts +13 -0
  90. package/lib/components/ConditionInput/utils.d.ts.map +1 -0
  91. package/lib/components/ConditionInput/utils.js +56 -0
  92. package/lib/components/ConditionInput/utils.js.map +1 -0
  93. package/lib/components/PromotedFilters/ConditionSelector.d.ts +31 -0
  94. package/lib/components/PromotedFilters/ConditionSelector.d.ts.map +1 -0
  95. package/lib/components/PromotedFilters/ConditionSelector.js +72 -0
  96. package/lib/components/PromotedFilters/ConditionSelector.js.map +1 -0
  97. package/lib/components/PromotedFilters/PromotedFilters.d.ts +11 -0
  98. package/lib/components/PromotedFilters/PromotedFilters.d.ts.map +1 -0
  99. package/lib/components/PromotedFilters/PromotedFilters.js +118 -0
  100. package/lib/components/PromotedFilters/PromotedFilters.js.map +1 -0
  101. package/lib/components/PromotedFilters/PromotedFilters.styles.d.ts +4 -0
  102. package/lib/components/PromotedFilters/PromotedFilters.styles.d.ts.map +1 -0
  103. package/lib/components/PromotedFilters/PromotedFilters.styles.js +26 -0
  104. package/lib/components/PromotedFilters/PromotedFilters.styles.js.map +1 -0
  105. package/lib/components/PromotedFilters/PromotedFilters.types.d.ts +31 -0
  106. package/lib/components/PromotedFilters/PromotedFilters.types.d.ts.map +1 -0
  107. package/lib/components/PromotedFilters/PromotedFilters.types.js +2 -0
  108. package/lib/components/PromotedFilters/PromotedFilters.types.js.map +1 -0
  109. package/lib/components/PromotedFilters/index.d.ts +3 -0
  110. package/lib/components/PromotedFilters/index.d.ts.map +1 -0
  111. package/lib/components/PromotedFilters/index.js +2 -0
  112. package/lib/components/PromotedFilters/index.js.map +1 -0
  113. package/lib/index.d.ts +4 -0
  114. package/lib/index.d.ts.map +1 -1
  115. package/lib/index.js +4 -0
  116. package/lib/index.js.map +1 -1
  117. package/package.json +18 -12
  118. package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.d.ts +0 -16
  119. package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.d.ts.map +0 -1
  120. package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.js +0 -43
  121. 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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Q,SAAS,EAAE,cAAc;IAC9E,iEAAiE;IACjE,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB;;;OAGG;IACH,iBAAiB,EAAE,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,KAAK,IAAI,CAAC;IAE9D,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;CACvB"}
1
+ {"version":3,"file":"ConditionBuilder.types.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExF,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,qCAAqC;AACrC,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,oEAAoE;AACpE,MAAM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- {"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 }, void 0), _jsx(Flex, { container: { justify: 'end' }, children: _jsx(Button, { name: 'field-condition-submit', variant: 'primary', onClick: handleSubmission, children: t('condition_builder_submit_button_label') }, void 0) }, void 0)] }, void 0));
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,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAG9F,kEAAkE;AAClE,MAAM,cAAc,GAA0D,CAC5E,KAA0B,EAC1B,EAAE;IACF,MAAM,EACJ,WAAW,EACX,MAAM,EACN,QAAQ,EACR,SAAS,EAAE,aAAa,EACxB,gBAAgB,EAChB,aAAa,GAAG,IAAI,GAAG,CAAU,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,EACtD,aAAa,EACd,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;IAC5H,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IAEpB,MAAM,gBAAgB,GAAG,GAAG,EAAE;QAC5B,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,0BAA0B;QAErD,IAAI,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;YAC7C,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,uCAAuC;SAC7D;aAAM;YACL,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,6BAA6B;SACxD;IACH,CAAC,CAAC;IAEF,OAAO,CACL,MAAC,IAAI,IAAC,SAAS,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,EAAE,aAC9C,KAAC,eAAe,IACd,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,mBAAmB,EACnC,gBAAgB,EAAE,gBAAgB,EAClC,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,EAC9B,aAAa,EAAC,QAAQ,EACtB,aAAa,EAAE,aAAa,EAC5B,cAAc,iBACd,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,WACpC,WACJ,YACF,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"]}
@@ -5,7 +5,7 @@ const HelpButton = (props) => {
5
5
  const { children } = props;
6
6
  const [iconEl, setIconEl] = useElement();
7
7
  const id = useUID();
8
- return (_jsxs(_Fragment, { children: [_jsx(Icon, { name: 'information', ref: setIconEl, "aria-describedby": id }, void 0), iconEl && (_jsx(Tooltip, { target: iconEl, id: id, children: children }, void 0))] }, void 0));
8
+ return (_jsxs(_Fragment, { children: [_jsx(Icon, { name: 'information', ref: setIconEl, "aria-describedby": id }), iconEl && (_jsx(Tooltip, { target: iconEl, id: id, children: children }))] }));
9
9
  };
10
10
  export default HelpButton;
11
11
  //# sourceMappingURL=HelpButton.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"HelpButton.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/HelpButton.tsx"],"names":[],"mappings":";AAEA,OAAO,EACL,IAAI,EACJ,OAAO,EAGP,UAAU,EACV,MAAM,EACP,MAAM,yBAAyB,CAAC;AAOjC,mEAAmE;AACnE,MAAM,UAAU,GAAsD,CAAC,KAAsB,EAAE,EAAE;IAC/F,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAC3B,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,UAAU,EAAE,CAAC;IACzC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;IAEpB,OAAO,CACL,8BACE,KAAC,IAAI,IAAC,IAAI,EAAC,aAAa,EAAC,GAAG,EAAE,SAAS,sBAAoB,EAAE,WAAI,EAChE,MAAM,IAAI,CACT,KAAC,OAAO,IAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,YAC5B,QAAQ,WACD,CACX,YACA,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import { FunctionComponent } from 'react';\n\nimport {\n Icon,\n Tooltip,\n BaseProps,\n ForwardProps,\n useElement,\n useUID\n} from '@pega/cosmos-react-core';\n\ninterface HelpButtonProps extends BaseProps {\n /** Content to show on hover of the button */\n children: string;\n}\n\n/** Renders an inline Help icon that shows help content on hover */\nconst HelpButton: FunctionComponent<HelpButtonProps & ForwardProps> = (props: HelpButtonProps) => {\n const { children } = props;\n const [iconEl, setIconEl] = useElement();\n const id = useUID();\n\n return (\n <>\n <Icon name='information' ref={setIconEl} aria-describedby={id} />\n {iconEl && (\n <Tooltip target={iconEl} id={id}>\n {children}\n </Tooltip>\n )}\n </>\n );\n};\n\nexport default HelpButton;\n"]}
1
+ {"version":3,"file":"HelpButton.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/HelpButton.tsx"],"names":[],"mappings":";AAEA,OAAO,EACL,IAAI,EACJ,OAAO,EAGP,UAAU,EACV,MAAM,EACP,MAAM,yBAAyB,CAAC;AAOjC,mEAAmE;AACnE,MAAM,UAAU,GAAsD,CAAC,KAAsB,EAAE,EAAE;IAC/F,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAC3B,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,UAAU,EAAE,CAAC;IACzC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;IAEpB,OAAO,CACL,8BACE,KAAC,IAAI,IAAC,IAAI,EAAC,aAAa,EAAC,GAAG,EAAE,SAAS,sBAAoB,EAAE,GAAI,EAChE,MAAM,IAAI,CACT,KAAC,OAAO,IAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,YAC5B,QAAQ,GACD,CACX,IACA,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import { FunctionComponent } from 'react';\n\nimport {\n Icon,\n Tooltip,\n BaseProps,\n ForwardProps,\n useElement,\n useUID\n} from '@pega/cosmos-react-core';\n\ninterface HelpButtonProps extends BaseProps {\n /** Content to show on hover of the button */\n children: string;\n}\n\n/** Renders an inline Help icon that shows help content on hover */\nconst HelpButton: FunctionComponent<HelpButtonProps & ForwardProps> = (props: HelpButtonProps) => {\n const { children } = props;\n const [iconEl, setIconEl] = useElement();\n const id = useUID();\n\n return (\n <>\n <Icon name='information' ref={setIconEl} aria-describedby={id} />\n {iconEl && (\n <Tooltip target={iconEl} id={id}>\n {children}\n </Tooltip>\n )}\n </>\n );\n};\n\nexport default HelpButton;\n"]}
@@ -109,7 +109,7 @@ const DateFunctionMenu = (props) => {
109
109
  const onDayOfWeekChange = (value) => {
110
110
  onChange({ ...rhs, value });
111
111
  };
112
- return (_jsxs(_Fragment, { children: [_jsx(Select, { label: t('condition_builder_date_part'), value: rhs.dateFunction, onChange: handleDatePartChange, children: dateFunctionOptions.map(o => (_jsx(Option, { value: o.id, children: o.label }, o.id))) }, void 0), rhs.dateFunction === 'YEARS' && (_jsxs(Select, { ...valueComponentProps, onChange: onYearChange, name: 'year-selector', children: [_jsx(Option, { children: " " }, void 0), yearOptions.map(o => (_jsx(Option, { value: o.id, children: o.label }, o.id)))] }, void 0)), rhs.dateFunction === 'QUARTERS' && _jsx(QuarterInput, { ...dateComponentProps }, void 0), rhs.dateFunction === 'MONTHS' && _jsx(MonthInput, { ...dateComponentProps }, void 0), rhs.dateFunction === 'WEEKS' && _jsx(WeekInput, { ...dateComponentProps }, void 0), rhs.dateFunction === 'DAYS' && _jsx(DateInput, { ...dateComponentProps }, void 0), rhs.dateFunction === 'HOURS' && (_jsx(DateTimeInput, { ...dateComponentProps, pickerInterval: 60 }, void 0)), rhs.dateFunction === 'MONTHS_OF_YEAR' && (_jsxs(Select, { ...valueComponentProps, onChange: onMonthOfYearChange, name: 'month-of-year-selector', children: [_jsx(Option, { children: " " }, void 0), monthOfYearOptions.map(o => (_jsx(Option, { value: o.id, children: o.label }, o.id)))] }, void 0)), rhs.dateFunction === 'DAYS_OF_MONTH' && (_jsx(NumberInput, { ...valueComponentProps, placeholder: '1 - 31', min: 1, max: 31, step: 1, showDecimal: false, onChange: onDayOfMonthChange }, void 0)), rhs.dateFunction === 'DAYS_OF_WEEK' && (_jsx(DayOfWeekInput, { ...valueComponentProps, value: rhs.value, onChange: onDayOfWeekChange }, void 0))] }, void 0));
112
+ return (_jsxs(_Fragment, { children: [_jsx(Select, { label: t('condition_builder_date_part'), value: rhs.dateFunction, onChange: handleDatePartChange, children: dateFunctionOptions.map(o => (_jsx(Option, { value: o.id, children: o.label }, o.id))) }), rhs.dateFunction === 'YEARS' && (_jsxs(Select, { ...valueComponentProps, onChange: onYearChange, name: 'year-selector', children: [_jsx(Option, { children: " " }), yearOptions.map(o => (_jsx(Option, { value: o.id, children: o.label }, o.id)))] })), rhs.dateFunction === 'QUARTERS' && _jsx(QuarterInput, { ...dateComponentProps }), rhs.dateFunction === 'MONTHS' && _jsx(MonthInput, { ...dateComponentProps }), rhs.dateFunction === 'WEEKS' && _jsx(WeekInput, { ...dateComponentProps }), rhs.dateFunction === 'DAYS' && _jsx(DateInput, { ...dateComponentProps }), rhs.dateFunction === 'HOURS' && (_jsx(DateTimeInput, { ...dateComponentProps, pickerInterval: 60 })), rhs.dateFunction === 'MONTHS_OF_YEAR' && (_jsxs(Select, { ...valueComponentProps, onChange: onMonthOfYearChange, name: 'month-of-year-selector', children: [_jsx(Option, { children: " " }), monthOfYearOptions.map(o => (_jsx(Option, { value: o.id, children: o.label }, o.id)))] })), rhs.dateFunction === 'DAYS_OF_MONTH' && (_jsx(NumberInput, { ...valueComponentProps, placeholder: '1 - 31', min: 1, max: 31, step: 1, showDecimal: false, onChange: onDayOfMonthChange })), rhs.dateFunction === 'DAYS_OF_WEEK' && (_jsx(DayOfWeekInput, { ...valueComponentProps, value: rhs.value, onChange: onDayOfWeekChange }))] }));
113
113
  };
114
114
  export default DateFunctionMenu;
115
115
  //# sourceMappingURL=DateFunctionMenu.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DateFunctionMenu.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/DateFunctionMenu.tsx"],"names":[],"mappings":";AAAA,4BAA4B;AAC5B,OAAO,EAAkC,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhE,OAAO,EAGL,MAAM,EACN,MAAM,EACN,UAAU,EACV,SAAS,EACT,SAAS,EACT,aAAa,EACb,WAAW,EAEX,cAAc,EACd,OAAO,EACP,gBAAgB,EAChB,YAAY,EACZ,KAAK,EAEN,MAAM,yBAAyB,CAAC;AASjC;;;;;;;;;GASG;AACH,SAAS,uBAAuB,CAAC,aAAqB,EAAE,YAA0B;IAChF,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,aAAa,CAAC,CAAC;IACrC,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC/D,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAChE,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACzD,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAE1D,QAAQ,YAAY,EAAE;QACpB,KAAK,UAAU,CAAC;QAChB,KAAK,QAAQ;YACX,OAAO,GAAG,IAAI,IAAI,EAAE,KAAK,CAAC;QAC5B,KAAK,OAAO,CAAC;QACb,KAAK,MAAM;YACT,OAAO,GAAG,IAAI,IAAI,E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AC,SAAS,OAAK,kBAAkB,WAAI,EACrE,GAAG,CAAC,YAAY,KAAK,MAAM,IAAI,KAAC,SAAS,OAAK,kBAAkB,WAAI,EACpE,GAAG,CAAC,YAAY,KAAK,OAAO,IAAI,CAC/B,KAAC,aAAa,OAAK,kBAAkB,EAAE,cAAc,EAAE,EAAE,WAAI,CAC9D,EACA,GAAG,CAAC,YAAY,KAAK,gBAAgB,IAAI,CACxC,MAAC,MAAM,OACD,mBAAmB,EACvB,QAAQ,EAAE,mBAAmB,EAC7B,IAAI,EAAC,wBAAwB,aAE7B,KAAC,MAAM,4BAAW,EACjB,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAC3B,KAAC,MAAM,IAAY,KAAK,EAAE,CAAC,CAAC,EAAE,YAC3B,CAAC,CAAC,KAAK,IADG,CAAC,CAAC,EAAE,CAER,CACV,CAAC,YACK,CACV,EACA,GAAG,CAAC,YAAY,KAAK,eAAe,IAAI,CACvC,KAAC,WAAW,OACN,mBAAmB,EACvB,WAAW,EAAC,QAAQ,EACpB,GAAG,EAAE,CAAC,EACN,GAAG,EAAE,EAAE,EACP,IAAI,EAAE,CAAC,EACP,WAAW,EAAE,KAAK,EAClB,QAAQ,EAAE,kBAAkB,WAC5B,CACH,EACA,GAAG,CAAC,YAAY,KAAK,cAAc,IAAI,CACtC,KAAC,cAAc,OACT,mBAAmB,EACvB,KAAK,EAAE,GAAG,CAAC,KAAkB,EAC7B,QAAQ,EAAE,iBAAiB,WAC3B,CACH,YACA,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,gBAAgB,CAAC","sourcesContent":["// cspell:ignore words DDTHH\nimport { ChangeEvent, FunctionComponent, useMemo } from 'react';\n\nimport {\n BaseProps,\n ForwardProps,\n Select,\n Option,\n MonthInput,\n WeekInput,\n DateInput,\n DateTimeInput,\n NumberInput,\n FormControlProps,\n DayOfWeekInput,\n useI18n,\n useConfiguration,\n QuarterInput,\n range,\n NoChildrenProp\n} from '@pega/cosmos-react-core';\nimport DateTimeProps, {\n DateTimeCallbackParameter\n} from '@pega/cosmos-react-core/lib/components/DateTime/DateTime.types';\nimport { DayOfWeek } from '@pega/cosmos-react-core/lib/components/DateTime/Input/DayOfWeekInput';\n\nimport { RhsWithDateFunction } from '../ConditionBuilder.types';\nimport { DateFunction } from '../core/types';\n\n/**\n * Formats the input date string to match the spec expected for the given date function\n * NOTE: This assumes that the input date is set up on the UTC timezone\n * SPEC:\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 */\nfunction formatDateFunctionValue(isoDateString: string, dateFunction: DateFunction): string {\n const date = new Date(isoDateString);\n const YYYY = date.getUTCFullYear().toString().padStart(4, '0');\n const MM = (date.getUTCMonth() + 1).toString().padStart(2, '0');\n const DD = date.getUTCDate().toString().padStart(2, '0');\n const HH = date.getUTCHours().toString().padStart(2, '0');\n\n switch (dateFunction) {\n case 'QUARTERS':\n case 'MONTHS':\n return `${YYYY}-${MM}-01`;\n case 'WEEKS':\n case 'DAYS':\n return `${YYYY}-${MM}-${DD}`;\n default:\n return `${YYYY}-${MM}-${DD}T${HH}:00:00`; // HOURS\n }\n}\n\nexport interface DateFunctionMenuProps extends BaseProps, NoChildrenProp {\n /** Rhs for the condition */\n rhs: RhsWithDateFunction;\n\n /** Callback for any modifications to the Rhs */\n onChange: (rhs: RhsWithDateFunction) => void;\n\n /** List of date functions enabled for the current LHS field type */\n dateFunctionsList: DateFunction[];\n\n /** Used to indicate any errors on the control */\n status?: 'error';\n}\n\n/** A menu with controls to select a Time period value on RHS */\nconst DateFunctionMenu: FunctionComponent<DateFunctionMenuProps & ForwardProps> = (\n props: DateFunctionMenuProps\n) => {\n const { rhs, onChange, dateFunctionsList, status } = props;\n const { locale } = useConfiguration();\n const t = useI18n();\n\n // Options for the Date-function selector\n const dateFunctionOptions = useMemo(() => {\n const dateFunctionLabels: Record<DateFunction, string> = {\n YEARS: t('condition_builder_date_function_year'),\n QUARTERS: t('condition_builder_date_function_quarter'),\n MONTHS: t('condition_builder_date_function_month'),\n WEEKS: t('condition_builder_date_function_week'),\n DAYS: t('condition_builder_date_function_day'),\n HOURS: t('condition_builder_date_function_hour'),\n MONTHS_OF_YEAR: t('condition_builder_date_function_month_of_year'),\n DAYS_OF_MONTH: t('condition_builder_date_function_day_of_month'),\n DAYS_OF_WEEK: t('condition_builder_date_function_day_of_week')\n };\n\n return dateFunctionsList.map(func => ({ id: func, label: dateFunctionLabels[func] }));\n }, [dateFunctionsList, t]);\n\n // Handle changes to the Date-function selector\n const handleDatePartChange = (e: ChangeEvent<HTMLSelectElement>) => {\n const selection = e.target.value as DateFunction;\n onChange({ dateFunction: selection, value: '' });\n };\n\n // Common props for all value controls\n const valueComponentProps: FormControlProps = {\n value: rhs.value === '' ? undefined : rhs.value.toString(),\n label: t('condition_builder_value_label'),\n status,\n info: status ? t('condition_builder_invalid_value') : undefined\n };\n\n // Props for all functions that use a component from the DateTime package\n const dateComponentProps: DateTimeProps = {\n ...valueComponentProps,\n onChange: ({ valueAsISOString, valueAsTimestamp, state }: DateTimeCallbackParameter) => {\n // NOTE: Not relying fully on `state` since in some cases state and valueAsTimestamp are both undefined\n if (valueAsTimestamp === undefined || state === 'incomplete' || state === 'invalid') return;\n\n // Format the value as per spec and return\n onChange({ ...rhs, value: formatDateFunctionValue(valueAsISOString, rhs.dateFunction) });\n }\n };\n\n // YEARS\n const yearOptions = useMemo(() => {\n const currentYear = new Date().getFullYear();\n const years = range(currentYear - 10, currentYear + 10);\n return years.map(year => ({\n id: `${year}-01-01`,\n label: new Date(year, 0, 1).toLocaleString(locale, { year: 'numeric' })\n }));\n }, [locale]);\n const onYearChange = (e: ChangeEvent<HTMLSelectElement>) => {\n onChange({ ...rhs, value: e.target.value });\n };\n\n // MONTHS_OF_YEAR\n const monthOfYearOptions = useMemo(\n () =>\n range(1, 12).map(n => ({\n id: `${n}`,\n label: new Date(2021, n - 1, 1).toLocaleString(locale, { month: 'long' })\n })),\n [locale]\n );\n const onMonthOfYearChange = (e: ChangeEvent<HTMLSelectElement>) => {\n const value = e.target.value ? Number(e.target.value) : '';\n onChange({ ...rhs, value });\n };\n\n // DAYS_OF_MONTH\n const onDayOfMonthChange = (value: string) => {\n let newValue: string | number = value;\n if (newValue !== '') {\n newValue = Number(newValue);\n if (newValue > 31) newValue = 31;\n if (newValue < 1) newValue = 1;\n }\n onChange({ ...rhs, value: newValue });\n };\n\n // DAYS_OF_WEEK\n const onDayOfWeekChange = (value: DayOfWeek) => {\n onChange({ ...rhs, value });\n };\n\n return (\n <>\n {/* Date function selector */}\n <Select\n label={t('condition_builder_date_part')}\n value={rhs.dateFunction}\n onChange={handleDatePartChange}\n >\n {dateFunctionOptions.map(o => (\n <Option key={o.id} value={o.id}>\n {o.label}\n </Option>\n ))}\n </Select>\n\n {rhs.dateFunction === 'YEARS' && (\n <Select {...valueComponentProps} onChange={onYearChange} name='year-selector'>\n <Option> </Option>\n {yearOptions.map(o => (\n <Option key={o.id} value={o.id}>\n {o.label}\n </Option>\n ))}\n </Select>\n )}\n {rhs.dateFunction === 'QUARTERS' && <QuarterInput {...dateComponentProps} />}\n {rhs.dateFunction === 'MONTHS' && <MonthInput {...dateComponentProps} />}\n {rhs.dateFunction === 'WEEKS' && <WeekInput {...dateComponentProps} />}\n {rhs.dateFunction === 'DAYS' && <DateInput {...dateComponentProps} />}\n {rhs.dateFunction === 'HOURS' && (\n <DateTimeInput {...dateComponentProps} pickerInterval={60} />\n )}\n {rhs.dateFunction === 'MONTHS_OF_YEAR' && (\n <Select\n {...valueComponentProps}\n onChange={onMonthOfYearChange}\n name='month-of-year-selector'\n >\n <Option> </Option>\n {monthOfYearOptions.map(o => (\n <Option key={o.id} value={o.id}>\n {o.label}\n </Option>\n ))}\n </Select>\n )}\n {rhs.dateFunction === 'DAYS_OF_MONTH' && (\n <NumberInput\n {...valueComponentProps}\n placeholder='1 - 31'\n min={1}\n max={31}\n step={1}\n showDecimal={false}\n onChange={onDayOfMonthChange}\n />\n )}\n {rhs.dateFunction === 'DAYS_OF_WEEK' && (\n <DayOfWeekInput\n {...valueComponentProps}\n value={rhs.value as DayOfWeek}\n onChange={onDayOfWeekChange}\n />\n )}\n </>\n );\n};\n\nexport default DateFunctionMenu;\n"]}
1
+ {"version":3,"file":"DateFunctionMenu.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/DateFunctionMenu.tsx"],"names":[],"mappings":";AAAA,4BAA4B;AAC5B,OAAO,EAAkC,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhE,OAAO,EAGL,MAAM,EACN,MAAM,EACN,UAAU,EACV,SAAS,EACT,SAAS,EACT,aAAa,EACb,WAAW,EAEX,cAAc,EACd,OAAO,EACP,gBAAgB,EAChB,YAAY,EACZ,KAAK,EAEN,MAAM,yBAAyB,CAAC;AASjC;;;;;;;;;GASG;AACH,SAAS,uBAAuB,CAAC,aAAqB,EAAE,YAA0B;IAChF,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,aAAa,CAAC,CAAC;IACrC,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC/D,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAChE,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACzD,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IA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ctionComponent, useMemo } from 'react';\n\nimport {\n BaseProps,\n ForwardProps,\n Select,\n Option,\n MonthInput,\n WeekInput,\n DateInput,\n DateTimeInput,\n NumberInput,\n FormControlProps,\n DayOfWeekInput,\n useI18n,\n useConfiguration,\n QuarterInput,\n range,\n NoChildrenProp\n} from '@pega/cosmos-react-core';\nimport DateTimeProps, {\n DateTimeCallbackParameter\n} from '@pega/cosmos-react-core/lib/components/DateTime/DateTime.types';\nimport { DayOfWeek } from '@pega/cosmos-react-core/lib/components/DateTime/Input/DayOfWeekInput';\n\nimport { RhsWithDateFunction } from '../ConditionBuilder.types';\nimport { DateFunction } from '../core/types';\n\n/**\n * Formats the input date string to match the spec expected for the given date function\n * NOTE: This assumes that the input date is set up on the UTC timezone\n * SPEC:\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 */\nfunction formatDateFunctionValue(isoDateString: string, dateFunction: DateFunction): string {\n const date = new Date(isoDateString);\n const YYYY = date.getUTCFullYear().toString().padStart(4, '0');\n const MM = (date.getUTCMonth() + 1).toString().padStart(2, '0');\n const DD = date.getUTCDate().toString().padStart(2, '0');\n const HH = date.getUTCHours().toString().padStart(2, '0');\n\n switch (dateFunction) {\n case 'QUARTERS':\n case 'MONTHS':\n return `${YYYY}-${MM}-01`;\n case 'WEEKS':\n case 'DAYS':\n return `${YYYY}-${MM}-${DD}`;\n default:\n return `${YYYY}-${MM}-${DD}T${HH}:00:00`; // HOURS\n }\n}\n\nexport interface DateFunctionMenuProps extends BaseProps, NoChildrenProp {\n /** Rhs for the condition */\n rhs: RhsWithDateFunction;\n\n /** Callback for any modifications to the Rhs */\n onChange: (rhs: RhsWithDateFunction) => void;\n\n /** List of date functions enabled for the current LHS field type */\n dateFunctionsList: DateFunction[];\n\n /** Used to indicate any errors on the control */\n status?: 'error';\n}\n\n/** A menu with controls to select a Time period value on RHS */\nconst DateFunctionMenu: FunctionComponent<DateFunctionMenuProps & ForwardProps> = (\n props: DateFunctionMenuProps\n) => {\n const { rhs, onChange, dateFunctionsList, status } = props;\n const { locale } = useConfiguration();\n const t = useI18n();\n\n // Options for the Date-function selector\n const dateFunctionOptions = useMemo(() => {\n const dateFunctionLabels: Record<DateFunction, string> = {\n YEARS: t('condition_builder_date_function_year'),\n QUARTERS: t('condition_builder_date_function_quarter'),\n MONTHS: t('condition_builder_date_function_month'),\n WEEKS: t('condition_builder_date_function_week'),\n DAYS: t('condition_builder_date_function_day'),\n HOURS: t('condition_builder_date_function_hour'),\n MONTHS_OF_YEAR: t('condition_builder_date_function_month_of_year'),\n DAYS_OF_MONTH: t('condition_builder_date_function_day_of_month'),\n DAYS_OF_WEEK: t('condition_builder_date_function_day_of_week')\n };\n\n return dateFunctionsList.map(func => ({ id: func, label: dateFunctionLabels[func] }));\n }, [dateFunctionsList, t]);\n\n // Handle changes to the Date-function selector\n const handleDatePartChange = (e: ChangeEvent<HTMLSelectElement>) => {\n const selection = e.target.value as DateFunction;\n onChange({ dateFunction: selection, value: '' });\n };\n\n // Common props for all value controls\n const valueComponentProps: FormControlProps = {\n value: rhs.value === '' ? undefined : rhs.value.toString(),\n label: t('condition_builder_value_label'),\n status,\n info: status ? t('condition_builder_invalid_value') : undefined\n };\n\n // Props for all functions that use a component from the DateTime package\n const dateComponentProps: DateTimeProps = {\n ...valueComponentProps,\n onChange: ({ valueAsISOString, valueAsTimestamp, state }: DateTimeCallbackParameter) => {\n // NOTE: Not relying fully on `state` since in some cases state and valueAsTimestamp are both undefined\n if (valueAsTimestamp === undefined || state === 'incomplete' || state === 'invalid') return;\n\n // Format the value as per spec and return\n onChange({ ...rhs, value: formatDateFunctionValue(valueAsISOString, rhs.dateFunction) });\n }\n };\n\n // YEARS\n const yearOptions = useMemo(() => {\n const currentYear = new Date().getFullYear();\n const years = range(currentYear - 10, currentYear + 10);\n return years.map(year => ({\n id: `${year}-01-01`,\n label: new Date(year, 0, 1).toLocaleString(locale, { year: 'numeric' })\n }));\n }, [locale]);\n const onYearChange = (e: ChangeEvent<HTMLSelectElement>) => {\n onChange({ ...rhs, value: e.target.value });\n };\n\n // MONTHS_OF_YEAR\n const monthOfYearOptions = useMemo(\n () =>\n range(1, 12).map(n => ({\n id: `${n}`,\n label: new Date(2021, n - 1, 1).toLocaleString(locale, { month: 'long' })\n })),\n [locale]\n );\n const onMonthOfYearChange = (e: ChangeEvent<HTMLSelectElement>) => {\n const value = e.target.value ? Number(e.target.value) : '';\n onChange({ ...rhs, value });\n };\n\n // DAYS_OF_MONTH\n const onDayOfMonthChange = (value: string) => {\n let newValue: string | number = value;\n if (newValue !== '') {\n newValue = Number(newValue);\n if (newValue > 31) newValue = 31;\n if (newValue < 1) newValue = 1;\n }\n onChange({ ...rhs, value: newValue });\n };\n\n // DAYS_OF_WEEK\n const onDayOfWeekChange = (value: DayOfWeek) => {\n onChange({ ...rhs, value });\n };\n\n return (\n <>\n {/* Date function selector */}\n <Select\n label={t('condition_builder_date_part')}\n value={rhs.dateFunction}\n onChange={handleDatePartChange}\n >\n {dateFunctionOptions.map(o => (\n <Option key={o.id} value={o.id}>\n {o.label}\n </Option>\n ))}\n </Select>\n\n {rhs.dateFunction === 'YEARS' && (\n <Select {...valueComponentProps} onChange={onYearChange} name='year-selector'>\n <Option> </Option>\n {yearOptions.map(o => (\n <Option key={o.id} value={o.id}>\n {o.label}\n </Option>\n ))}\n </Select>\n )}\n {rhs.dateFunction === 'QUARTERS' && <QuarterInput {...dateComponentProps} />}\n {rhs.dateFunction === 'MONTHS' && <MonthInput {...dateComponentProps} />}\n {rhs.dateFunction === 'WEEKS' && <WeekInput {...dateComponentProps} />}\n {rhs.dateFunction === 'DAYS' && <DateInput {...dateComponentProps} />}\n {rhs.dateFunction === 'HOURS' && (\n <DateTimeInput {...dateComponentProps} pickerInterval={60} />\n )}\n {rhs.dateFunction === 'MONTHS_OF_YEAR' && (\n <Select\n {...valueComponentProps}\n onChange={onMonthOfYearChange}\n name='month-of-year-selector'\n >\n <Option> </Option>\n {monthOfYearOptions.map(o => (\n <Option key={o.id} value={o.id}>\n {o.label}\n </Option>\n ))}\n </Select>\n )}\n {rhs.dateFunction === 'DAYS_OF_MONTH' && (\n <NumberInput\n {...valueComponentProps}\n placeholder='1 - 31'\n min={1}\n max={31}\n step={1}\n showDecimal={false}\n onChange={onDayOfMonthChange}\n />\n )}\n {rhs.dateFunction === 'DAYS_OF_WEEK' && (\n <DayOfWeekInput\n {...valueComponentProps}\n value={rhs.value as DayOfWeek}\n onChange={onDayOfWeekChange}\n />\n )}\n </>\n );\n};\n\nexport default DateFunctionMenu;\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,CAAC;AA4BlD,UAAU,kBAAmB,SAAQ,SAAS,EAAE,cAAc;IAC5D,wBAAwB;IACxB,KAAK,EAAE,MAAM,CAAC;IAEd,qBAAqB;IACrB,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAEtC,kEAAkE;IAClE,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB,8BAA8B;IAC9B,MAAM,CAAC,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAEpC,4BAA4B;IAC5B,IAAI,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;CACjC;AAED,+EAA+E;AAC/E,QAAA,MAAM,aAAa,EAAE,iBAAiB,CAAC,kBAAkB,GAAG,YAAY,CAwDvE,CAAC;AAEF,eAAe,aAAa,CAAC"}
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,EAGf,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAiBlD,UAAU,kBAAmB,SAAQ,SAAS,EAAE,cAAc;IAC5D,wBAAwB;IACxB,KAAK,EAAE,MAAM,CAAC;IAEd,qBAAqB;IACrB,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAEtC,kEAAkE;IAClE,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB,8BAA8B;IAC9B,MAAM,CAAC,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAEpC,4BAA4B;IAC5B,IAAI,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;CACjC;AAED,+EAA+E;AAC/E,QAAA,MAAM,aAAa,EAAE,iBAAiB,CAAC,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('');
@@ -61,7 +54,7 @@ const FieldSelector = (props) => {
61
54
  onChange(id);
62
55
  setFilterValue(''); // To show the selected value in the input
63
56
  }
64
- } }, void 0));
57
+ } }));
65
58
  };
66
59
  export default FieldSelector;
67
60
  //# sourceMappingURL=FieldSelector.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FieldSelector.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/FieldSelector.tsx"],"names":[],"mappings":";AAAA,O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L,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,WACD,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,UAAU;SAClB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAmBD,+EAA+E;AAC/E,MAAM,aAAa,GAAyD,CAC1E,KAAyB,EACzB,EAAE;IACF,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;IAExD,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IAEpB,gDAAgD;IAChD,MAAM,KAAK,GAAG,OAAO,CAAC,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E,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,11 +9,14 @@ 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]);
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
15
18
  };
16
- return (_jsx(NumberInput, { value: localValue, onChange: handleInputChange, status: status, info: status === 'error' ? t('condition_builder_invalid_number') : undefined, label: t('condition_builder_compare_with_numeric_value'), labelHidden: true }, void 0));
19
+ return (_jsx(NumberInput, { value: localValue, onChange: handleInputChange, status: status, info: status === 'error' ? t('condition_builder_invalid_number') : undefined, label: t('condition_builder_compare_with_numeric_value'), labelHidden: true }));
17
20
  };
18
21
  export default NumericInput;
19
22
  //# sourceMappingURL=NumericInput.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"NumericInput.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/NumericInput.tsx"],"names":[],"mappings":";AAAA,OAAO,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,iBACX,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,CAAC,CAAC;IAEV,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]);\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"]}
@@ -103,7 +103,7 @@ const RelativeDateMenu = (props) => {
103
103
  });
104
104
  }
105
105
  };
106
- return (_jsxs(_Fragment, { children: [_jsx(Select, { label: t('condition_builder_time_period_label'), value: rhs.relativeDate.timePeriod, onChange: handleTimePeriodChange, children: timePeriodOptions.map(o => (_jsx(Option, { value: o.id, children: o.label }, o.id))) }, void 0), _jsxs(Flex, { container: { direction: 'row', colGap: 1 }, children: [relativeDate.timePeriod !== 'CURRENT' && (_jsx(Flex, { item: { basis: '30%' }, children: _jsx(NumberInput, { ...valueComponentProps, min: 1, step: 1, showDecimal: false, onChange: handleIntervalChange }, void 0) }, void 0)), _jsx(Flex, { item: { basis: relativeDate.timePeriod !== 'CURRENT' ? '70%' : '100%' }, children: _jsx(Select, { label: t('condition_builder_date_part'), value: relativeDate.datePart, onChange: handleDatePartChange, children: datePartOptions.map(o => (_jsx(Option, { value: o.id, children: o.label }, o.id))) }, void 0) }, void 0)] }, void 0)] }, void 0));
106
+ return (_jsxs(_Fragment, { children: [_jsx(Select, { label: t('condition_builder_time_period_label'), value: rhs.relativeDate.timePeriod, onChange: handleTimePeriodChange, children: timePeriodOptions.map(o => (_jsx(Option, { value: o.id, children: o.label }, o.id))) }), _jsxs(Flex, { container: { direction: 'row', colGap: 1 }, children: [relativeDate.timePeriod !== 'CURRENT' && (_jsx(Flex, { item: { basis: '30%' }, children: _jsx(NumberInput, { ...valueComponentProps, min: 1, step: 1, showDecimal: false, onChange: handleIntervalChange }) })), _jsx(Flex, { item: { basis: relativeDate.timePeriod !== 'CURRENT' ? '70%' : '100%' }, children: _jsx(Select, { label: t('condition_builder_date_part'), value: relativeDate.datePart, onChange: handleDatePartChange, children: datePartOptions.map(o => (_jsx(Option, { value: o.id, children: o.label }, o.id))) }) })] })] }));
107
107
  };
108
108
  export default RelativeDateMenu;
109
109
  //# sourceMappingURL=RelativeDateMenu.js.map