@pega/cosmos-react-condition-builder 2.2.1 → 2.2.4

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 (105) hide show
  1. package/lib/components/ConditionBuilder/AtomicCondition.d.ts +51 -0
  2. package/lib/components/ConditionBuilder/AtomicCondition.d.ts.map +1 -0
  3. package/lib/components/ConditionBuilder/AtomicCondition.js +119 -0
  4. package/lib/components/ConditionBuilder/AtomicCondition.js.map +1 -0
  5. package/lib/components/ConditionBuilder/ConditionBuilder.d.ts +6 -0
  6. package/lib/components/ConditionBuilder/ConditionBuilder.d.ts.map +1 -0
  7. package/lib/components/ConditionBuilder/ConditionBuilder.js +234 -0
  8. package/lib/components/ConditionBuilder/ConditionBuilder.js.map +1 -0
  9. package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts +112 -0
  10. package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts.map +1 -0
  11. package/lib/components/ConditionBuilder/ConditionBuilder.types.js +2 -0
  12. package/lib/components/ConditionBuilder/ConditionBuilder.types.js.map +1 -0
  13. package/lib/components/ConditionBuilder/FieldCondition.d.ts +7 -0
  14. package/lib/components/ConditionBuilder/FieldCondition.d.ts.map +1 -0
  15. package/lib/components/ConditionBuilder/FieldCondition.js +26 -0
  16. package/lib/components/ConditionBuilder/FieldCondition.js.map +1 -0
  17. package/lib/components/ConditionBuilder/FieldCondition.types.d.ts +25 -0
  18. package/lib/components/ConditionBuilder/FieldCondition.types.d.ts.map +1 -0
  19. package/lib/components/ConditionBuilder/FieldCondition.types.js +2 -0
  20. package/lib/components/ConditionBuilder/FieldCondition.types.js.map +1 -0
  21. package/lib/components/ConditionBuilder/HelpButton.d.ts +10 -0
  22. package/lib/components/ConditionBuilder/HelpButton.d.ts.map +1 -0
  23. package/lib/components/ConditionBuilder/HelpButton.js +11 -0
  24. package/lib/components/ConditionBuilder/HelpButton.js.map +1 -0
  25. package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.d.ts +18 -0
  26. package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.d.ts.map +1 -0
  27. package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.js +115 -0
  28. package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.js.map +1 -0
  29. package/lib/components/ConditionBuilder/RhsControls/FieldSelector.d.ts +19 -0
  30. package/lib/components/ConditionBuilder/RhsControls/FieldSelector.d.ts.map +1 -0
  31. package/lib/components/ConditionBuilder/RhsControls/FieldSelector.js +67 -0
  32. package/lib/components/ConditionBuilder/RhsControls/FieldSelector.js.map +1 -0
  33. package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.d.ts +16 -0
  34. package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.d.ts.map +1 -0
  35. package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.js +43 -0
  36. package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.js.map +1 -0
  37. package/lib/components/ConditionBuilder/RhsControls/NumericInput.d.ts +18 -0
  38. package/lib/components/ConditionBuilder/RhsControls/NumericInput.d.ts.map +1 -0
  39. package/lib/components/ConditionBuilder/RhsControls/NumericInput.js +19 -0
  40. package/lib/components/ConditionBuilder/RhsControls/NumericInput.js.map +1 -0
  41. package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.d.ts +18 -0
  42. package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.d.ts.map +1 -0
  43. package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.js +109 -0
  44. package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.js.map +1 -0
  45. package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.d.ts +24 -0
  46. package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.d.ts.map +1 -0
  47. package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.js +122 -0
  48. package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.js.map +1 -0
  49. package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.d.ts +8 -0
  50. package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.d.ts.map +1 -0
  51. package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.js +89 -0
  52. package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.js.map +1 -0
  53. package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.d.ts +20 -0
  54. package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.d.ts.map +1 -0
  55. package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.js +11 -0
  56. package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.js.map +1 -0
  57. package/lib/components/ConditionBuilder/RhsControls/index.d.ts +39 -0
  58. package/lib/components/ConditionBuilder/RhsControls/index.d.ts.map +1 -0
  59. package/lib/components/ConditionBuilder/RhsControls/index.js +219 -0
  60. package/lib/components/ConditionBuilder/RhsControls/index.js.map +1 -0
  61. package/lib/components/ConditionBuilder/core/comparators.d.ts +12 -0
  62. package/lib/components/ConditionBuilder/core/comparators.d.ts.map +1 -0
  63. package/lib/components/ConditionBuilder/core/comparators.js +74 -0
  64. package/lib/components/ConditionBuilder/core/comparators.js.map +1 -0
  65. package/lib/components/ConditionBuilder/core/evaluator.d.ts +14 -0
  66. package/lib/components/ConditionBuilder/core/evaluator.d.ts.map +1 -0
  67. package/lib/components/ConditionBuilder/core/evaluator.js +257 -0
  68. package/lib/components/ConditionBuilder/core/evaluator.js.map +1 -0
  69. package/lib/components/ConditionBuilder/core/extendDayJs.d.ts +2 -0
  70. package/lib/components/ConditionBuilder/core/extendDayJs.d.ts.map +1 -0
  71. package/lib/components/ConditionBuilder/core/extendDayJs.js +4 -0
  72. package/lib/components/ConditionBuilder/core/extendDayJs.js.map +1 -0
  73. package/lib/components/ConditionBuilder/core/formatter.d.ts +16 -0
  74. package/lib/components/ConditionBuilder/core/formatter.d.ts.map +1 -0
  75. package/lib/components/ConditionBuilder/core/formatter.js +190 -0
  76. package/lib/components/ConditionBuilder/core/formatter.js.map +1 -0
  77. package/lib/components/ConditionBuilder/core/rows-reducer.d.ts +27 -0
  78. package/lib/components/ConditionBuilder/core/rows-reducer.d.ts.map +1 -0
  79. package/lib/components/ConditionBuilder/core/rows-reducer.js +50 -0
  80. package/lib/components/ConditionBuilder/core/rows-reducer.js.map +1 -0
  81. package/lib/components/ConditionBuilder/core/time-utils.d.ts +5 -0
  82. package/lib/components/ConditionBuilder/core/time-utils.d.ts.map +1 -0
  83. package/lib/components/ConditionBuilder/core/time-utils.js +23 -0
  84. package/lib/components/ConditionBuilder/core/time-utils.js.map +1 -0
  85. package/lib/components/ConditionBuilder/core/transformer.d.ts +7 -0
  86. package/lib/components/ConditionBuilder/core/transformer.d.ts.map +1 -0
  87. package/lib/components/ConditionBuilder/core/transformer.js +154 -0
  88. package/lib/components/ConditionBuilder/core/transformer.js.map +1 -0
  89. package/lib/components/ConditionBuilder/core/types.d.ts +47 -0
  90. package/lib/components/ConditionBuilder/core/types.d.ts.map +1 -0
  91. package/lib/components/ConditionBuilder/core/types.js +2 -0
  92. package/lib/components/ConditionBuilder/core/types.js.map +1 -0
  93. package/lib/components/ConditionBuilder/core/utils.d.ts +37 -0
  94. package/lib/components/ConditionBuilder/core/utils.d.ts.map +1 -0
  95. package/lib/components/ConditionBuilder/core/utils.js +439 -0
  96. package/lib/components/ConditionBuilder/core/utils.js.map +1 -0
  97. package/lib/components/ConditionBuilder/index.d.ts +11 -0
  98. package/lib/components/ConditionBuilder/index.d.ts.map +1 -0
  99. package/lib/components/ConditionBuilder/index.js +8 -0
  100. package/lib/components/ConditionBuilder/index.js.map +1 -0
  101. package/lib/index.d.ts +3 -0
  102. package/lib/index.d.ts.map +1 -0
  103. package/lib/index.js +4 -0
  104. package/lib/index.js.map +1 -0
  105. package/package.json +2 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MultiValueSelector.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/MultiValueSelector.tsx"],"names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ForwardProps,\n ComboBox,\n createStringMatcher,\n useAfterInitialEffect,\n NoChildrenProp\n} from '@pega/cosmos-react-core';\n\ninterface MultiSelectorProps extends BaseProps, NoChildrenProp {\n /** Previous selection */\n values: string[];\n\n /** Options for the selector */\n options: string[];\n\n /** Callback for changes */\n onChange: (selection: string[]) => void;\n\n /** Used to indicate any errors on the control */\n status?: 'error';\n}\n\n/** A control for selecting multiple values using checkboxes in an overlay */\nconst MultiValueSelector: FunctionComponent<MultiSelectorProps & ForwardProps> = ({\n values,\n options,\n onChange,\n status\n}: MultiSelectorProps) => {\n const t = useI18n();\n\n const [selections, setSelections] = useState(values);\n const [filterValue, setFilterValue] = useState('');\n\n const itemsToRender = useMemo(() => {\n let opts = options;\n\n if (filterValue) {\n const matcher = createStringMatcher(filterValue, 'boundary');\n opts = opts.filter(opt => matcher.test(opt));\n }\n\n return opts.map(option => {\n return {\n id: option,\n primary: option,\n selected: selections.includes(option)\n };\n });\n }, [options, filterValue, selections]);\n\n useAfterInitialEffect(() => {\n onChange(selections);\n }, [selections]);\n\n return (\n <ComboBox\n mode='multi-select'\n label={t('condition_builder_possible_values_label')}\n labelHidden\n placeholder={t('condition_builder_selection_text_default')}\n value={filterValue}\n onChange={e => {\n setFilterValue(e.target.value);\n }}\n menu={{\n items: itemsToRender,\n onItemClick: option => {\n setSelections(cur =>\n cur.includes(option) ? cur.filter(selection => selection !== option) : [...cur, option]\n );\n }\n }}\n selected={\n selections.length > 0\n ? {\n items: selections.map(s => ({ id: s, text: s })),\n onRemove: value => {\n setSelections(cur => cur.filter(selection => selection !== value));\n }\n }\n : undefined\n }\n status={status}\n info={status === 'error' ? t('condition_builder_empty_selection_error_text') : undefined}\n />\n );\n};\n\nexport default MultiValueSelector;\n"]}
