@k-int/stripes-kint-components 2.4.0 → 2.4.1
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/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _excluded = ["searchKey", "filterKeys", "sortKeys", "stats", "sort", "filters"];
|
|
7
|
+
var _excluded = ["searchKey", "filterConfig", "filterKeys", "sortKeys", "stats", "sort", "filters"];
|
|
8
8
|
|
|
9
9
|
(function () {
|
|
10
10
|
var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
|
|
@@ -49,6 +49,8 @@ var generateKiwtQueryParams = function generateKiwtQueryParams(options, nsValues
|
|
|
49
49
|
|
|
50
50
|
var _options$searchKey = options.searchKey,
|
|
51
51
|
searchKey = _options$searchKey === void 0 ? '' : _options$searchKey,
|
|
52
|
+
_options$filterConfig = options.filterConfig,
|
|
53
|
+
filterConfig = _options$filterConfig === void 0 ? [] : _options$filterConfig,
|
|
52
54
|
_options$filterKeys = options.filterKeys,
|
|
53
55
|
filterKeys = _options$filterKeys === void 0 ? {} : _options$filterKeys,
|
|
54
56
|
_options$sortKeys = options.sortKeys,
|
|
@@ -118,18 +120,33 @@ var generateKiwtQueryParams = function generateKiwtQueryParams(options, nsValues
|
|
|
118
120
|
filterName = _ref2[0],
|
|
119
121
|
filterValues = _ref2[1];
|
|
120
122
|
|
|
123
|
+
var filterConfigEntry = filterConfig.find(function (conf) {
|
|
124
|
+
return conf.name === filterName;
|
|
125
|
+
});
|
|
121
126
|
var filterKey = filterKeys[filterName];
|
|
122
127
|
|
|
123
|
-
if (
|
|
128
|
+
if (filterConfigEntry) {
|
|
129
|
+
// We have a direct mapping instruction, use it
|
|
130
|
+
var filterString = filterValues.map(function (v) {
|
|
131
|
+
var _filterConfigEntry$va, _filterConfigEntry$va2;
|
|
132
|
+
|
|
133
|
+
var fceValue = filterConfigEntry === null || filterConfigEntry === void 0 ? void 0 : (_filterConfigEntry$va = filterConfigEntry.values) === null || _filterConfigEntry$va === void 0 ? void 0 : (_filterConfigEntry$va2 = _filterConfigEntry$va.find(function (fce) {
|
|
134
|
+
return fce.name === v;
|
|
135
|
+
})) === null || _filterConfigEntry$va2 === void 0 ? void 0 : _filterConfigEntry$va2.value;
|
|
136
|
+
return "".concat(filterName, "==").concat(fceValue !== null && fceValue !== void 0 ? fceValue : v);
|
|
137
|
+
}).join('||');
|
|
138
|
+
paramsArray.push("filters=".concat(filterString));
|
|
139
|
+
} else if (!filterKey) {
|
|
124
140
|
// These filters have no key mapping so we just pass the values to the backend as-is.
|
|
125
141
|
paramsArray.push.apply(paramsArray, _toConsumableArray(filterValues === null || filterValues === void 0 ? void 0 : filterValues.map(function (f) {
|
|
126
142
|
return "filters=".concat(f);
|
|
127
143
|
})));
|
|
128
144
|
} else {
|
|
129
|
-
var
|
|
145
|
+
var _filterString = filterValues.map(function (v) {
|
|
130
146
|
return "".concat(filterKey, "==").concat(v);
|
|
131
147
|
}).join('||');
|
|
132
|
-
|
|
148
|
+
|
|
149
|
+
paramsArray.push("filters=".concat(_filterString));
|
|
133
150
|
}
|
|
134
151
|
});
|
|
135
152
|
}
|
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@ const generateKiwtQueryParams = (options, nsValues) => {
|
|
|
2
2
|
const { qindex, query, filters, sort } = nsValues;
|
|
3
3
|
const {
|
|
4
4
|
searchKey = '',
|
|
5
|
+
filterConfig = [],
|
|
5
6
|
/* Assumtion made that if no filterKey is provided then the given filterValues for that key are standalaone, ie require no comparator or key */
|
|
6
7
|
filterKeys = {},
|
|
7
8
|
sortKeys = {},
|
|
@@ -74,9 +75,17 @@ const generateKiwtQueryParams = (options, nsValues) => {
|
|
|
74
75
|
|
|
75
76
|
// We now have a filterMap of shape { status: ['active', 'cancelled'], type: ['local'] }
|
|
76
77
|
Object.entries(filterMap).forEach(([filterName, filterValues]) => {
|
|
78
|
+
const filterConfigEntry = filterConfig.find(conf => conf.name === filterName);
|
|
77
79
|
const filterKey = filterKeys[filterName];
|
|
80
|
+
if (filterConfigEntry) {
|
|
81
|
+
// We have a direct mapping instruction, use it
|
|
82
|
+
const filterString = filterValues.map(v => {
|
|
83
|
+
const fceValue = filterConfigEntry?.values?.find(fce => fce.name === v)?.value;
|
|
84
|
+
return `${filterName}==${fceValue ?? v}`;
|
|
85
|
+
}).join('||');
|
|
78
86
|
|
|
79
|
-
|
|
87
|
+
paramsArray.push(`filters=${filterString}`);
|
|
88
|
+
} else if (!filterKey) {
|
|
80
89
|
// These filters have no key mapping so we just pass the values to the backend as-is.
|
|
81
90
|
paramsArray.push(...filterValues?.map(f => `filters=${f}`));
|
|
82
91
|
} else {
|