@pega/cosmos-react-condition-builder 4.0.0-dev.6.1 → 4.0.0-dev.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/ConditionBuilder/AtomicCondition.d.ts +9 -3
- package/lib/components/ConditionBuilder/AtomicCondition.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/AtomicCondition.js +45 -10
- 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 +26 -3
- package/lib/components/ConditionBuilder/ConditionBuilder.js.map +1 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts +2 -0
- 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/RhsControls/DateFunctionMenu.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.js +9 -1
- package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.js +14 -4
- package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.js +9 -2
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.d.ts +5 -3
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.js +69 -18
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/index.d.ts +5 -3
- package/lib/components/ConditionBuilder/RhsControls/index.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/index.js +29 -8
- package/lib/components/ConditionBuilder/RhsControls/index.js.map +1 -1
- package/lib/components/ConditionBuilder/core/evaluator.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/evaluator.js +14 -2
- package/lib/components/ConditionBuilder/core/evaluator.js.map +1 -1
- package/lib/components/ConditionBuilder/core/formatter.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/formatter.js +21 -0
- 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 +1 -0
- 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/ConditionInput/ConditionInput.d.ts.map +1 -1
- package/lib/components/ConditionInput/ConditionInput.js +100 -51
- package/lib/components/ConditionInput/ConditionInput.js.map +1 -1
- package/lib/components/ConditionInput/ConditionInput.styles.d.ts +2 -2
- package/lib/components/ConditionInput/ConditionInput.styles.d.ts.map +1 -1
- package/lib/components/ConditionInput/ConditionInput.styles.js +4 -4
- package/lib/components/ConditionInput/ConditionInput.styles.js.map +1 -1
- package/lib/components/ConditionInput/ConditionInput.types.d.ts +3 -0
- package/lib/components/ConditionInput/ConditionInput.types.d.ts.map +1 -1
- package/lib/components/ConditionInput/ConditionInput.types.js.map +1 -1
- package/lib/components/ConditionInput/utils.d.ts +2 -0
- package/lib/components/ConditionInput/utils.d.ts.map +1 -1
- package/lib/components/ConditionInput/utils.js +23 -0
- package/lib/components/ConditionInput/utils.js.map +1 -1
- package/lib/components/PromotedFilters/PromotedFilters.d.ts.map +1 -1
- package/lib/components/PromotedFilters/PromotedFilters.js +9 -5
- package/lib/components/PromotedFilters/PromotedFilters.js.map +1 -1
- package/lib/components/PromotedFilters/PromotedFilters.types.d.ts +3 -1
- package/lib/components/PromotedFilters/PromotedFilters.types.d.ts.map +1 -1
- package/lib/components/PromotedFilters/PromotedFilters.types.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LeafCondition } from '../ConditionBuilder';
|
|
1
2
|
import type { Comparator, FieldType } from '../ConditionBuilder/core/types';
|
|
2
3
|
import type { ConditionFieldType } from './ConditionInput.types';
|
|
3
4
|
export declare const defaultComparators: Record<ConditionFieldType, Comparator>;
|
|
@@ -10,4 +11,5 @@ export declare const compareRangeValues: (value1: {
|
|
|
10
11
|
start: string | number | undefined;
|
|
11
12
|
end: string | number | undefined;
|
|
12
13
|
} | undefined) => boolean;
|
|
14
|
+
export declare const compareCondition: (condition1: LeafCondition | undefined, condition2: LeafCondition | undefined) => boolean;
|
|
13
15
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionInput/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionInput/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAE5E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,kBAAkB,EAAE,UAAU,CAc5D,CAAC;AAEX,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,kBAAkB,EAAE,SAAS,CActD,CAAC;AAEX,eAAO,MAAM,aAAa,WAChB,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,UAC7B,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,YAiBtC,CAAC;AAEF,eAAO,MAAM,kBAAkB,WACrB;IAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;CAAE,GAAG,SAAS,UACpF;IAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;CAAE,GAAG,SAAS,YAS7F,CAAC;AAEF,eAAO,MAAM,gBAAgB,eACf,aAAa,GAAG,SAAS,cACzB,aAAa,GAAG,SAAS,YA0BtC,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { hasProp } from '@pega/cosmos-react-core';
|
|
1
2
|
export const defaultComparators = {
|
|
2
3
|
TEXT: 'CONTAINS',
|
|
3
4
|
EMAIL: 'CONTAINS',
|
|
@@ -53,4 +54,26 @@ export const compareRangeValues = (value1, value2) => {
|
|
|
53
54
|
return false;
|
|
54
55
|
return value1.start === value2.start && value1.end === value2.end;
|
|
55
56
|
};
|
|
57
|
+
export const compareCondition = (condition1, condition2) => {
|
|
58
|
+
// both values are undefined
|
|
59
|
+
if (!condition1 && !condition2)
|
|
60
|
+
return true;
|
|
61
|
+
// only one value is undefined
|
|
62
|
+
if (!condition1 || !condition2)
|
|
63
|
+
return false;
|
|
64
|
+
if (condition1.comparator !== condition2.comparator)
|
|
65
|
+
return false;
|
|
66
|
+
if (condition1.rhs && condition2.rhs) {
|
|
67
|
+
if (hasProp(condition1.rhs, 'value') && hasProp(condition2.rhs, 'value')) {
|
|
68
|
+
return compareValues(condition1.rhs.value.toString(), condition2.rhs.value.toString());
|
|
69
|
+
}
|
|
70
|
+
if (hasProp(condition1.rhs, 'values') && hasProp(condition2.rhs, 'values')) {
|
|
71
|
+
return compareValues(condition1.rhs.values.map(p => p.toString()), condition2.rhs.values.map(p => p.toString()));
|
|
72
|
+
}
|
|
73
|
+
if (hasProp(condition1.rhs, 'start') && hasProp(condition2.rhs, 'start')) {
|
|
74
|
+
return compareRangeValues(condition1.rhs, condition2.rhs);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
};
|
|
56
79
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/components/ConditionInput/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/components/ConditionInput/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAOlD,MAAM,CAAC,MAAM,kBAAkB,GAA2C;IACxE,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE,UAAU;IACjB,GAAG,EAAE,UAAU;IACf,KAAK,EAAE,UAAU;IACjB,OAAO,EAAE,KAAK;IACd,OAAO,EAAE,KAAK;IACd,UAAU,EAAE,KAAK;IACjB,QAAQ,EAAE,KAAK;IACf,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,KAAK;IAChB,QAAQ,EAAE,IAAI;CACN,CAAC;AAEX,MAAM,CAAC,MAAM,aAAa,GAA0C;IAClE,KAAK,EAAE,MAAM;IACb,GAAG,EAAE,MAAM;IACX,KAAK,EAAE,MAAM;IACb,OAAO,EAAE,QAAQ;IACjB,OAAO,EAAE,QAAQ;IACjB,UAAU,EAAE,QAAQ;IACpB,QAAQ,EAAE,QAAQ;IAClB,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,WAAW;IACtB,SAAS,EAAE,WAAW;IACtB,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,MAAM;CACR,CAAC;AAEX,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,MAAqC,EACrC,MAAq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GAAG,IAAI,UAAU,CAAC,GAAG,EAAE;QACpC,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE;YACxE,OAAO,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;SACxF;QACD,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE;YAC1E,OAAO,aAAa,CAClB,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,EAC5C,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAC7C,CAAC;SACH;QACD,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE;YACxE,OAAO,kBAAkB,CAAC,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;SAC3D;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["import { hasProp } from '@pega/cosmos-react-core';\n\nimport { LeafCondition } from '../ConditionBuilder';\nimport type { Comparator, FieldType } from '../ConditionBuilder/core/types';\n\nimport type { ConditionFieldType } from './ConditionInput.types';\n\nexport const defaultComparators: Record<ConditionFieldType, Comparator> = {\n TEXT: 'CONTAINS',\n EMAIL: 'CONTAINS',\n URL: 'CONTAINS',\n PHONE: 'CONTAINS',\n INTEGER: 'BTW',\n DECIMAL: 'BTW',\n PERCENTAGE: 'BTW',\n CURRENCY: 'BTW',\n BOOLEAN: 'IS_TRUE',\n DATE_ONLY: 'BTW',\n TIME_ONLY: 'BTW',\n DATE_TIME: 'BTW',\n PICKLIST: 'IN'\n} as const;\n\nexport const basicFieldMap: Record<ConditionFieldType, FieldType> = {\n EMAIL: 'TEXT',\n URL: 'TEXT',\n PHONE: 'TEXT',\n INTEGER: 'NUMBER',\n DECIMAL: 'NUMBER',\n PERCENTAGE: 'NUMBER',\n CURRENCY: 'NUMBER',\n TEXT: 'TEXT',\n BOOLEAN: 'BOOLEAN',\n DATE_ONLY: 'DATE_ONLY',\n TIME_ONLY: 'TIME_ONLY',\n DATE_TIME: 'DATE_TIME',\n PICKLIST: 'TEXT'\n} as const;\n\nexport const compareValues = (\n value1: string | string[] | undefined,\n value2: string | string[] | undefined\n) => {\n // both values are undefined\n if (!value1 && !value2) return true;\n\n // only one value is undefined\n if (!value1 || !value2) return false;\n\n // for strings compare only value\n if (typeof value1 === 'string') {\n return value1 === value2;\n }\n\n // for arrays compare length and every value\n if (value1.length !== value2.length) return false;\n\n return value1.every((value, index) => value === value2[index]);\n};\n\nexport const compareRangeValues = (\n value1: { start: string | number | undefined; end: string | number | undefined } | undefined,\n value2: { start: string | number | undefined; end: string | number | undefined } | undefined\n) => {\n // both values are undefined\n if (!value1 && !value2) return true;\n\n // only one value is undefined\n if (!value1 || !value2) return false;\n\n return value1.start === value2.start && value1.end === value2.end;\n};\n\nexport const compareCondition = (\n condition1: LeafCondition | undefined,\n condition2: LeafCondition | undefined\n) => {\n // both values are undefined\n if (!condition1 && !condition2) return true;\n\n // only one value is undefined\n if (!condition1 || !condition2) return false;\n\n if (condition1.comparator !== condition2.comparator) return false;\n\n if (condition1.rhs && condition2.rhs) {\n if (hasProp(condition1.rhs, 'value') && hasProp(condition2.rhs, 'value')) {\n return compareValues(condition1.rhs.value.toString(), condition2.rhs.value.toString());\n }\n if (hasProp(condition1.rhs, 'values') && hasProp(condition2.rhs, 'values')) {\n return compareValues(\n condition1.rhs.values.map(p => p.toString()),\n condition2.rhs.values.map(p => p.toString())\n );\n }\n if (hasProp(condition1.rhs, 'start') && hasProp(condition2.rhs, 'start')) {\n return compareRangeValues(condition1.rhs, condition2.rhs);\n }\n }\n\n return false;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PromotedFilters.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAMlB,MAAM,OAAO,CAAC;AAEf,OAAO,EAGL,YAAY,
|
|
1
|
+
{"version":3,"file":"PromotedFilters.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAMlB,MAAM,OAAO,CAAC;AAEf,OAAO,EAGL,YAAY,EASb,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,SAAS,EAAiB,MAAM,4CAA4C,CAAC;AAOtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAO/D,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,oBAAoB,EAAE,SAAS,GAAG,WAAW,CAAC;IAC3F,oDAAoD;IACpD,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,KAAK,IAAI,CAAC;CACtD;AAqKD,eAAO,MAAM,eAAe,EAAE,iBAAiB,CAAC,oBAAoB,GAAG,YAAY,CAwHlF,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -3,11 +3,11 @@ import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
|
|
|
3
3
|
import { Button, Flex, Icon, Modal, useModalManager, useBreakpoint, useI18n, useModalContext } from '@pega/cosmos-react-core';
|
|
4
4
|
import { splitConditionForBuilder } from '../ConditionBuilder/core/utils';
|
|
5
5
|
import ConditionInput from '../ConditionInput';
|
|
6
|
-
import {
|
|
6
|
+
import { StyledVerticalFieldGroup } from '../ConditionInput/ConditionInput.styles';
|
|
7
7
|
import { basicFieldMap } from '../ConditionInput/utils';
|
|
8
8
|
import ConditionSelector from './ConditionSelector';
|
|
9
9
|
import { StyledPromotedFilters, StyledClearAllButton, StyledTextWithEllipsis } from './PromotedFilters.styles';
|
|
10
|
-
const PromotedFiltersContent = forwardRef(({ filters, condition, onChange, orientation: orientationProp = 'horizontal' }, ref) => {
|
|
10
|
+
const PromotedFiltersContent = forwardRef(({ filters, condition, onChange, orientation: orientationProp = 'horizontal', handle }, ref) => {
|
|
11
11
|
const t = useI18n();
|
|
12
12
|
const isSmallOrAbove = useBreakpoint('sm');
|
|
13
13
|
const orientation = isSmallOrAbove && orientationProp === 'horizontal' ? 'horizontal' : 'vertical';
|
|
@@ -43,7 +43,7 @@ const PromotedFiltersContent = forwardRef(({ filters, condition, onChange, orien
|
|
|
43
43
|
if (mode !== 'predefined')
|
|
44
44
|
return (_jsx(ConditionInput, { field: field, mode: mode, label: label ?? field.name, condition: conditionsMap[field.name], flat: orientation === 'vertical', onChange: (newCondition) => {
|
|
45
45
|
onChange(createUpdatedCondition(field.name, newCondition));
|
|
46
|
-
} }, field.name));
|
|
46
|
+
}, handle: handle }, field.name));
|
|
47
47
|
const selector = (_jsx(ConditionSelector, { label: label ?? field.name, labelHidden: orientation === 'vertical', fields: [
|
|
48
48
|
{
|
|
49
49
|
id: field.name,
|
|
@@ -55,7 +55,7 @@ const PromotedFiltersContent = forwardRef(({ filters, condition, onChange, orien
|
|
|
55
55
|
}, onClear: orientation === 'horizontal'
|
|
56
56
|
? () => onChange(createUpdatedCondition(field.name, undefined))
|
|
57
57
|
: undefined }, field.name));
|
|
58
|
-
return orientation === 'vertical' ? (_jsx(
|
|
58
|
+
return orientation === 'vertical' ? (_jsx(StyledVerticalFieldGroup, { name: label ?? field.name, collapsible: true, actions: [
|
|
59
59
|
{
|
|
60
60
|
id: 'clear',
|
|
61
61
|
text: t('clear'),
|
|
@@ -97,6 +97,7 @@ export const PromotedFilters = forwardRef(({ filters, condition, onChange, orien
|
|
|
97
97
|
onApply: onChange
|
|
98
98
|
});
|
|
99
99
|
};
|
|
100
|
+
const clearHandle = useRef(null);
|
|
100
101
|
return (_jsx(Flex, { as: StyledPromotedFilters, container: {
|
|
101
102
|
alignItems: orientation === 'horizontal' && isSmallOrAbove ? 'start' : undefined,
|
|
102
103
|
justify: 'between',
|
|
@@ -109,10 +110,13 @@ export const PromotedFilters = forwardRef(({ filters, condition, onChange, orien
|
|
|
109
110
|
pad: [0, 0, 1, 0]
|
|
110
111
|
}, children: [_jsx(StyledTextWithEllipsis, { variant: 'h3', children: t('filters') }), _jsx(Button, { variant: 'simple', onClick: () => {
|
|
111
112
|
onChange();
|
|
112
|
-
|
|
113
|
+
clearHandle.current?.clear();
|
|
114
|
+
}, children: t('clear_all') })] })), _jsx(PromotedFiltersContent, { filters: filters, onChange: onChange, condition: condition, orientation: orientation, ref: ref, handle: clearHandle }), orientation === 'horizontal' && (_jsx("div", { children: _jsx(StyledClearAllButton, { variant: 'simple', onClick: () => {
|
|
113
115
|
onChange();
|
|
116
|
+
clearHandle.current?.clear();
|
|
114
117
|
}, 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: () => {
|
|
115
118
|
onChange();
|
|
119
|
+
clearHandle.current?.clear();
|
|
116
120
|
}, children: t('clear_all') })] })) }));
|
|
117
121
|
});
|
|
118
122
|
export default PromotedFilters;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PromotedFilters.js","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.tsx"],"names":[],"mappings":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U,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 alignItems: orientation === 'vertical' ? 'stretch' : 'start'\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 ?? field.name}\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 <>\n <Button onClick={dismiss}>{t('cancel')}</Button>\n <Button variant='primary' onClick={onApplyClick}>\n {t('apply')}\n </Button>\n </>\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"]}
|
|
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,EAEhB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AACnF,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,sB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WithoutRef,\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 HandleValue\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 { StyledVerticalFieldGroup } 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 handle\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 alignItems: orientation === 'vertical' ? 'stretch' : 'start'\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 handle={handle}\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 <StyledVerticalFieldGroup\n key={field.name}\n name={label ?? field.name}\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 </StyledVerticalFieldGroup>\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 <>\n <Button onClick={dismiss}>{t('cancel')}</Button>\n <Button variant='primary' onClick={onApplyClick}>\n {t('apply')}\n </Button>\n </>\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 const clearHandle = useRef<HandleValue>(null);\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 clearHandle.current?.clear();\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 handle={clearHandle}\n />\n\n {orientation === 'horizontal' && (\n <div>\n <StyledClearAllButton\n variant='simple'\n onClick={() => {\n onChange();\n clearHandle.current?.clear();\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 clearHandle.current?.clear();\n }}\n >\n {t('clear_all')}\n </Button>\n </>\n )}\n </Flex>\n );\n }\n);\n\nexport default PromotedFilters;\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Ref } from 'react';
|
|
2
|
-
import { BaseProps, NoChildrenProp } from '@pega/cosmos-react-core';
|
|
2
|
+
import { BaseProps, HandleValue, NoChildrenProp } from '@pega/cosmos-react-core';
|
|
3
3
|
import type { Condition, LeafCondition } from '../ConditionBuilder/ConditionBuilder.types';
|
|
4
4
|
import type { ConditionInputMode, ConditionField } from '../ConditionInput/ConditionInput.types';
|
|
5
5
|
export interface PromotedFilter {
|
|
@@ -27,5 +27,7 @@ export interface PromotedFiltersProps extends BaseProps, NoChildrenProp {
|
|
|
27
27
|
onChange: (condition?: Condition) => void;
|
|
28
28
|
/** Ref for the wrapping element. */
|
|
29
29
|
ref?: Ref<HTMLDivElement>;
|
|
30
|
+
/** Imperative handle */
|
|
31
|
+
handle?: Ref<HandleValue>;
|
|
30
32
|
}
|
|
31
33
|
//# sourceMappingURL=PromotedFilters.types.d.ts.map
|
|
@@ -1 +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;
|
|
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,WAAW,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEjF,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;IAC1B,wBAAwB;IACxB,MAAM,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;CAC3B"}
|
|
@@ -1 +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"]}
|
|
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, HandleValue, 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 /** Imperative handle */\n handle?: Ref<HandleValue>;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pega/cosmos-react-condition-builder",
|
|
3
|
-
"version": "4.0.0-dev.
|
|
3
|
+
"version": "4.0.0-dev.8.0",
|
|
4
4
|
"author": "Pegasystems",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"repository": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"build": "tsc -b"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@pega/cosmos-react-core": "4.0.0-dev.
|
|
26
|
+
"@pega/cosmos-react-core": "4.0.0-dev.8.0",
|
|
27
27
|
"@types/react": "^16.14.24 || ^17.0.38",
|
|
28
28
|
"@types/react-dom": "^16.9.14 || ^17.0.11",
|
|
29
29
|
"@types/styled-components": "^5.1.26",
|