@pega/cosmos-react-condition-builder 4.0.0-dev.2.0 → 4.0.0-dev.21.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 -5
- package/lib/components/ConditionBuilder/AtomicCondition.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/AtomicCondition.js +48 -13
- 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 +85 -22
- package/lib/components/ConditionBuilder/ConditionBuilder.js.map +1 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.styles.d.ts +2 -0
- package/lib/components/ConditionBuilder/ConditionBuilder.styles.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.styles.js +18 -3
- package/lib/components/ConditionBuilder/ConditionBuilder.styles.js.map +1 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts +7 -5
- 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.types.d.ts +1 -3
- 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/DateFunctionMenu.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.js +18 -10
- package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/FieldSelector.d.ts +5 -3
- package/lib/components/ConditionBuilder/RhsControls/FieldSelector.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/FieldSelector.js +2 -2
- 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 +1 -1
- package/lib/components/ConditionBuilder/RhsControls/NumericInput.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.js +21 -11
- package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.js +2 -2
- package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.d.ts +0 -2
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.js +84 -68
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.js +2 -1
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodMenu.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.d.ts +7 -3
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.js +71 -20
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/index.d.ts +5 -5
- package/lib/components/ConditionBuilder/RhsControls/index.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/index.js +56 -16
- 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 +15 -3
- 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 +22 -1
- package/lib/components/ConditionBuilder/core/formatter.js.map +1 -1
- package/lib/components/ConditionBuilder/core/rows-reducer.d.ts +1 -1
- package/lib/components/ConditionBuilder/core/rows-reducer.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/transformer.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/transformer.js +4 -2
- package/lib/components/ConditionBuilder/core/transformer.js.map +1 -1
- package/lib/components/ConditionBuilder/core/types.d.ts +17 -17
- 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 +2 -6
- package/lib/components/ConditionBuilder/core/utils.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/utils.js +4 -7
- package/lib/components/ConditionBuilder/core/utils.js.map +1 -1
- package/lib/components/ConditionBuilder/index.d.ts +3 -3
- 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.map +1 -1
- package/lib/components/ConditionInput/ConditionInput.js +145 -58
- 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 +5 -5
- package/lib/components/ConditionInput/ConditionInput.styles.js.map +1 -1
- package/lib/components/ConditionInput/ConditionInput.types.d.ts +5 -2
- 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/index.d.ts +1 -1
- package/lib/components/ConditionInput/index.d.ts.map +1 -1
- package/lib/components/ConditionInput/index.js.map +1 -1
- package/lib/components/ConditionInput/utils.d.ts +7 -3
- package/lib/components/ConditionInput/utils.d.ts.map +1 -1
- package/lib/components/ConditionInput/utils.js +67 -2
- package/lib/components/ConditionInput/utils.js.map +1 -1
- package/lib/components/PromotedFilters/ConditionSelector.d.ts.map +1 -1
- package/lib/components/PromotedFilters/ConditionSelector.js +3 -31
- package/lib/components/PromotedFilters/ConditionSelector.js.map +1 -1
- package/lib/components/PromotedFilters/PromotedFilters.d.ts.map +1 -1
- package/lib/components/PromotedFilters/PromotedFilters.js +46 -12
- package/lib/components/PromotedFilters/PromotedFilters.js.map +1 -1
- package/lib/components/PromotedFilters/PromotedFilters.styles.d.ts.map +1 -1
- package/lib/components/PromotedFilters/PromotedFilters.styles.js +12 -0
- package/lib/components/PromotedFilters/PromotedFilters.styles.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/lib/components/PromotedFilters/index.d.ts +1 -1
- package/lib/components/PromotedFilters/index.d.ts.map +1 -1
- package/lib/components/PromotedFilters/index.js.map +1 -1
- package/package.json +15 -16
- package/lib/components/ConditionBuilder/HelpButton.d.ts +0 -10
- package/lib/components/ConditionBuilder/HelpButton.d.ts.map +0 -1
- package/lib/components/ConditionBuilder/HelpButton.js +0 -11
- package/lib/components/ConditionBuilder/HelpButton.js.map +0 -1
|
@@ -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',
|
|
@@ -28,7 +29,7 @@ export const basicFieldMap = {
|
|
|
28
29
|
DATE_TIME: 'DATE_TIME',
|
|
29
30
|
PICKLIST: 'TEXT'
|
|
30
31
|
};
|
|
31
|
-
export const
|
|
32
|
+
export const valuesEqual = (value1, value2) => {
|
|
32
33
|
// both values are undefined
|
|
33
34
|
if (!value1 && !value2)
|
|
34
35
|
return true;
|
|
@@ -44,7 +45,7 @@ export const compareValues = (value1, value2) => {
|
|
|
44
45
|
return false;
|
|
45
46
|
return value1.every((value, index) => value === value2[index]);
|
|
46
47
|
};
|
|
47
|
-
export const
|
|
48
|
+
export const rangeValuesEqual = (value1, value2) => {
|
|
48
49
|
// both values are undefined
|
|
49
50
|
if (!value1 && !value2)
|
|
50
51
|
return true;
|
|
@@ -53,4 +54,68 @@ 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 conditionsEqual = (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
|
+
// conditions are for different fields
|
|
65
|
+
if (condition1.lhs?.field !== condition2.lhs?.field)
|
|
66
|
+
return false;
|
|
67
|
+
// comparators are different
|
|
68
|
+
if (condition1.comparator !== condition2.comparator)
|
|
69
|
+
return false;
|
|
70
|
+
// comparators are unary
|
|
71
|
+
if (!condition1.rhs && !condition2.rhs)
|
|
72
|
+
return true;
|
|
73
|
+
if (condition1.rhs && condition2.rhs) {
|
|
74
|
+
// datefunction is first, cause it contains also 'value' prop, so it would fall into next condition block
|
|
75
|
+
if (hasProp(condition1.rhs, 'dateFunction') && hasProp(condition2.rhs, 'dateFunction')) {
|
|
76
|
+
return (condition1.rhs.dateFunction === condition2.rhs.dateFunction &&
|
|
77
|
+
valuesEqual(condition1.rhs.value.toString(), condition2.rhs.value.toString()));
|
|
78
|
+
}
|
|
79
|
+
if (hasProp(condition1.rhs, 'value') && hasProp(condition2.rhs, 'value')) {
|
|
80
|
+
if (typeof condition1.rhs.value !== typeof condition2.rhs.value)
|
|
81
|
+
return false;
|
|
82
|
+
return valuesEqual(condition1.rhs.value.toString(), condition2.rhs.value.toString());
|
|
83
|
+
}
|
|
84
|
+
if (hasProp(condition1.rhs, 'values') && hasProp(condition2.rhs, 'values')) {
|
|
85
|
+
if (typeof condition1.rhs.values[0] !== typeof condition2.rhs.values[0])
|
|
86
|
+
return false;
|
|
87
|
+
return valuesEqual(condition1.rhs.values.map(p => p.toString()), condition2.rhs.values.map(p => p.toString()));
|
|
88
|
+
}
|
|
89
|
+
if (hasProp(condition1.rhs, 'start') && hasProp(condition2.rhs, 'start')) {
|
|
90
|
+
return rangeValuesEqual(condition1.rhs, condition2.rhs);
|
|
91
|
+
}
|
|
92
|
+
if (hasProp(condition1.rhs, 'relativeDate') && hasProp(condition2.rhs, 'relativeDate')) {
|
|
93
|
+
return (condition1.rhs.relativeDate.datePart === condition2.rhs.relativeDate.datePart &&
|
|
94
|
+
condition1.rhs.relativeDate.interval === condition2.rhs.relativeDate.interval &&
|
|
95
|
+
condition1.rhs.relativeDate.timePeriod === condition2.rhs.relativeDate.timePeriod);
|
|
96
|
+
}
|
|
97
|
+
if (hasProp(condition1.rhs, 'field') && hasProp(condition2.rhs, 'field')) {
|
|
98
|
+
return condition1.rhs.field === condition2.rhs.field;
|
|
99
|
+
}
|
|
100
|
+
if (hasProp(condition1.rhs, 'parameterId') && hasProp(condition2.rhs, 'parameterId')) {
|
|
101
|
+
return condition1.rhs.parameterId === condition2.rhs.parameterId;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return false;
|
|
105
|
+
};
|
|
106
|
+
export const convertFieldToConditionField = (lhs) => {
|
|
107
|
+
return lhs && hasProp(lhs, 'type')
|
|
108
|
+
? {
|
|
109
|
+
name: lhs.id,
|
|
110
|
+
type: lhs.type === 'NUMBER' ? 'INTEGER' : lhs.type
|
|
111
|
+
}
|
|
112
|
+
: undefined;
|
|
113
|
+
};
|
|
114
|
+
export const possibleFieldValuesToConditionFieldValues = (possibleValues) => {
|
|
115
|
+
if (possibleValues === undefined || typeof possibleValues !== 'function')
|
|
116
|
+
return possibleValues;
|
|
117
|
+
return ({ searchString, comparator, lhs }) => {
|
|
118
|
+
return possibleValues({ searchString, comparator, lhs: convertFieldToConditionField(lhs) });
|
|
119
|
+
};
|
|
120
|
+
};
|
|
56
121
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/components/ConditionInput/utils.ts"],"names":[],"mappings":"AAIA,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,MAAqC,EACrC,EAAE;IACF,4BAA4B;IAC5B,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAEpC,8BAA8B;IAC9B,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAErC,iCAAiC;IACjC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC9B,OAAO,MAAM,KAAK,MAAM,CAAC;KAC1B;IAED,4CAA4C;IAC5C,IAAI,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAElD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AACjE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,MAA4F,EAC5F,MAA4F,EAC5F,EAAE;IACF,4BAA4B;IAC5B,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAEpC,8BAA8B;IAC9B,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAErC,OAAO,MAAM,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,GAAG,KAAK,MAAM,CAAC,GAAG,CAAC;AACpE,CAAC,CAAC","sourcesContent":["import 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"]}
|
|
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,OA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n\nimport { Field, LeafCondition, ValueSelection } from '../ConditionBuilder';\nimport type { Comparator, FieldType } from '../ConditionBuilder/core/types';\n\nimport type { ConditionField, 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 valuesEqual = (\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 rangeValuesEqual = (\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 conditionsEqual = (\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 // conditions are for different fields\n if (condition1.lhs?.field !== condition2.lhs?.field) return false;\n\n // comparators are different\n if (condition1.comparator !== condition2.comparator) return false;\n\n // comparators are unary\n if (!condition1.rhs && !condition2.rhs) return true;\n\n if (condition1.rhs && condition2.rhs) {\n // datefunction is first, cause it contains also 'value' prop, so it would fall into next condition block\n if (hasProp(condition1.rhs, 'dateFunction') && hasProp(condition2.rhs, 'dateFunction')) {\n return (\n condition1.rhs.dateFunction === condition2.rhs.dateFunction &&\n valuesEqual(condition1.rhs.value.toString(), condition2.rhs.value.toString())\n );\n }\n if (hasProp(condition1.rhs, 'value') && hasProp(condition2.rhs, 'value')) {\n if (typeof condition1.rhs.value !== typeof condition2.rhs.value) return false;\n return valuesEqual(condition1.rhs.value.toString(), condition2.rhs.value.toString());\n }\n if (hasProp(condition1.rhs, 'values') && hasProp(condition2.rhs, 'values')) {\n if (typeof condition1.rhs.values[0] !== typeof condition2.rhs.values[0]) return false;\n return valuesEqual(\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 rangeValuesEqual(condition1.rhs, condition2.rhs);\n }\n if (hasProp(condition1.rhs, 'relativeDate') && hasProp(condition2.rhs, 'relativeDate')) {\n return (\n condition1.rhs.relativeDate.datePart === condition2.rhs.relativeDate.datePart &&\n condition1.rhs.relativeDate.interval === condition2.rhs.relativeDate.interval &&\n condition1.rhs.relativeDate.timePeriod === condition2.rhs.relativeDate.timePeriod\n );\n }\n if (hasProp(condition1.rhs, 'field') && hasProp(condition2.rhs, 'field')) {\n return condition1.rhs.field === condition2.rhs.field;\n }\n if (hasProp(condition1.rhs, 'parameterId') && hasProp(condition2.rhs, 'parameterId')) {\n return condition1.rhs.parameterId === condition2.rhs.parameterId;\n }\n }\n\n return false;\n};\n\nexport const convertFieldToConditionField = (lhs?: Field) => {\n return lhs && hasProp(lhs, 'type')\n ? ({\n name: lhs.id,\n type: lhs.type === 'NUMBER' ? 'INTEGER' : lhs.type\n } as ConditionField)\n : undefined;\n};\n\nexport const possibleFieldValuesToConditionFieldValues = (\n possibleValues: ConditionField['possibleValues']\n): ValueSelection<Field> | undefined => {\n if (possibleValues === undefined || typeof possibleValues !== 'function') return possibleValues;\n\n return ({\n searchString,\n comparator,\n lhs\n }: {\n searchString?: string;\n comparator?: string;\n lhs?: Field;\n }) => {\n return possibleValues({ searchString, comparator, lhs: convertFieldToConditionField(lhs) });\n };\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConditionSelector.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/ConditionSelector.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAmB,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE3D,OAAO,EAEL,SAAS,EAET,cAAc,EACd,aAAa,EAKb,YAAY,
|
|
1
|
+
{"version":3,"file":"ConditionSelector.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/ConditionSelector.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAmB,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE3D,OAAO,EAEL,SAAS,EAET,cAAc,EACd,aAAa,EAKb,YAAY,EAEb,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAE3E,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,UAAU,sBAAuB,SAAQ,SAAS,EAAE,cAAc;IAChE,4BAA4B;IAC5B,QAAQ,EAAE,CAAC,SAAS,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IAC9C,yBAAyB;IACzB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,iDAAiD;IACjD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,+DAA+D;IAC/D,KAAK,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;IAC/B,uCAAuC;IACvC,WAAW,CAAC,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;IAC3C,mDAAmD;IACnD,IAAI,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC7B,4DAA4D;IAC5D,MAAM,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IACvC,6CAA6C;IAC7C,UAAU,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,aAAa,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACnE,oCAAoC;IACpC,SAAS,CAAC,EAAE,aAAa,CAAC;CAC3B;AAED,QAAA,MAAM,iBAAiB,EAAE,iBAAiB,CAAC,sBAAsB,GAAG,YAAY,CAkF/E,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -1,36 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useMemo, useRef } from 'react';
|
|
3
|
-
import { useI18n, ComboBox, Button, Icon, useConfiguration, menuHelpers
|
|
3
|
+
import { useI18n, ComboBox, Button, Icon, useConfiguration, menuHelpers } from '@pega/cosmos-react-core';
|
|
4
4
|
import formatCondition from '../ConditionBuilder/core/formatter';
|
|
5
|
-
|
|
6
|
-
if (c1.comparator !== c2.comparator)
|
|
7
|
-
return false;
|
|
8
|
-
if (c1.rhs && c2.rhs) {
|
|
9
|
-
if (hasProp(c1.rhs, 'field') && hasProp(c2.rhs, 'field'))
|
|
10
|
-
return c1.rhs.field === c2.rhs.field;
|
|
11
|
-
if (hasProp(c1.rhs, 'dateFunction') && hasProp(c2.rhs, 'dateFunction')) {
|
|
12
|
-
return c1.rhs.dateFunction === c2.rhs.dateFunction && c1.rhs.value === c2.rhs.value;
|
|
13
|
-
}
|
|
14
|
-
if (hasProp(c1.rhs, 'value') && hasProp(c2.rhs, 'value'))
|
|
15
|
-
return c1.rhs.value === c2.rhs.value;
|
|
16
|
-
if (hasProp(c1.rhs, 'values') && hasProp(c2.rhs, 'values')) {
|
|
17
|
-
const rhs1 = c1.rhs;
|
|
18
|
-
const rhs2 = c2.rhs;
|
|
19
|
-
// due to https://github.com/microsoft/TypeScript/issues/44373
|
|
20
|
-
return (rhs1.values.length === rhs2.values.length &&
|
|
21
|
-
rhs1.values.every((v, i) => v === rhs2.values[i]));
|
|
22
|
-
}
|
|
23
|
-
if (hasProp(c1.rhs, 'parameterId') && hasProp(c2.rhs, 'parameterId')) {
|
|
24
|
-
return c1.rhs.parameterId === c2.rhs.parameterId;
|
|
25
|
-
}
|
|
26
|
-
if (hasProp(c1.rhs, 'relativeDate') && hasProp(c2.rhs, 'relativeDate')) {
|
|
27
|
-
return (c1.rhs.relativeDate.datePart === c2.rhs.relativeDate.datePart &&
|
|
28
|
-
c1.rhs.relativeDate.interval === c2.rhs.relativeDate.interval &&
|
|
29
|
-
c1.rhs.relativeDate.timePeriod === c2.rhs.relativeDate.timePeriod);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return c1.rhs === c2.rhs;
|
|
33
|
-
};
|
|
5
|
+
import { conditionsEqual } from '../ConditionInput/utils';
|
|
34
6
|
const ConditionSelector = ({ onChange, onClear, status, label, info, fields, labelHidden, conditions, condition, ...restProps }) => {
|
|
35
7
|
const t = useI18n();
|
|
36
8
|
const { locale } = useConfiguration();
|
|
@@ -44,7 +16,7 @@ const ConditionSelector = ({ onChange, onClear, status, label, info, fields, lab
|
|
|
44
16
|
locale,
|
|
45
17
|
omitLhs: true
|
|
46
18
|
}),
|
|
47
|
-
selected: !!value && !!condition &&
|
|
19
|
+
selected: !!value && !!condition && conditionsEqual(value, condition)
|
|
48
20
|
};
|
|
49
21
|
});
|
|
50
22
|
}, [conditions, condition]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConditionSelector.js","sourceRoot":"","sources":["../../../src/components/PromotedFilters/ConditionSelector.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAqB,MAAM,OAAO,CAAC;AAE3D,OAAO,EACL,OAAO,EAEP,QAAQ,EAGR,MAAM,EACN,IAAI,EACJ,gBAAgB,EAGhB,WAAW,
|
|
1
|
+
{"version":3,"file":"ConditionSelector.js","sourceRoot":"","sources":["../../../src/components/PromotedFilters/ConditionSelector.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAqB,MAAM,OAAO,CAAC;AAE3D,OAAO,EACL,OAAO,EAEP,QAAQ,EAGR,MAAM,EACN,IAAI,EACJ,gBAAgB,EAGhB,WAAW,EACZ,MAAM,yBAAyB,CAAC;AAGjC,OAAO,eAAe,MAAM,oCAAoC,CAAC;AAEjE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAuB1D,MAAM,iBAAiB,GAA6D,CAAC,EACnF,QAAQ,EACR,OAAO,EACP,MAAM,EACN,KAAK,EACL,IAAI,EACJ,MAAM,EACN,WAAW,EACX,UAAU,EACV,SAAS,EACT,GAAG,SAAS,EACW,EAAE,EAAE;IAC3B,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IACpB,MAAM,EAAE,MAAM,EAAE,GAAG,gBAAgB,EAAE,CAAC;IAEtC,MAAM,QAAQ,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAC9C,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,EAAE;QACjC,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,EAAE,EAAE;YAC7D,OAAO;gBACL,EAAE;gBACF,OAAO,EACL,cAAc;oBACd,eAAe,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE;wBAC/C,MAAM;wBACN,OAAO,EAAE,IAAI;qBACd,CAAC;gBACJ,QAA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AE;gBACZ,OAAO,EAAE,CAAC;gBACV,IAAI,QAAQ,CAAC,OAAO,EAAE;oBACpB,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;oBACxD,OAAO,EAAE,KAAK,EAAE,CAAC;iBAClB;YACH,CAAC,YAED,KAAC,IAAI,IAAC,IAAI,EAAC,OAAO,GAAG,GACd,CACV,GAEH,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,iBAAiB,CAAC","sourcesContent":["import { useMemo, useRef, FunctionComponent } from 'react';\n\nimport {\n useI18n,\n BaseProps,\n ComboBox,\n NoChildrenProp,\n ComboBoxProps,\n Button,\n Icon,\n useConfiguration,\n MenuItemProps,\n ForwardProps,\n menuHelpers\n} from '@pega/cosmos-react-core';\n\nimport { AtomicConditionProps } from '../ConditionBuilder/AtomicCondition';\nimport formatCondition from '../ConditionBuilder/core/formatter';\nimport { LeafCondition } from '../ConditionBuilder';\nimport { conditionsEqual } from '../ConditionInput/utils';\n\ninterface ConditionSelectorProps extends BaseProps, NoChildrenProp {\n /** Callback for onChange */\n onChange: (condition?: LeafCondition) => void;\n /** Callback for clear */\n onClear?: () => void;\n /** Used to indicate any errors on the control */\n status?: 'error';\n /** Custom label for input. Makes label visible if provided. */\n label?: ComboBoxProps['label'];\n /** Visually hides the label region. */\n labelHidden?: ComboBoxProps['labelHidden'];\n /** Guidance text that apppears below the input. */\n info?: ComboBoxProps['info'];\n /** Definition of the field the condition is created for. */\n fields: AtomicConditionProps['fields'];\n /** List of possible predefined Conditions */\n conditions: { id: string; value: LeafCondition; label?: string }[];\n /** Currently selected condition. */\n condition?: LeafCondition;\n}\n\nconst ConditionSelector: FunctionComponent<ConditionSelectorProps & ForwardProps> = ({\n onChange,\n onClear,\n status,\n label,\n info,\n fields,\n labelHidden,\n conditions,\n condition,\n ...restProps\n}: ConditionSelectorProps) => {\n const t = useI18n();\n const { locale } = useConfiguration();\n\n const inputRef = useRef<HTMLDivElement>(null);\n const itemsToRender = useMemo(() => {\n return conditions.map(({ id, label: conditionLabel, value }) => {\n return {\n id,\n primary:\n conditionLabel ??\n formatCondition({ condition: value }, fields, t, {\n locale,\n omitLhs: true\n }),\n selected: !!value && !!condition && conditionsEqual(value, condition)\n };\n });\n }, [conditions, condition]);\n\n const selected = useMemo<MenuItemProps | undefined>(\n () => menuHelpers.getSelected(itemsToRender)[0],\n [itemsToRender]\n );\n\n return (\n <ComboBox\n {...restProps}\n ref={inputRef}\n mode='single-select'\n label={label ?? t('condition_builder_possible_values_label')}\n labelHidden={labelHidden}\n placeholder={t('all')}\n selected={\n selected\n ? {\n items: {\n id: selected.id,\n text: selected.primary\n }\n }\n : undefined\n }\n menu={{\n items: itemsToRender,\n onItemClick: (id: MenuItemProps['id']) =>\n onChange(conditions.find(cnd => cnd.id === id)?.value)\n }}\n status={status}\n info={status === 'error' ? t('condition_builder_empty_selection_error_text') : info}\n actions={\n onClear &&\n condition !== undefined && (\n <Button\n icon\n variant='simple'\n label={t('clear')}\n onClick={() => {\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 ConditionSelector;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PromotedFilters.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,
|
|
1
|
+
{"version":3,"file":"PromotedFilters.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAOlB,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;AAyND,eAAO,MAAM,eAAe,EAAE,iBAAiB,CAAC,oBAAoB,GAAG,YAAY,CAqHlF,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { forwardRef, useCallback, useEffect, useRef, useState, useImperativeHandle } 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';
|
|
14
|
+
const [collapsed, setCollapsed] = useState(false);
|
|
14
15
|
// map of Conditions indexed by field name
|
|
15
16
|
const conditionsMap = condition
|
|
16
17
|
? splitConditionForBuilder(condition).rows.reduce((result, item) => {
|
|
@@ -34,15 +35,45 @@ const PromotedFiltersContent = forwardRef(({ filters, condition, onChange, orien
|
|
|
34
35
|
})
|
|
35
36
|
};
|
|
36
37
|
};
|
|
38
|
+
// list of fields names used to count down onChange callbacks when Clear All action is invoked
|
|
39
|
+
// if undefined - Clear All was not triggered
|
|
40
|
+
// if stores any values - Clear All is in progress, waiting for all onChange callbacks to be invoked
|
|
41
|
+
const fieldsToClear = useRef(undefined);
|
|
42
|
+
const handleOnChange = (fieldName, newCondition) => {
|
|
43
|
+
// single onChange was invoked
|
|
44
|
+
if (fieldsToClear.current === undefined) {
|
|
45
|
+
onChange(createUpdatedCondition(fieldName, newCondition));
|
|
46
|
+
}
|
|
47
|
+
// prevent main onChange from being called for every onChange invoked from ConditionInput, when Clear All action was run
|
|
48
|
+
// counting down onChange callbacks, to wait when all are done
|
|
49
|
+
else {
|
|
50
|
+
fieldsToClear.current.delete(fieldName);
|
|
51
|
+
if (fieldsToClear.current.size === 0)
|
|
52
|
+
fieldsToClear.current = undefined;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
// ref to store clear handles for all filters
|
|
56
|
+
const handlesRef = useRef([]);
|
|
57
|
+
useImperativeHandle(handle, () => ({
|
|
58
|
+
clear: () => {
|
|
59
|
+
// initialize array with all fields, which trigger onChange callbacks
|
|
60
|
+
fieldsToClear.current = new Set(handlesRef.current.filter(Boolean).map(c => {
|
|
61
|
+
return c.id;
|
|
62
|
+
}));
|
|
63
|
+
handlesRef.current.forEach(item => item.handle.clear());
|
|
64
|
+
onChange();
|
|
65
|
+
}
|
|
66
|
+
}), [onChange]);
|
|
37
67
|
return (_jsx(Flex, { container: {
|
|
38
|
-
|
|
68
|
+
rowGap: 1,
|
|
69
|
+
colGap: 2,
|
|
39
70
|
direction: orientation === 'vertical' ? 'column' : 'row',
|
|
40
71
|
wrap: 'wrap',
|
|
41
72
|
alignItems: orientation === 'vertical' ? 'stretch' : 'start'
|
|
42
|
-
}, ref: ref, children: filters.map(({ field, mode, label, predefinedConditions }) => {
|
|
73
|
+
}, ref: ref, children: filters.map(({ field, mode, label, predefinedConditions }, i) => {
|
|
43
74
|
if (mode !== 'predefined')
|
|
44
|
-
return (_jsx(ConditionInput, { field: field, mode: mode, label: label ?? field.name, condition: conditionsMap[field.name], flat: orientation === 'vertical', onChange: (newCondition) => {
|
|
45
|
-
|
|
75
|
+
return (_jsx(ConditionInput, { field: field, mode: mode, label: label ?? field.name, condition: conditionsMap[field.name], flat: orientation === 'vertical', onChange: newCondition => handleOnChange(field.name, newCondition), handle: (handleItem) => {
|
|
76
|
+
handlesRef.current[i] = { id: field.name, handle: handleItem };
|
|
46
77
|
} }, field.name));
|
|
47
78
|
const selector = (_jsx(ConditionSelector, { label: label ?? field.name, labelHidden: orientation === 'vertical', fields: [
|
|
48
79
|
{
|
|
@@ -55,7 +86,7 @@ const PromotedFiltersContent = forwardRef(({ filters, condition, onChange, orien
|
|
|
55
86
|
}, onClear: orientation === 'horizontal'
|
|
56
87
|
? () => onChange(createUpdatedCondition(field.name, undefined))
|
|
57
88
|
: undefined }, field.name));
|
|
58
|
-
return orientation === 'vertical' ? (_jsx(
|
|
89
|
+
return orientation === 'vertical' ? (_jsx(StyledVerticalFieldGroup, { name: label ?? field.name, collapsed: collapsed, onToggleCollapsed: () => setCollapsed(cur => !cur), actions: [
|
|
59
90
|
{
|
|
60
91
|
id: 'clear',
|
|
61
92
|
text: t('clear'),
|
|
@@ -72,10 +103,12 @@ const FilterModal = ({ filters, condition, onApply }) => {
|
|
|
72
103
|
onApply?.(newCondition);
|
|
73
104
|
dismiss();
|
|
74
105
|
}, [newCondition, onApply]);
|
|
106
|
+
const clearHandle = useRef(null);
|
|
75
107
|
const actions = (_jsxs(_Fragment, { children: [_jsx(Button, { onClick: dismiss, children: t('cancel') }), _jsx(Button, { variant: 'primary', onClick: onApplyClick, children: t('apply') })] }));
|
|
76
108
|
return (_jsxs(Modal, { heading: t('filters'), actions: actions, stretch: true, children: [_jsx(Flex, { container: { justify: 'end' }, children: _jsx(StyledClearAllButton, { variant: 'simple', onClick: () => {
|
|
77
109
|
setNewCondition(undefined);
|
|
78
|
-
|
|
110
|
+
clearHandle.current?.clear();
|
|
111
|
+
}, children: t('clear_all') }) }), _jsx(PromotedFiltersContent, { filters: filters, condition: newCondition, onChange: setNewCondition, orientation: 'vertical', handle: clearHandle })] }));
|
|
79
112
|
};
|
|
80
113
|
export const PromotedFilters = forwardRef(({ filters, condition, onChange, orientation = 'horizontal' }, ref) => {
|
|
81
114
|
const t = useI18n();
|
|
@@ -97,6 +130,7 @@ export const PromotedFilters = forwardRef(({ filters, condition, onChange, orien
|
|
|
97
130
|
onApply: onChange
|
|
98
131
|
});
|
|
99
132
|
};
|
|
133
|
+
const clearHandle = useRef(null);
|
|
100
134
|
return (_jsx(Flex, { as: StyledPromotedFilters, container: {
|
|
101
135
|
alignItems: orientation === 'horizontal' && isSmallOrAbove ? 'start' : undefined,
|
|
102
136
|
justify: 'between',
|
|
@@ -108,9 +142,9 @@ export const PromotedFilters = forwardRef(({ filters, condition, onChange, orien
|
|
|
108
142
|
alignItems: 'center',
|
|
109
143
|
pad: [0, 0, 1, 0]
|
|
110
144
|
}, children: [_jsx(StyledTextWithEllipsis, { variant: 'h3', children: t('filters') }), _jsx(Button, { variant: 'simple', onClick: () => {
|
|
111
|
-
|
|
112
|
-
}, 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: () => {
|
|
113
|
-
|
|
145
|
+
clearHandle.current?.clear();
|
|
146
|
+
}, 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: () => {
|
|
147
|
+
clearHandle.current?.clear();
|
|
114
148
|
}, 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
149
|
onChange();
|
|
116
150
|
}, children: t('clear_all') })] })) }));
|
|
@@ -1 +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,CA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IAAI,CAC/B,wBACE,KAAC,oBAAoB,IACnB,OAAO,EAAC,QAAQ,EAChB,OAAO,EAAE,GAAG,EAAE;4BACZ,QAAQ,EAAE,CAAC;wBACb,CAAC,YAEA,CAAC,CAAC,yCAAyC,CAAC,GACxB,GACnB,CACP,IACA,CACJ,CAAC,CAAC,CAAC,CACF,8BACE,KAAC,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 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,WA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AW,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;wBAC/B,CAAC,YAEA,CAAC,CAAC,yCAAyC,CAAC,GACxB,GACnB,CACP,IACA,CACJ,CAAC,CAAC,CAAC,CACF,8BACE,KAAC,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 useImperativeHandle\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\ninterface HandleValueObj {\n /** Identifier for the corresponding field */\n id: string;\n /** Handle value for clear action */\n handle: HandleValue;\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 const [collapsed, setCollapsed] = useState(false);\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 // list of fields names used to count down onChange callbacks when Clear All action is invoked\n // if undefined - Clear All was not triggered\n // if stores any values - Clear All is in progress, waiting for all onChange callbacks to be invoked\n const fieldsToClear = useRef<Set<string> | undefined>(undefined);\n\n const handleOnChange = (fieldName: string, newCondition?: LeafCondition) => {\n // single onChange was invoked\n if (fieldsToClear.current === undefined) {\n onChange(createUpdatedCondition(fieldName, newCondition));\n }\n // prevent main onChange from being called for every onChange invoked from ConditionInput, when Clear All action was run\n // counting down onChange callbacks, to wait when all are done\n else {\n fieldsToClear.current.delete(fieldName);\n if (fieldsToClear.current.size === 0) fieldsToClear.current = undefined;\n }\n };\n\n // ref to store clear handles for all filters\n const handlesRef = useRef<HandleValueObj[]>([]);\n\n useImperativeHandle(\n handle,\n () => ({\n clear: () => {\n // initialize array with all fields, which trigger onChange callbacks\n fieldsToClear.current = new Set(\n handlesRef.current.filter(Boolean).map(c => {\n return c.id;\n })\n );\n handlesRef.current.forEach(item => item.handle.clear());\n onChange();\n }\n }),\n [onChange]\n );\n\n return (\n <Flex\n container={{\n rowGap: 1,\n colGap: 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 }, i) => {\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 => handleOnChange(field.name, newCondition)}\n handle={(handleItem: HandleValue) => {\n handlesRef.current[i] = { id: field.name, handle: handleItem };\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 <StyledVerticalFieldGroup\n key={field.name}\n name={label ?? field.name}\n collapsed={collapsed}\n onToggleCollapsed={() => setCollapsed(cur => !cur)}\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 clearHandle = useRef<HandleValue>(null);\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 clearHandle.current?.clear();\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 handle={clearHandle}\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 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 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 }}\n >\n {t('clear_all')}\n </Button>\n </>\n )}\n </Flex>\n );\n }\n);\n\nexport default PromotedFilters;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PromotedFilters.styles.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.styles.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PromotedFilters.styles.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.styles.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,qBAAqB,yGAgBhC,CAAC;AAIH,eAAO,MAAM,oBAAoB,qOAOhC,CAAC;AAIF,eAAO,MAAM,sBAAsB,mOAIlC,CAAC"}
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import styled, { css } from 'styled-components';
|
|
2
2
|
import { defaultThemeProp, Button, Text } from '@pega/cosmos-react-core';
|
|
3
3
|
import { StyledModalChildrenWrap } from '@pega/cosmos-react-core/lib/components/Modal/Modal.styles';
|
|
4
|
+
import { StyledSelectInput } from '@pega/cosmos-react-core/lib/components/ComboBox/ComboBox.styles';
|
|
4
5
|
export const StyledPromotedFilters = styled.div(({ theme }) => {
|
|
5
6
|
return css `
|
|
6
7
|
border-radius: ${theme.components.card['border-radius']};
|
|
7
8
|
background-color: ${theme.base.palette['secondary-background']};
|
|
9
|
+
padding-block: ${theme.base.spacing};
|
|
10
|
+
|
|
11
|
+
${StyledSelectInput} {
|
|
12
|
+
min-width: calc(${theme.base['content-width'].xs} + ${theme.base['hit-area']['mouse-min']});
|
|
13
|
+
|
|
14
|
+
@media (pointer: coarse) {
|
|
15
|
+
min-width: calc(
|
|
16
|
+
${theme.base['content-width'].xs} + ${theme.base['hit-area']['finger-min']}
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
8
20
|
`;
|
|
9
21
|
});
|
|
10
22
|
StyledPromotedFilters.defaultProps = defaultThemeProp;
|
|
@@ -1 +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;
|
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BAAgB,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';\nimport { StyledSelectInput } from '@pega/cosmos-react-core/lib/components/ComboBox/ComboBox.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 padding-block: ${theme.base.spacing};\n\n ${StyledSelectInput} {\n min-width: calc(${theme.base['content-width'].xs} + ${theme.base['hit-area']['mouse-min']});\n\n @media (pointer: coarse) {\n min-width: calc(\n ${theme.base['content-width'].xs} + ${theme.base['hit-area']['finger-min']}\n );\n }\n }\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"]}
|
|
@@ -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"]}
|
|
@@ -1 +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,
|
|
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,YAAY,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -1 +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"]}
|
|
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 type { PromotedFiltersProps, PromotedFilter } from './PromotedFilters.types';\n"]}
|
package/package.json
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pega/cosmos-react-condition-builder",
|
|
3
|
-
"version": "4.0.0-dev.
|
|
4
|
-
"author": "Pegasystems",
|
|
5
|
-
"license": "SEE LICENSE IN LICENSE",
|
|
3
|
+
"version": "4.0.0-dev.21.0",
|
|
6
4
|
"repository": {
|
|
7
5
|
"type": "git",
|
|
8
6
|
"url": "https://github.com/pegasystems/cosmos-react.git",
|
|
9
7
|
"directory": "packages/cosmos-condition-builder"
|
|
10
8
|
},
|
|
9
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
10
|
+
"author": "Pegasystems",
|
|
11
|
+
"sideEffects": [
|
|
12
|
+
"./src/components/ConditionBuilder/core/extendDayJs.ts",
|
|
13
|
+
"./lib/components/ConditionBuilder/core/extendDayJs.js"
|
|
14
|
+
],
|
|
11
15
|
"main": "lib/index.js",
|
|
12
16
|
"types": "lib/index.d.ts",
|
|
13
17
|
"files": [
|
|
@@ -15,15 +19,11 @@
|
|
|
15
19
|
"README.md",
|
|
16
20
|
"lib"
|
|
17
21
|
],
|
|
18
|
-
"sideEffects": [
|
|
19
|
-
"./src/components/ConditionBuilder/core/extendDayJs.ts",
|
|
20
|
-
"./lib/components/ConditionBuilder/core/extendDayJs.js"
|
|
21
|
-
],
|
|
22
22
|
"scripts": {
|
|
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.21.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",
|
|
@@ -34,15 +34,14 @@
|
|
|
34
34
|
"styled-components": "^5.2.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@storybook/addon-a11y": "^
|
|
38
|
-
"@storybook/addon-actions": "^
|
|
39
|
-
"@storybook/addon-storysource": "^
|
|
40
|
-
"@storybook/addon-toolbars": "^
|
|
41
|
-
"@storybook/
|
|
42
|
-
"@storybook/
|
|
43
|
-
"@storybook/theming": "^6.4.19",
|
|
37
|
+
"@storybook/addon-a11y": "^7.0.24",
|
|
38
|
+
"@storybook/addon-actions": "^7.0.24",
|
|
39
|
+
"@storybook/addon-storysource": "^7.0.24",
|
|
40
|
+
"@storybook/addon-toolbars": "^7.0.24",
|
|
41
|
+
"@storybook/react": "^7.0.24",
|
|
42
|
+
"@storybook/theming": "^7.0.24",
|
|
44
43
|
"@testing-library/react": "^12.1.3",
|
|
45
44
|
"@testing-library/user-event": "^13.5.0",
|
|
46
|
-
"typescript": "~
|
|
45
|
+
"typescript": "~5.0.2"
|
|
47
46
|
}
|
|
48
47
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { FunctionComponent } from 'react';
|
|
2
|
-
import { BaseProps, ForwardProps } from '@pega/cosmos-react-core';
|
|
3
|
-
interface HelpButtonProps extends BaseProps {
|
|
4
|
-
/** Content to show on hover of the button */
|
|
5
|
-
children: string;
|
|
6
|
-
}
|
|
7
|
-
/** Renders an inline Help icon that shows help content on hover */
|
|
8
|
-
declare const HelpButton: FunctionComponent<HelpButtonProps & ForwardProps>;
|
|
9
|
-
export default HelpButton;
|
|
10
|
-
//# sourceMappingURL=HelpButton.d.ts.map
|