@k-int/stripes-kint-components 3.2.1 → 4.1.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/CHANGELOG.md +3 -4
- package/es/lib/utils/generateKiwtQuery.js +3 -4
- package/es/lib/utils/generateKiwtQueryParams.js +22 -12
- package/package.json +1 -1
- package/src/lib/utils/README.md +3 -1
- package/src/lib/utils/generateKiwtQuery.js +3 -3
- package/src/lib/utils/generateKiwtQueryParams.js +27 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
##
|
|
2
|
-
*
|
|
3
|
-
|
|
1
|
+
## 4.0.0 2022-11-10
|
|
2
|
+
* generateKiwtQuery now encodes each interior query chunk using `encodeURIComponent` instead of using `encodeURI` on the entire chunk. ie `filters=(checklist.definition.name%3D%3Dtest_1%26%26checklist.outcome.value%3D%3Dyes)` (Everything after `filters=` is encoded).
|
|
4
3
|
## 3.2.0 2022-11-10
|
|
5
4
|
* RichSelect now passes `disabled` prop to Dropdown, so trigger will no longer be overriden by `disabled: undefined` from `getTriggerProps`.
|
|
6
|
-
|
|
5
|
+
|
|
7
6
|
## 3.1.0 2022-11-03
|
|
8
7
|
* Added `searchFieldAria label` and `searchFieldProps` to SASQLookupComponent
|
|
9
8
|
* Removed unnecessary validate prop on CustomPropertyField, fixed broken out of range validator
|
|
@@ -7,10 +7,9 @@ exports.default = void 0;
|
|
|
7
7
|
var _generateKiwtQueryParams = _interopRequireDefault(require("./generateKiwtQueryParams"));
|
|
8
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
9
|
var generateKiwtQuery = function generateKiwtQuery(options, nsValues) {
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}).join('&') : '';
|
|
10
|
+
var encode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
11
|
+
var paramsArray = (0, _generateKiwtQueryParams.default)(options, nsValues, encode);
|
|
12
|
+
return paramsArray.length ? '?' + paramsArray.join('&') : '';
|
|
14
13
|
};
|
|
15
14
|
var _default = generateKiwtQuery;
|
|
16
15
|
exports.default = _default;
|
|
@@ -19,6 +19,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
19
19
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
20
20
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
21
21
|
var generateKiwtQueryParams = function generateKiwtQueryParams(options, nsValues) {
|
|
22
|
+
var encode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
22
23
|
var qindex = nsValues.qindex,
|
|
23
24
|
query = nsValues.query,
|
|
24
25
|
filters = nsValues.filters,
|
|
@@ -36,13 +37,19 @@ var generateKiwtQueryParams = function generateKiwtQueryParams(options, nsValues
|
|
|
36
37
|
optionsSort = options.sort,
|
|
37
38
|
optionsFilters = options.filters,
|
|
38
39
|
rest = _objectWithoutProperties(options, _excluded);
|
|
40
|
+
var conditionalEncodeURIComponent = function conditionalEncodeURIComponent(str) {
|
|
41
|
+
if (encode) {
|
|
42
|
+
return encodeURIComponent(str);
|
|
43
|
+
}
|
|
44
|
+
return str;
|
|
45
|
+
};
|
|
39
46
|
var paramsArray = [];
|
|
40
47
|
if (query) {
|
|
41
48
|
var _split;
|
|
42
49
|
paramsArray.push.apply(paramsArray, _toConsumableArray((_split = (qindex || searchKey).split(',')) === null || _split === void 0 ? void 0 : _split.map(function (m) {
|
|
43
|
-
return "match=".concat(m);
|
|
50
|
+
return "match=".concat(conditionalEncodeURIComponent(m));
|
|
44
51
|
})));
|
|
45
|
-
paramsArray.push("term=".concat(query));
|
|
52
|
+
paramsArray.push("term=".concat(conditionalEncodeURIComponent(query)));
|
|
46
53
|
}
|
|
47
54
|
if (optionsFilters) {
|
|
48
55
|
optionsFilters.forEach(function (opf) {
|
|
@@ -57,14 +64,15 @@ var generateKiwtQueryParams = function generateKiwtQueryParams(options, nsValues
|
|
|
57
64
|
innerFilters.push(opfv);
|
|
58
65
|
}
|
|
59
66
|
});
|
|
60
|
-
paramsArray.push("filters=".concat(innerFilters.join('||')));
|
|
67
|
+
paramsArray.push("filters=".concat(conditionalEncodeURIComponent(innerFilters.join('||'))));
|
|
61
68
|
} else if (opf !== null && opf !== void 0 && opf.value) {
|
|
62
69
|
// If no value OR values, then ignore
|
|
63
70
|
if (opf.path) {
|
|
64
71
|
var _opf$comparator2;
|
|
65
|
-
|
|
72
|
+
var filterString = "".concat(opf.path).concat((_opf$comparator2 = opf.comparator) !== null && _opf$comparator2 !== void 0 ? _opf$comparator2 : '==').concat(opf.value);
|
|
73
|
+
paramsArray.push("filters=".concat(conditionalEncodeURIComponent(filterString)));
|
|
66
74
|
} else {
|
|
67
|
-
paramsArray.push("filters=".concat(opf.value));
|
|
75
|
+
paramsArray.push("filters=".concat(conditionalEncodeURIComponent(opf.value)));
|
|
68
76
|
}
|
|
69
77
|
}
|
|
70
78
|
});
|
|
@@ -100,28 +108,29 @@ var generateKiwtQueryParams = function generateKiwtQueryParams(options, nsValues
|
|
|
100
108
|
})) === null || _filterConfigEntry$va2 === void 0 ? void 0 : _filterConfigEntry$va2.value;
|
|
101
109
|
return "".concat(filterName, "==").concat(fceValue !== null && fceValue !== void 0 ? fceValue : v);
|
|
102
110
|
}).join('||');
|
|
103
|
-
paramsArray.push("filters=".concat(filterString));
|
|
111
|
+
paramsArray.push("filters=".concat(conditionalEncodeURIComponent(filterString)));
|
|
104
112
|
} else if (!filterKey) {
|
|
105
113
|
// These filters have no key mapping so we just pass the values to the backend as-is.
|
|
106
114
|
paramsArray.push.apply(paramsArray, _toConsumableArray(filterValues === null || filterValues === void 0 ? void 0 : filterValues.map(function (f) {
|
|
107
|
-
return "filters=".concat(f);
|
|
115
|
+
return "filters=".concat(conditionalEncodeURIComponent(f));
|
|
108
116
|
})));
|
|
109
117
|
} else {
|
|
110
118
|
var _filterString = filterValues.map(function (v) {
|
|
111
119
|
return "".concat(filterKey, "==").concat(v);
|
|
112
120
|
}).join('||');
|
|
113
|
-
paramsArray.push("filters=".concat(_filterString));
|
|
121
|
+
paramsArray.push("filters=".concat(conditionalEncodeURIComponent(_filterString)));
|
|
114
122
|
}
|
|
115
123
|
});
|
|
116
124
|
}
|
|
117
125
|
if (optionsSort && optionsSort.length > 0) {
|
|
118
126
|
optionsSort.forEach(function (os) {
|
|
119
127
|
if (os.value) {
|
|
120
|
-
paramsArray.push("sort=".concat(os.value));
|
|
128
|
+
paramsArray.push("sort=".concat(conditionalEncodeURIComponent(os.value)));
|
|
121
129
|
} else if (os.path) {
|
|
122
130
|
var _os$direction;
|
|
123
131
|
// If no path then ignore
|
|
124
|
-
|
|
132
|
+
var sortString = "".concat(os.path, ";").concat((_os$direction = os.direction) !== null && _os$direction !== void 0 ? _os$direction : 'asc');
|
|
133
|
+
paramsArray.push("sort=".concat(conditionalEncodeURIComponent(sortString)));
|
|
125
134
|
}
|
|
126
135
|
});
|
|
127
136
|
}
|
|
@@ -133,7 +142,8 @@ var generateKiwtQueryParams = function generateKiwtQueryParams(options, nsValues
|
|
|
133
142
|
if (term in sortKeys) {
|
|
134
143
|
term = term.replace(term, sortKeys[term]);
|
|
135
144
|
}
|
|
136
|
-
|
|
145
|
+
var sortString = "".concat(term, ";").concat(descending ? 'desc' : 'asc');
|
|
146
|
+
return "sort=".concat(conditionalEncodeURIComponent(sortString));
|
|
137
147
|
})));
|
|
138
148
|
}
|
|
139
149
|
if (stats) {
|
|
@@ -143,7 +153,7 @@ var generateKiwtQueryParams = function generateKiwtQueryParams(options, nsValues
|
|
|
143
153
|
var _Object$entries$_i = _slicedToArray(_Object$entries[_i2], 2),
|
|
144
154
|
key = _Object$entries$_i[0],
|
|
145
155
|
value = _Object$entries$_i[1];
|
|
146
|
-
paramsArray.push("".concat(key, "=").concat(value));
|
|
156
|
+
paramsArray.push("".concat(key, "=").concat(conditionalEncodeURIComponent(value)));
|
|
147
157
|
}
|
|
148
158
|
return paramsArray;
|
|
149
159
|
};
|
package/package.json
CHANGED
package/src/lib/utils/README.md
CHANGED
|
@@ -31,6 +31,7 @@ Name | Type | Description | default | required
|
|
|
31
31
|
--- | --- | --- | --- | ---
|
|
32
32
|
options | object | An object with keys: `searchKey`, `filterKeys`, `sortKeys` and `stats`, which maps the incoming nsValues objects to a KIWT query. You can also pass arbitrary `key`/`value` pairs to append `key==value` onto the query. | | ✓ |
|
|
33
33
|
nsValues | object | An object containing the actual query parameters to become the mapped KIWT query | | ✓ |
|
|
34
|
+
encode | boolean | A boolean prop which determines if each query param chunk will be encoded using encodeURIComponent or not | true | ✕ |
|
|
34
35
|
|
|
35
36
|
## generateKiwtQueryParams
|
|
36
37
|
A util function for generating an array of "KIWT" (K-Int Web-Toolkit) style backend query parameters from a SASQ query object
|
|
@@ -68,4 +69,5 @@ import { generateKiwtQueryParams } from '@k-int/stripes-kint-components'
|
|
|
68
69
|
Name | Type | Description | default | required
|
|
69
70
|
--- | --- | --- | --- | ---
|
|
70
71
|
options | object | An object with keys: `searchKey`, `filterKeys`, `sortKeys` and `stats`, which maps the incoming nsValues objects to an KIWT query array. You can also pass arbitrary `key`/`value` pairs to append `key==value` onto the query. | | ✓ |
|
|
71
|
-
nsValues | object | An object containing the actual query parameters to become the mapped KIWT query | | ✓ |
|
|
72
|
+
nsValues | object | An object containing the actual query parameters to become the mapped KIWT query | | ✓ |
|
|
73
|
+
encode | boolean | A boolean prop which determines if each query param chunk will be encoded using encodeURIComponent or not | true | ✕ |
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import generateKiwtQueryParams from './generateKiwtQueryParams';
|
|
2
2
|
|
|
3
|
-
const generateKiwtQuery = (options, nsValues) => {
|
|
4
|
-
const paramsArray = generateKiwtQueryParams(options, nsValues);
|
|
5
|
-
return paramsArray.length ? '?' + paramsArray.
|
|
3
|
+
const generateKiwtQuery = (options, nsValues, encode = true) => {
|
|
4
|
+
const paramsArray = generateKiwtQueryParams(options, nsValues, encode);
|
|
5
|
+
return paramsArray.length ? '?' + paramsArray.join('&') : '';
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
export default generateKiwtQuery;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const generateKiwtQueryParams = (options, nsValues) => {
|
|
1
|
+
const generateKiwtQueryParams = (options, nsValues, encode = true) => {
|
|
2
2
|
const { qindex, query, filters, sort } = nsValues;
|
|
3
3
|
const {
|
|
4
4
|
searchKey = '',
|
|
@@ -33,11 +33,20 @@ const generateKiwtQueryParams = (options, nsValues) => {
|
|
|
33
33
|
...rest
|
|
34
34
|
} = options;
|
|
35
35
|
|
|
36
|
+
const conditionalEncodeURIComponent = (str) => {
|
|
37
|
+
if (encode) {
|
|
38
|
+
return encodeURIComponent(str);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return str;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
|
|
36
45
|
const paramsArray = [];
|
|
37
46
|
|
|
38
47
|
if (query) {
|
|
39
|
-
paramsArray.push(...(qindex || searchKey).split(',')?.map(m => `match=${m}`));
|
|
40
|
-
paramsArray.push(`term=${query}`);
|
|
48
|
+
paramsArray.push(...(qindex || searchKey).split(',')?.map(m => `match=${conditionalEncodeURIComponent(m)}`));
|
|
49
|
+
paramsArray.push(`term=${conditionalEncodeURIComponent(query)}`);
|
|
41
50
|
}
|
|
42
51
|
|
|
43
52
|
if (optionsFilters) {
|
|
@@ -52,12 +61,14 @@ const generateKiwtQueryParams = (options, nsValues) => {
|
|
|
52
61
|
innerFilters.push(opfv);
|
|
53
62
|
}
|
|
54
63
|
});
|
|
55
|
-
|
|
64
|
+
|
|
65
|
+
paramsArray.push(`filters=${conditionalEncodeURIComponent(innerFilters.join('||'))}`);
|
|
56
66
|
} else if (opf?.value) { // If no value OR values, then ignore
|
|
57
67
|
if (opf.path) {
|
|
58
|
-
|
|
68
|
+
const filterString = `${opf.path}${opf.comparator ?? '=='}${opf.value}`;
|
|
69
|
+
paramsArray.push(`filters=${conditionalEncodeURIComponent(filterString)}`);
|
|
59
70
|
} else {
|
|
60
|
-
paramsArray.push(`filters=${opf.value}`);
|
|
71
|
+
paramsArray.push(`filters=${conditionalEncodeURIComponent(opf.value)}`);
|
|
61
72
|
}
|
|
62
73
|
}
|
|
63
74
|
});
|
|
@@ -84,13 +95,13 @@ const generateKiwtQueryParams = (options, nsValues) => {
|
|
|
84
95
|
return `${filterName}==${fceValue ?? v}`;
|
|
85
96
|
}).join('||');
|
|
86
97
|
|
|
87
|
-
paramsArray.push(`filters=${filterString}`);
|
|
98
|
+
paramsArray.push(`filters=${conditionalEncodeURIComponent(filterString)}`);
|
|
88
99
|
} else if (!filterKey) {
|
|
89
100
|
// These filters have no key mapping so we just pass the values to the backend as-is.
|
|
90
|
-
paramsArray.push(...filterValues?.map(f => `filters=${f}`));
|
|
101
|
+
paramsArray.push(...filterValues?.map(f => `filters=${conditionalEncodeURIComponent(f)}`));
|
|
91
102
|
} else {
|
|
92
103
|
const filterString = filterValues.map(v => `${filterKey}==${v}`).join('||');
|
|
93
|
-
paramsArray.push(`filters=${filterString}`);
|
|
104
|
+
paramsArray.push(`filters=${conditionalEncodeURIComponent(filterString)}`);
|
|
94
105
|
}
|
|
95
106
|
});
|
|
96
107
|
}
|
|
@@ -98,9 +109,10 @@ const generateKiwtQueryParams = (options, nsValues) => {
|
|
|
98
109
|
if (optionsSort && optionsSort.length > 0) {
|
|
99
110
|
optionsSort.forEach(os => {
|
|
100
111
|
if (os.value) {
|
|
101
|
-
paramsArray.push(`sort=${os.value}`);
|
|
112
|
+
paramsArray.push(`sort=${conditionalEncodeURIComponent(os.value)}`);
|
|
102
113
|
} else if (os.path) { // If no path then ignore
|
|
103
|
-
|
|
114
|
+
const sortString = `${os.path};${os.direction ?? 'asc'}`;
|
|
115
|
+
paramsArray.push(`sort=${conditionalEncodeURIComponent(sortString)}`);
|
|
104
116
|
}
|
|
105
117
|
});
|
|
106
118
|
}
|
|
@@ -114,7 +126,9 @@ const generateKiwtQueryParams = (options, nsValues) => {
|
|
|
114
126
|
term = term.replace(term, sortKeys[term]);
|
|
115
127
|
}
|
|
116
128
|
|
|
117
|
-
|
|
129
|
+
const sortString = `${term};${descending ? 'desc' : 'asc'}`;
|
|
130
|
+
|
|
131
|
+
return `sort=${conditionalEncodeURIComponent(sortString)}`;
|
|
118
132
|
}));
|
|
119
133
|
}
|
|
120
134
|
|
|
@@ -123,7 +137,7 @@ const generateKiwtQueryParams = (options, nsValues) => {
|
|
|
123
137
|
}
|
|
124
138
|
|
|
125
139
|
for (const [key, value] of Object.entries(rest)) {
|
|
126
|
-
paramsArray.push(`${key}=${value}`);
|
|
140
|
+
paramsArray.push(`${key}=${conditionalEncodeURIComponent(value)}`);
|
|
127
141
|
}
|
|
128
142
|
|
|
129
143
|
return paramsArray;
|