@@ -0,0 +1,18 @@
1
+ import { FunctionComponent } from 'react';
2
+ import { BaseProps, NoChildrenProp } from '@pega/cosmos-react-core';
3
+ interface NumericInputProps extends BaseProps, NoChildrenProp {
4
+ /** Rhs for the condition */
5
+ rhs: {
6
+ value: string | number;
7
+ };
8
+ /** Callback for any modifications to the Rhs */
9
+ onChange: (rhs: {
10
+ value: string | number;
11
+ }) => void;
12
+ /** Used to indicate any errors on the control */
13
+ status?: 'error';
14
+ }
15
+ /** Wrapper over the NumberInput to parse values as Numbers, while still allowing the user to type partial values like `12.`, `12.0`, ... */
16
+ declare const NumericInput: FunctionComponent<NumericInputProps>;
17
+ export default NumericInput;
18
+ //# sourceMappingURL=NumericInput.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { NumberInput, useI18n } from '@pega/cosmos-react-core';
4
+ /** Wrapper over the NumberInput to parse values as Numbers, while still allowing the user to type partial values like `12.`, `12.0`, ... */
5
+ const NumericInput = (props) => {
6
+ const { rhs, onChange, status } = props;
7
+ const t = useI18n();
8
+ // Since we want to always call onChange with parsed Numbers,
9
+ // if we parse values like `12.`, `12.0`, etc., the decimals will be lost leading to bad UX
10
+ // Using a local state to avoid that
11
+ const [localValue, setLocalValue] = useState(rhs.value.toString());
12
+ const handleInputChange = (newValue) => {
13
+ setLocalValue(newValue);
14
+ onChange({ value: newValue.trim() ? Number(newValue) : '' }); // Save as a number unless the input is empty
15
+ };
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));
17
+ };
18
+ export default NumericInput;
19
+ //# sourceMappingURL=NumericInput.js.map
@@ -0,0 +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"]}
@@ -0,0 +1,18 @@
1
+ import { FunctionComponent } from 'react';
2
+ import { BaseProps, ForwardProps, NoChildrenProp } from '@pega/cosmos-react-core';
3
+ import { RhsWithRelativeDate } from '../ConditionBuilder.types';
4
+ import { FieldType } from '../core/types';
5
+ export interface RelativeDateMenuProps extends BaseProps, NoChildrenProp {
6
+ /** Rhs for the condition */
7
+ rhs: RhsWithRelativeDate;
8
+ /** Callback for any modifications to the Rhs */
9
+ onChange: (rhs: RhsWithRelativeDate) => void;
10
+ /** FieldType of the LHS Field. Will only be DATE_TIME or DATE_ONLY */
11
+ fieldType: FieldType;
12
+ /** Used to indicate any errors on the control */
13
+ status?: 'error';
14
+ }
15
+ /** A menu with controls to select a Time period value on RHS */
16
+ declare const RelativeDateMenu: FunctionComponent<RelativeDateMenuProps & ForwardProps>;
17
+ export default RelativeDateMenu;
18
+ //# sourceMappingURL=RelativeDateMenu.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RelativeDateMenu.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/RelativeDateMenu.tsx"],"names":[],"mappings":"AACA,OAAO,EAAe,iBAAiB,EAAW,MAAM,OAAO,CAAC;AAEhE,OAAO,EACL,SAAS,EACT,YAAY,EAOZ,cAAc,EACf,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAsC,SAAS,EAAE,MAAM,eAAe,CAAC;AAE9E,MAAM,WAAW,qBAAsB,SAAQ,SAAS,EAAE,cAAc;IACtE,4BAA4B;IAC5B,GAAG,EAAE,mBAAmB,CAAC;IAEzB,gDAAgD;IAChD,QAAQ,EAAE,CAAC,GAAG,EAAE,mBAAmB,KAAK,IAAI,CAAC;IAE7C,sEAAsE;IACtE,SAAS,EAAE,SAAS,CAAC;IAErB,iDAAiD;IACjD,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,gEAAgE;AAChE,QAAA,MAAM,gBAAgB,EAAE,iBAAiB,CAAC,qBAAqB,GAAG,YAAY,CAqJ7E,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,109 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ // cspell:ignore words DDTHH
3
+ import { useMemo } from 'react';
4
+ import { Flex, Select, Option, NumberInput, useI18n } from '@pega/cosmos-react-core';
5
+ /** A menu with controls to select a Time period value on RHS */
6
+ const RelativeDateMenu = (props) => {
7
+ const { rhs, onChange, status, fieldType } = props;
8
+ const t = useI18n();
9
+ const { relativeDate } = rhs;
10
+ // Options for the Date Part selector
11
+ const datePartOptions = useMemo(() => {
12
+ const allOptions = ['YEARS', 'QUARTERS', 'MONTHS', 'WEEKS', 'DAYS', 'HOURS'];
13
+ const datePartLabels = {
14
+ YEARS: t('condition_builder_relative_dates_year'),
15
+ QUARTERS: t('condition_builder_relative_dates_quarter'),
16
+ MONTHS: t('condition_builder_relative_dates_month'),
17
+ WEEKS: t('condition_builder_relative_dates_week'),
18
+ DAYS: t('condition_builder_relative_dates_day'),
19
+ HOURS: t('condition_builder_relative_dates_hour'),
20
+ MINUTES: t('condition_builder_relative_dates_minute')
21
+ };
22
+ if (fieldType === 'DATE_TIME') {
23
+ // TODO: Remove temporary hide MINUTES option
24
+ return allOptions.map(datePart => ({
25
+ id: datePart,
26
+ label: datePartLabels[datePart]
27
+ }));
28
+ }
29
+ // Removes MINUTES and HOURS for DATE_ONLY fields
30
+ return allOptions.splice(0, allOptions.length - 1).map(datePart => ({
31
+ id: datePart,
32
+ label: datePartLabels[datePart]
33
+ }));
34
+ }, [t, fieldType]);
35
+ // Options for the Date-function selector
36
+ const timePeriodOptions = useMemo(() => {
37
+ const allOptions = ['CURRENT', 'LAST', 'PREVIOUS', 'NEXT'];
38
+ const timePeriodLabels = {
39
+ CURRENT: t('condition_builder_time_period_current'),
40
+ LAST: t('condition_builder_time_period_last'),
41
+ PREVIOUS: t('condition_builder_time_period_previous'),
42
+ NEXT: t('condition_builder_time_period_next')
43
+ };
44
+ return allOptions.map(timePeriod => ({
45
+ id: timePeriod,
46
+ label: timePeriodLabels[timePeriod]
47
+ }));
48
+ }, [t]);
49
+ const handleTimePeriodChange = (e) => {
50
+ const selection = e.target.value;
51
+ if (selection === 'CURRENT') {
52
+ onChange({
53
+ relativeDate: {
54
+ timePeriod: selection,
55
+ datePart: relativeDate.datePart
56
+ }
57
+ });
58
+ }
59
+ else {
60
+ onChange({
61
+ relativeDate: {
62
+ ...relativeDate,
63
+ timePeriod: selection,
64
+ interval: relativeDate.interval ?? undefined
65
+ }
66
+ });
67
+ }
68
+ };
69
+ // Handle changes to the Date-function selector
70
+ const handleDatePartChange = (e) => {
71
+ const selection = e.target.value;
72
+ onChange({
73
+ relativeDate: {
74
+ ...relativeDate,
75
+ datePart: selection
76
+ }
77
+ });
78
+ };
79
+ // Common props for all value controls
80
+ const valueComponentProps = {
81
+ value: relativeDate.interval?.toString(),
82
+ label: t('condition_builder_value_label'),
83
+ status,
84
+ info: status ? t('condition_builder_invalid_value') : undefined
85
+ };
86
+ const handleIntervalChange = (value) => {
87
+ let newValue;
88
+ if (value !== '' && !Number.isNaN(Number(value))) {
89
+ newValue = Number(value);
90
+ onChange({
91
+ relativeDate: {
92
+ ...relativeDate,
93
+ interval: newValue
94
+ }
95
+ });
96
+ }
97
+ else {
98
+ onChange({
99
+ relativeDate: {
100
+ ...relativeDate,
101
+ interval: undefined
102
+ }
103
+ });
104
+ }
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));
107
+ };
108
+ export default RelativeDateMenu;
109
+ //# sourceMappingURL=RelativeDateMenu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RelativeDateMenu.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/RelativeDateMenu.tsx"],"names":[],"mappings":";AAAA,4BAA4B;AAC5B,OAAO,EAAkC,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhE,OAAO,EAGL,IAAI,EACJ,MAAM,EACN,MAAM,EACN,WAAW,EAEX,OAAO,EAER,MAAM,yBAAyB,CAAC;AAmBjC,gEAAgE;AAChE,MAAM,gBAAgB,GAA4D,CAChF,KAA4B,EAC5B,EAAE;IACF,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;IACnD,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IAEpB,MAAM,EAAE,YAAY,EAAE,GAAG,GAAG,CAAC;IAE7B,qCAAqC;IACrC,MAAM,eAAe,GAAG,OAAO,CAAC,GAAG,EAAE;QACnC,MAAM,UAAU,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAC7E,MAAM,cAAc,GAA6B;YAC/C,KAAK,EAAE,CAAC,CAAC,uCAAuC,CAAC;YACjD,QAAQ,EAAE,CAAC,CAAC,0CAA0C,CAAC;YACvD,MAAM,EAAE,CAAC,CAAC,wCAAwC,CAAC;YACnD,KAAK,EAAE,CAAC,CAAC,uCAAuC,CAAC;YACjD,IAAI,EAAE,CAAC,CAAC,sCAAsC,CAAC;YAC/C,KAAK,EAAE,CAAC,CAAC,uCAAuC,CAAC;YACjD,OAAO,EAAE,CAAC,CAAC,yCAAyC,CAAC;SACtD,CAAC;QACF,IAAI,S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,CAAC,CAAC;AAEF,eAAe,gBAAgB,CAAC","sourcesContent":["// cspell:ignore words DDTHH\nimport { ChangeEvent, FunctionComponent, useMemo } from 'react';\n\nimport {\n BaseProps,\n ForwardProps,\n Flex,\n Select,\n Option,\n NumberInput,\n FormControlProps,\n useI18n,\n NoChildrenProp\n} from '@pega/cosmos-react-core';\n\nimport { RhsWithRelativeDate } from '../ConditionBuilder.types';\nimport { DateFunction, DatePart, TimePeriod, FieldType } from '../core/types';\n\nexport interface RelativeDateMenuProps extends BaseProps, NoChildrenProp {\n /** Rhs for the condition */\n rhs: RhsWithRelativeDate;\n\n /** Callback for any modifications to the Rhs */\n onChange: (rhs: RhsWithRelativeDate) => void;\n\n /** FieldType of the LHS Field. Will only be DATE_TIME or DATE_ONLY */\n fieldType: FieldType;\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 RelativeDateMenu: FunctionComponent<RelativeDateMenuProps & ForwardProps> = (\n props: RelativeDateMenuProps\n) => {\n const { rhs, onChange, status, fieldType } = props;\n const t = useI18n();\n\n const { relativeDate } = rhs;\n\n // Options for the Date Part selector\n const datePartOptions = useMemo(() => {\n const allOptions = ['YEARS', 'QUARTERS', 'MONTHS', 'WEEKS', 'DAYS', 'HOURS'];\n const datePartLabels: Record<DatePart, string> = {\n YEARS: t('condition_builder_relative_dates_year'),\n QUARTERS: t('condition_builder_relative_dates_quarter'),\n MONTHS: t('condition_builder_relative_dates_month'),\n WEEKS: t('condition_builder_relative_dates_week'),\n DAYS: t('condition_builder_relative_dates_day'),\n HOURS: t('condition_builder_relative_dates_hour'),\n MINUTES: t('condition_builder_relative_dates_minute')\n };\n if (fieldType === 'DATE_TIME') {\n // TODO: Remove temporary hide MINUTES option\n return allOptions.map(datePart => ({\n id: datePart,\n label: datePartLabels[datePart as DatePart]\n }));\n }\n // Removes MINUTES and HOURS for DATE_ONLY fields\n return allOptions.splice(0, allOptions.length - 1).map(datePart => ({\n id: datePart,\n label: datePartLabels[datePart as DatePart]\n }));\n }, [t, fieldType]);\n\n // Options for the Date-function selector\n const timePeriodOptions = useMemo(() => {\n const allOptions = ['CURRENT', 'LAST', 'PREVIOUS', 'NEXT'];\n const timePeriodLabels: Record<TimePeriod, string> = {\n CURRENT: t('condition_builder_time_period_current'),\n LAST: t('condition_builder_time_period_last'),\n PREVIOUS: t('condition_builder_time_period_previous'),\n NEXT: t('condition_builder_time_period_next')\n };\n return allOptions.map(timePeriod => ({\n id: timePeriod,\n label: timePeriodLabels[timePeriod as TimePeriod]\n }));\n }, [t]);\n\n const handleTimePeriodChange = (e: ChangeEvent<HTMLSelectElement>) => {\n const selection = e.target.value;\n if (selection === 'CURRENT') {\n onChange({\n relativeDate: {\n timePeriod: selection as TimePeriod,\n datePart: relativeDate.datePart\n }\n });\n } else {\n onChange({\n relativeDate: {\n ...relativeDate,\n timePeriod: selection as TimePeriod,\n interval: relativeDate.interval ?? undefined\n }\n });\n }\n };\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({\n relativeDate: {\n ...relativeDate,\n datePart: selection as DatePart\n }\n });\n };\n\n // Common props for all value controls\n const valueComponentProps: FormControlProps = {\n value: relativeDate.interval?.toString(),\n label: t('condition_builder_value_label'),\n status,\n info: status ? t('condition_builder_invalid_value') : undefined\n };\n\n const handleIntervalChange = (value: string) => {\n let newValue: number;\n if (value !== '' && !Number.isNaN(Number(value))) {\n newValue = Number(value);\n onChange({\n relativeDate: {\n ...relativeDate,\n interval: newValue\n }\n });\n } else {\n onChange({\n relativeDate: {\n ...relativeDate,\n interval: undefined\n }\n });\n }\n };\n\n return (\n <>\n <Select\n label={t('condition_builder_time_period_label')}\n value={rhs.relativeDate.timePeriod}\n onChange={handleTimePeriodChange}\n >\n {timePeriodOptions.map(o => (\n <Option key={o.id} value={o.id}>\n {o.label}\n </Option>\n ))}\n </Select>\n <Flex container={{ direction: 'row', colGap: 1 }}>\n {relativeDate.timePeriod !== 'CURRENT' && (\n <Flex item={{ basis: '30%' }}>\n <NumberInput\n {...valueComponentProps}\n min={1}\n step={1}\n showDecimal={false}\n onChange={handleIntervalChange}\n />\n </Flex>\n )}\n <Flex item={{ basis: relativeDate.timePeriod !== 'CURRENT' ? '70%' : '100%' }}>\n <Select\n label={t('condition_builder_date_part')}\n value={relativeDate.datePart}\n onChange={handleDatePartChange}\n >\n {datePartOptions.map(o => (\n <Option key={o.id} value={o.id}>\n {o.label}\n </Option>\n ))}\n </Select>\n </Flex>\n </Flex>\n </>\n );\n};\n\nexport default RelativeDateMenu;\n"]}
@@ -0,0 +1,24 @@
1
+ import { FunctionComponent } from 'react';
2
+ import { BaseProps, ForwardProps, NoChildrenProp } from '@pega/cosmos-react-core';
3
+ import { Comparator, FieldType, RHSType } from '../core/types';
4
+ import { DateFunctionsByType, LeafCondition } from '../ConditionBuilder.types';
5
+ interface RhsMenuButtonProps extends BaseProps, NoChildrenProp {
6
+ /** Type of field on the LHS */
7
+ fieldType: FieldType;
8
+ /** Comparator for the condition */
9
+ comparator: Comparator;
10
+ /** Rhs for the condition */
11
+ rhs: LeafCondition['rhs'];
12
+ /** Callback for any modifications to the Rhs */
13
+ onChange: (rhs: LeafCondition['rhs']) => void;
14
+ /** Display mode */
15
+ mode: 'combo-box' | 'menu-button';
16
+ /** Restricts RHS values to only specified RHS types */
17
+ validRhsTypes: Set<RHSType>;
18
+ /** Passed to enable additional date controls on the RHS, when a DATE_TIME/DATE_ONLY field is selected on the LHS */
19
+ dateFunctions?: DateFunctionsByType;
20
+ }
21
+ /** Renders a Gear MenuButton on the RHS (when applicable) */
22
+ declare const RhsModeSwitch: FunctionComponent<RhsMenuButtonProps & ForwardProps>;
23
+ export default RhsModeSwitch;
24
+ //# sourceMappingURL=RhsModeSwitch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RhsModeSwitch.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/RhsModeSwitch.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAW,MAAM,OAAO,CAAC;AAEnD,OAAO,EACL,SAAS,EAET,YAAY,EAKZ,cAAc,EAGf,MAAM,yBAAyB,CAAC;AAIjC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AA6B/E,UAAU,kBAAmB,SAAQ,SAAS,EAAE,cAAc;IAC5D,+BAA+B;IAC/B,SAAS,EAAE,SAAS,CAAC;IAErB,mCAAmC;IACnC,UAAU,EAAE,UAAU,CAAC;IAEvB,4BAA4B;IAC5B,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;IAE1B,gDAAgD;IAChD,QAAQ,EAAE,CAAC,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;IAE9C,mBAAmB;IACnB,IAAI,EAAE,WAAW,GAAG,aAAa,CAAC;IAElC,uDAAuD;IACvD,aAAa,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAE5B,oHAAoH;IACpH,aAAa,CAAC,EAAE,mBAAmB,CAAC;CACrC;AAED,6DAA6D;AAC7D,QAAA,MAAM,aAAa,EAAE,iBAAiB,CAAC,kBAAkB,GAAG,YAAY,CAqHvE,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -0,0 +1,122 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useMemo } from 'react';
3
+ import { ComboBox, hasProp, MenuButton, menuHelpers, useI18n } from '@pega/cosmos-react-core';
4
+ var ItemID;
5
+ (function (ItemID) {
6
+ ItemID["LITERAL_VALUE"] = "LITERAL_VALUE";
7
+ ItemID["DATE_PART"] = "DATE_PART";
8
+ ItemID["RELATIVE_DATE"] = "RELATIVE_DATE";
9
+ ItemID["ANOTHER_FIELD"] = "ANOTHER_FIELD";
10
+ })(ItemID || (ItemID = {}));
11
+ // Label for the `Enter <value>` option on the gear-menu
12
+ function getValueOptionLabel(fieldType, t) {
13
+ switch (fieldType) {
14
+ case 'TEXT':
15
+ return t('condition_builder_compare_with_text_value');
16
+ case 'NUMBER':
17
+ return t('condition_builder_compare_with_numeric_value');
18
+ case 'DATE_TIME':
19
+ case 'DATE_ONLY':
20
+ return t('condition_builder_compare_with_date_value');
21
+ case 'TIME_ONLY':
22
+ return t('condition_builder_compare_with_time_value');
23
+ default:
24
+ return t('condition_builder_value_label'); // Not needed (BOOLEAN is not expected to be passed to the function)
25
+ }
26
+ }
27
+ /** Renders a Gear MenuButton on the RHS (when applicable) */
28
+ const RhsModeSwitch = (props) => {
29
+ const { fieldType, comparator, rhs, onChange, mode, validRhsTypes, dateFunctions } = props;
30
+ const t = useI18n();
31
+ // Identify current mode
32
+ const currentMode = useMemo(() => {
33
+ // rhs should already be defined if this component is being rendered. Indicating the same to TS using `!`
34
+ if (hasProp(rhs, 'field'))
35
+ return ItemID.ANOTHER_FIELD;
36
+ if (hasProp(rhs, 'value') && hasProp(rhs, 'dateFunction'))
37
+ return ItemID.DATE_PART;
38
+ if (hasProp(rhs, 'relativeDate'))
39
+ return ItemID.RELATIVE_DATE;
40
+ return ItemID.LITERAL_VALUE;
41
+ }, [rhs]);
42
+ // Determine actions for the menu
43
+ const menu = useMemo(() => {
44
+ const items = [];
45
+ // Boolean conditions either don't use an rhs or always use the field-selector
46
+ // For IN/NOT_IN comparators, only one mode is possible for a given case - CSV Input or a Value-selector
47
+ if (fieldType !== 'BOOLEAN' && !['IN', 'NOT_IN'].includes(comparator)) {
48
+ // Literal value input
49
+ if (validRhsTypes.has('LITERAL')) {
50
+ // Literal Value inputs
51
+ items.push({
52
+ id: ItemID.LITERAL_VALUE,
53
+ primary: getValueOptionLabel(fieldType, t),
54
+ onClick: id => {
55
+ if (id === currentMode)
56
+ return; // Ignore if already in that mode
57
+ onChange({ value: '' }); // Submit a new RHS to re-render with the new mode
58
+ }
59
+ });
60
+ }
61
+ // Field selector
62
+ if (validRhsTypes.has('FIELD')) {
63
+ items.push({
64
+ id: ItemID.ANOTHER_FIELD,
65
+ primary: t('condition_builder_compare_with_another_field'),
66
+ onClick: id => {
67
+ if (id === currentMode)
68
+ return; // Ignore if already in that mode
69
+ onChange({ field: '' }); // Submit a new RHS to re-render with the new mode
70
+ }
71
+ });
72
+ }
73
+ // Relative Date value input
74
+ if (validRhsTypes.has('RELATIVE_DATE') &&
75
+ (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY')) {
76
+ items.push({
77
+ id: ItemID.RELATIVE_DATE,
78
+ primary: t('condition_builder_compare_with_relative_date'),
79
+ onClick: id => {
80
+ if (id === currentMode)
81
+ return; // Ignore if already in that mode
82
+ onChange({
83
+ relativeDate: {
84
+ timePeriod: 'CURRENT',
85
+ datePart: 'DAYS'
86
+ }
87
+ });
88
+ }
89
+ });
90
+ }
91
+ // Date Part value input
92
+ if (validRhsTypes.has('DATE_FUNCTION') &&
93
+ dateFunctions &&
94
+ (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY')) {
95
+ items.push({
96
+ id: ItemID.DATE_PART,
97
+ primary: t('condition_builder_date_part'),
98
+ onClick: id => {
99
+ if (id === currentMode)
100
+ return; // Ignore if already in that mode
101
+ onChange({ value: '', dateFunction: dateFunctions[fieldType][0] }); // Submit a new RHS to re-render with the new mode. Initializing with the first available date function
102
+ }
103
+ });
104
+ }
105
+ }
106
+ return { items, mode: 'action' };
107
+ }, [fieldType, comparator, onChange, validRhsTypes, dateFunctions, currentMode, t]);
108
+ // Identify current selection for ComboBox
109
+ const selected = useMemo(() => {
110
+ const selectedItem = menuHelpers.getItem(menu.items, currentMode);
111
+ return selectedItem ? { id: selectedItem.id, text: selectedItem.primary } : undefined;
112
+ }, [menu, currentMode]);
113
+ // Render the button only when there are multiple options in the menu
114
+ if (menu.items.length < 2)
115
+ return null;
116
+ if (mode === 'combo-box') {
117
+ return (_jsx(ComboBox, { label: t('condition_builder_compare_with'), labelHidden: true, mode: 'single-select', selected: { items: selected }, menu: menu }, void 0));
118
+ }
119
+ return (_jsx(MenuButton, { text: t('condition_builder_compare_with'), icon: 'gear', iconOnly: true, variant: 'simple', menu: menu }, void 0));
120
+ };
121
+ export default RhsModeSwitch;
122
+ //# sourceMappingURL=RhsModeSwitch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RhsModeSwitch.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/RhsModeSwitch.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAqB,OAAO,EAAE,MAAM,OAAO,CAAC;AAEnD,OAAO,EAEL,QAAQ,EAER,OAAO,EACP,UAAU,EACV,WAAW,EAIX,OAAO,EACR,MAAM,yBAAyB,CAAC;AAOjC,IAAK,MAKJ;AALD,WAAK,MAAM;IACT,yCAA+B,CAAA;IAC/B,iCAAuB,CAAA;IACvB,yCAA+B,CAAA;IAC/B,yCAA+B,CAAA;AACjC,CAAC,EALI,MAAM,KAAN,MAAM,QAKV;AAED,wDAAwD;AACxD,SAAS,mBAAmB,CAC1B,SAAoB,EACpB,CAAuC;IAEvC,QAAQ,SAAS,EAAE;QACjB,KAAK,MAAM;YACT,OAAO,CAAC,CAAC,2CAA2C,CAAC,CAAC;QACxD,KAAK,QAAQ;YACX,OAAO,CAAC,CAAC,8CAA8C,CAAC,CAAC;QAC3D,KAAK,WAAW,CAAC;QACjB,KAAK,WAAW;YACd,OAAO,CAAC,CAAC,2CAA2C,CAAC,CAAC;QACxD,KAAK,WAAW;YACd,OAAO,CAAC,CAAC,2CAA2C,CAAC,CAAC;QACxD;YACE,OAAO,CAAC,CAAC,+BAA+B,CAAC,CAAC,CAAC,oEAAoE;KAClH;AACH,CAAC;AAyBD,6DAA6D;AAC7D,MAAM,aAAa,GAAyD,CAC1E,KAAyB,EACzB,EAAE;IACF,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,EAAE,QAAQ,EAAE,I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AAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { FunctionComponent, useMemo } from 'react';\n\nimport {\n BaseProps,\n ComboBox,\n ForwardProps,\n hasProp,\n MenuButton,\n menuHelpers,\n MenuProps,\n NoChildrenProp,\n TranslationPack,\n useI18n\n} from '@pega/cosmos-react-core';\nimport { TranslationFunction } from '@pega/cosmos-react-core/lib/i18n/translate';\nimport { Selected } from '@pega/cosmos-react-core/lib/components/ComboBox/ComboBox.types';\n\nimport { Comparator, FieldType, RHSType } from '../core/types';\nimport { DateFunctionsByType, LeafCondition } from '../ConditionBuilder.types';\n\nenum ItemID {\n LITERAL_VALUE = 'LITERAL_VALUE',\n DATE_PART = 'DATE_PART',\n RELATIVE_DATE = 'RELATIVE_DATE',\n ANOTHER_FIELD = 'ANOTHER_FIELD'\n}\n\n// Label for the `Enter <value>` option on the gear-menu\nfunction getValueOptionLabel(\n fieldType: FieldType,\n t: TranslationFunction<TranslationPack>\n): string {\n switch (fieldType) {\n case 'TEXT':\n return t('condition_builder_compare_with_text_value');\n case 'NUMBER':\n return t('condition_builder_compare_with_numeric_value');\n case 'DATE_TIME':\n case 'DATE_ONLY':\n return t('condition_builder_compare_with_date_value');\n case 'TIME_ONLY':\n return t('condition_builder_compare_with_time_value');\n default:\n return t('condition_builder_value_label'); // Not needed (BOOLEAN is not expected to be passed to the function)\n }\n}\n\ninterface RhsMenuButtonProps extends BaseProps, NoChildrenProp {\n /** Type of field on the LHS */\n fieldType: FieldType;\n\n /** Comparator for the condition */\n comparator: Comparator;\n\n /** Rhs for the condition */\n rhs: LeafCondition['rhs'];\n\n /** Callback for any modifications to the Rhs */\n onChange: (rhs: LeafCondition['rhs']) => void;\n\n /** Display mode */\n mode: 'combo-box' | 'menu-button';\n\n /** Restricts RHS values to only specified RHS types */\n validRhsTypes: Set<RHSType>;\n\n /** Passed to enable additional date controls on the RHS, when a DATE_TIME/DATE_ONLY field is selected on the LHS */\n dateFunctions?: DateFunctionsByType;\n}\n\n/** Renders a Gear MenuButton on the RHS (when applicable) */\nconst RhsModeSwitch: FunctionComponent<RhsMenuButtonProps & ForwardProps> = (\n props: RhsMenuButtonProps\n) => {\n const { fieldType, comparator, rhs, onChange, mode, validRhsTypes, dateFunctions } = props;\n const t = useI18n();\n\n // Identify current mode\n const currentMode = useMemo(() => {\n // rhs should already be defined if this component is being rendered. Indicating the same to TS using `!`\n if (hasProp(rhs!, 'field')) return ItemID.ANOTHER_FIELD;\n if (hasProp(rhs!, 'value') && hasProp(rhs!, 'dateFunction')) return ItemID.DATE_PART;\n if (hasProp(rhs!, 'relativeDate')) return ItemID.RELATIVE_DATE;\n return ItemID.LITERAL_VALUE;\n }, [rhs]);\n\n // Determine actions for the menu\n const menu = useMemo<MenuProps>(() => {\n const items: MenuProps['items'] = [];\n\n // Boolean conditions either don't use an rhs or always use the field-selector\n // For IN/NOT_IN comparators, only one mode is possible for a given case - CSV Input or a Value-selector\n if (fieldType !== 'BOOLEAN' && !['IN', 'NOT_IN'].includes(comparator)) {\n // Literal value input\n if (validRhsTypes.has('LITERAL')) {\n // Literal Value inputs\n items.push({\n id: ItemID.LITERAL_VALUE,\n primary: getValueOptionLabel(fieldType, t),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({ value: '' }); // Submit a new RHS to re-render with the new mode\n }\n });\n }\n\n // Field selector\n if (validRhsTypes.has('FIELD')) {\n items.push({\n id: ItemID.ANOTHER_FIELD,\n primary: t('condition_builder_compare_with_another_field'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({ field: '' }); // Submit a new RHS to re-render with the new mode\n }\n });\n }\n\n // Relative Date value input\n if (\n validRhsTypes.has('RELATIVE_DATE') &&\n (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY')\n ) {\n items.push({\n id: ItemID.RELATIVE_DATE,\n primary: t('condition_builder_compare_with_relative_date'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({\n relativeDate: {\n timePeriod: 'CURRENT',\n datePart: 'DAYS'\n }\n });\n }\n });\n }\n\n // Date Part value input\n if (\n validRhsTypes.has('DATE_FUNCTION') &&\n dateFunctions &&\n (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY')\n ) {\n items.push({\n id: ItemID.DATE_PART,\n primary: t('condition_builder_date_part'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({ value: '', dateFunction: dateFunctions[fieldType][0] }); // Submit a new RHS to re-render with the new mode. Initializing with the first available date function\n }\n });\n }\n }\n\n return { items, mode: 'action' };\n }, [fieldType, comparator, onChange, validRhsTypes, dateFunctions, currentMode, t]);\n\n // Identify current selection for ComboBox\n const selected = useMemo<Selected | undefined>(() => {\n const selectedItem = menuHelpers.getItem(menu.items, currentMode);\n return selectedItem ? { id: selectedItem.id, text: selectedItem.primary } : undefined;\n }, [menu, currentMode]);\n\n // Render the button only when there are multiple options in the menu\n if (menu.items.length < 2) return null;\n\n if (mode === 'combo-box') {\n return (\n <ComboBox\n label={t('condition_builder_compare_with')}\n labelHidden\n mode='single-select'\n selected={{ items: selected }}\n menu={menu}\n />\n );\n }\n\n return (\n <MenuButton\n text={t('condition_builder_compare_with')}\n icon='gear'\n iconOnly\n variant='simple'\n menu={menu}\n />\n );\n};\n\nexport default RhsModeSwitch;\n"]}
@@ -0,0 +1,8 @@
1
+ import { FunctionComponent } from 'react';
2
+ import { ForwardProps } from '@pega/cosmos-react-core';
3
+ import { TimePeriodMenuProps } from './TimePeriodMenu';
4
+ export declare const StyledOpenerButton: import("styled-components").StyledComponent<FunctionComponent<import("@pega/cosmos-react-core").ButtonProps & ForwardProps>, import("styled-components").DefaultTheme, {}, never>;
5
+ /** Renders a button that opens up TimePeriodMenu in a Popover */
6
+ declare const TimePeriodInput: FunctionComponent<TimePeriodMenuProps & ForwardProps>;
7
+ export default TimePeriodInput;
8
+ //# sourceMappingURL=TimePeriodInput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TimePeriodInput.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/TimePeriodInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAoB,MAAM,OAAO,CAAC;AAG5D,OAAO,EAEL,YAAY,EAWb,MAAM,yBAAyB,CAAC;AAUjC,OAAuB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAGvE,eAAO,MAAM,kBAAkB,mLAa7B,CAAC;AAwEH,iEAAiE;AACjE,QAAA,MAAM,eAAe,EAAE,iBAAiB,CAAC,mBAAmB,GAAG,YAAY,CAkE1E,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -0,0 +1,89 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useRef, useState } from 'react';
3
+ import styled, { css } from 'styled-components';
4
+ import { Flex, Icon, Popover, Text, useElement, useOuterEvent, useConfiguration, useI18n, hasProp, Button, defaultThemeProp } from '@pega/cosmos-react-core';
5
+ import { StyledFormFieldInfo } from '@pega/cosmos-react-core/lib/components/FormField/FormField';
6
+ import DateTimeDisplay from '@pega/cosmos-react-core/lib/components/DateTime/DateTimeDisplay';
7
+ import { formatRelativeDate } from '../core/formatter';
8
+ import TimePeriodMenu from './TimePeriodMenu';
9
+ // Custom styles for the button to match the designs
10
+ export const StyledOpenerButton = styled(Button)(props => {
11
+ const { 'border-radius': baseBorderRadius } = props.theme.base;
12
+ const { 'form-control': formControl } = props.theme.components;
13
+ const { 'status-color': errorColor } = props.theme.components['form-field'].error;
14
+ return css `
15
+ width: 100%;
16
+ padding: 0 ${formControl.padding};
17
+ color: ${formControl['foreground-color']};
18
+ border-radius: calc(${baseBorderRadius} * ${formControl['border-radius']});
19
+ background-color: ${formControl['background-color']};
20
+ border-color: ${props.hasError ? errorColor : formControl['border-color']};
21
+ `;
22
+ });
23
+ StyledOpenerButton.defaultProps = defaultThemeProp;
24
+ const dateDisplayVariants = {
25
+ YEARS: 'year',
26
+ QUARTERS: 'quarteryear',
27
+ MONTHS: 'monthyear',
28
+ WEEKS: 'week',
29
+ DAYS: 'date',
30
+ HOURS: 'datetime'
31
+ };
32
+ const EllipsisLabel = styled.div `
33
+ white-space: nowrap;
34
+ overflow: hidden;
35
+ text-overflow: ellipsis;
36
+ `;
37
+ /** Display for the selected time period value */
38
+ const TimePeriodDisplay = (props) => {
39
+ const { locale } = useConfiguration();
40
+ const t = useI18n();
41
+ const { rhs } = props;
42
+ if (hasProp(rhs, 'relativeDate')) {
43
+ const { relativeDate: { timePeriod, interval, datePart } } = rhs;
44
+ return _jsx(Text, { children: formatRelativeDate(t, timePeriod, datePart, interval) }, void 0);
45
+ }
46
+ const { value, dateFunction } = rhs;
47
+ if (!value) {
48
+ return _jsx(Text, { children: t('condition_builder_select_placeholder') }, void 0);
49
+ }
50
+ if (dateFunction === 'MONTHS_OF_YEAR') {
51
+ return (_jsx(Text, { children: new Date(2021, value - 1, 1).toLocaleString(locale, { month: 'long' }) }, void 0));
52
+ }
53
+ if (dateFunction === 'DAYS_OF_MONTH') {
54
+ return (_jsx(Text, { children: t('condition_builder_day_number_of_month', [value], {
55
+ count: Number(value),
56
+ pluralType: 'ordinal'
57
+ }) }, void 0));
58
+ }
59
+ if (dateFunction === 'DAYS_OF_WEEK') {
60
+ return (
61
+ // Choosing Feb-2021 as it starts on a Monday
62
+ _jsx(Text, { children: new Date(2021, 1, value).toLocaleString(locale, { weekday: 'long' }) }, void 0));
63
+ }
64
+ return _jsx(DateTimeDisplay, { value: value, variant: dateDisplayVariants[dateFunction] }, void 0);
65
+ };
66
+ /** Renders a button that opens up TimePeriodMenu in a Popover */
67
+ const TimePeriodInput = (props) => {
68
+ const { rhs, onChange, dateFunctionsList, status, fieldType } = props;
69
+ const t = useI18n();
70
+ // Ref for the opener button
71
+ const buttonRef = useRef(null);
72
+ // Set up a Popover for the controls
73
+ const [isOpen, setIsOpen] = useState(false);
74
+ const [popoverEl, setPopoverEl] = useElement(null);
75
+ const hidePopup = () => {
76
+ if (isOpen)
77
+ setIsOpen(false);
78
+ };
79
+ useOuterEvent('mousedown', [popoverEl, buttonRef.current], hidePopup); // Call the method on clicking outside these elements
80
+ const hideOnEscape = (e) => {
81
+ if (e.key === 'Escape')
82
+ hidePopup(); // Call the method when Escape key is pressed
83
+ };
84
+ return (_jsxs(_Fragment, { children: [_jsx(StyledOpenerButton, { ref: buttonRef, "aria-haspopup": true, "aria-expanded": isOpen, onClick: () => setIsOpen(!isOpen), onKeyDown: hideOnEscape, hasError: status === 'error', name: 'time-period-button', children: _jsxs(Flex, { container: { justify: 'between', alignItems: 'center', gap: 1 }, item: { grow: 1 }, children: [_jsx(EllipsisLabel, { children: _jsx(TimePeriodDisplay, { rhs: rhs }, void 0) }, void 0), _jsx(Icon, { name: isOpen ? 'times' : 'calendar' }, void 0)] }, void 0) }, void 0), status === 'error' && (_jsx(StyledFormFieldInfo, { status: 'error', children: hasProp(rhs, 'relativeDate')
85
+ ? t('condition_builder_invalid_relative_date')
86
+ : t('condition_builder_invalid_time_period') }, void 0)), _jsx(Popover, { show: isOpen, ref: setPopoverEl, target: buttonRef.current, placement: 'bottom-start', style: { width: '40ch' }, children: _jsx(Flex, { container: { pad: 1 }, children: _jsx(TimePeriodMenu, { rhs: rhs, fieldType: fieldType, onChange: onChange, dateFunctionsList: dateFunctionsList, status: status }, void 0) }, void 0) }, void 0)] }, void 0));
87
+ };
88
+ export default TimePeriodInput;
89
+ //# sourceMappingURL=TimePeriodInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TimePeriodInput.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/TimePeriodInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAqB,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5D,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,IAAI,EAEJ,IAAI,EACJ,OAAO,EACP,IAAI,E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,YAAY,EACvB,QAAQ,EAAE,MAAM,KAAK,OAAO,EAC5B,IAAI,EAAC,oBAAoB,YAEzB,MAAC,IAAI,IAAC,SAAS,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,aACtF,KAAC,aAAa,cACZ,KAAC,iBAAiB,IAAC,GAAG,EAAE,GAAG,WAAI,WACjB,EAChB,KAAC,IAAI,IAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,WAAI,YACxC,WACY,EAEpB,MAAM,KAAK,OAAO,IAAI,CACrB,KAAC,mBAAmB,IAAC,MAAM,EAAC,OAAO,YAChC,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC;oBAC3B,CAAC,CAAC,CAAC,CAAC,yCAAyC,CAAC;oBAC9C,CAAC,CAAC,CAAC,CAAC,uCAAuC,CAAC,WAC1B,CACvB,EAED,KAAC,OAAO,IACN,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,YAAY,EACjB,MAAM,EAAE,SAAS,CAAC,OAAO,EACzB,SAAS,EAAC,cAAc,EACxB,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,YAExB,KAAC,IAAI,IAAC,SAAS,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,YACzB,KAAC,cAAc,IACb,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,QAAQ,EAClB,iBAAiB,EAAE,iBAAiB,EACpC,MAAM,EAAE,MAAM,WACd,WACG,WACC,YACT,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { FunctionComponent, useRef, useState } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport {\n Flex,\n ForwardProps,\n Icon,\n Popover,\n Text,\n useElement,\n useOuterEvent,\n useConfiguration,\n useI18n,\n hasProp,\n Button,\n defaultThemeProp\n} from '@pega/cosmos-react-core';\nimport { StyledFormFieldInfo } from '@pega/cosmos-react-core/lib/components/FormField/FormField';\nimport DateTimeDisplay, {\n DateTimeVariant\n} from '@pega/cosmos-react-core/lib/components/DateTime/DateTimeDisplay';\n\nimport { RhsWithDateFunction, RhsWithRelativeDate } from '../ConditionBuilder.types';\nimport { formatRelativeDate } from '../core/formatter';\nimport { DateFunction } from '../core/types';\n\nimport TimePeriodMenu, { TimePeriodMenuProps } from './TimePeriodMenu';\n\n// Custom styles for the button to match the designs\nexport const StyledOpenerButton = styled(Button)(props => {\n const { 'border-radius': baseBorderRadius } = props.theme.base;\n const { 'form-control': formControl } = props.theme.components;\n const { 'status-color': errorColor } = props.theme.components['form-field'].error;\n\n return css`\n width: 100%;\n padding: 0 ${formControl.padding};\n color: ${formControl['foreground-color']};\n border-radius: calc(${baseBorderRadius} * ${formControl['border-radius']});\n background-color: ${formControl['background-color']};\n border-color: ${props.hasError ? errorColor : formControl['border-color']};\n `;\n});\nStyledOpenerButton.defaultProps = defaultThemeProp;\n\nconst dateDisplayVariants: Record<\n Exclude<DateFunction, 'MONTHS_OF_YEAR' | 'DAYS_OF_MONTH' | 'DAYS_OF_WEEK'>,\n DateTimeVariant\n> = {\n YEARS: 'year',\n QUARTERS: 'quarteryear',\n MONTHS: 'monthyear',\n WEEKS: 'week',\n DAYS: 'date',\n HOURS: 'datetime'\n};\n\nconst EllipsisLabel = styled.div`\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n`;\n\n/** Display for the selected time period value */\nconst TimePeriodDisplay: FunctionComponent<{ rhs: RhsWithDateFunction | RhsWithRelativeDate }> =\n (props: { rhs: RhsWithDateFunction | RhsWithRelativeDate }) => {\n const { locale } = useConfiguration();\n const t = useI18n();\n const { rhs } = props;\n\n if (hasProp(rhs, 'relativeDate')) {\n const {\n relativeDate: { timePeriod, interval, datePart }\n } = rhs;\n return <Text>{formatRelativeDate(t, timePeriod, datePart, interval)}</Text>;\n }\n\n const { value, dateFunction } = rhs;\n\n if (!value) {\n return <Text>{t('condition_builder_select_placeholder')}</Text>;\n }\n\n if (dateFunction === 'MONTHS_OF_YEAR') {\n return (\n <Text>\n {new Date(2021, (value as number) - 1, 1).toLocaleString(locale, { month: 'long' })}\n </Text>\n );\n }\n\n if (dateFunction === 'DAYS_OF_MONTH') {\n return (\n <Text>\n {t('condition_builder_day_number_of_month', [value], {\n count: Number(value),\n pluralType: 'ordinal'\n })}\n </Text>\n );\n }\n\n if (dateFunction === 'DAYS_OF_WEEK') {\n return (\n // Choosing Feb-2021 as it starts on a Monday\n <Text>\n {new Date(2021, 1, value as number).toLocaleString(locale, { weekday: 'long' })}\n </Text>\n );\n }\n\n return <DateTimeDisplay value={value} variant={dateDisplayVariants[dateFunction]} />;\n };\n\n/** Renders a button that opens up TimePeriodMenu in a Popover */\nconst TimePeriodInput: FunctionComponent<TimePeriodMenuProps & ForwardProps> = (\n props: TimePeriodMenuProps\n) => {\n const { rhs, onChange, dateFunctionsList, status, fieldType } = props;\n const t = useI18n();\n\n // Ref for the opener button\n const buttonRef = useRef(null);\n\n // Set up a Popover for the controls\n const [isOpen, setIsOpen] = useState(false);\n const [popoverEl, setPopoverEl] = useElement<HTMLElement>(null);\n const hidePopup = () => {\n if (isOpen) setIsOpen(false);\n };\n useOuterEvent('mousedown', [popoverEl, buttonRef.current], hidePopup); // Call the method on clicking outside these elements\n const hideOnEscape = (e: KeyboardEvent) => {\n if (e.key === 'Escape') hidePopup(); // Call the method when Escape key is pressed\n };\n\n return (\n <>\n <StyledOpenerButton\n ref={buttonRef}\n aria-haspopup\n aria-expanded={isOpen}\n onClick={() => setIsOpen(!isOpen)}\n onKeyDown={hideOnEscape}\n hasError={status === 'error'}\n name='time-period-button'\n >\n <Flex container={{ justify: 'between', alignItems: 'center', gap: 1 }} item={{ grow: 1 }}>\n <EllipsisLabel>\n <TimePeriodDisplay rhs={rhs} />\n </EllipsisLabel>\n <Icon name={isOpen ? 'times' : 'calendar'} />\n </Flex>\n </StyledOpenerButton>\n\n {status === 'error' && (\n <StyledFormFieldInfo status='error'>\n {hasProp(rhs, 'relativeDate')\n ? t('condition_builder_invalid_relative_date')\n : t('condition_builder_invalid_time_period')}\n </StyledFormFieldInfo>\n )}\n\n <Popover\n show={isOpen}\n ref={setPopoverEl}\n target={buttonRef.current}\n placement='bottom-start'\n style={{ width: '40ch' }}\n >\n <Flex container={{ pad: 1 }}>\n <TimePeriodMenu\n rhs={rhs}\n fieldType={fieldType}\n onChange={onChange}\n dateFunctionsList={dateFunctionsList}\n status={status}\n />\n </Flex>\n </Popover>\n </>\n );\n};\n\nexport default TimePeriodInput;\n"]}
@@ -0,0 +1,20 @@
1
+ import { FunctionComponent } from 'react';
2
+ import { BaseProps, ForwardProps, NoChildrenProp } from '@pega/cosmos-react-core';
3
+ import { RhsWithDateFunction, RhsWithRelativeDate } from '../ConditionBuilder.types';
4
+ import { DateFunction, FieldType } from '../core/types';
5
+ export interface TimePeriodMenuProps extends BaseProps, NoChildrenProp {
6
+ /** Rhs for the condition */
7
+ rhs: RhsWithDateFunction | RhsWithRelativeDate;
8
+ /** Callback for any modifications to the Rhs */
9
+ onChange: (rhs: RhsWithDateFunction | RhsWithRelativeDate) => void;
10
+ /** List of date functions enabled for the current LHS field type */
11
+ dateFunctionsList: DateFunction[];
12
+ /** FieldType of the LHS Field. Will only be DATE_TIME or DATE_ONLY */
13
+ fieldType: FieldType;
14
+ /** Used to indicate any errors on the control */
15
+ status?: 'error';
16
+ }
17
+ /** A menu with controls to select a Time period value on RHS */
18
+ declare const TimePeriodMenu: FunctionComponent<TimePeriodMenuProps & ForwardProps>;
19
+ export default TimePeriodMenu;
20
+ //# sourceMappingURL=TimePeriodMenu.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TimePeriodMenu.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/TimePeriodMenu.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAQ,YAAY,EAAW,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEjG,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACrF,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAKxD,MAAM,WAAW,mBAAoB,SAAQ,SAAS,EAAE,cAAc;IACpE,4BAA4B;IAC5B,GAAG,EAAE,mBAAmB,GAAG,mBAAmB,CAAC;IAE/C,gDAAgD;IAChD,QAAQ,EAAE,CAAC,GAAG,EAAE,mBAAmB,GAAG,mBAAmB,KAAK,IAAI,CAAC;IAEnE,oEAAoE;IACpE,iBAAiB,EAAE,YAAY,EAAE,CAAC;IAElC,sEAAsE;IACtE,SAAS,EAAE,SAAS,CAAC;IAErB,iDAAiD;IACjD,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,gEAAgE;AAChE,QAAA,MAAM,cAAc,EAAE,iBAAiB,CAAC,mBAAmB,GAAG,YAAY,CAmBzE,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Flex, hasProp } from '@pega/cosmos-react-core';
3
+ import DateFunctionMenu from './DateFunctionMenu';
4
+ import RelativeDateMenu from './RelativeDateMenu';
5
+ /** A menu with controls to select a Time period value on RHS */
6
+ const TimePeriodMenu = (props) => {
7
+ const { rhs, onChange, dateFunctionsList, status, fieldType } = props;
8
+ return (_jsxs(Flex, { container: { direction: 'column', rowGap: 0.5 }, item: { grow: 1 }, children: [hasProp(rhs, 'dateFunction') && (_jsx(DateFunctionMenu, { rhs: rhs, onChange: onChange, dateFunctionsList: dateFunctionsList, status: status }, void 0)), hasProp(rhs, 'relativeDate') && (_jsx(RelativeDateMenu, { rhs: rhs, fieldType: fieldType, onChange: onChange, status: status }, void 0))] }, void 0));
9
+ };
10
+ export default TimePeriodMenu;
11
+ //# sourceMappingURL=TimePeriodMenu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TimePeriodMenu.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/TimePeriodMenu.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAa,IAAI,EAAgB,OAAO,EAAkB,MAAM,yBAAyB,CAAC;AAKjG,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAClD,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAmBlD,gEAAgE;AAChE,MAAM,cAAc,GAA0D,CAC5E,KAA0B,EAC1B,EAAE;IACF,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;IACtE,OAAO,CACL,MAAC,IAAI,IAAC,SAAS,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,aACrE,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC,IAAI,CAC/B,KAAC,gBAAgB,IACf,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,QAAQ,EAClB,iBAAiB,EAAE,iBAAiB,EACpC,MAAM,EAAE,MAAM,WACd,CACH,EACA,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC,IAAI,CAC/B,KAAC,gBAAgB,IAAC,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,WAAI,CACzF,YACI,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["// cspell:ignore words DDTHH\nimport { FunctionComponent } from 'react';\n\nimport { BaseProps, Flex, ForwardProps, hasProp, NoChildrenProp } from '@pega/cosmos-react-core';\n\nimport { RhsWithDateFunction, RhsWithRelativeDate } from '../ConditionBuilder.types';\nimport { DateFunction, FieldType } from '../core/types';\n\nimport DateFunctionMenu from './DateFunctionMenu';\nimport RelativeDateMenu from './RelativeDateMenu';\n\nexport interface TimePeriodMenuProps extends BaseProps, NoChildrenProp {\n /** Rhs for the condition */\n rhs: RhsWithDateFunction | RhsWithRelativeDate;\n\n /** Callback for any modifications to the Rhs */\n onChange: (rhs: RhsWithDateFunction | RhsWithRelativeDate) => void;\n\n /** List of date functions enabled for the current LHS field type */\n dateFunctionsList: DateFunction[];\n\n /** FieldType of the LHS Field. Will only be DATE_TIME or DATE_ONLY */\n fieldType: FieldType;\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 TimePeriodMenu: FunctionComponent<TimePeriodMenuProps & ForwardProps> = (\n props: TimePeriodMenuProps\n) => {\n const { rhs, onChange, dateFunctionsList, status, fieldType } = props;\n return (\n <Flex container={{ direction: 'column', rowGap: 0.5 }} item={{ grow: 1 }}>\n {hasProp(rhs, 'dateFunction') && (\n <DateFunctionMenu\n rhs={rhs}\n onChange={onChange}\n dateFunctionsList={dateFunctionsList}\n status={status}\n />\n )}\n {hasProp(rhs, 'relativeDate') && (\n <RelativeDateMenu rhs={rhs} fieldType={fieldType} onChange={onChange} status={status} />\n )}\n </Flex>\n );\n};\n\nexport default TimePeriodMenu;\n"]}