@pega/cosmos-react-condition-builder 2.0.0-dev.9.2 → 2.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/ConditionBuilder/AtomicCondition.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/AtomicCondition.js +10 -16
- package/lib/components/ConditionBuilder/AtomicCondition.js.map +1 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.js +4 -12
- package/lib/components/ConditionBuilder/ConditionBuilder.js.map +1 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts +15 -4
- package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.types.js.map +1 -1
- package/lib/components/ConditionBuilder/FieldCondition.js +1 -2
- package/lib/components/ConditionBuilder/FieldCondition.js.map +1 -1
- package/lib/components/ConditionBuilder/HelpButton.js +1 -2
- package/lib/components/ConditionBuilder/HelpButton.js.map +1 -1
- package/lib/components/ConditionBuilder/{TimePeriodMenu.d.ts → RhsControls/DateFunctionMenu.d.ts} +7 -7
- package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/{TimePeriodMenu.js → RhsControls/DateFunctionMenu.js} +36 -14
- package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.js.map +1 -0
- package/lib/components/ConditionBuilder/{FieldSelector.d.ts → RhsControls/FieldSelector.d.ts} +3 -3
- package/lib/components/ConditionBuilder/RhsControls/FieldSelector.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/{FieldSelector.js → RhsControls/FieldSelector.js} +2 -3
- package/lib/components/ConditionBuilder/RhsControls/FieldSelector.js.map +1 -0
- package/lib/components/ConditionBuilder/{MultiValueSelector.d.ts → RhsControls/MultiValueSelector.d.ts} +2 -3
- package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.js +43 -0
- package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.js.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/NumericInput.d.ts +18 -0
- package/lib/components/ConditionBuilder/RhsControls/NumericInput.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/NumericInput.js +19 -0
- package/lib/components/ConditionBuilder/RhsControls/NumericInput.js.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.d.ts +18 -0
- package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.js +109 -0
- package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.js.map +1 -0
- package/lib/components/ConditionBuilder/{RhsModeSwitch.d.ts → RhsControls/RhsModeSwitch.d.ts} +4 -4
- package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/{RhsModeSwitch.js → RhsControls/RhsModeSwitch.js} +35 -13
- package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.js.map +1 -0
- package/lib/components/ConditionBuilder/{TimePeriodInput.d.ts → RhsControls/TimePeriodInput.d.ts} +1 -0
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.js +89 -0
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.js.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.d.ts +20 -0
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.js +11 -0
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.js.map +1 -0
- package/lib/components/ConditionBuilder/{RhsControls.d.ts → RhsControls/index.d.ts} +3 -3
- package/lib/components/ConditionBuilder/RhsControls/index.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/{RhsControls.js → RhsControls/index.js} +29 -35
- package/lib/components/ConditionBuilder/RhsControls/index.js.map +1 -0
- package/lib/components/ConditionBuilder/core/evaluator.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/evaluator.js +50 -12
- package/lib/components/ConditionBuilder/core/evaluator.js.map +1 -1
- package/lib/components/ConditionBuilder/core/extendDayJs.d.ts +2 -0
- package/lib/components/ConditionBuilder/core/extendDayJs.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/core/extendDayJs.js +4 -0
- package/lib/components/ConditionBuilder/core/extendDayJs.js.map +1 -0
- package/lib/components/ConditionBuilder/core/formatter.d.ts +5 -1
- package/lib/components/ConditionBuilder/core/formatter.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/formatter.js +42 -12
- package/lib/components/ConditionBuilder/core/formatter.js.map +1 -1
- package/lib/components/ConditionBuilder/core/transformer.d.ts +7 -0
- package/lib/components/ConditionBuilder/core/transformer.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/core/transformer.js +154 -0
- package/lib/components/ConditionBuilder/core/transformer.js.map +1 -0
- package/lib/components/ConditionBuilder/core/types.d.ts +6 -2
- package/lib/components/ConditionBuilder/core/types.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/types.js.map +1 -1
- package/lib/components/ConditionBuilder/core/utils.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/utils.js +4 -8
- package/lib/components/ConditionBuilder/core/utils.js.map +1 -1
- package/lib/components/ConditionBuilder/index.d.ts +2 -1
- package/lib/components/ConditionBuilder/index.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/index.js +2 -1
- package/lib/components/ConditionBuilder/index.js.map +1 -1
- package/package.json +15 -13
- package/lib/components/ConditionBuilder/FieldSelector.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/FieldSelector.js.map +0 -1
- package/lib/components/ConditionBuilder/MultiValueSelector.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/MultiValueSelector.js +0 -72
- package/lib/components/ConditionBuilder/MultiValueSelector.js.map +0 -1
- package/lib/components/ConditionBuilder/RhsControls.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/RhsControls.js.map +0 -1
- package/lib/components/ConditionBuilder/RhsModeSwitch.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/RhsModeSwitch.js.map +0 -1
- package/lib/components/ConditionBuilder/TimePeriodInput.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/TimePeriodInput.js +0 -72
- package/lib/components/ConditionBuilder/TimePeriodInput.js.map +0 -1
- package/lib/components/ConditionBuilder/TimePeriodMenu.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/TimePeriodMenu.js.map +0 -1
|
@@ -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,2CAA2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,EAC7B,IAAI,EAAE,IAAI,WACV,CACH,CAAC;KACH;IAED,OAAO,CACL,KAAC,UAAU,IACT,IAAI,EAAE,CAAC,CAAC,gCAAgC,CAAC,EACzC,IAAI,EAAC,MAAM,EACX,QAAQ,QACR,OAAO,EAAC,QAAQ,EAChB,IAAI,EAAE,IAAI,WACV,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { FunctionComponent, useMemo } from 'react';\n\nimport {\n BaseProps,\n ComboBox,\n ForwardProps,\n hasProp,\n MenuButton,\n menuHelpers,\n MenuProps,\n NoChildrenProp,\n TranslationPack,\n useI18n\n} from '@pega/cosmos-react-core';\nimport { TranslationFunction } from '@pega/cosmos-react-core/lib/i18n/translate';\nimport { Selected } from '@pega/cosmos-react-core/lib/components/ComboBox/ComboBox.types';\n\nimport { Comparator, FieldType, RHSType } from '../core/types';\nimport { DateFunctionsByType, LeafCondition } from '../ConditionBuilder.types';\n\nenum ItemID {\n LITERAL_VALUE = 'LITERAL_VALUE',\n DATE_PART = 'DATE_PART',\n RELATIVE_DATE = 'RELATIVE_DATE',\n ANOTHER_FIELD = 'ANOTHER_FIELD'\n}\n\n// Label for the `Enter <value>` option on the gear-menu\nfunction getValueOptionLabel(\n fieldType: FieldType,\n t: TranslationFunction<TranslationPack>\n): string {\n switch (fieldType) {\n case 'TEXT':\n return t('condition_builder_compare_with_text_value');\n case 'NUMBER':\n return t('condition_builder_compare_with_numeric_value');\n case 'DATE_TIME':\n case 'DATE_ONLY':\n return t('condition_builder_compare_with_date_value');\n case 'TIME_ONLY':\n return t('condition_builder_compare_with_time_value');\n default:\n return t('condition_builder_value_label'); // Not needed (BOOLEAN is not expected to be passed to the function)\n }\n}\n\ninterface RhsMenuButtonProps extends BaseProps, NoChildrenProp {\n /** Type of field on the LHS */\n fieldType: FieldType;\n\n /** Comparator for the condition */\n comparator: Comparator;\n\n /** Rhs for the condition */\n rhs: LeafCondition['rhs'];\n\n /** Callback for any modifications to the Rhs */\n onChange: (rhs: LeafCondition['rhs']) => void;\n\n /** Display mode */\n mode: 'combo-box' | 'menu-button';\n\n /** Restricts RHS values to only specified RHS types */\n validRhsTypes: Set<RHSType>;\n\n /** Passed to enable additional date controls on the RHS, when a DATE_TIME/DATE_ONLY field is selected on the LHS */\n dateFunctions?: DateFunctionsByType;\n}\n\n/** Renders a Gear MenuButton on the RHS (when applicable) */\nconst RhsModeSwitch: FunctionComponent<RhsMenuButtonProps & ForwardProps> = (\n props: RhsMenuButtonProps\n) => {\n const { fieldType, comparator, rhs, onChange, mode, validRhsTypes, dateFunctions } = props;\n const t = useI18n();\n\n // Identify current mode\n const currentMode = useMemo(() => {\n // rhs should already be defined if this component is being rendered. Indicating the same to TS using `!`\n if (hasProp(rhs!, 'field')) return ItemID.ANOTHER_FIELD;\n if (hasProp(rhs!, 'value') && hasProp(rhs!, 'dateFunction')) return ItemID.DATE_PART;\n if (hasProp(rhs!, 'relativeDate')) return ItemID.RELATIVE_DATE;\n return ItemID.LITERAL_VALUE;\n }, [rhs]);\n\n // Determine actions for the menu\n const menu = useMemo<MenuProps>(() => {\n const items: MenuProps['items'] = [];\n\n // Boolean conditions either don't use an rhs or always use the field-selector\n // For IN/NOT_IN comparators, only one mode is possible for a given case - CSV Input or a Value-selector\n if (fieldType !== 'BOOLEAN' && !['IN', 'NOT_IN'].includes(comparator)) {\n // Literal value input\n if (validRhsTypes.has('LITERAL')) {\n // Literal Value inputs\n items.push({\n id: ItemID.LITERAL_VALUE,\n primary: getValueOptionLabel(fieldType, t),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({ value: '' }); // Submit a new RHS to re-render with the new mode\n }\n });\n }\n\n // Field selector\n if (validRhsTypes.has('FIELD')) {\n items.push({\n id: ItemID.ANOTHER_FIELD,\n primary: t('condition_builder_compare_with_another_field'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({ field: '' }); // Submit a new RHS to re-render with the new mode\n }\n });\n }\n\n // Relative Date value input\n if (\n validRhsTypes.has('RELATIVE_DATE') &&\n (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY')\n ) {\n items.push({\n id: ItemID.RELATIVE_DATE,\n primary: t('condition_builder_compare_with_relative_date'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({\n relativeDate: {\n timePeriod: 'CURRENT',\n datePart: 'DAYS'\n }\n });\n }\n });\n }\n\n // Date Part value input\n if (\n validRhsTypes.has('DATE_FUNCTION') &&\n dateFunctions &&\n (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY')\n ) {\n items.push({\n id: ItemID.DATE_PART,\n primary: t('condition_builder_date_part'),\n onClick: id => {\n if (id === currentMode) return; // Ignore if already in that mode\n onChange({ value: '', dateFunction: dateFunctions[fieldType][0] }); // Submit a new RHS to re-render with the new mode. Initializing with the first available date function\n }\n });\n }\n }\n\n return { items, mode: 'action' };\n }, [fieldType, comparator, onChange, validRhsTypes, dateFunctions, currentMode, t]);\n\n // Identify current selection for ComboBox\n const selected = useMemo<Selected | undefined>(() => {\n const selectedItem = menuHelpers.getItem(menu.items, currentMode);\n return selectedItem ? { id: selectedItem.id, text: selectedItem.primary } : undefined;\n }, [menu, currentMode]);\n\n // Render the button only when there are multiple options in the menu\n if (menu.items.length < 2) return null;\n\n if (mode === 'combo-box') {\n return (\n <ComboBox\n label={t('condition_builder_compare_with')}\n labelHidden\n mode='single-select'\n selected={{ items: selected }}\n menu={menu}\n />\n );\n }\n\n return (\n <MenuButton\n text={t('condition_builder_compare_with')}\n icon='gear'\n iconOnly\n variant='simple'\n menu={menu}\n />\n );\n};\n\nexport default RhsModeSwitch;\n"]}
|
package/lib/components/ConditionBuilder/{TimePeriodInput.d.ts → RhsControls/TimePeriodInput.d.ts}
RENAMED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FunctionComponent } from 'react';
|
|
2
2
|
import { ForwardProps } from '@pega/cosmos-react-core';
|
|
3
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>;
|
|
4
5
|
/** Renders a button that opens up TimePeriodMenu in a Popover */
|
|
5
6
|
declare const TimePeriodInput: FunctionComponent<TimePeriodMenuProps & ForwardProps>;
|
|
6
7
|
export default TimePeriodInput;
|
|
@@ -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,EACJ,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,OAAO,EACP,OAAO,EACP,MAAM,EACN,gBAAgB,EACjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,4DAA4D,CAAC;AACjG,OAAO,eAEN,MAAM,iEAAiE,CAAC;AAGzE,OAAO,EAAE,kBAAkB,EAAE,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AE,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"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FunctionComponent } from 'react';
|
|
2
2
|
import { BaseProps, ForwardProps } from '@pega/cosmos-react-core';
|
|
3
|
-
import { FieldType, Comparator, RHSType } from '
|
|
4
|
-
import { LeafCondition, Field, DateFunctionsByType } from '
|
|
3
|
+
import { FieldType, Comparator, RHSType } from '../core/types';
|
|
4
|
+
import { LeafCondition, Field, DateFunctionsByType } from '../ConditionBuilder.types';
|
|
5
5
|
/**
|
|
6
6
|
* Verifies if the condition has all valid values.
|
|
7
7
|
* NOTES:
|
|
@@ -36,4 +36,4 @@ interface RhsControlProps extends BaseProps {
|
|
|
36
36
|
/** A controlled component for controls on a Condition's RHS */
|
|
37
37
|
declare const RhsControls: FunctionComponent<RhsControlProps & ForwardProps>;
|
|
38
38
|
export default RhsControls;
|
|
39
|
-
//# sourceMappingURL=
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA6C,MAAM,OAAO,CAAC;AAErF,OAAO,EAQL,SAAS,EACT,YAAY,EACb,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAUtF;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,EACzB,SAAS,CAAC,EAAE,SAAS,EACrB,UAAU,GAAE,OAAe,GAC1B,OAAO,CA2DT;AAED,wHAAwH;AACxH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,GAAG,CAAC,OAAO,CAAC,EAC3B,aAAa,CAAC,EAAE,mBAAmB,GAClC,aAAa,CAAC,KAAK,CAAC,CAyCtB;AAqBD,yDAAyD;AACzD,UAAU,eAAgB,SAAQ,SAAS;IACzC,4BAA4B;IAC5B,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;IAE1B,mCAAmC;IACnC,UAAU,EAAE,UAAU,CAAC;IAEvB,4BAA4B;IAC5B,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;IAE1B,4EAA4E;IAC5E,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB,gDAAgD;IAChD,QAAQ,EAAE,CAAC,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;IAE9C,+DAA+D;IAC/D,cAAc,EAAE,OAAO,CAAC;IAExB,0BAA0B;IAC1B,aAAa,EAAE,KAAK,GAAG,QAAQ,CAAC;IAEhC,uDAAuD;IACvD,aAAa,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAE5B,oHAAoH;IACpH,aAAa,CAAC,EAAE,mBAAmB,CAAC;CACrC;AAED,+DAA+D;AAC/D,QAAA,MAAM,WAAW,EAAE,iBAAiB,CAAC,eAAe,GAAG,YAAY,CAuQlE,CAAC;AACF,eAAe,WAAW,CAAC"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useState, useEffect, useMemo } from 'react';
|
|
3
3
|
import { DateInput, DateTimeInput, Flex, Input, Select, Option, hasProp } from '@pega/cosmos-react-core';
|
|
4
|
+
import { convertTimeValueToMs, convertMsToTimeValue } from '../core/time-utils';
|
|
4
5
|
import MultiValueSelector from './MultiValueSelector';
|
|
5
6
|
import FieldSelector from './FieldSelector';
|
|
6
7
|
import RhsModeSwitch from './RhsModeSwitch';
|
|
7
|
-
import { convertTimeValueToMs, convertMsToTimeValue } from './core/time-utils';
|
|
8
8
|
import TimePeriodInput from './TimePeriodInput';
|
|
9
9
|
import TimePeriodMenu from './TimePeriodMenu';
|
|
10
|
+
import NumericInput from './NumericInput';
|
|
10
11
|
/**
|
|
11
12
|
* Verifies if the condition has all valid values.
|
|
12
13
|
* NOTES:
|
|
@@ -31,14 +32,12 @@ export function isValidRhs(rhs, fieldType, trimValues = false) {
|
|
|
31
32
|
return false;
|
|
32
33
|
}
|
|
33
34
|
// For numeric fields, RHS is invalid if any NaN values are present in the list
|
|
34
|
-
if (fieldType === 'NUMBER') {
|
|
35
|
-
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
35
|
+
if (fieldType === 'NUMBER' && rhs.values.some(v => Number.isNaN(v))) {
|
|
36
|
+
return false;
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
39
|
if (hasProp(rhs, 'value')) {
|
|
41
|
-
// Identify any invalid numbers (
|
|
40
|
+
// Identify any invalid numbers (e.g. when `-` is entered)
|
|
42
41
|
if (typeof rhs.value === 'number') {
|
|
43
42
|
return !Number.isNaN(rhs.value);
|
|
44
43
|
}
|
|
@@ -51,12 +50,17 @@ export function isValidRhs(rhs, fieldType, trimValues = false) {
|
|
|
51
50
|
return false;
|
|
52
51
|
}
|
|
53
52
|
// This check is needed to eliminate invalid dates like `Feb 31` (02/31/2020), which the input allows
|
|
54
|
-
if (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY')
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
53
|
+
if ((fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY') &&
|
|
54
|
+
Number.isNaN(new Date(rhs.value).getTime())) {
|
|
55
|
+
return false;
|
|
58
56
|
}
|
|
59
57
|
}
|
|
58
|
+
if (hasProp(rhs, 'relativeDate') &&
|
|
59
|
+
((rhs.relativeDate.timePeriod === 'CURRENT' && rhs.relativeDate.interval) ||
|
|
60
|
+
(rhs.relativeDate.timePeriod !== 'CURRENT' &&
|
|
61
|
+
(!rhs.relativeDate.interval || rhs.relativeDate.interval <= 0)))) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
60
64
|
return true;
|
|
61
65
|
}
|
|
62
66
|
/** For a condition with the given comparator and lhs-field-type, determines an appropriate default value for the Rhs */
|
|
@@ -81,6 +85,15 @@ export function getDefaultRhs(fieldType, comparator, validRhsTypes, dateFunction
|
|
|
81
85
|
dateFunctions &&
|
|
82
86
|
(fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY'))
|
|
83
87
|
return { value: '', dateFunction: dateFunctions[fieldType][0] };
|
|
88
|
+
if (validRhsTypes.has('RELATIVE_DATE') &&
|
|
89
|
+
(fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY')) {
|
|
90
|
+
return {
|
|
91
|
+
relativeDate: {
|
|
92
|
+
timePeriod: 'CURRENT',
|
|
93
|
+
datePart: 'DAYS'
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
84
97
|
return { field: '' };
|
|
85
98
|
}
|
|
86
99
|
}
|
|
@@ -159,13 +172,7 @@ const RhsControls = (props) => {
|
|
|
159
172
|
// Handle changes from a Value-input
|
|
160
173
|
const handleValueChange = (e) => {
|
|
161
174
|
// NOTE: Not trimming the value here so that users can freely type spaces between words. Trimming is done on Submit, via the isValidRhs call
|
|
162
|
-
|
|
163
|
-
if (fieldType === 'NUMBER' && newValue !== '') {
|
|
164
|
-
// Save as a number unless it is an empty string
|
|
165
|
-
// If empty strings aren't allowed, users wont be able to clear a value to type something else
|
|
166
|
-
newValue = Number(newValue);
|
|
167
|
-
}
|
|
168
|
-
onChange({ value: newValue }); // Submit a new RHS
|
|
175
|
+
onChange({ value: e.target.value }); // Submit a new RHS
|
|
169
176
|
};
|
|
170
177
|
// Handle changes from a Time-input
|
|
171
178
|
const handleTimeValueChange = (e) => {
|
|
@@ -199,27 +206,14 @@ const RhsControls = (props) => {
|
|
|
199
206
|
};
|
|
200
207
|
// Render the menu directly if in a vertical layout
|
|
201
208
|
const TimePeriodComp = itemDirection === 'column' ? TimePeriodMenu : TimePeriodInput;
|
|
202
|
-
return (_jsxs(Flex,
|
|
209
|
+
return (_jsxs(Flex, { container: {
|
|
203
210
|
direction: itemDirection,
|
|
204
211
|
alignItems: itemDirection === 'column' ? 'stretch' : 'start',
|
|
205
212
|
justify: 'between',
|
|
206
213
|
gap: 0.5
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
possibleValues.map(value => (_jsx(Option, Object.assign({ value: value }, { children: value }), value)))] }), void 0)),
|
|
211
|
-
fieldType === 'TEXT' && !useValueSelector && (_jsx(Input, { value: rhs.value, onChange: handleValueChange, status: showError ? 'error' : undefined, info: showError ? 'Empty value' : undefined, name: 'rhs-text-literal-input', label: '-', labelHidden: true }, void 0)),
|
|
212
|
-
fieldType === 'NUMBER' && (
|
|
213
|
-
// NOTE: If `as string` is used instead of `.toString()`, users won't be able to enter the value `0`
|
|
214
|
-
_jsx(Input, { type: 'number', value: rhs.value.toString(), onChange: handleValueChange, status: showError ? 'error' : undefined, info: showError ? 'Invalid number' : undefined, label: '-', labelHidden: true }, void 0)),
|
|
215
|
-
fieldType === 'TIME_ONLY' && (_jsx(Input, { type: 'time', step: '1', value: typeof rhs.value === 'string' ? rhs.value : convertMsToTimeValue(rhs.value), onChange: handleTimeValueChange, status: showError ? 'error' : undefined, info: showError ? 'Invalid time' : undefined, label: '-', labelHidden: true }, void 0)),
|
|
216
|
-
fieldType === 'DATE_ONLY' && !hasProp(rhs, 'dateFunction') && (_jsx(DateInput, { value: rhs.value, onBlur: handleDateValueChange, status: showError ? 'error' : undefined, info: showError ? 'Invalid date' : '', label: '-', labelHidden: true }, void 0)),
|
|
217
|
-
fieldType === 'DATE_TIME' && !hasProp(rhs, 'dateFunction') && (_jsx(DateTimeInput, { value: rhs.value !== '' ? rhs.value : undefined, onBlur: handleDateValueChange, status: showError ? 'error' : undefined, info: showError ? 'Invalid date' : '', label: '-', labelHidden: true }, void 0)),
|
|
218
|
-
(fieldType === 'DATE_ONLY' || fieldType === 'DATE_TIME') &&
|
|
219
|
-
hasProp(rhs, 'dateFunction') && (_jsx(TimePeriodComp, { rhs: rhs, onChange: onChange, dateFunctionsList: dateFunctions[fieldType], status: showError ? 'error' : undefined }, void 0))] }), void 0)),
|
|
220
|
-
hasProp(rhs, 'values') && (_jsxs(Flex, Object.assign({ item: { grow: 1 } }, { children: [useValueSelector && (_jsx(MultiValueSelector, { values: rhs.values, options: possibleValues, onChange: handleValueSelection, status: showError ? 'error' : undefined }, void 0)),
|
|
221
|
-
!useValueSelector && (_jsx(Input, { value: csvInput, onChange: handleCSVChange, status: showError ? 'error' : undefined, info: showError ? 'Invalid values' : undefined, label: '-', labelHidden: true, placeholder: 'Enter comma separated values' // FIXME: TR
|
|
222
|
-
}, void 0))] }), void 0))] }), void 0));
|
|
214
|
+
}, children: [_jsx(RhsModeSwitch, { fieldType: fieldType, comparator: comparator, rhs: rhs, onChange: onChange, mode: itemDirection === 'column' ? 'combo-box' : 'menu-button', validRhsTypes: validRhsTypes, dateFunctions: dateFunctions }, void 0), hasProp(rhs, 'field') && (_jsx(Flex, { item: { grow: 1 }, children: _jsx(FieldSelector, { value: rhs.field, onChange: handleFieldChange, fields: fieldOptions, status: showError ? 'error' : undefined, info: showError ? 'No selection' : undefined }, void 0) }, void 0)), hasProp(rhs, 'value') && !hasProp(rhs, 'dateFunction') && (_jsxs(Flex, { item: { grow: 1 }, children: [fieldType === 'TEXT' && useValueSelector && (_jsxs(Select, { value: rhs.value, onChange: (e) => handleValueSelection(e.target.value), status: showError ? 'error' : undefined, info: showError ? 'No selection' : undefined, label: '-', labelHidden: true, children: [_jsx(Option, { value: '', children: "Select value" }, void 0), possibleValues.map(value => (_jsx(Option, { value: value, children: value }, value)))] }, void 0)), fieldType === 'TEXT' && !useValueSelector && (_jsx(Input, { value: rhs.value, onChange: handleValueChange, status: showError ? 'error' : undefined, info: showError ? 'Empty value' : undefined, name: 'rhs-text-literal-input', label: '-', labelHidden: true }, void 0)), fieldType === 'NUMBER' && (_jsx(NumericInput, { rhs: rhs, onChange: onChange, status: showError ? 'error' : undefined }, void 0)), fieldType === 'TIME_ONLY' && (_jsx(Input, { type: 'time', step: '1', value: typeof rhs.value === 'string' ? rhs.value : convertMsToTimeValue(rhs.value), onChange: handleTimeValueChange, status: showError ? 'error' : undefined, info: showError ? 'Invalid time' : undefined, label: '-', labelHidden: true }, void 0)), fieldType === 'DATE_ONLY' && (_jsx(DateInput, { value: rhs.value, onChange: handleDateValueChange, status: showError ? 'error' : undefined, info: showError ? 'Invalid date' : '', label: '-', labelHidden: true }, void 0)), fieldType === 'DATE_TIME' && (_jsx(DateTimeInput, { value: rhs.value !== '' ? rhs.value : undefined, onChange: handleDateValueChange, status: showError ? 'error' : undefined, info: showError ? 'Invalid date' : '', label: '-', labelHidden: true }, void 0))] }, void 0)), (fieldType === 'DATE_ONLY' || fieldType === 'DATE_TIME') &&
|
|
215
|
+
(hasProp(rhs, 'relativeDate') || hasProp(rhs, 'dateFunction')) && (_jsx(Flex, { item: { grow: 1 }, children: _jsx(TimePeriodComp, { rhs: rhs, fieldType: fieldType, onChange: onChange, dateFunctionsList: dateFunctions ? dateFunctions[fieldType] : [], status: showError ? 'error' : undefined }, void 0) }, void 0)), hasProp(rhs, 'values') && (_jsxs(Flex, { item: { grow: 1 }, children: [useValueSelector && (_jsx(MultiValueSelector, { values: rhs.values, options: possibleValues, onChange: handleValueSelection, status: showError ? 'error' : undefined }, void 0)), !useValueSelector && (_jsx(Input, { value: csvInput, onChange: handleCSVChange, status: showError ? 'error' : undefined, info: showError ? 'Invalid values' : undefined, label: '-', labelHidden: true, placeholder: 'Enter comma separated values' // FIXME: TR
|
|
216
|
+
}, void 0))] }, void 0))] }, void 0));
|
|
223
217
|
};
|
|
224
218
|
export default RhsControls;
|
|
225
|
-
//# sourceMappingURL=
|
|
219
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAkC,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAErF,OAAO,EACL,SAAS,EACT,aAAa,EACb,IAAI,EACJ,KAAK,EACL,MAAM,EACN,MAAM,EACN,OAAO,EAGR,MAAM,yBAAyB,CAAC;AAKjC,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAEhF,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AACtD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AAE,eAAe,EACzB,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EACvC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS,EAC9C,KAAK,EAAC,GAAG,EACT,WAAW,QACX,WAAW,EAAC,8BAA8B,CAAC,YAAY;+BACvD,CACH,YACI,CACR,YACI,CACR,CAAC;AACJ,CAAC,CAAC;AACF,eAAe,WAAW,CAAC","sourcesContent":["import { FunctionComponent, ChangeEvent, useState, useEffect, useMemo } from 'react';\n\nimport {\n DateInput,\n DateTimeInput,\n Flex,\n Input,\n Select,\n Option,\n hasProp,\n BaseProps,\n ForwardProps\n} from '@pega/cosmos-react-core';\nimport type { DateTimeCallbackParameter } from '@pega/cosmos-react-core/lib/components/DateTime/DateTime.types';\n\nimport { FieldType, Comparator, RHSType } from '../core/types';\nimport { LeafCondition, Field, DateFunctionsByType } from '../ConditionBuilder.types';\nimport { convertTimeValueToMs, convertMsToTimeValue } from '../core/time-utils';\n\nimport MultiValueSelector from './MultiValueSelector';\nimport FieldSelector from './FieldSelector';\nimport RhsModeSwitch from './RhsModeSwitch';\nimport TimePeriodInput from './TimePeriodInput';\nimport TimePeriodMenu from './TimePeriodMenu';\nimport NumericInput from './NumericInput';\n\n/**\n * Verifies if the condition has all valid values.\n * NOTES:\n * - This is intended to be used only on conditions emitted by the components in this package.\n * - If a condition is manually constructed outside these components, this utility could miss some malformed conditions.\n * - Also, this does not try to validate if the given `rhs` matches the `lhs`/`comparator`/`validRhsTypes`. Instead, it assumes that the appropriate LHS/Comparator/validRhsTypes must have been already in place for this rhs to be generated.\n */\nexport function isValidRhs(\n rhs: LeafCondition['rhs'],\n fieldType?: FieldType,\n trimValues: boolean = false\n): boolean {\n // RHS would be `undefined` when no RHS is needed. Treat it as a valid value\n if (rhs === undefined) {\n return true;\n }\n\n // Field-selector on the RHS\n if (hasProp(rhs, 'field')) {\n // RHS is invalid if no field is selected\n return rhs.field !== '';\n }\n\n // List-input cases\n if (hasProp(rhs, 'values')) {\n // RHS is invalid if the list is empty\n if (rhs.values.length === 0) {\n return false;\n }\n // For numeric fields, RHS is invalid if any NaN values are present in the list\n if (fieldType === 'NUMBER' && (rhs.values as number[]).some(v => Number.isNaN(v))) {\n return false;\n }\n }\n\n if (hasProp(rhs, 'value')) {\n // Identify any invalid numbers (e.g. when `-` is entered)\n if (typeof rhs.value === 'number') {\n return !Number.isNaN(rhs.value);\n }\n\n // NOTE: Not trimming the value in the change-handler so that users can freely type spaces between words\n if (trimValues) {\n rhs.value = rhs.value.trim();\n }\n\n // Can be empty on init and on clearing the value\n if (rhs.value.trim() === '') {\n return false;\n }\n\n // This check is needed to eliminate invalid dates like `Feb 31` (02/31/2020), which the input allows\n if (\n (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY') &&\n Number.isNaN(new Date(rhs.value).getTime())\n ) {\n return false;\n }\n }\n\n if (\n hasProp(rhs, 'relativeDate') &&\n ((rhs.relativeDate.timePeriod === 'CURRENT' && rhs.relativeDate.interval) ||\n (rhs.relativeDate.timePeriod !== 'CURRENT' &&\n (!rhs.relativeDate.interval || rhs.relativeDate.interval <= 0)))\n ) {\n return false;\n }\n\n return true;\n}\n\n/** For a condition with the given comparator and lhs-field-type, determines an appropriate default value for the Rhs */\nexport function getDefaultRhs(\n fieldType: FieldType,\n comparator: Comparator,\n validRhsTypes: Set<RHSType>,\n dateFunctions?: DateFunctionsByType\n): LeafCondition['rhs'] {\n switch (comparator) {\n case 'IS_TRUE':\n case 'IS_FALSE':\n case 'IS_NULL':\n case 'IS_NOT_NULL':\n return undefined; // These comparators do not have an Rhs\n\n case 'IN':\n case 'NOT_IN':\n return { values: [] };\n\n default: {\n if (fieldType === 'BOOLEAN' && (comparator === 'EQ' || comparator === 'NEQ')) {\n // For booleans, these comparators can only be used for comparing with other fields\n return { field: '' };\n }\n\n if (validRhsTypes.has('LITERAL')) return { value: '' };\n if (\n validRhsTypes.has('DATE_FUNCTION') &&\n dateFunctions &&\n (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY')\n )\n return { value: '', dateFunction: dateFunctions[fieldType][0] };\n\n if (\n validRhsTypes.has('RELATIVE_DATE') &&\n (fieldType === 'DATE_TIME' || fieldType === 'DATE_ONLY')\n ) {\n return {\n relativeDate: {\n timePeriod: 'CURRENT',\n datePart: 'DAYS'\n }\n };\n }\n\n return { field: '' };\n }\n }\n}\n\n// Truncates output values from DateInput/DateTimeInput to return a wall time on the RHS\n// NOTE: This assumes that the input date is set up on the UTC timezone\nfunction truncateISODateString(dateString: string, fieldType: FieldType): string {\n const date = new Date(dateString);\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\n // For DATE_ONLY fields, returning a YYYY-MM-DD format as per spec\n if (fieldType === 'DATE_ONLY') return `${YYYY}-${MM}-${DD}`;\n\n const hh = date.getUTCHours().toString().padStart(2, '0');\n const mm = date.getUTCMinutes().toString().padStart(2, '0');\n\n // cspell:disable-next-line\n // For DATE_TIME fields, returning a YYYY-MM-DDTHH:mm format and discarding the time-zone etc. to be consistent with the previous spec which was returning a wall time\n return `${YYYY}-${MM}-${DD}T${hh}:${mm}`;\n}\n\n/** Type definition for the input props of RhsControls */\ninterface RhsControlProps extends BaseProps {\n /** Lhs for the condition */\n lhs: LeafCondition['lhs'];\n\n /** Comparator for the condition */\n comparator: Comparator;\n\n /** Rhs for the condition */\n rhs: LeafCondition['rhs'];\n\n /** Metadata (data-model) for the Fields to use in the RHS field-selector */\n fields: Field[];\n\n /** Callback for any modifications to the Rhs */\n onChange: (rhs: LeafCondition['rhs']) => void;\n\n /** Used to enable inline error indicators on invalid inputs */\n indicateErrors: boolean;\n\n /** Item flow direction */\n itemDirection: 'row' | 'column';\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/** A controlled component for controls on a Condition's RHS */\nconst RhsControls: FunctionComponent<RhsControlProps & ForwardProps> = (props: RhsControlProps) => {\n const {\n lhs,\n comparator,\n rhs,\n fields,\n onChange,\n indicateErrors,\n itemDirection,\n validRhsTypes,\n dateFunctions\n } = props;\n\n // Find the field corresponding to the LHS\n const matchingField = fields.find(f => f.name === lhs.field);\n\n // Options for the Field-selector (if applicable)\n const fieldOptions = useMemo(() => {\n if (!matchingField) return [];\n // Show all other fields of the same data type as the LHS\n return fields.filter(f => f.type === matchingField.type && f.name !== lhs.field);\n }, [fields, lhs]);\n\n // Set up a CSV input for IN/NOT_IN comparators\n const [csvInput, setCsvInput] = useState(\n rhs && hasProp(rhs, 'values') ? rhs.values.join(', ') : ''\n );\n useEffect(() => {\n // If moving away from the CSV-mode, clear the CSV Input.\n // This ensures that if a different `rhs.values` is passed (a new empty array can be passed when an applicable comparator is selected), the local state matches the new input.\n if (csvInput && (!rhs || !hasProp(rhs, 'values'))) {\n setCsvInput('');\n }\n }, [rhs]);\n\n // If a field is not selected or if the comparator doesn't need any RHS, don't render anything\n if (rhs === undefined) {\n return <div />; // Rendering a placeholder div to keep the layout consistent\n }\n\n if (matchingField === undefined) {\n // For safety against any rare cases where the LHS from an input condition is not present in the input fields to the ConditionBuilder\n // In those cases, don't render an RHS and wait for a valid value to be picked on LHS\n return <div />; // Rendering a placeholder div to keep the layout consistent\n }\n const fieldType = matchingField.type;\n\n // If errors should be indicated inline, validate the current rhs\n let showError = false;\n if (indicateErrors) {\n showError = !isValidRhs(rhs, fieldType, false);\n }\n\n // Set up Value-selector (if applicable)\n const { possibleValues } = matchingField; // These are passed when possible values are known ahead of time\n const isValueSelectorPossible =\n fieldType === 'TEXT' &&\n possibleValues !== undefined &&\n ['EQ', 'NEQ', 'IN', 'NOT_IN'].includes(comparator); // A ValueSelector in single/multiple mode is possible when these criteria are met\n const useValueSelector = isValueSelectorPossible && !hasProp(rhs, 'field'); // Use the ValueSelector component if it is applicable and if not in ANOTHER_FIELD mode\n\n // Handle changes from the Value-selector\n const handleValueSelection = (selection: string | string[]) => {\n if (typeof selection === 'string') {\n onChange({ value: selection }); // Submit a new RHS\n } else {\n onChange({ values: selection }); // Submit a new RHS\n }\n };\n\n // Handle changes from the Field-selector\n const handleFieldChange = (id: string) => {\n onChange({ field: id }); // Submit a new RHS\n };\n\n // Handle changes from a Value-input\n const handleValueChange = (e: ChangeEvent<HTMLInputElement>) => {\n // NOTE: Not trimming the value here so that users can freely type spaces between words. Trimming is done on Submit, via the isValidRhs call\n onChange({ value: e.target.value }); // Submit a new RHS\n };\n\n // Handle changes from a Time-input\n const handleTimeValueChange = (e: ChangeEvent<HTMLInputElement>) => {\n let newValue = e.target.value;\n if (newValue.length === 5) {\n newValue += ':00'; // Enforce a fixed hh:mm:ss format\n }\n onChange({ value: convertTimeValueToMs(newValue) }); // Submit a new RHS\n };\n\n // Handle changes from a DateInput\n const handleDateValueChange = ({\n valueAsISOString,\n valueAsTimestamp,\n state\n }: DateTimeCallbackParameter) => {\n // NOTE: Not relying fully on `state` since in some cases state and valueAsTimestamp as both undefined\n if (valueAsTimestamp === undefined || state === 'incomplete' || state === 'invalid') return;\n\n const truncatedValue = truncateISODateString(valueAsISOString, fieldType); // Truncate to return a wall time as per spec\n onChange({ value: truncatedValue });\n };\n\n // Handle changes from a CSV-input\n const handleCSVChange = (e: ChangeEvent<HTMLInputElement>) => {\n // Update the controlled input\n setCsvInput(e.target.value);\n\n // Submit a new RHS\n let newValues: string[] | number[] = e.target.value\n .split(',')\n .map(v => v.trim())\n .filter(v => v.length > 0); // Ignore empty strings\n if (fieldType === 'NUMBER') {\n newValues = newValues.map(v => Number(v)); // This can set up some NaN values. Those are used to show an appropriate feedback when the submit button is hit\n }\n onChange({ values: newValues });\n };\n\n // Render the menu directly if in a vertical layout\n const TimePeriodComp = itemDirection === 'column' ? TimePeriodMenu : TimePeriodInput;\n\n return (\n <Flex\n container={{\n direction: itemDirection,\n alignItems: itemDirection === 'column' ? 'stretch' : 'start',\n justify: 'between',\n gap: 0.5\n }}\n >\n {/* Gear MenuButton */}\n <RhsModeSwitch\n fieldType={fieldType}\n comparator={comparator}\n rhs={rhs}\n onChange={onChange}\n mode={itemDirection === 'column' ? 'combo-box' : 'menu-button'}\n validRhsTypes={validRhsTypes}\n dateFunctions={dateFunctions}\n />\n\n {/* Field-selector */}\n {hasProp(rhs, 'field') && (\n <Flex item={{ grow: 1 }}>\n <FieldSelector\n value={rhs.field}\n onChange={handleFieldChange}\n fields={fieldOptions}\n status={showError ? 'error' : undefined}\n info={showError ? 'No selection' : undefined} // FIXME: TR\n />\n </Flex>\n )}\n\n {/* Value input */}\n {hasProp(rhs, 'value') && !hasProp(rhs, 'dateFunction') && (\n <Flex item={{ grow: 1 }}>\n {fieldType === 'TEXT' && useValueSelector && (\n <Select\n value={rhs.value as string}\n onChange={(e: ChangeEvent<HTMLSelectElement>) => handleValueSelection(e.target.value)}\n status={showError ? 'error' : undefined}\n info={showError ? 'No selection' : undefined} // FIXME: TR\n label='-'\n labelHidden\n >\n <Option value=''>Select value</Option>\n {possibleValues!.map(value => (\n <Option key={value} value={value}>\n {value}\n </Option>\n ))}\n </Select>\n )}\n {fieldType === 'TEXT' && !useValueSelector && (\n <Input\n value={rhs.value as string}\n onChange={handleValueChange}\n status={showError ? 'error' : undefined}\n info={showError ? 'Empty value' : undefined} // FIXME: TR\n name='rhs-text-literal-input'\n label='-'\n labelHidden\n />\n )}\n {fieldType === 'NUMBER' && (\n <NumericInput rhs={rhs} onChange={onChange} status={showError ? 'error' : undefined} />\n )}\n {fieldType === 'TIME_ONLY' && (\n <Input\n type='time'\n step='1'\n value={typeof rhs.value === 'string' ? rhs.value : convertMsToTimeValue(rhs.value)}\n onChange={handleTimeValueChange}\n status={showError ? 'error' : undefined}\n info={showError ? 'Invalid time' : undefined} // FIXME: TR\n label='-'\n labelHidden\n />\n )}\n {fieldType === 'DATE_ONLY' && (\n <DateInput\n value={rhs.value}\n onChange={handleDateValueChange}\n status={showError ? 'error' : undefined}\n info={showError ? 'Invalid date' : ''} // FIXME: TR , NOTE: Using empty quotes to disable the default info which indicates the format\n label='-'\n labelHidden\n />\n )}\n {fieldType === 'DATE_TIME' && (\n <DateTimeInput\n value={rhs.value !== '' ? rhs.value : undefined}\n onChange={handleDateValueChange}\n status={showError ? 'error' : undefined}\n info={showError ? 'Invalid date' : ''} // FIXME: TR , NOTE: Using empty quotes to disable the default info which indicates the format\n label='-'\n labelHidden\n />\n )}\n </Flex>\n )}\n\n {(fieldType === 'DATE_ONLY' || fieldType === 'DATE_TIME') &&\n (hasProp(rhs, 'relativeDate') || hasProp(rhs, 'dateFunction')) && (\n <Flex item={{ grow: 1 }}>\n <TimePeriodComp\n rhs={rhs}\n fieldType={fieldType}\n onChange={onChange}\n dateFunctionsList={dateFunctions ? dateFunctions[fieldType] : []}\n status={showError ? 'error' : undefined}\n />\n </Flex>\n )}\n\n {/* Multiple-values input */}\n {hasProp(rhs, 'values') && (\n <Flex item={{ grow: 1 }}>\n {useValueSelector && (\n <MultiValueSelector\n values={rhs.values as string[]}\n options={possibleValues!}\n onChange={handleValueSelection}\n status={showError ? 'error' : undefined}\n />\n )}\n {!useValueSelector && (\n <Input\n value={csvInput}\n onChange={handleCSVChange}\n status={showError ? 'error' : undefined}\n info={showError ? 'Invalid values' : undefined} // FIXME: TR\n label='-'\n labelHidden\n placeholder='Enter comma separated values' // FIXME: TR\n />\n )}\n </Flex>\n )}\n </Flex>\n );\n};\nexport default RhsControls;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/evaluator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAiB,KAAK,EAAuB,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/evaluator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAiB,KAAK,EAAuB,MAAM,2BAA2B,CAAC;AAyQjG;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACvC,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE;IAAE,CAAC,SAAS,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAClC,MAAM,EAAE,KAAK,EAAE,GACd,OAAO,CAoBT"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
// cspell:ignore words YYYYMM, YYYYMMDD, YYYYMMDDHH
|
|
1
|
+
// cspell:ignore words YYYYQQ, YYYYMM, YYYYMMDD, YYYYMMDDHH
|
|
2
2
|
import { hasProp } from '@pega/cosmos-react-core';
|
|
3
|
+
import transformComplexCondition from './transformer';
|
|
4
|
+
const QUOTE = '"';
|
|
3
5
|
/** Evaluates leaf conditions with BOOLEAN fields */
|
|
4
6
|
function evaluateBoolCondition(lhsValue, comparator, rhsValue // undefined for IS_TRUE/IS_FALSE comparators
|
|
5
7
|
) {
|
|
@@ -21,10 +23,24 @@ function evaluateTextCondition(lhsValue, comparator, rhsValue) {
|
|
|
21
23
|
lhsValue = lhsValue.toLowerCase(); // Converting to lowerCase to perform case-insensitive comparisons
|
|
22
24
|
// For IN/NOT_IN comparators, the rhsValue is of type `string[]`
|
|
23
25
|
if (Array.isArray(rhsValue)) {
|
|
24
|
-
const lhsInRhs = rhsValue
|
|
26
|
+
const lhsInRhs = rhsValue
|
|
27
|
+
.map(v => {
|
|
28
|
+
v = v.toLowerCase().trim();
|
|
29
|
+
// Handle text in quotes
|
|
30
|
+
if (v.startsWith(QUOTE) && v.endsWith(QUOTE)) {
|
|
31
|
+
v = v.slice(1, -1);
|
|
32
|
+
}
|
|
33
|
+
return v;
|
|
34
|
+
})
|
|
35
|
+
.includes(lhsValue); // Converting to lowerCase to perform case-insensitive comparisons
|
|
25
36
|
return comparator === 'IN' ? lhsInRhs : !lhsInRhs; // Handling IN/NOT_IN comparators
|
|
26
37
|
}
|
|
27
|
-
|
|
38
|
+
// Converting to lowerCase to perform case-insensitive comparisons
|
|
39
|
+
rhsValue = rhsValue.toLowerCase().trim();
|
|
40
|
+
// Handle if rhs is in quotes
|
|
41
|
+
if (rhsValue.startsWith(QUOTE) && rhsValue.endsWith(QUOTE)) {
|
|
42
|
+
rhsValue = rhsValue.slice(1, -1);
|
|
43
|
+
}
|
|
28
44
|
switch (comparator) {
|
|
29
45
|
case 'EQ':
|
|
30
46
|
return lhsValue === rhsValue;
|
|
@@ -74,6 +90,7 @@ function evaluateNumericCondition(lhsValue, comparator, rhsValue) {
|
|
|
74
90
|
function getDateParts(date) {
|
|
75
91
|
return {
|
|
76
92
|
YYYY: date.getFullYear().toString().padStart(4, '0'),
|
|
93
|
+
QQ: (3 * Math.floor(date.getMonth() / 3) + 1).toString().padStart(2, '0'),
|
|
77
94
|
MM: (date.getMonth() + 1).toString().padStart(2, '0'),
|
|
78
95
|
DD: date.getDate().toString().padStart(2, '0'),
|
|
79
96
|
HH: date.getHours().toString().padStart(2, '0')
|
|
@@ -84,12 +101,21 @@ function evaluateDateFuncCondition(lhsValue, fieldType, comparator, rhs) {
|
|
|
84
101
|
if (fieldType === 'DATE_ONLY')
|
|
85
102
|
lhsValue += 'T00:00:00'; // `T00:00:00` is needed for the `Date()` constructor to treat it as local (not UTC)
|
|
86
103
|
const lhsDateObj = new Date(lhsValue);
|
|
87
|
-
const { YYYY: lhsYYYY, MM: lhsMM, DD: lhsDD, HH: lhsHH } = getDateParts(lhsDateObj);
|
|
104
|
+
const { YYYY: lhsYYYY, QQ: lhsQQ, MM: lhsMM, DD: lhsDD, HH: lhsHH } = getDateParts(lhsDateObj);
|
|
88
105
|
// Determine a numeric representation of the values for the given date function
|
|
89
106
|
let lhsNumVal = 0;
|
|
90
107
|
let rhsNumVal = 0;
|
|
91
108
|
switch (rhs.dateFunction) {
|
|
92
|
-
|
|
109
|
+
case 'YEARS':
|
|
110
|
+
// Using YYYY as a number
|
|
111
|
+
lhsNumVal = Number(lhsYYYY);
|
|
112
|
+
rhsNumVal = Number(rhs.value.slice(0, 4));
|
|
113
|
+
break;
|
|
114
|
+
case 'QUARTERS':
|
|
115
|
+
// Using YYYYQQ as a number
|
|
116
|
+
lhsNumVal = Number(`${lhsYYYY}${lhsQQ}`);
|
|
117
|
+
rhsNumVal = Number(rhs.value.replace(/-/g, '').slice(0, 6));
|
|
118
|
+
break;
|
|
93
119
|
case 'MONTHS':
|
|
94
120
|
// Using YYYYMM as a number
|
|
95
121
|
lhsNumVal = Number(`${lhsYYYY}${lhsMM}`);
|
|
@@ -116,6 +142,10 @@ function evaluateDateFuncCondition(lhsValue, fieldType, comparator, rhs) {
|
|
|
116
142
|
lhsNumVal = Number(`${lhsYYYY}${lhsMM}${lhsDD}${lhsHH}`);
|
|
117
143
|
rhsNumVal = Number(rhs.value.replace(/-|T/g, '').slice(0, 10));
|
|
118
144
|
break;
|
|
145
|
+
case 'MONTHS_OF_YEAR':
|
|
146
|
+
lhsNumVal = Number(lhsMM);
|
|
147
|
+
rhsNumVal = rhs.value;
|
|
148
|
+
break;
|
|
119
149
|
case 'DAYS_OF_MONTH':
|
|
120
150
|
lhsNumVal = Number(lhsDD);
|
|
121
151
|
rhsNumVal = rhs.value;
|
|
@@ -144,6 +174,9 @@ function evaluateLeafCondition(leaf, data, fields) {
|
|
|
144
174
|
else if (hasProp(rhs, 'value')) {
|
|
145
175
|
rhsValue = rhs.value; // If RHS is a single value
|
|
146
176
|
}
|
|
177
|
+
else if (hasProp(rhs, 'relativeDate')) {
|
|
178
|
+
rhsValue = true; // TODO: When we transform relative dates to LT/GT statements, we won't need this.
|
|
179
|
+
}
|
|
147
180
|
else {
|
|
148
181
|
rhsValue = rhs.values; // If RHS is a list of values
|
|
149
182
|
}
|
|
@@ -174,6 +207,9 @@ function evaluateLeafCondition(leaf, data, fields) {
|
|
|
174
207
|
if (rhs && hasProp(rhs, 'dateFunction')) {
|
|
175
208
|
return evaluateDateFuncCondition(lhsValue, field.type, comparator, rhs);
|
|
176
209
|
}
|
|
210
|
+
if (rhs && hasProp(rhs, 'relativeDate')) {
|
|
211
|
+
return true; // TODO: When we transform relative dates to LT/GT statements, we won't need this.
|
|
212
|
+
}
|
|
177
213
|
// Both the values are expected to be in an ISO-8601 format
|
|
178
214
|
const lhsAsTicks = new Date(lhsValue).getTime();
|
|
179
215
|
const rhsAsTicks = new Date(rhsValue).getTime();
|
|
@@ -199,18 +235,20 @@ function evaluateLeafCondition(leaf, data, fields) {
|
|
|
199
235
|
export default function evaluateCondition(condition, data, fields) {
|
|
200
236
|
// For safety against any malformed trees
|
|
201
237
|
try {
|
|
202
|
-
|
|
238
|
+
// Update relative date conditions to be LT/GT date range conditions
|
|
239
|
+
const updatedCondition = transformComplexCondition(condition, fields);
|
|
240
|
+
if (hasProp(updatedCondition, 'AND')) {
|
|
203
241
|
// Return true if all the child nodes are true
|
|
204
|
-
return
|
|
242
|
+
return updatedCondition.AND.every(child => evaluateCondition(child, data, fields));
|
|
205
243
|
}
|
|
206
|
-
if (hasProp(
|
|
244
|
+
if (hasProp(updatedCondition, 'OR')) {
|
|
207
245
|
// Return true if any one of the child nodes is true
|
|
208
|
-
return
|
|
246
|
+
return updatedCondition.OR.some(child => evaluateCondition(child, data, fields));
|
|
209
247
|
}
|
|
210
|
-
if (hasProp(
|
|
211
|
-
return !evaluateCondition(
|
|
248
|
+
if (hasProp(updatedCondition, 'NOT')) {
|
|
249
|
+
return !evaluateCondition(updatedCondition.NOT, data, fields);
|
|
212
250
|
}
|
|
213
|
-
return evaluateLeafCondition(
|
|
251
|
+
return evaluateLeafCondition(updatedCondition.condition, data, fields);
|
|
214
252
|
}
|
|
215
253
|
catch {
|
|
216
254
|
return false;
|