@pega/cosmos-react-condition-builder 3.0.0-dev.9.0 → 3.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/ConditionBuilder/AtomicCondition.d.ts +6 -4
- package/lib/components/ConditionBuilder/AtomicCondition.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/AtomicCondition.js +31 -21
- package/lib/components/ConditionBuilder/AtomicCondition.js.map +1 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.js +15 -41
- package/lib/components/ConditionBuilder/ConditionBuilder.js.map +1 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.styles.d.ts +5 -0
- package/lib/components/ConditionBuilder/ConditionBuilder.styles.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/ConditionBuilder.styles.js +44 -0
- package/lib/components/ConditionBuilder/ConditionBuilder.styles.js.map +1 -0
- package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts +41 -20
- 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.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/FieldCondition.js +12 -12
- package/lib/components/ConditionBuilder/FieldCondition.js.map +1 -1
- package/lib/components/ConditionBuilder/FieldCondition.types.d.ts +11 -4
- package/lib/components/ConditionBuilder/FieldCondition.types.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/FieldCondition.types.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/FieldSelector.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/FieldSelector.js +13 -20
- package/lib/components/ConditionBuilder/RhsControls/FieldSelector.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/NumericInput.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/NumericInput.js +4 -1
- package/lib/components/ConditionBuilder/RhsControls/NumericInput.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.d.ts +5 -3
- package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.js +48 -14
- package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.d.ts +38 -0
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.d.ts.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.js +133 -0
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.js.map +1 -0
- package/lib/components/ConditionBuilder/RhsControls/index.d.ts +5 -2
- package/lib/components/ConditionBuilder/RhsControls/index.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/index.js +89 -28
- package/lib/components/ConditionBuilder/RhsControls/index.js.map +1 -1
- package/lib/components/ConditionBuilder/core/comparators.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/comparators.js +4 -0
- package/lib/components/ConditionBuilder/core/comparators.js.map +1 -1
- package/lib/components/ConditionBuilder/core/evaluator.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/evaluator.js +10 -3
- package/lib/components/ConditionBuilder/core/evaluator.js.map +1 -1
- package/lib/components/ConditionBuilder/core/formatter.d.ts +1 -0
- package/lib/components/ConditionBuilder/core/formatter.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/formatter.js +84 -38
- package/lib/components/ConditionBuilder/core/formatter.js.map +1 -1
- package/lib/components/ConditionBuilder/core/transformer.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/transformer.js +55 -2
- package/lib/components/ConditionBuilder/core/transformer.js.map +1 -1
- package/lib/components/ConditionBuilder/core/types.d.ts +2 -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 +5 -1
- package/lib/components/ConditionBuilder/core/utils.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/utils.js +18 -0
- package/lib/components/ConditionBuilder/core/utils.js.map +1 -1
- package/lib/components/ConditionBuilder/index.d.ts +1 -1
- package/lib/components/ConditionBuilder/index.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/index.js.map +1 -1
- package/lib/components/ConditionInput/ConditionInput.d.ts +6 -0
- package/lib/components/ConditionInput/ConditionInput.d.ts.map +1 -0
- package/lib/components/ConditionInput/ConditionInput.js +215 -0
- package/lib/components/ConditionInput/ConditionInput.js.map +1 -0
- package/lib/components/ConditionInput/ConditionInput.styles.d.ts +5 -0
- package/lib/components/ConditionInput/ConditionInput.styles.d.ts.map +1 -0
- package/lib/components/ConditionInput/ConditionInput.styles.js +27 -0
- package/lib/components/ConditionInput/ConditionInput.styles.js.map +1 -0
- package/lib/components/ConditionInput/ConditionInput.types.d.ts +29 -0
- package/lib/components/ConditionInput/ConditionInput.types.d.ts.map +1 -0
- package/lib/components/ConditionInput/ConditionInput.types.js +2 -0
- package/lib/components/ConditionInput/ConditionInput.types.js.map +1 -0
- package/lib/components/ConditionInput/index.d.ts +3 -0
- package/lib/components/ConditionInput/index.d.ts.map +1 -0
- package/lib/components/ConditionInput/index.js +2 -0
- package/lib/components/ConditionInput/index.js.map +1 -0
- package/lib/components/ConditionInput/utils.d.ts +13 -0
- package/lib/components/ConditionInput/utils.d.ts.map +1 -0
- package/lib/components/ConditionInput/utils.js +56 -0
- package/lib/components/ConditionInput/utils.js.map +1 -0
- package/lib/components/PromotedFilters/ConditionSelector.d.ts +31 -0
- package/lib/components/PromotedFilters/ConditionSelector.d.ts.map +1 -0
- package/lib/components/PromotedFilters/ConditionSelector.js +72 -0
- package/lib/components/PromotedFilters/ConditionSelector.js.map +1 -0
- package/lib/components/PromotedFilters/PromotedFilters.d.ts +11 -0
- package/lib/components/PromotedFilters/PromotedFilters.d.ts.map +1 -0
- package/lib/components/PromotedFilters/PromotedFilters.js +118 -0
- package/lib/components/PromotedFilters/PromotedFilters.js.map +1 -0
- package/lib/components/PromotedFilters/PromotedFilters.styles.d.ts +4 -0
- package/lib/components/PromotedFilters/PromotedFilters.styles.d.ts.map +1 -0
- package/lib/components/PromotedFilters/PromotedFilters.styles.js +26 -0
- package/lib/components/PromotedFilters/PromotedFilters.styles.js.map +1 -0
- package/lib/components/PromotedFilters/PromotedFilters.types.d.ts +31 -0
- package/lib/components/PromotedFilters/PromotedFilters.types.d.ts.map +1 -0
- package/lib/components/PromotedFilters/PromotedFilters.types.js +2 -0
- package/lib/components/PromotedFilters/PromotedFilters.types.js.map +1 -0
- package/lib/components/PromotedFilters/index.d.ts +3 -0
- package/lib/components/PromotedFilters/index.d.ts.map +1 -0
- package/lib/components/PromotedFilters/index.js +2 -0
- package/lib/components/PromotedFilters/index.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -0
- package/lib/index.js.map +1 -1
- package/package.json +8 -4
- package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.d.ts +0 -16
- package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.js +0 -43
- package/lib/components/ConditionBuilder/RhsControls/MultiValueSelector.js.map +0 -1
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { Button, Flex, Icon, Modal, useModalManager, useBreakpoint, useI18n, useModalContext } from '@pega/cosmos-react-core';
|
|
4
|
+
import { splitConditionForBuilder } from '../ConditionBuilder/core/utils';
|
|
5
|
+
import ConditionInput from '../ConditionInput';
|
|
6
|
+
import { StyledFieldGroup } from '../ConditionInput/ConditionInput.styles';
|
|
7
|
+
import { basicFieldMap } from '../ConditionInput/utils';
|
|
8
|
+
import ConditionSelector from './ConditionSelector';
|
|
9
|
+
import { StyledPromotedFilters, StyledClearAllButton, StyledTextWithEllipsis } from './PromotedFilters.styles';
|
|
10
|
+
const PromotedFiltersContent = forwardRef(({ filters, condition, onChange, orientation: orientationProp = 'horizontal' }, ref) => {
|
|
11
|
+
const t = useI18n();
|
|
12
|
+
const isSmallOrAbove = useBreakpoint('sm');
|
|
13
|
+
const orientation = isSmallOrAbove && orientationProp === 'horizontal' ? 'horizontal' : 'vertical';
|
|
14
|
+
// map of Conditions indexed by field name
|
|
15
|
+
const conditionsMap = condition
|
|
16
|
+
? splitConditionForBuilder(condition).rows.reduce((result, item) => {
|
|
17
|
+
const { id, label, ...leaf } = item;
|
|
18
|
+
result[item.lhs.field] = leaf;
|
|
19
|
+
return result;
|
|
20
|
+
}, {})
|
|
21
|
+
: {};
|
|
22
|
+
const createUpdatedCondition = (key, newCondition) => {
|
|
23
|
+
if (newCondition) {
|
|
24
|
+
conditionsMap[key] = newCondition;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
delete conditionsMap[key];
|
|
28
|
+
}
|
|
29
|
+
return Object.values(conditionsMap).length === 0
|
|
30
|
+
? undefined
|
|
31
|
+
: {
|
|
32
|
+
AND: Object.values(conditionsMap).map(c => {
|
|
33
|
+
return { condition: c };
|
|
34
|
+
})
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
return (_jsx(Flex, { container: {
|
|
38
|
+
gap: 2,
|
|
39
|
+
direction: orientation === 'vertical' ? 'column' : 'row',
|
|
40
|
+
wrap: 'wrap'
|
|
41
|
+
}, ref: ref, children: filters.map(({ field, mode, label, predefinedConditions }) => {
|
|
42
|
+
if (mode !== 'predefined')
|
|
43
|
+
return (_jsx(ConditionInput, { field: field, mode: mode, label: label ?? field.name, condition: conditionsMap[field.name], flat: orientation === 'vertical', onChange: (newCondition) => {
|
|
44
|
+
onChange(createUpdatedCondition(field.name, newCondition));
|
|
45
|
+
} }, field.name));
|
|
46
|
+
const selector = (_jsx(ConditionSelector, { label: label ?? field.name, labelHidden: orientation === 'vertical', fields: [
|
|
47
|
+
{
|
|
48
|
+
id: field.name,
|
|
49
|
+
type: basicFieldMap[field.type],
|
|
50
|
+
primary: label || field.name
|
|
51
|
+
}
|
|
52
|
+
], condition: conditionsMap[field.name], conditions: predefinedConditions ?? [], onChange: (newCondition) => {
|
|
53
|
+
onChange(createUpdatedCondition(field.name, newCondition));
|
|
54
|
+
}, onClear: orientation === 'horizontal'
|
|
55
|
+
? () => onChange(createUpdatedCondition(field.name, undefined))
|
|
56
|
+
: undefined }, field.name));
|
|
57
|
+
return orientation === 'vertical' ? (_jsx(StyledFieldGroup, { name: label, collapsible: true, actions: [
|
|
58
|
+
{
|
|
59
|
+
id: 'clear',
|
|
60
|
+
text: t('clear'),
|
|
61
|
+
onClick: () => onChange(createUpdatedCondition(field.name, undefined))
|
|
62
|
+
}
|
|
63
|
+
], children: selector }, field.name)) : (selector);
|
|
64
|
+
}) }));
|
|
65
|
+
});
|
|
66
|
+
const FilterModal = ({ filters, condition, onApply }) => {
|
|
67
|
+
const t = useI18n();
|
|
68
|
+
const { dismiss } = useModalContext();
|
|
69
|
+
const [newCondition, setNewCondition] = useState(condition);
|
|
70
|
+
const onApplyClick = useCallback(() => {
|
|
71
|
+
onApply?.(newCondition);
|
|
72
|
+
dismiss();
|
|
73
|
+
}, [newCondition, onApply]);
|
|
74
|
+
const actions = (_jsx(Button, { variant: 'primary', onClick: onApplyClick, children: t('apply') }));
|
|
75
|
+
return (_jsxs(Modal, { heading: t('filters'), actions: actions, stretch: true, children: [_jsx(Flex, { container: { justify: 'end' }, children: _jsx(StyledClearAllButton, { variant: 'simple', onClick: () => {
|
|
76
|
+
setNewCondition(undefined);
|
|
77
|
+
}, children: t('clear_all') }) }), _jsx(PromotedFiltersContent, { filters: filters, condition: newCondition, onChange: setNewCondition, orientation: 'vertical' })] }));
|
|
78
|
+
};
|
|
79
|
+
export const PromotedFilters = forwardRef(({ filters, condition, onChange, orientation = 'horizontal' }, ref) => {
|
|
80
|
+
const t = useI18n();
|
|
81
|
+
const isSmallOrAbove = useBreakpoint('sm');
|
|
82
|
+
const { create } = useModalManager();
|
|
83
|
+
const modalMethods = useRef();
|
|
84
|
+
// map of Conditions indexed by field name
|
|
85
|
+
const conditionsCount = condition ? splitConditionForBuilder(condition).rows.length : undefined;
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
modalMethods.current?.update({
|
|
88
|
+
filters,
|
|
89
|
+
condition
|
|
90
|
+
});
|
|
91
|
+
}, [filters, condition]);
|
|
92
|
+
const openFiltersModal = () => {
|
|
93
|
+
modalMethods.current = create(FilterModal, {
|
|
94
|
+
filters,
|
|
95
|
+
condition,
|
|
96
|
+
onApply: onChange
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
return (_jsx(Flex, { as: StyledPromotedFilters, container: {
|
|
100
|
+
alignItems: orientation === 'horizontal' && isSmallOrAbove ? 'start' : undefined,
|
|
101
|
+
justify: 'between',
|
|
102
|
+
direction: !isSmallOrAbove || orientation === 'horizontal' ? 'row' : 'column',
|
|
103
|
+
pad: 2,
|
|
104
|
+
gap: 2
|
|
105
|
+
}, ref: ref, children: isSmallOrAbove ? (_jsxs(_Fragment, { children: [orientation === 'vertical' && (_jsxs(Flex, { container: {
|
|
106
|
+
justify: 'between',
|
|
107
|
+
alignItems: 'center',
|
|
108
|
+
pad: [0, 0, 1, 0]
|
|
109
|
+
}, children: [_jsx(StyledTextWithEllipsis, { variant: 'h3', children: t('filters') }), _jsx(Button, { variant: 'simple', onClick: () => {
|
|
110
|
+
onChange();
|
|
111
|
+
}, children: t('clear_all') })] })), _jsx(PromotedFiltersContent, { filters: filters, onChange: onChange, condition: condition, orientation: orientation, ref: ref }), orientation === 'horizontal' && (_jsx("div", { children: _jsx(StyledClearAllButton, { variant: 'simple', onClick: () => {
|
|
112
|
+
onChange();
|
|
113
|
+
}, children: t('promoted_filters_clear_all_button_label') }) }))] })) : (_jsxs(_Fragment, { children: [_jsx(Button, { type: 'button', variant: 'text', onClick: openFiltersModal, children: _jsxs(Flex, { container: { alignItems: 'center', gap: 0.5 }, forwardedAs: 'span', children: [_jsx(Icon, { name: 'filter' }), _jsxs("span", { children: [t('filters'), conditionsCount && `\u00a0(${conditionsCount})`] })] }) }), _jsx(Button, { variant: 'simple', onClick: () => {
|
|
114
|
+
onChange();
|
|
115
|
+
}, children: t('clear_all') })] })) }));
|
|
116
|
+
});
|
|
117
|
+
export default PromotedFilters;
|
|
118
|
+
//# sourceMappingURL=PromotedFilters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PromotedFilters.js","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAGV,WAAW,EACX,SAAS,EACT,MAAM,EACN,QAAQ,EACT,MAAM,OAAO,CAAC;AAEf,OAAO,EACL,MAAM,EACN,IAAI,EAEJ,IAAI,EACJ,KAAK,EAEL,eAAe,EACf,aAAa,EACb,OAAO,EACP,eAAe,EAChB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,0BAA0B,CAAC;AAOlC,MAAM,sBAAsB,GAA2D,UAAU,CAC/F,CACE,EACE,OAAO,EACP,SAAS,EACT,QAAQ,EACR,WAAW,EAAE,eAAe,GAAG,YAAY,EACL,EACxC,GAAgC,EAChC,EAAE;IACF,MAAM,CAAC,GAAG,OAAO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AAC,MAAM,IAAC,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAC,MAAM,EAAC,OAAO,EAAE,gBAAgB,YAC5D,MAAC,IAAI,IAAC,SAAS,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,WAAW,EAAC,MAAM,aACrE,KAAC,IAAI,IAAC,IAAI,EAAC,QAAQ,GAAG,EACtB,2BACG,CAAC,CAAC,SAAS,CAAC,EACZ,eAAe,IAAI,UAAU,eAAe,GAAG,IAC3C,IACF,GACA,EACT,KAAC,MAAM,IACL,OAAO,EAAC,QAAQ,EAChB,OAAO,EAAE,GAAG,EAAE;wBACZ,QAAQ,EAAE,CAAC;oBACb,CAAC,YAEA,CAAC,CAAC,WAAW,CAAC,GACR,IACR,CACJ,GACI,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n PropsWithoutRef,\n useCallback,\n useEffect,\n useRef,\n useState\n} from 'react';\n\nimport {\n Button,\n Flex,\n ForwardProps,\n Icon,\n Modal,\n ModalMethods,\n useModalManager,\n useBreakpoint,\n useI18n,\n useModalContext\n} from '@pega/cosmos-react-core';\n\nimport { Condition, LeafCondition } from '../ConditionBuilder/ConditionBuilder.types';\nimport { splitConditionForBuilder } from '../ConditionBuilder/core/utils';\nimport ConditionInput from '../ConditionInput';\nimport { StyledFieldGroup } from '../ConditionInput/ConditionInput.styles';\nimport { basicFieldMap } from '../ConditionInput/utils';\n\nimport ConditionSelector from './ConditionSelector';\nimport { PromotedFiltersProps } from './PromotedFilters.types';\nimport {\n StyledPromotedFilters,\n StyledClearAllButton,\n StyledTextWithEllipsis\n} from './PromotedFilters.styles';\n\nexport interface FilterModalProps extends Pick<PromotedFiltersProps, 'filters' | 'condition'> {\n /** Callback fired on apply of any of the filters */\n onApply?: (condition: Condition | undefined) => void;\n}\n\nconst PromotedFiltersContent: FunctionComponent<PromotedFiltersProps & ForwardProps> = forwardRef(\n (\n {\n filters,\n condition,\n onChange,\n orientation: orientationProp = 'horizontal'\n }: PropsWithoutRef<PromotedFiltersProps>,\n ref: PromotedFiltersProps['ref']\n ) => {\n const t = useI18n();\n const isSmallOrAbove = useBreakpoint('sm');\n const orientation =\n isSmallOrAbove && orientationProp === 'horizontal' ? 'horizontal' : 'vertical';\n\n // map of Conditions indexed by field name\n const conditionsMap = condition\n ? splitConditionForBuilder(condition).rows.reduce(\n (result: { [key: string]: LeafCondition }, item) => {\n const { id, label, ...leaf } = item;\n result[item.lhs.field] = leaf;\n return result;\n },\n {}\n )\n : {};\n\n const createUpdatedCondition = (key: string, newCondition?: LeafCondition) => {\n if (newCondition) {\n conditionsMap[key] = newCondition;\n } else {\n delete conditionsMap[key];\n }\n\n return Object.values(conditionsMap).length === 0\n ? undefined\n : {\n AND: Object.values(conditionsMap).map(c => {\n return { condition: c } as Condition;\n })\n };\n };\n\n return (\n <Flex\n container={{\n gap: 2,\n direction: orientation === 'vertical' ? 'column' : 'row',\n wrap: 'wrap'\n }}\n ref={ref}\n >\n {filters.map(({ field, mode, label, predefinedConditions }) => {\n if (mode !== 'predefined')\n return (\n <ConditionInput\n key={field.name}\n field={field}\n mode={mode}\n label={label ?? field.name}\n condition={conditionsMap[field.name]}\n flat={orientation === 'vertical'}\n onChange={(newCondition?: LeafCondition) => {\n onChange(createUpdatedCondition(field.name, newCondition));\n }}\n />\n );\n\n const selector = (\n <ConditionSelector\n key={field.name}\n label={label ?? field.name}\n labelHidden={orientation === 'vertical'}\n fields={[\n {\n id: field.name,\n type: basicFieldMap[field.type],\n primary: label || field.name\n }\n ]}\n condition={conditionsMap[field.name]}\n conditions={predefinedConditions ?? []}\n onChange={(newCondition?: LeafCondition) => {\n onChange(createUpdatedCondition(field.name, newCondition));\n }}\n onClear={\n orientation === 'horizontal'\n ? () => onChange(createUpdatedCondition(field.name, undefined))\n : undefined\n }\n />\n );\n\n return orientation === 'vertical' ? (\n <StyledFieldGroup\n key={field.name}\n name={label}\n collapsible\n actions={[\n {\n id: 'clear',\n text: t('clear'),\n onClick: () => onChange(createUpdatedCondition(field.name, undefined))\n }\n ]}\n >\n {selector}\n </StyledFieldGroup>\n ) : (\n selector\n );\n })}\n </Flex>\n );\n }\n);\n\nconst FilterModal = ({ filters, condition, onApply }: FilterModalProps) => {\n const t = useI18n();\n\n const { dismiss } = useModalContext();\n const [newCondition, setNewCondition] = useState<Condition | undefined>(condition);\n\n const onApplyClick = useCallback(() => {\n onApply?.(newCondition);\n dismiss();\n }, [newCondition, onApply]);\n\n const actions = (\n <Button variant='primary' onClick={onApplyClick}>\n {t('apply')}\n </Button>\n );\n\n return (\n <Modal heading={t('filters')} actions={actions} stretch>\n <Flex container={{ justify: 'end' }}>\n <StyledClearAllButton\n variant='simple'\n onClick={() => {\n setNewCondition(undefined);\n }}\n >\n {t('clear_all')}\n </StyledClearAllButton>\n </Flex>\n\n <PromotedFiltersContent\n filters={filters}\n condition={newCondition}\n onChange={setNewCondition}\n orientation='vertical'\n />\n </Modal>\n );\n};\n\nexport const PromotedFilters: FunctionComponent<PromotedFiltersProps & ForwardProps> = forwardRef(\n (\n {\n filters,\n condition,\n onChange,\n orientation = 'horizontal'\n }: PropsWithoutRef<PromotedFiltersProps>,\n ref: PromotedFiltersProps['ref']\n ) => {\n const t = useI18n();\n\n const isSmallOrAbove = useBreakpoint('sm');\n\n const { create } = useModalManager();\n const modalMethods = useRef<ModalMethods<FilterModalProps>>();\n\n // map of Conditions indexed by field name\n const conditionsCount = condition ? splitConditionForBuilder(condition).rows.length : undefined;\n\n useEffect(() => {\n modalMethods.current?.update({\n filters,\n condition\n });\n }, [filters, condition]);\n\n const openFiltersModal = () => {\n modalMethods.current = create(FilterModal, {\n filters,\n condition,\n onApply: onChange\n });\n };\n\n return (\n <Flex\n as={StyledPromotedFilters}\n container={{\n alignItems: orientation === 'horizontal' && isSmallOrAbove ? 'start' : undefined,\n justify: 'between',\n direction: !isSmallOrAbove || orientation === 'horizontal' ? 'row' : 'column',\n pad: 2,\n gap: 2\n }}\n ref={ref}\n >\n {isSmallOrAbove ? (\n <>\n {orientation === 'vertical' && (\n <Flex\n container={{\n justify: 'between',\n alignItems: 'center',\n pad: [0, 0, 1, 0]\n }}\n >\n <StyledTextWithEllipsis variant='h3'>{t('filters')}</StyledTextWithEllipsis>\n <Button\n variant='simple'\n onClick={() => {\n onChange();\n }}\n >\n {t('clear_all')}\n </Button>\n </Flex>\n )}\n\n <PromotedFiltersContent\n filters={filters}\n onChange={onChange}\n condition={condition}\n orientation={orientation}\n ref={ref}\n />\n\n {orientation === 'horizontal' && (\n <div>\n <StyledClearAllButton\n variant='simple'\n onClick={() => {\n onChange();\n }}\n >\n {t('promoted_filters_clear_all_button_label')}\n </StyledClearAllButton>\n </div>\n )}\n </>\n ) : (\n <>\n <Button type='button' variant='text' onClick={openFiltersModal}>\n <Flex container={{ alignItems: 'center', gap: 0.5 }} forwardedAs='span'>\n <Icon name='filter' />\n <span>\n {t('filters')}\n {conditionsCount && `\\u00a0(${conditionsCount})`}\n </span>\n </Flex>\n </Button>\n <Button\n variant='simple'\n onClick={() => {\n onChange();\n }}\n >\n {t('clear_all')}\n </Button>\n </>\n )}\n </Flex>\n );\n }\n);\n\nexport default PromotedFilters;\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const StyledPromotedFilters: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
2
|
+
export declare const StyledClearAllButton: import("styled-components").StyledComponent<import("react").FunctionComponent<import("@pega/cosmos-react-core").ButtonProps & import("@pega/cosmos-react-core").ForwardProps>, import("styled-components").DefaultTheme, {}, never>;
|
|
3
|
+
export declare const StyledTextWithEllipsis: import("styled-components").StyledComponent<import("react").FunctionComponent<import("@pega/cosmos-react-core").TextProps & import("@pega/cosmos-react-core").ForwardProps>, import("styled-components").DefaultTheme, {}, never>;
|
|
4
|
+
//# sourceMappingURL=PromotedFilters.styles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PromotedFilters.styles.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.styles.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,qBAAqB,yGAKhC,CAAC;AAIH,eAAO,MAAM,oBAAoB,qOAOhC,CAAC;AAIF,eAAO,MAAM,sBAAsB,mOAIlC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import styled, { css } from 'styled-components';
|
|
2
|
+
import { defaultThemeProp, Button, Text } from '@pega/cosmos-react-core';
|
|
3
|
+
import { StyledModalChildrenWrap } from '@pega/cosmos-react-core/lib/components/Modal/Modal.styles';
|
|
4
|
+
export const StyledPromotedFilters = styled.div(({ theme }) => {
|
|
5
|
+
return css `
|
|
6
|
+
border-radius: ${theme.components.card['border-radius']};
|
|
7
|
+
background-color: ${theme.base.palette['secondary-background']};
|
|
8
|
+
`;
|
|
9
|
+
});
|
|
10
|
+
StyledPromotedFilters.defaultProps = defaultThemeProp;
|
|
11
|
+
export const StyledClearAllButton = styled(Button) `
|
|
12
|
+
margin: 1.125rem 0 0.625rem;
|
|
13
|
+
white-space: nowrap;
|
|
14
|
+
|
|
15
|
+
${StyledModalChildrenWrap} & {
|
|
16
|
+
margin-top: 0;
|
|
17
|
+
}
|
|
18
|
+
`;
|
|
19
|
+
StyledClearAllButton.defaultProps = defaultThemeProp;
|
|
20
|
+
export const StyledTextWithEllipsis = styled(Text) `
|
|
21
|
+
overflow: hidden;
|
|
22
|
+
white-space: nowrap;
|
|
23
|
+
text-overflow: ellipsis;
|
|
24
|
+
`;
|
|
25
|
+
StyledTextWithEllipsis.defaultProps = defaultThemeProp;
|
|
26
|
+
//# sourceMappingURL=PromotedFilters.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PromotedFilters.styles.js","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.styles.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2DAA2D,CAAC;AAEpG,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IAC5D,OAAO,GAAG,CAAA;qBACS,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC;wBACnC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC;GAC/D,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,qBAAqB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAEtD,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;;;;IAI9C,uBAAuB;;;CAG1B,CAAC;AAEF,oBAAoB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAErD,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;;;;CAIjD,CAAC;AAEF,sBAAsB,CAAC,YAAY,GAAG,gBAAgB,CAAC","sourcesContent":["import styled, { css } from 'styled-components';\n\nimport { defaultThemeProp, Button, Text } from '@pega/cosmos-react-core';\nimport { StyledModalChildrenWrap } from '@pega/cosmos-react-core/lib/components/Modal/Modal.styles';\n\nexport const StyledPromotedFilters = styled.div(({ theme }) => {\n return css`\n border-radius: ${theme.components.card['border-radius']};\n background-color: ${theme.base.palette['secondary-background']};\n `;\n});\n\nStyledPromotedFilters.defaultProps = defaultThemeProp;\n\nexport const StyledClearAllButton = styled(Button)`\n margin: 1.125rem 0 0.625rem;\n white-space: nowrap;\n\n ${StyledModalChildrenWrap} & {\n margin-top: 0;\n }\n`;\n\nStyledClearAllButton.defaultProps = defaultThemeProp;\n\nexport const StyledTextWithEllipsis = styled(Text)`\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n`;\n\nStyledTextWithEllipsis.defaultProps = defaultThemeProp;\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Ref } from 'react';
|
|
2
|
+
import { BaseProps, NoChildrenProp } from '@pega/cosmos-react-core';
|
|
3
|
+
import type { Condition, LeafCondition } from '../ConditionBuilder/ConditionBuilder.types';
|
|
4
|
+
import type { ConditionInputMode, ConditionField } from '../ConditionInput/ConditionInput.types';
|
|
5
|
+
export interface PromotedFilter {
|
|
6
|
+
/** Definition of the field to be filtered. */
|
|
7
|
+
field: ConditionField;
|
|
8
|
+
/** Display mode. */
|
|
9
|
+
mode: ConditionInputMode;
|
|
10
|
+
/** Label for the filter. */
|
|
11
|
+
label?: string;
|
|
12
|
+
/** List of possible predefined Conditions */
|
|
13
|
+
predefinedConditions?: {
|
|
14
|
+
id: string;
|
|
15
|
+
value: LeafCondition;
|
|
16
|
+
label?: string;
|
|
17
|
+
}[];
|
|
18
|
+
}
|
|
19
|
+
export interface PromotedFiltersProps extends BaseProps, NoChildrenProp {
|
|
20
|
+
/** Configuration of filters for every field that has been defined as promoted. */
|
|
21
|
+
filters: PromotedFilter[];
|
|
22
|
+
/** A value representing the current condition state. */
|
|
23
|
+
condition?: Condition;
|
|
24
|
+
/** Orientation mode. The default is horizontal. */
|
|
25
|
+
orientation?: 'vertical' | 'horizontal';
|
|
26
|
+
/** Callback fired on change of any of the filters. */
|
|
27
|
+
onChange: (condition?: Condition) => void;
|
|
28
|
+
/** Ref for the wrapping element. */
|
|
29
|
+
ref?: Ref<HTMLDivElement>;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=PromotedFilters.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PromotedFilters.types.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEpE,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAC3F,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAEjG,MAAM,WAAW,cAAc;IAC7B,8CAA8C;IAC9C,KAAK,EAAE,cAAc,CAAC;IACtB,oBAAoB;IACpB,IAAI,EAAE,kBAAkB,CAAC;IACzB,4BAA4B;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6CAA6C;IAC7C,oBAAoB,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,aAAa,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC/E;AAED,MAAM,WAAW,oBAAqB,SAAQ,SAAS,EAAE,cAAc;IACrE,kFAAkF;IAClF,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,wDAAwD;IACxD,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,mDAAmD;IACnD,WAAW,CAAC,EAAE,UAAU,GAAG,YAAY,CAAC;IACxC,sDAAsD;IACtD,QAAQ,EAAE,CAAC,SAAS,CAAC,EAAE,SAAS,KAAK,IAAI,CAAC;IAC1C,oCAAoC;IACpC,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PromotedFilters.types.js","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.types.ts"],"names":[],"mappings":"","sourcesContent":["import { Ref } from 'react';\n\nimport { BaseProps, NoChildrenProp } from '@pega/cosmos-react-core';\n\nimport type { Condition, LeafCondition } from '../ConditionBuilder/ConditionBuilder.types';\nimport type { ConditionInputMode, ConditionField } from '../ConditionInput/ConditionInput.types';\n\nexport interface PromotedFilter {\n /** Definition of the field to be filtered. */\n field: ConditionField;\n /** Display mode. */\n mode: ConditionInputMode;\n /** Label for the filter. */\n label?: string;\n /** List of possible predefined Conditions */\n predefinedConditions?: { id: string; value: LeafCondition; label?: string }[];\n}\n\nexport interface PromotedFiltersProps extends BaseProps, NoChildrenProp {\n /** Configuration of filters for every field that has been defined as promoted. */\n filters: PromotedFilter[];\n /** A value representing the current condition state. */\n condition?: Condition;\n /** Orientation mode. The default is horizontal. */\n orientation?: 'vertical' | 'horizontal';\n /** Callback fired on change of any of the filters. */\n onChange: (condition?: Condition) => void;\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLDivElement>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/PromotedFilters/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC","sourcesContent":["export { default } from './PromotedFilters';\nexport { PromotedFiltersProps, PromotedFilter } from './PromotedFilters.types';\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
export { default as ConditionBuilder } from './components/ConditionBuilder';
|
|
2
2
|
export * from './components/ConditionBuilder';
|
|
3
|
+
export { default as ConditionInput } from './components/ConditionInput';
|
|
4
|
+
export * from './components/ConditionInput';
|
|
5
|
+
export { default as PromotedFilters } from './components/PromotedFilters';
|
|
6
|
+
export * from './components/PromotedFilters';
|
|
3
7
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,cAAc,+BAA+B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,cAAc,+BAA+B,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,6BAA6B,CAAC;AACxE,cAAc,6BAA6B,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC1E,cAAc,8BAA8B,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
// This file is autogenerated. Any changes will be overwritten.
|
|
2
2
|
export { default as ConditionBuilder } from './components/ConditionBuilder';
|
|
3
3
|
export * from './components/ConditionBuilder';
|
|
4
|
+
export { default as ConditionInput } from './components/ConditionInput';
|
|
5
|
+
export * from './components/ConditionInput';
|
|
6
|
+
export { default as PromotedFilters } from './components/PromotedFilters';
|
|
7
|
+
export * from './components/PromotedFilters';
|
|
4
8
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,cAAc,+BAA+B,CAAC","sourcesContent":["// This file is autogenerated. Any changes will be overwritten.\nexport { default as ConditionBuilder } from './components/ConditionBuilder';\nexport * from './components/ConditionBuilder';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,cAAc,+BAA+B,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,6BAA6B,CAAC;AACxE,cAAc,6BAA6B,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC1E,cAAc,8BAA8B,CAAC","sourcesContent":["// This file is autogenerated. Any changes will be overwritten.\nexport { default as ConditionBuilder } from './components/ConditionBuilder';\nexport * from './components/ConditionBuilder';\nexport { default as ConditionInput } from './components/ConditionInput';\nexport * from './components/ConditionInput';\nexport { default as PromotedFilters } from './components/PromotedFilters';\nexport * from './components/PromotedFilters';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pega/cosmos-react-condition-builder",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-rc.2",
|
|
4
4
|
"author": "Pegasystems",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"repository": {
|
|
@@ -16,17 +16,18 @@
|
|
|
16
16
|
"lib"
|
|
17
17
|
],
|
|
18
18
|
"sideEffects": [
|
|
19
|
+
"./src/components/ConditionBuilder/core/extendDayJs.ts",
|
|
19
20
|
"./lib/components/ConditionBuilder/core/extendDayJs.js"
|
|
20
21
|
],
|
|
21
22
|
"scripts": {
|
|
22
23
|
"build": "tsc -b"
|
|
23
24
|
},
|
|
24
25
|
"dependencies": {
|
|
25
|
-
"@pega/cosmos-react-core": "3.0.0-
|
|
26
|
+
"@pega/cosmos-react-core": "3.0.0-rc.2",
|
|
26
27
|
"@types/react": "^16.14.24 || ^17.0.38",
|
|
27
28
|
"@types/react-dom": "^16.9.14 || ^17.0.11",
|
|
28
29
|
"@types/styled-components": "^5.1.7",
|
|
29
|
-
"dayjs": "1.
|
|
30
|
+
"dayjs": "^1.10.7",
|
|
30
31
|
"polished": "^4.1.0",
|
|
31
32
|
"react": "^16.14.0 || ^17.0.0",
|
|
32
33
|
"react-dom": "^16.14.0 || ^17.0.0",
|
|
@@ -40,7 +41,10 @@
|
|
|
40
41
|
"@storybook/addons": "^6.4.19",
|
|
41
42
|
"@storybook/react": "^6.4.19",
|
|
42
43
|
"@storybook/theming": "^6.4.19",
|
|
44
|
+
"@testing-library/jest-dom": "^5.16.2",
|
|
45
|
+
"@testing-library/react": "^12.1.3",
|
|
46
|
+
"@testing-library/user-event": "^13.5.0",
|
|
43
47
|
"enzyme": "^3.11.0",
|
|
44
|
-
"typescript": "~4.
|
|
48
|
+
"typescript": "~4.7.2"
|
|
45
49
|
}
|
|
46
50
|
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { FunctionComponent } from 'react';
|
|
2
|
-
import { BaseProps, ForwardProps, NoChildrenProp } from '@pega/cosmos-react-core';
|
|
3
|
-
interface MultiSelectorProps extends BaseProps, NoChildrenProp {
|
|
4
|
-
/** Previous selection */
|
|
5
|
-
values: string[];
|
|
6
|
-
/** Options for the selector */
|
|
7
|
-
options: string[];
|
|
8
|
-
/** Callback for changes */
|
|
9
|
-
onChange: (selection: string[]) => void;
|
|
10
|
-
/** Used to indicate any errors on the control */
|
|
11
|
-
status?: 'error';
|
|
12
|
-
}
|
|
13
|
-
/** A control for selecting multiple values using checkboxes in an overlay */
|
|
14
|
-
declare const MultiValueSelector: FunctionComponent<MultiSelectorProps & ForwardProps>;
|
|
15
|
-
export default MultiValueSelector;
|
|
16
|
-
//# sourceMappingURL=MultiValueSelector.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MultiValueSelector.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/MultiValueSelector.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAqB,MAAM,OAAO,CAAC;AAE7D,OAAO,EAEL,SAAS,EACT,YAAY,EAIZ,cAAc,EACf,MAAM,yBAAyB,CAAC;AAEjC,UAAU,kBAAmB,SAAQ,SAAS,EAAE,cAAc;IAC5D,yBAAyB;IACzB,MAAM,EAAE,MAAM,EAAE,CAAC;IAEjB,+BAA+B;IAC/B,OAAO,EAAE,MAAM,EAAE,CAAC;IAElB,2BAA2B;IAC3B,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAExC,iDAAiD;IACjD,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,6EAA6E;AAC7E,QAAA,MAAM,kBAAkB,EAAE,iBAAiB,CAAC,kBAAkB,GAAG,YAAY,CAgE5E,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useState, useMemo } from 'react';
|
|
3
|
-
import { useI18n, ComboBox, createStringMatcher, useAfterInitialEffect } from '@pega/cosmos-react-core';
|
|
4
|
-
/** A control for selecting multiple values using checkboxes in an overlay */
|
|
5
|
-
const MultiValueSelector = ({ values, options, onChange, status }) => {
|
|
6
|
-
const t = useI18n();
|
|
7
|
-
const [selections, setSelections] = useState(values);
|
|
8
|
-
const [filterValue, setFilterValue] = useState('');
|
|
9
|
-
const itemsToRender = useMemo(() => {
|
|
10
|
-
let opts = options;
|
|
11
|
-
if (filterValue) {
|
|
12
|
-
const matcher = createStringMatcher(filterValue, 'boundary');
|
|
13
|
-
opts = opts.filter(opt => matcher.test(opt));
|
|
14
|
-
}
|
|
15
|
-
return opts.map(option => {
|
|
16
|
-
return {
|
|
17
|
-
id: option,
|
|
18
|
-
primary: option,
|
|
19
|
-
selected: selections.includes(option)
|
|
20
|
-
};
|
|
21
|
-
});
|
|
22
|
-
}, [options, filterValue, selections]);
|
|
23
|
-
useAfterInitialEffect(() => {
|
|
24
|
-
onChange(selections);
|
|
25
|
-
}, [selections]);
|
|
26
|
-
return (_jsx(ComboBox, { mode: 'multi-select', label: t('condition_builder_possible_values_label'), labelHidden: true, placeholder: t('condition_builder_selection_text_default'), value: filterValue, onChange: e => {
|
|
27
|
-
setFilterValue(e.target.value);
|
|
28
|
-
}, menu: {
|
|
29
|
-
items: itemsToRender,
|
|
30
|
-
onItemClick: option => {
|
|
31
|
-
setSelections(cur => cur.includes(option) ? cur.filter(selection => selection !== option) : [...cur, option]);
|
|
32
|
-
}
|
|
33
|
-
}, selected: selections.length > 0
|
|
34
|
-
? {
|
|
35
|
-
items: selections.map(s => ({ id: s, text: s })),
|
|
36
|
-
onRemove: value => {
|
|
37
|
-
setSelections(cur => cur.filter(selection => selection !== value));
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
: undefined, status: status, info: status === 'error' ? t('condition_builder_empty_selection_error_text') : undefined }));
|
|
41
|
-
};
|
|
42
|
-
export default MultiValueSelector;
|
|
43
|
-
//# sourceMappingURL=MultiValueSelector.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MultiValueSelector.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/MultiValueSelector.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAqB,QAAQ,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAE7D,OAAO,EACL,OAAO,EAGP,QAAQ,EACR,mBAAmB,EACnB,qBAAqB,EAEtB,MAAM,yBAAyB,CAAC;AAgBjC,6EAA6E;AAC7E,MAAM,kBAAkB,GAAyD,CAAC,EAChF,MAAM,EACN,OAAO,EACP,QAAQ,EACR,MAAM,EACa,EAAE,EAAE;IACvB,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IAEpB,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IACrD,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IAEnD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,CAAC,CAAC,CAAC,GAAG,GAAG,EAAE,MAAM,CAAC,CACxF,CAAC;YACJ,CAAC;SACF,EACD,QAAQ,EACN,UAAU,CAAC,MAAM,GAAG,CAAC;YACnB,CAAC,CAAC;gBACE,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;gBAChD,QAAQ,EAAE,KAAK,CAAC,EAAE;oBAChB,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC;gBACrE,CAAC;aACF;YACH,CAAC,CAAC,SAAS,EAEf,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,8CAA8C,CAAC,CAAC,CAAC,CAAC,SAAS,GACxF,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,kBAAkB,CAAC","sourcesContent":["import { FunctionComponent, useState, useMemo } from 'react';\n\nimport {\n useI18n,\n BaseProps,\n ForwardProps,\n ComboBox,\n createStringMatcher,\n useAfterInitialEffect,\n NoChildrenProp\n} from '@pega/cosmos-react-core';\n\ninterface MultiSelectorProps extends BaseProps, NoChildrenProp {\n /** Previous selection */\n values: string[];\n\n /** Options for the selector */\n options: string[];\n\n /** Callback for changes */\n onChange: (selection: string[]) => void;\n\n /** Used to indicate any errors on the control */\n status?: 'error';\n}\n\n/** A control for selecting multiple values using checkboxes in an overlay */\nconst MultiValueSelector: FunctionComponent<MultiSelectorProps & ForwardProps> = ({\n values,\n options,\n onChange,\n status\n}: MultiSelectorProps) => {\n const t = useI18n();\n\n const [selections, setSelections] = useState(values);\n const [filterValue, setFilterValue] = useState('');\n\n const itemsToRender = useMemo(() => {\n let opts = options;\n\n if (filterValue) {\n const matcher = createStringMatcher(filterValue, 'boundary');\n opts = opts.filter(opt => matcher.test(opt));\n }\n\n return opts.map(option => {\n return {\n id: option,\n primary: option,\n selected: selections.includes(option)\n };\n });\n }, [options, filterValue, selections]);\n\n useAfterInitialEffect(() => {\n onChange(selections);\n }, [selections]);\n\n return (\n <ComboBox\n mode='multi-select'\n label={t('condition_builder_possible_values_label')}\n labelHidden\n placeholder={t('condition_builder_selection_text_default')}\n value={filterValue}\n onChange={e => {\n setFilterValue(e.target.value);\n }}\n menu={{\n items: itemsToRender,\n onItemClick: option => {\n setSelections(cur =>\n cur.includes(option) ? cur.filter(selection => selection !== option) : [...cur, option]\n );\n }\n }}\n selected={\n selections.length > 0\n ? {\n items: selections.map(s => ({ id: s, text: s })),\n onRemove: value => {\n setSelections(cur => cur.filter(selection => selection !== value));\n }\n }\n : undefined\n }\n status={status}\n info={status === 'error' ? t('condition_builder_empty_selection_error_text') : undefined}\n />\n );\n};\n\nexport default MultiValueSelector;\n"]}
|