@pega/cosmos-react-condition-builder 5.0.0-dev.4.7 → 5.0.0-dev.4.9
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/package.json +2 -2
- package/lib/components/ConditionBuilder/AtomicCondition.d.ts +0 -57
- package/lib/components/ConditionBuilder/AtomicCondition.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/AtomicCondition.js +0 -164
- package/lib/components/ConditionBuilder/AtomicCondition.js.map +0 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.d.ts +0 -6
- package/lib/components/ConditionBuilder/ConditionBuilder.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.js +0 -271
- package/lib/components/ConditionBuilder/ConditionBuilder.js.map +0 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.styles.d.ts +0 -7
- package/lib/components/ConditionBuilder/ConditionBuilder.styles.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.styles.js +0 -59
- package/lib/components/ConditionBuilder/ConditionBuilder.styles.js.map +0 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts +0 -136
- package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.types.js +0 -2
- package/lib/components/ConditionBuilder/ConditionBuilder.types.js.map +0 -1
- package/lib/components/ConditionBuilder/FieldCondition.d.ts +0 -7
- package/lib/components/ConditionBuilder/FieldCondition.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/FieldCondition.js +0 -26
- package/lib/components/ConditionBuilder/FieldCondition.js.map +0 -1
- package/lib/components/ConditionBuilder/FieldCondition.types.d.ts +0 -30
- package/lib/components/ConditionBuilder/FieldCondition.types.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/FieldCondition.types.js +0 -2
- package/lib/components/ConditionBuilder/FieldCondition.types.js.map +0 -1
- package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.d.ts +0 -18
- package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.js +0 -155
- package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.js.map +0 -1
- package/lib/components/ConditionBuilder/RhsControls/FieldSelector.d.ts +0 -21
- package/lib/components/ConditionBuilder/RhsControls/FieldSelector.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/RhsControls/FieldSelector.js +0 -60
- package/lib/components/ConditionBuilder/RhsControls/FieldSelector.js.map +0 -1
- package/lib/components/ConditionBuilder/RhsControls/NumericInput.d.ts +0 -18
- package/lib/components/ConditionBuilder/RhsControls/NumericInput.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/RhsControls/NumericInput.js +0 -22
- package/lib/components/ConditionBuilder/RhsControls/NumericInput.js.map +0 -1
- package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.d.ts +0 -18
- package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.js +0 -119
- package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.js.map +0 -1
- package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.d.ts +0 -26
- package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.js +0 -156
- package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.js.map +0 -1
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.d.ts +0 -6
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.js +0 -112
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.js.map +0 -1
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.d.ts +0 -20
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.js +0 -12
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.js.map +0 -1
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.d.ts +0 -45
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.js +0 -196
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.js.map +0 -1
- package/lib/components/ConditionBuilder/RhsControls/index.d.ts +0 -42
- package/lib/components/ConditionBuilder/RhsControls/index.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/RhsControls/index.js +0 -321
- package/lib/components/ConditionBuilder/RhsControls/index.js.map +0 -1
- package/lib/components/ConditionBuilder/core/comparators.d.ts +0 -12
- package/lib/components/ConditionBuilder/core/comparators.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/core/comparators.js +0 -78
- package/lib/components/ConditionBuilder/core/comparators.js.map +0 -1
- package/lib/components/ConditionBuilder/core/evaluator.d.ts +0 -17
- package/lib/components/ConditionBuilder/core/evaluator.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/core/evaluator.js +0 -314
- package/lib/components/ConditionBuilder/core/evaluator.js.map +0 -1
- package/lib/components/ConditionBuilder/core/extendDayJs.d.ts +0 -2
- package/lib/components/ConditionBuilder/core/extendDayJs.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/core/extendDayJs.js +0 -4
- package/lib/components/ConditionBuilder/core/extendDayJs.js.map +0 -1
- package/lib/components/ConditionBuilder/core/formatter.d.ts +0 -17
- package/lib/components/ConditionBuilder/core/formatter.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/core/formatter.js +0 -262
- package/lib/components/ConditionBuilder/core/formatter.js.map +0 -1
- package/lib/components/ConditionBuilder/core/rows-reducer.d.ts +0 -27
- package/lib/components/ConditionBuilder/core/rows-reducer.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/core/rows-reducer.js +0 -50
- package/lib/components/ConditionBuilder/core/rows-reducer.js.map +0 -1
- package/lib/components/ConditionBuilder/core/time-utils.d.ts +0 -5
- package/lib/components/ConditionBuilder/core/time-utils.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/core/time-utils.js +0 -23
- package/lib/components/ConditionBuilder/core/time-utils.js.map +0 -1
- package/lib/components/ConditionBuilder/core/transformer.d.ts +0 -7
- package/lib/components/ConditionBuilder/core/transformer.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/core/transformer.js +0 -210
- package/lib/components/ConditionBuilder/core/transformer.js.map +0 -1
- package/lib/components/ConditionBuilder/core/types.d.ts +0 -47
- package/lib/components/ConditionBuilder/core/types.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/core/types.js +0 -2
- package/lib/components/ConditionBuilder/core/types.js.map +0 -1
- package/lib/components/ConditionBuilder/core/utils.d.ts +0 -37
- package/lib/components/ConditionBuilder/core/utils.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/core/utils.js +0 -454
- package/lib/components/ConditionBuilder/core/utils.js.map +0 -1
- package/lib/components/ConditionBuilder/index.d.ts +0 -11
- package/lib/components/ConditionBuilder/index.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/index.js +0 -8
- package/lib/components/ConditionBuilder/index.js.map +0 -1
- package/lib/components/ConditionInput/ConditionInput.d.ts +0 -6
- package/lib/components/ConditionInput/ConditionInput.d.ts.map +0 -1
- package/lib/components/ConditionInput/ConditionInput.js +0 -302
- package/lib/components/ConditionInput/ConditionInput.js.map +0 -1
- package/lib/components/ConditionInput/ConditionInput.styles.d.ts +0 -5
- package/lib/components/ConditionInput/ConditionInput.styles.d.ts.map +0 -1
- package/lib/components/ConditionInput/ConditionInput.styles.js +0 -27
- package/lib/components/ConditionInput/ConditionInput.styles.js.map +0 -1
- package/lib/components/ConditionInput/ConditionInput.types.d.ts +0 -32
- package/lib/components/ConditionInput/ConditionInput.types.d.ts.map +0 -1
- package/lib/components/ConditionInput/ConditionInput.types.js +0 -2
- package/lib/components/ConditionInput/ConditionInput.types.js.map +0 -1
- package/lib/components/ConditionInput/index.d.ts +0 -3
- package/lib/components/ConditionInput/index.d.ts.map +0 -1
- package/lib/components/ConditionInput/index.js +0 -2
- package/lib/components/ConditionInput/index.js.map +0 -1
- package/lib/components/ConditionInput/utils.d.ts +0 -17
- package/lib/components/ConditionInput/utils.d.ts.map +0 -1
- package/lib/components/ConditionInput/utils.js +0 -121
- package/lib/components/ConditionInput/utils.js.map +0 -1
- package/lib/components/PromotedFilters/ConditionSelector.d.ts +0 -31
- package/lib/components/PromotedFilters/ConditionSelector.d.ts.map +0 -1
- package/lib/components/PromotedFilters/ConditionSelector.js +0 -44
- package/lib/components/PromotedFilters/ConditionSelector.js.map +0 -1
- package/lib/components/PromotedFilters/PromotedFilters.d.ts +0 -11
- package/lib/components/PromotedFilters/PromotedFilters.d.ts.map +0 -1
- package/lib/components/PromotedFilters/PromotedFilters.js +0 -153
- package/lib/components/PromotedFilters/PromotedFilters.js.map +0 -1
- package/lib/components/PromotedFilters/PromotedFilters.styles.d.ts +0 -4
- package/lib/components/PromotedFilters/PromotedFilters.styles.d.ts.map +0 -1
- package/lib/components/PromotedFilters/PromotedFilters.styles.js +0 -38
- package/lib/components/PromotedFilters/PromotedFilters.styles.js.map +0 -1
- package/lib/components/PromotedFilters/PromotedFilters.types.d.ts +0 -33
- package/lib/components/PromotedFilters/PromotedFilters.types.d.ts.map +0 -1
- package/lib/components/PromotedFilters/PromotedFilters.types.js +0 -2
- package/lib/components/PromotedFilters/PromotedFilters.types.js.map +0 -1
- package/lib/components/PromotedFilters/index.d.ts +0 -3
- package/lib/components/PromotedFilters/index.d.ts.map +0 -1
- package/lib/components/PromotedFilters/index.js +0 -2
- package/lib/components/PromotedFilters/index.js.map +0 -1
- package/lib/index.d.ts +0 -7
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -8
- package/lib/index.js.map +0 -1
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
import { Flex, useConfiguration, useI18n, hasProp, CompositeInput, parseToDate, useAfterInitialEffect } from '@pega/cosmos-react-core';
|
|
4
|
-
import { formatDateTime } from '@pega/cosmos-react-core/lib/components/DateTime/utils';
|
|
5
|
-
import { getDayOfWeekNamesMap } from '@pega/cosmos-react-core/lib/components/DateTime/Input/utils';
|
|
6
|
-
import { formatRelativeDate } from '../core/formatter';
|
|
7
|
-
import TimePeriodMenu from './TimePeriodMenu';
|
|
8
|
-
const dateDisplayVariants = {
|
|
9
|
-
YEARS: 'year',
|
|
10
|
-
QUARTERS: 'quarteryear',
|
|
11
|
-
MONTHS: 'monthyear',
|
|
12
|
-
WEEKS: 'week',
|
|
13
|
-
DAYS: 'date',
|
|
14
|
-
HOURS: 'datetime',
|
|
15
|
-
MINUTES: 'datetime',
|
|
16
|
-
SECONDS: 'datetime'
|
|
17
|
-
};
|
|
18
|
-
/** Creating display value for the selected time period value */
|
|
19
|
-
const createDisplayValue = (rhsValue, t, locale) => {
|
|
20
|
-
if (hasProp(rhsValue, 'relativeDate')) {
|
|
21
|
-
const { relativeDate: { timePeriod, interval, datePart } } = rhsValue;
|
|
22
|
-
return formatRelativeDate(t, timePeriod, datePart, interval);
|
|
23
|
-
}
|
|
24
|
-
const { value, dateFunction } = rhsValue;
|
|
25
|
-
if (!value && !(dateFunction === 'HOURS_OF_DAY' && value === 0)) {
|
|
26
|
-
return t('condition_builder_select_placeholder');
|
|
27
|
-
}
|
|
28
|
-
switch (dateFunction) {
|
|
29
|
-
case 'MONTHS_OF_YEAR':
|
|
30
|
-
return new Date(2021, value - 1, 1).toLocaleString(locale, { month: 'long' });
|
|
31
|
-
case 'DAYS_OF_MONTH':
|
|
32
|
-
return t('condition_builder_day_number_of_month', [value], {
|
|
33
|
-
count: Number(value),
|
|
34
|
-
pluralType: 'ordinal'
|
|
35
|
-
});
|
|
36
|
-
case 'DAYS_OF_WEEK': {
|
|
37
|
-
const dayOfWeekOptions = getDayOfWeekNamesMap();
|
|
38
|
-
return dayOfWeekOptions[Number(value)];
|
|
39
|
-
}
|
|
40
|
-
case 'HOURS_OF_DAY':
|
|
41
|
-
return t('condition_builder_hour_number_of_day', [`${value.toString().padStart(2, '0')}:00`]);
|
|
42
|
-
case 'MINUTES':
|
|
43
|
-
case 'SECONDS': {
|
|
44
|
-
const result = dateFunction === 'SECONDS' ? t('seconds_text') : t('minutes_text');
|
|
45
|
-
let output = formatDateTime(parseToDate(value), {
|
|
46
|
-
t,
|
|
47
|
-
locale,
|
|
48
|
-
format: dateFunction === 'SECONDS' ? 'long' : 'short',
|
|
49
|
-
variant: dateDisplayVariants[dateFunction],
|
|
50
|
-
timeZone: 'UTC'
|
|
51
|
-
});
|
|
52
|
-
output += ` (${result.toLowerCase()})`;
|
|
53
|
-
return output;
|
|
54
|
-
}
|
|
55
|
-
default: {
|
|
56
|
-
return formatDateTime(parseToDate(value), {
|
|
57
|
-
t,
|
|
58
|
-
locale,
|
|
59
|
-
format: 'short',
|
|
60
|
-
variant: dateDisplayVariants[dateFunction],
|
|
61
|
-
timeZone: 'UTC'
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
const TimePeriodInput = (props) => {
|
|
67
|
-
const { rhs, onChange, dateFunctionsList, status, fieldType } = props;
|
|
68
|
-
const t = useI18n();
|
|
69
|
-
const { locale } = useConfiguration();
|
|
70
|
-
const [newRhsValue, setNewRhsValue] = useState(rhs);
|
|
71
|
-
let info;
|
|
72
|
-
if (status === 'error') {
|
|
73
|
-
info = hasProp(rhs, 'relativeDate')
|
|
74
|
-
? t('condition_builder_invalid_relative_date')
|
|
75
|
-
: t('condition_builder_invalid_time_period');
|
|
76
|
-
}
|
|
77
|
-
useAfterInitialEffect(() => {
|
|
78
|
-
setNewRhsValue(rhs);
|
|
79
|
-
}, [rhs]);
|
|
80
|
-
return (_jsx(Flex, { container: { direction: 'column', pad: [0, 0, 0.25] }, children: _jsx(CompositeInput, { value: createDisplayValue(rhs, t, locale), label: t('condition_builder_value_label'), status: status, info: info, dialog: {
|
|
81
|
-
renderer: TimePeriodMenu,
|
|
82
|
-
rendererProps: {
|
|
83
|
-
rhs: newRhsValue,
|
|
84
|
-
fieldType,
|
|
85
|
-
onChange: setNewRhsValue,
|
|
86
|
-
dateFunctionsList,
|
|
87
|
-
status
|
|
88
|
-
},
|
|
89
|
-
onApply: ({ close }) => {
|
|
90
|
-
if (newRhsValue)
|
|
91
|
-
onChange(newRhsValue);
|
|
92
|
-
close();
|
|
93
|
-
},
|
|
94
|
-
onCancel: ({ close }) => {
|
|
95
|
-
close();
|
|
96
|
-
}
|
|
97
|
-
}, onClear: () => {
|
|
98
|
-
if (hasProp(newRhsValue, 'relativeDate')) {
|
|
99
|
-
onChange({
|
|
100
|
-
relativeDate: {
|
|
101
|
-
timePeriod: 'CURRENT',
|
|
102
|
-
datePart: 'DAYS'
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
else if (hasProp(newRhsValue, 'dateFunction')) {
|
|
107
|
-
onChange({ value: '', dateFunction: dateFunctionsList[0] });
|
|
108
|
-
}
|
|
109
|
-
} }) }));
|
|
110
|
-
};
|
|
111
|
-
export default TimePeriodInput;
|
|
112
|
-
//# sourceMappingURL=TimePeriodInput.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TimePeriodInput.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/TimePeriodInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAqB,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,EACL,IAAI,EAEJ,gBAAgB,EAChB,OAAO,EACP,OAAO,EACP,cAAc,EACd,WAAW,EACX,qBAAqB,EAItB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,MAAM,uDAAuD,CAAC;AACvF,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,EAAE,EAAE;oBACtB,KAAK,EAAE,CAAC;gBACV,CAAC;aACF,EACD,OAAO,EAAE,GAAG,EAAE;gBACZ,IAAI,OAAO,CAAC,WAAW,EAAE,cAAc,CAAC,EAAE;oBACxC,QAAQ,CAAC;wBACP,YAAY,EAAE;4BACZ,UAAU,EAAE,SAAS;4BACrB,QAAQ,EAAE,MAAM;yBACjB;qBACF,CAAC,CAAC;iBACJ;qBAAM,IAAI,OAAO,CAAC,WAAW,EAAE,cAAc,CAAC,EAAE;oBAC/C,QAAQ,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,YAAY,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;iBAC7D;YACH,CAAC,GACD,GACG,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { FunctionComponent, useState } from 'react';\n\nimport {\n Flex,\n ForwardProps,\n useConfiguration,\n useI18n,\n hasProp,\n CompositeInput,\n parseToDate,\n useAfterInitialEffect,\n TranslationFunction,\n TranslationPack,\n ExcludeStrict\n} from '@pega/cosmos-react-core';\nimport { DateTimeVariant } from '@pega/cosmos-react-core/lib/components/DateTime/DateTime.types';\nimport { formatDateTime } from '@pega/cosmos-react-core/lib/components/DateTime/utils';\nimport { getDayOfWeekNamesMap } from '@pega/cosmos-react-core/lib/components/DateTime/Input/utils';\n\nimport { RhsWithDateFunction, RhsWithRelativeDate } from '../ConditionBuilder.types';\nimport { formatRelativeDate } from '../core/formatter';\nimport { DateFunction } from '../core/types';\n\nimport TimePeriodMenu, { TimePeriodMenuProps } from './TimePeriodMenu';\n\nconst dateDisplayVariants: Record<\n ExcludeStrict<DateFunction, 'MONTHS_OF_YEAR' | 'DAYS_OF_MONTH' | 'DAYS_OF_WEEK' | 'HOURS_OF_DAY'>,\n DateTimeVariant\n> = {\n YEARS: 'year',\n QUARTERS: 'quarteryear',\n MONTHS: 'monthyear',\n WEEKS: 'week',\n DAYS: 'date',\n HOURS: 'datetime',\n MINUTES: 'datetime',\n SECONDS: 'datetime'\n};\n\n/** Creating display value for the selected time period value */\nconst createDisplayValue = (\n rhsValue: RhsWithDateFunction | RhsWithRelativeDate,\n t: TranslationFunction<TranslationPack>,\n locale: string\n) => {\n if (hasProp(rhsValue, 'relativeDate')) {\n const {\n relativeDate: { timePeriod, interval, datePart }\n } = rhsValue;\n return formatRelativeDate(t, timePeriod, datePart, interval);\n }\n\n const { value, dateFunction } = rhsValue;\n\n if (!value && !(dateFunction === 'HOURS_OF_DAY' && value === 0)) {\n return t('condition_builder_select_placeholder');\n }\n\n switch (dateFunction) {\n case 'MONTHS_OF_YEAR':\n return new Date(2021, (value as number) - 1, 1).toLocaleString(locale, { month: 'long' });\n\n case 'DAYS_OF_MONTH':\n return t('condition_builder_day_number_of_month', [value], {\n count: Number(value),\n pluralType: 'ordinal'\n });\n case 'DAYS_OF_WEEK': {\n const dayOfWeekOptions = getDayOfWeekNamesMap();\n return dayOfWeekOptions[Number(value)];\n }\n case 'HOURS_OF_DAY':\n return t('condition_builder_hour_number_of_day', [`${value.toString().padStart(2, '0')}:00`]);\n case 'MINUTES':\n case 'SECONDS': {\n const result = dateFunction === 'SECONDS' ? t('seconds_text') : t('minutes_text');\n let output = formatDateTime(parseToDate(value), {\n t,\n locale,\n format: dateFunction === 'SECONDS' ? 'long' : 'short',\n variant: dateDisplayVariants[dateFunction],\n timeZone: 'UTC'\n });\n output += ` (${result.toLowerCase()})`;\n return output;\n }\n default: {\n return formatDateTime(parseToDate(value), {\n t,\n locale,\n format: 'short',\n variant: dateDisplayVariants[dateFunction],\n timeZone: 'UTC'\n });\n }\n }\n};\n\nconst TimePeriodInput: FunctionComponent<TimePeriodMenuProps & ForwardProps> = (\n props: TimePeriodMenuProps\n) => {\n const { rhs, onChange, dateFunctionsList, status, fieldType } = props;\n const t = useI18n();\n const { locale } = useConfiguration();\n const [newRhsValue, setNewRhsValue] = useState<TimePeriodMenuProps['rhs']>(rhs);\n\n let info;\n if (status === 'error') {\n info = hasProp(rhs, 'relativeDate')\n ? t('condition_builder_invalid_relative_date')\n : t('condition_builder_invalid_time_period');\n }\n\n useAfterInitialEffect(() => {\n setNewRhsValue(rhs);\n }, [rhs]);\n\n return (\n <Flex container={{ direction: 'column', pad: [0, 0, 0.25] }}>\n <CompositeInput\n value={createDisplayValue(rhs, t, locale)}\n label={t('condition_builder_value_label')}\n status={status}\n info={info}\n dialog={{\n renderer: TimePeriodMenu,\n rendererProps: {\n rhs: newRhsValue,\n fieldType,\n onChange: setNewRhsValue,\n dateFunctionsList,\n status\n },\n onApply: ({ close }) => {\n if (newRhsValue) onChange(newRhsValue);\n close();\n },\n onCancel: ({ close }) => {\n close();\n }\n }}\n onClear={() => {\n if (hasProp(newRhsValue, 'relativeDate')) {\n onChange({\n relativeDate: {\n timePeriod: 'CURRENT',\n datePart: 'DAYS'\n }\n });\n } else if (hasProp(newRhsValue, 'dateFunction')) {\n onChange({ value: '', dateFunction: dateFunctionsList[0] });\n }\n }}\n />\n </Flex>\n );\n};\n\nexport default TimePeriodInput;\n"]}
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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;AAMxD,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,CAuBzE,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Flex, hasProp } from '@pega/cosmos-react-core';
|
|
3
|
-
import { StyledTimePeriodContainer } from '../ConditionBuilder.styles';
|
|
4
|
-
import DateFunctionMenu from './DateFunctionMenu';
|
|
5
|
-
import RelativeDateMenu from './RelativeDateMenu';
|
|
6
|
-
/** A menu with controls to select a Time period value on RHS */
|
|
7
|
-
const TimePeriodMenu = (props) => {
|
|
8
|
-
const { rhs, onChange, dateFunctionsList, status, fieldType } = props;
|
|
9
|
-
return (_jsxs(Flex, { as: StyledTimePeriodContainer, container: { direction: 'column', rowGap: 0.5 }, item: { grow: 1 }, children: [hasProp(rhs, 'dateFunction') && (_jsx(DateFunctionMenu, { rhs: rhs, onChange: onChange, dateFunctionsList: dateFunctionsList, status: status })), hasProp(rhs, 'relativeDate') && (_jsx(RelativeDateMenu, { rhs: rhs, fieldType: fieldType, onChange: onChange, status: status }))] }));
|
|
10
|
-
};
|
|
11
|
-
export default TimePeriodMenu;
|
|
12
|
-
//# sourceMappingURL=TimePeriodMenu.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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;AAIjG,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAEvE,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,IACH,EAAE,EAAE,yBAAyB,EAC7B,SAAS,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,EAC/C,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,aAEhB,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,GACd,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,GAAI,CACzF,IACI,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["// cspell: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';\nimport { StyledTimePeriodContainer } from '../ConditionBuilder.styles';\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\n as={StyledTimePeriodContainer}\n container={{ direction: 'column', rowGap: 0.5 }}\n item={{ grow: 1 }}\n >\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,45 +0,0 @@
|
|
|
1
|
-
import { Dispatch, SetStateAction, Ref } from 'react';
|
|
2
|
-
import { BaseProps, NoChildrenProp, ComboBoxProps, HandleValue } from '@pega/cosmos-react-core';
|
|
3
|
-
import { LeafCondition, ParameterValue, ValueSelection } from '../ConditionBuilder.types';
|
|
4
|
-
import { Comparator } from '../core/types';
|
|
5
|
-
interface ValueSelectorProps<T extends {
|
|
6
|
-
id: string;
|
|
7
|
-
possibleValues?: ValueSelection<T>;
|
|
8
|
-
}> extends BaseProps, NoChildrenProp {
|
|
9
|
-
mode: ComboBoxProps['mode'];
|
|
10
|
-
/** Previous selection */
|
|
11
|
-
values: string[] | string;
|
|
12
|
-
/** Current selected LHS */
|
|
13
|
-
selectedField: T;
|
|
14
|
-
/** Current selected comparator */
|
|
15
|
-
comparator: Comparator;
|
|
16
|
-
/** Rhs for the condition */
|
|
17
|
-
rhs: NonNullable<LeafCondition['rhs']>;
|
|
18
|
-
/** Passed Parameters array for Rhstype PARAMETER */
|
|
19
|
-
parameters: ParameterValue[];
|
|
20
|
-
/** Callback for changes */
|
|
21
|
-
onChange: (selection: string[] | string) => void;
|
|
22
|
-
/** Callback for blur */
|
|
23
|
-
onBlur?: (selection?: string[] | string) => void;
|
|
24
|
-
/** Callback for clear */
|
|
25
|
-
onClear?: () => void;
|
|
26
|
-
/** Used to indicate any errors on the control */
|
|
27
|
-
status?: 'error';
|
|
28
|
-
/** Placeholder text to display in empty control */
|
|
29
|
-
placeholder?: ComboBoxProps['placeholder'];
|
|
30
|
-
/** Custom label for input. Makes label visible if provided. */
|
|
31
|
-
label?: ComboBoxProps['label'];
|
|
32
|
-
/** Guidance text that apppears below the input. */
|
|
33
|
-
info?: ComboBoxProps['info'];
|
|
34
|
-
/** sets status and info */
|
|
35
|
-
setApiError?: Dispatch<SetStateAction<string | null>>;
|
|
36
|
-
/** Imperative handle */
|
|
37
|
-
handle?: Ref<HandleValue>;
|
|
38
|
-
}
|
|
39
|
-
/** A control for selecting multiple values using checkboxes in an overlay */
|
|
40
|
-
declare const ValueSelector: <F extends object & {
|
|
41
|
-
id: string;
|
|
42
|
-
possibleValues?: ValueSelection<F> | undefined;
|
|
43
|
-
}>({ values, selectedField, comparator, rhs, onChange, onBlur, onClear, status, mode, parameters, placeholder, label, info, setApiError, handle }: ValueSelectorProps<F>) => JSX.Element;
|
|
44
|
-
export default ValueSelector;
|
|
45
|
-
//# sourceMappingURL=ValueSelector.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ValueSelector.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/ValueSelector.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,QAAQ,EACR,cAAc,EAEd,GAAG,EAEJ,MAAM,OAAO,CAAC;AAEf,OAAO,EAEL,SAAS,EAIT,cAAc,EACd,aAAa,EAKb,WAAW,EACZ,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,aAAa,EACb,cAAc,EAEd,cAAc,EACf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,UAAU,kBAAkB,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAA;CAAE,CACvF,SAAQ,SAAS,EACf,cAAc;IAChB,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC5B,yBAAyB;IACzB,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC1B,2BAA2B;IAC3B,aAAa,EAAE,CAAC,CAAC;IACjB,kCAAkC;IAClC,UAAU,EAAE,UAAU,CAAC;IACvB,4BAA4B;IAC5B,GAAG,EAAE,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;IACvC,oDAAoD;IACpD,UAAU,EAAE,cAAc,EAAE,CAAC;IAC7B,2BAA2B;IAC3B,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,KAAK,IAAI,CAAC;IACjD,wBAAwB;IACxB,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,KAAK,IAAI,CAAC;IACjD,yBAAyB;IACzB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,iDAAiD;IACjD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,mDAAmD;IACnD,WAAW,CAAC,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;IAC3C,+DAA+D;IAC/D,KAAK,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;IAC/B,mDAAmD;IACnD,IAAI,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC7B,2BAA2B;IAC3B,WAAW,CAAC,EAAE,QAAQ,CAAC,cAAc,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;IACtD,wBAAwB;IACxB,MAAM,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;CAC3B;AAED,6EAA6E;AAC7E,QAAA,MAAM,aAAa;QAA6B,MAAM;;wLA6PrD,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useState, useEffect, useRef, useCallback, useImperativeHandle } from 'react';
|
|
3
|
-
import { useI18n, ComboBox, createStringMatcher, useAfterInitialEffect, hasProp, Button, Icon } from '@pega/cosmos-react-core';
|
|
4
|
-
/** A control for selecting multiple values using checkboxes in an overlay */
|
|
5
|
-
const ValueSelector = ({ values, selectedField, comparator, rhs, onChange, onBlur, onClear, status, mode, parameters, placeholder, label, info, setApiError, handle }) => {
|
|
6
|
-
const t = useI18n();
|
|
7
|
-
const inputRef = useRef(null);
|
|
8
|
-
const [selections, setSelections] = useState(values);
|
|
9
|
-
const [filterValue, setFilterValue] = useState('');
|
|
10
|
-
const [options, setOptions] = useState([]);
|
|
11
|
-
const [filterOptions, setFilterOptions] = useState([]);
|
|
12
|
-
const [loading, setLoading] = useState(false);
|
|
13
|
-
const [hasMore, setHasMore] = useState(true);
|
|
14
|
-
const [items, setItems] = useState([]);
|
|
15
|
-
const itemsToRender = (item) => {
|
|
16
|
-
return item.map(option => {
|
|
17
|
-
if (typeof option === 'object') {
|
|
18
|
-
return {
|
|
19
|
-
...option,
|
|
20
|
-
selected: Array.isArray(selections)
|
|
21
|
-
? selections.includes(option.id)
|
|
22
|
-
: selections === option.id
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
id: option,
|
|
27
|
-
primary: option,
|
|
28
|
-
selected: Array.isArray(selections) ? selections.includes(option) : selections === option
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
const updatedItems = items.map(item => {
|
|
34
|
-
const result = Array.isArray(selections)
|
|
35
|
-
? selections.includes(item.id)
|
|
36
|
-
: selections === item.id;
|
|
37
|
-
return { ...item, selected: result };
|
|
38
|
-
});
|
|
39
|
-
setItems(updatedItems);
|
|
40
|
-
}, [selections]);
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
const matcher = createStringMatcher(filterValue);
|
|
43
|
-
setFilterOptions(options.filter(option => {
|
|
44
|
-
if (typeof option === 'object')
|
|
45
|
-
return matcher.test(option.primary);
|
|
46
|
-
return matcher.test(option);
|
|
47
|
-
}));
|
|
48
|
-
}, [filterValue, options]);
|
|
49
|
-
useAfterInitialEffect(() => {
|
|
50
|
-
onChange(selections);
|
|
51
|
-
}, [selections]);
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
if (!selectedField) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
let subscribed = true;
|
|
57
|
-
if (hasProp(rhs, 'parameterId')) {
|
|
58
|
-
setOptions(parameters);
|
|
59
|
-
}
|
|
60
|
-
else if (hasProp(selectedField, 'possibleValues')) {
|
|
61
|
-
const { possibleValues } = selectedField;
|
|
62
|
-
if (typeof possibleValues === 'function') {
|
|
63
|
-
setLoading(true);
|
|
64
|
-
setOptions([]);
|
|
65
|
-
possibleValues({ searchString: filterValue, comparator, lhs: selectedField })
|
|
66
|
-
.then(response => {
|
|
67
|
-
if (!subscribed)
|
|
68
|
-
return;
|
|
69
|
-
setOptions(response);
|
|
70
|
-
setLoading(false);
|
|
71
|
-
})
|
|
72
|
-
.catch(err => {
|
|
73
|
-
if (err && subscribed) {
|
|
74
|
-
setApiError?.(t('condition_builder_possible_values_error'));
|
|
75
|
-
setOptions([]);
|
|
76
|
-
setLoading(false);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
else if (Array.isArray(possibleValues)) {
|
|
81
|
-
setOptions(possibleValues);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
setOptions([]);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return () => {
|
|
88
|
-
subscribed = false;
|
|
89
|
-
setApiError?.(null);
|
|
90
|
-
};
|
|
91
|
-
}, [filterValue, selectedField.id, comparator]);
|
|
92
|
-
useEffect(() => setFilterValue(''), [selectedField, comparator]);
|
|
93
|
-
const getSelections = () => {
|
|
94
|
-
if (typeof selections === 'string') {
|
|
95
|
-
let itemLabel;
|
|
96
|
-
if (hasProp(rhs, 'parameterId')) {
|
|
97
|
-
const selectedItem = parameters.find(item => item.id === selections);
|
|
98
|
-
itemLabel = selectedItem !== undefined ? selectedItem.primary : selections;
|
|
99
|
-
}
|
|
100
|
-
else
|
|
101
|
-
itemLabel = selections;
|
|
102
|
-
return {
|
|
103
|
-
items: { id: selections, text: itemLabel }
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
if (selections.length > 0) {
|
|
107
|
-
return {
|
|
108
|
-
items: selections.map(s => {
|
|
109
|
-
const optionLabel = options.find(opt => typeof opt === 'object' && opt.id === s);
|
|
110
|
-
return { id: s, text: optionLabel?.primary ?? s };
|
|
111
|
-
}),
|
|
112
|
-
onRemove: (value) => {
|
|
113
|
-
setSelections(cur => {
|
|
114
|
-
const current = cur;
|
|
115
|
-
return current.filter(selection => selection !== value);
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
return undefined;
|
|
121
|
-
};
|
|
122
|
-
useEffect(() => {
|
|
123
|
-
if (filterValue !== '') {
|
|
124
|
-
setItems(itemsToRender(filterOptions.slice(0, 10)));
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
setItems(itemsToRender(options.slice(0, 10)));
|
|
128
|
-
}
|
|
129
|
-
}, [options, filterOptions]);
|
|
130
|
-
const loadMore = useCallback(() => {
|
|
131
|
-
if (!loading) {
|
|
132
|
-
setLoading(true);
|
|
133
|
-
let totalItem;
|
|
134
|
-
if (filterOptions.length > 0)
|
|
135
|
-
totalItem = filterOptions;
|
|
136
|
-
else
|
|
137
|
-
totalItem = options;
|
|
138
|
-
const remItems = totalItem.length - items.length;
|
|
139
|
-
let newItemsLength = 10;
|
|
140
|
-
if (remItems <= newItemsLength) {
|
|
141
|
-
setHasMore(false);
|
|
142
|
-
newItemsLength = remItems;
|
|
143
|
-
}
|
|
144
|
-
setLoading(false);
|
|
145
|
-
setItems(prev => {
|
|
146
|
-
return [
|
|
147
|
-
...prev,
|
|
148
|
-
...itemsToRender(totalItem.slice(items.length, items.length + newItemsLength))
|
|
149
|
-
];
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
}, [options, loading, filterOptions, items, hasMore]);
|
|
153
|
-
useImperativeHandle(handle, () => ({
|
|
154
|
-
clear: () => {
|
|
155
|
-
setSelections([]);
|
|
156
|
-
}
|
|
157
|
-
}), []);
|
|
158
|
-
return (_jsx(ComboBox, { ref: inputRef, mode: mode, label: label ?? t('condition_builder_possible_values_label'), placeholder: placeholder ??
|
|
159
|
-
(mode === 'single-select'
|
|
160
|
-
? t('condition_builder_single_selection_text_default')
|
|
161
|
-
: t('condition_builder_multi_selection_text_default')), value: filterValue, onChange: e => {
|
|
162
|
-
setFilterValue(e.target.value);
|
|
163
|
-
setHasMore(true);
|
|
164
|
-
}, onBlur: () => {
|
|
165
|
-
onBlur?.(selections);
|
|
166
|
-
setFilterValue('');
|
|
167
|
-
}, menu: {
|
|
168
|
-
items,
|
|
169
|
-
onItemClick: id => {
|
|
170
|
-
setFilterValue('');
|
|
171
|
-
if (mode === 'single-select') {
|
|
172
|
-
setSelections(id);
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
setSelections(cur => {
|
|
176
|
-
const current = cur;
|
|
177
|
-
return current.includes(id)
|
|
178
|
-
? current.filter(selection => selection !== id)
|
|
179
|
-
: [...cur, id];
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
},
|
|
183
|
-
loading,
|
|
184
|
-
loadMore: hasMore ? loadMore : undefined
|
|
185
|
-
}, selected: getSelections(), status: status, info: info, actions: onClear &&
|
|
186
|
-
selections.length > 0 && (_jsx(Button, { icon: true, variant: 'simple', label: t('clear'), onClick: () => {
|
|
187
|
-
setSelections([]);
|
|
188
|
-
onClear();
|
|
189
|
-
if (inputRef.current) {
|
|
190
|
-
const inputEl = inputRef.current.querySelector('input');
|
|
191
|
-
inputEl?.focus();
|
|
192
|
-
}
|
|
193
|
-
}, children: _jsx(Icon, { name: 'times' }) })) }));
|
|
194
|
-
};
|
|
195
|
-
export default ValueSelector;
|
|
196
|
-
//# sourceMappingURL=ValueSelector.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ValueSelector.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/ValueSelector.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,QAAQ,EACR,SAAS,EACT,MAAM,EAGN,WAAW,EAEX,mBAAmB,EACpB,MAAM,OAAO,CAAC;AAEf,OAAO,EACL,OAAO,EAEP,QAAQ,EACR,mBAAmB,EACnB,qBAAqB,EAGrB,OAAO,EACP,MAAM,EACN,IAAI,EAGL,MAAM,yBAAyB,CAAC;AA4CjC,6EAA6E;AAC7E,MAAM,aAAa,GAAG,CAAwE,EAC5F,MAAM,EACN,aAAa,EACb,UAAU,EACV,GAAG,EACH,QAAQ,EACR,MAAM,EACN,OAAO,EACP,MAAM,EACN,IAAI,EACJ,UAAU,EACV,WAAW,EACX,KAAK,EACL,IAAI,EACJ,WAAW,EACX,MAAM,EACgB,EAAE,EAAE;IAC1B,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IAEpB,MAAM,QAAQ,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAE9C,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAoB,MAAM,CAAC,CAAC;IACxE,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IACnD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAA+C,EAAE,CAAC,CAAC;IACzF,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAChD,EAAE,CACH,CAAC;IACF,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9C,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC7C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GA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\n useState,\n useEffect,\n useRef,\n Dispatch,\n SetStateAction,\n useCallback,\n Ref,\n useImperativeHandle\n} from 'react';\n\nimport {\n useI18n,\n BaseProps,\n ComboBox,\n createStringMatcher,\n useAfterInitialEffect,\n NoChildrenProp,\n ComboBoxProps,\n hasProp,\n Button,\n Icon,\n MenuProps,\n HandleValue\n} from '@pega/cosmos-react-core';\n\nimport {\n LeafCondition,\n ParameterValue,\n ReferenceValue,\n ValueSelection\n} from '../ConditionBuilder.types';\nimport { Comparator } from '../core/types';\n\ninterface ValueSelectorProps<T extends { id: string; possibleValues?: ValueSelection<T> }>\n extends BaseProps,\n NoChildrenProp {\n mode: ComboBoxProps['mode'];\n /** Previous selection */\n values: string[] | string;\n /** Current selected LHS */\n selectedField: T;\n /** Current selected comparator */\n comparator: Comparator;\n /** Rhs for the condition */\n rhs: NonNullable<LeafCondition['rhs']>;\n /** Passed Parameters array for Rhstype PARAMETER */\n parameters: ParameterValue[];\n /** Callback for changes */\n onChange: (selection: string[] | string) => void;\n /** Callback for blur */\n onBlur?: (selection?: string[] | string) => void;\n /** Callback for clear */\n onClear?: () => void;\n /** Used to indicate any errors on the control */\n status?: 'error';\n /** Placeholder text to display in empty control */\n placeholder?: ComboBoxProps['placeholder'];\n /** Custom label for input. Makes label visible if provided. */\n label?: ComboBoxProps['label'];\n /** Guidance text that apppears below the input. */\n info?: ComboBoxProps['info'];\n /** sets status and info */\n setApiError?: Dispatch<SetStateAction<string | null>>;\n /** Imperative handle */\n handle?: Ref<HandleValue>;\n}\n\n/** A control for selecting multiple values using checkboxes in an overlay */\nconst ValueSelector = <F extends object & { id: string; possibleValues?: ValueSelection<F> }>({\n values,\n selectedField,\n comparator,\n rhs,\n onChange,\n onBlur,\n onClear,\n status,\n mode,\n parameters,\n placeholder,\n label,\n info,\n setApiError,\n handle\n}: ValueSelectorProps<F>) => {\n const t = useI18n();\n\n const inputRef = useRef<HTMLDivElement>(null);\n\n const [selections, setSelections] = useState<string[] | string>(values);\n const [filterValue, setFilterValue] = useState('');\n const [options, setOptions] = useState<(string | ParameterValue | ReferenceValue)[]>([]);\n const [filterOptions, setFilterOptions] = useState<(string | ParameterValue | ReferenceValue)[]>(\n []\n );\n const [loading, setLoading] = useState(false);\n const [hasMore, setHasMore] = useState(true);\n const [items, setItems] = useState<MenuProps['items']>([]);\n\n const itemsToRender = (item: (string | ParameterValue | ReferenceValue)[]) => {\n return item.map(option => {\n if (typeof option === 'object') {\n return {\n ...option,\n selected: Array.isArray(selections)\n ? selections.includes(option.id)\n : selections === option.id\n };\n }\n return {\n id: option,\n primary: option,\n selected: Array.isArray(selections) ? selections.includes(option) : selections === option\n };\n });\n };\n\n useEffect(() => {\n const updatedItems = items.map(item => {\n const result = Array.isArray(selections)\n ? selections.includes(item.id)\n : selections === item.id;\n return { ...item, selected: result };\n });\n setItems(updatedItems);\n }, [selections]);\n\n useEffect(() => {\n const matcher = createStringMatcher(filterValue);\n setFilterOptions(\n options.filter(option => {\n if (typeof option === 'object') return matcher.test(option.primary);\n return matcher.test(option);\n })\n );\n }, [filterValue, options]);\n\n useAfterInitialEffect(() => {\n onChange(selections);\n }, [selections]);\n\n useEffect(() => {\n if (!selectedField) {\n return;\n }\n let subscribed = true;\n\n if (hasProp(rhs, 'parameterId')) {\n setOptions(parameters);\n } else if (hasProp(selectedField, 'possibleValues')) {\n const { possibleValues } = selectedField;\n if (typeof possibleValues === 'function') {\n setLoading(true);\n setOptions([]);\n possibleValues({ searchString: filterValue, comparator, lhs: selectedField })\n .then(response => {\n if (!subscribed) return;\n setOptions(response);\n setLoading(false);\n })\n .catch(err => {\n if (err && subscribed) {\n setApiError?.(t('condition_builder_possible_values_error'));\n setOptions([]);\n setLoading(false);\n }\n });\n } else if (Array.isArray(possibleValues)) {\n setOptions(possibleValues);\n } else {\n setOptions([]);\n }\n }\n\n return () => {\n subscribed = false;\n setApiError?.(null);\n };\n }, [filterValue, selectedField.id, comparator]);\n\n useEffect(() => setFilterValue(''), [selectedField, comparator]);\n\n const getSelections = () => {\n if (typeof selections === 'string') {\n let itemLabel;\n if (hasProp(rhs, 'parameterId')) {\n const selectedItem = parameters.find(item => item.id === selections);\n itemLabel = selectedItem !== undefined ? selectedItem.primary : selections;\n } else itemLabel = selections;\n\n return {\n items: { id: selections, text: itemLabel }\n };\n }\n if (selections.length > 0) {\n return {\n items: selections.map(s => {\n const optionLabel = options.find(opt => typeof opt === 'object' && opt.id === s) as\n | ParameterValue\n | ReferenceValue\n | undefined;\n return { id: s, text: optionLabel?.primary ?? s };\n }),\n onRemove: (value: string) => {\n setSelections(cur => {\n const current = cur as string[];\n return current.filter(selection => selection !== value);\n });\n }\n };\n }\n\n return undefined;\n };\n\n useEffect(() => {\n if (filterValue !== '') {\n setItems(itemsToRender(filterOptions.slice(0, 10)));\n } else {\n setItems(itemsToRender(options.slice(0, 10)));\n }\n }, [options, filterOptions]);\n\n const loadMore = useCallback(() => {\n if (!loading) {\n setLoading(true);\n\n let totalItem: (string | ParameterValue | ReferenceValue)[];\n if (filterOptions.length > 0) totalItem = filterOptions;\n else totalItem = options;\n\n const remItems = totalItem.length - items.length;\n let newItemsLength = 10;\n if (remItems <= newItemsLength) {\n setHasMore(false);\n newItemsLength = remItems;\n }\n\n setLoading(false);\n setItems(prev => {\n return [\n ...prev,\n ...itemsToRender(totalItem.slice(items.length, items.length + newItemsLength))\n ];\n });\n }\n }, [options, loading, filterOptions, items, hasMore]);\n\n useImperativeHandle(\n handle,\n () => ({\n clear: () => {\n setSelections([]);\n }\n }),\n []\n );\n\n return (\n <ComboBox\n ref={inputRef}\n mode={mode}\n label={label ?? t('condition_builder_possible_values_label')}\n placeholder={\n placeholder ??\n (mode === 'single-select'\n ? t('condition_builder_single_selection_text_default')\n : t('condition_builder_multi_selection_text_default'))\n }\n value={filterValue}\n onChange={e => {\n setFilterValue(e.target.value);\n setHasMore(true);\n }}\n onBlur={() => {\n onBlur?.(selections);\n setFilterValue('');\n }}\n menu={{\n items,\n onItemClick: id => {\n setFilterValue('');\n if (mode === 'single-select') {\n setSelections(id);\n } else {\n setSelections(cur => {\n const current = cur as string[];\n return current.includes(id)\n ? current.filter(selection => selection !== id)\n : [...cur, id];\n });\n }\n },\n loading,\n loadMore: hasMore ? loadMore : undefined\n }}\n selected={getSelections()}\n status={status}\n info={info}\n actions={\n onClear &&\n selections.length > 0 && (\n <Button\n icon\n variant='simple'\n label={t('clear')}\n onClick={() => {\n setSelections([]);\n onClear();\n if (inputRef.current) {\n const inputEl = inputRef.current.querySelector('input');\n inputEl?.focus();\n }\n }}\n >\n <Icon name='times' />\n </Button>\n )\n }\n />\n );\n};\n\nexport default ValueSelector;\n"]}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { FunctionComponent, Ref } from 'react';
|
|
2
|
-
import { BaseProps, ForwardProps, HandleValue } from '@pega/cosmos-react-core';
|
|
3
|
-
import { FieldType, Comparator, RHSType } from '../core/types';
|
|
4
|
-
import { LeafCondition, Field, DateFunctionsByType } from '../ConditionBuilder.types';
|
|
5
|
-
/**
|
|
6
|
-
* Verifies if the condition has all valid values.
|
|
7
|
-
* NOTES:
|
|
8
|
-
* - This is intended to be used only on conditions emitted by the components in this package.
|
|
9
|
-
* - If a condition is manually constructed outside these components, this utility could miss some malformed conditions.
|
|
10
|
-
* - Also, this does not try to validate if the given `rhs` matches the `lhs`/`comparator`/`validRhsTypes`. Instead, it assumes that the appropriate LHS/Comparator/validRhsTypes must have been already in place for this rhs to be generated.
|
|
11
|
-
*/
|
|
12
|
-
export declare function isValidRhs(rhs: LeafCondition['rhs'], lhs: LeafCondition['lhs'], fields: Field[], fieldType?: FieldType, trimValues?: boolean): boolean;
|
|
13
|
-
/** For a condition with the given comparator and lhs-field-type, determines an appropriate default value for the Rhs */
|
|
14
|
-
export declare function getDefaultRhs(fieldType: FieldType, comparator: Comparator, validRhsTypes: Set<RHSType>, dateFunctions?: DateFunctionsByType): LeafCondition['rhs'];
|
|
15
|
-
export declare function truncateISODateString(dateString: string, fieldType: FieldType): string;
|
|
16
|
-
/** Type definition for the input props of RhsControls */
|
|
17
|
-
interface RhsControlProps extends BaseProps {
|
|
18
|
-
/** Lhs for the condition */
|
|
19
|
-
lhs: LeafCondition['lhs'];
|
|
20
|
-
/** Comparator for the condition */
|
|
21
|
-
comparator: Comparator;
|
|
22
|
-
/** Rhs for the condition */
|
|
23
|
-
rhs: LeafCondition['rhs'];
|
|
24
|
-
/** Metadata (data-model) for the Fields to use in the RHS field-selector */
|
|
25
|
-
fields: Field[];
|
|
26
|
-
/** Callback for any modifications to the Rhs */
|
|
27
|
-
onChange: (rhs: LeafCondition['rhs'], status?: 'error') => void;
|
|
28
|
-
/** Used to enable inline error indicators on invalid inputs */
|
|
29
|
-
indicateErrors: boolean;
|
|
30
|
-
/** Item flow direction */
|
|
31
|
-
itemDirection: 'row' | 'column';
|
|
32
|
-
/** Restricts RHS values to only specified RHS types */
|
|
33
|
-
validRhsTypes: Set<RHSType>;
|
|
34
|
-
/** Passed to enable additional date controls on the RHS, when a DATE_TIME/DATE_ONLY field is selected on the LHS */
|
|
35
|
-
dateFunctions?: DateFunctionsByType;
|
|
36
|
-
/** Imperative handle */
|
|
37
|
-
handle?: Ref<HandleValue>;
|
|
38
|
-
}
|
|
39
|
-
/** A controlled component for controls on a Condition's RHS */
|
|
40
|
-
declare const RhsControls: FunctionComponent<RhsControlProps & ForwardProps>;
|
|
41
|
-
export default RhsControls;
|
|
42
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA6C,GAAG,EAAE,MAAM,OAAO,CAAC;AAE1F,OAAO,EAML,SAAS,EACT,YAAY,EAMZ,WAAW,EACZ,MAAM,yBAAyB,CAAC;AAMjC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,eAAe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