@k-int/stripes-kint-components 5.26.0 → 5.27.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 +8 -0
- package/es/lib/hooks/index.js +9 -1
- package/es/lib/hooks/useStandaloneSASQQueryParameter/index.js +13 -0
- package/es/lib/hooks/useStandaloneSASQQueryParameter/useStandaloneSASQQueryParameter.js +77 -0
- package/es/lib/utils/generateKiwtQueryParams/generateKiwtQueryParams.js +31 -2
- package/package.json +1 -1
- package/src/lib/hooks/index.js +1 -0
- package/src/lib/hooks/useStandaloneSASQQueryParameter/index.js +1 -0
- package/src/lib/hooks/useStandaloneSASQQueryParameter/useStandaloneSASQQueryParameter.js +67 -0
- package/src/lib/utils/generateKiwtQueryParams/generateKiwtQueryParams.js +38 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
# [5.27.0](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/compare/v5.26.0...v5.27.0) (2025-10-21)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **generateKiwtQueryParams:** Added filterConfig.filterPrefix and filterConfig.valuesMapping options ([77915db](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/commit/77915db6b9d189531e80e9ea8af3bbf82636b9cb))
|
|
7
|
+
* useStandaloneSASQQueryParameter for non-stripes filter options (not recommended) ([631ecfe](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/commit/631ecfe4dae3d90b71e9468a1c2a8e2f30babb6b))
|
|
8
|
+
|
|
1
9
|
# [5.26.0](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/compare/v5.25.3...v5.26.0) (2025-10-15)
|
|
2
10
|
|
|
3
11
|
|
package/es/lib/hooks/index.js
CHANGED
|
@@ -22,7 +22,8 @@ var _exportNames = {
|
|
|
22
22
|
useMutateRefdataCategory: true,
|
|
23
23
|
useMutateCustomProperties: true,
|
|
24
24
|
useMutateModConfigEntry: true,
|
|
25
|
-
usePrevNextPagination: true
|
|
25
|
+
usePrevNextPagination: true,
|
|
26
|
+
useStandaloneSASQQueryParameter: true
|
|
26
27
|
};
|
|
27
28
|
Object.defineProperty(exports, "useActionListRef", {
|
|
28
29
|
enumerable: true,
|
|
@@ -132,6 +133,12 @@ Object.defineProperty(exports, "useSASQQueryMeta", {
|
|
|
132
133
|
return _useSASQQueryMeta.default;
|
|
133
134
|
}
|
|
134
135
|
});
|
|
136
|
+
Object.defineProperty(exports, "useStandaloneSASQQueryParameter", {
|
|
137
|
+
enumerable: true,
|
|
138
|
+
get: function () {
|
|
139
|
+
return _useStandaloneSASQQueryParameter.default;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
135
142
|
Object.defineProperty(exports, "useTemplates", {
|
|
136
143
|
enumerable: true,
|
|
137
144
|
get: function () {
|
|
@@ -157,6 +164,7 @@ var _useMutateRefdataCategory = _interopRequireDefault(require("./useMutateRefda
|
|
|
157
164
|
var _useMutateCustomProperties = _interopRequireDefault(require("./useMutateCustomProperties"));
|
|
158
165
|
var _useMutateModConfigEntry = _interopRequireDefault(require("./useMutateModConfigEntry"));
|
|
159
166
|
var _usePrevNextPagination = _interopRequireDefault(require("./usePrevNextPagination"));
|
|
167
|
+
var _useStandaloneSASQQueryParameter = _interopRequireDefault(require("./useStandaloneSASQQueryParameter"));
|
|
160
168
|
var _intlHooks = require("./intlHooks");
|
|
161
169
|
Object.keys(_intlHooks).forEach(function (key) {
|
|
162
170
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "default", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _useStandaloneSASQQueryParameter.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _useStandaloneSASQQueryParameter = _interopRequireDefault(require("./useStandaloneSASQQueryParameter"));
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _reactRouter = require("react-router");
|
|
9
|
+
var _queryString = _interopRequireDefault(require("query-string"));
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
12
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
13
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
14
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
15
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
16
|
+
// !WARNING! This pattern is not recommended
|
|
17
|
+
// You likely want to make use of the filterConfig valuesMapping/filterPrefix
|
|
18
|
+
// instead so SASQ filters can be used natively
|
|
19
|
+
/**
|
|
20
|
+
* Custom hook for managing a single, standalone URL query parameter.
|
|
21
|
+
*
|
|
22
|
+
* This hook automatically reads a specified query parameter from the URL. If the
|
|
23
|
+
* parameter is missing on the initial load, it uses `defaultValue` and updates
|
|
24
|
+
* the URL to include it. It provides a `handler` function to update the
|
|
25
|
+
* parameter's value in the URL, which defaults to `fallbackValue` if no new
|
|
26
|
+
* value is explicitly provided to the handler.
|
|
27
|
+
*
|
|
28
|
+
* @param {object} props - The properties object.
|
|
29
|
+
* @param {string} props.name - The name of the query parameter to manage (e.g., 'showDetails').
|
|
30
|
+
* @param {string} [props.defaultValue='true'] - The value to set in the URL if the parameter is missing on initial load.
|
|
31
|
+
* @param {string} [props.fallbackValue='false'] - The value to set when the `handler` is called without a new value.
|
|
32
|
+
* @returns {{ handler: function, param: string }} An object containing the update handler and the current parameter value.
|
|
33
|
+
*/
|
|
34
|
+
const useStandaloneSASQQueryParameter = _ref => {
|
|
35
|
+
let {
|
|
36
|
+
name,
|
|
37
|
+
defaultValue,
|
|
38
|
+
// This is the value that will be spun up if no value is present in the url
|
|
39
|
+
fallbackValue // This is the value that will be set if there is no value passed to handler (values[0])
|
|
40
|
+
} = _ref;
|
|
41
|
+
const location = (0, _reactRouter.useLocation)();
|
|
42
|
+
const history = (0, _reactRouter.useHistory)();
|
|
43
|
+
|
|
44
|
+
// Special URL management for includeTerminal
|
|
45
|
+
const urlQuery = _queryString.default.parse(location.search);
|
|
46
|
+
const param = urlQuery[name];
|
|
47
|
+
const handler = _ref2 => {
|
|
48
|
+
var _values$;
|
|
49
|
+
let {
|
|
50
|
+
name: _name,
|
|
51
|
+
values
|
|
52
|
+
} = _ref2;
|
|
53
|
+
const newQuery = _objectSpread(_objectSpread({}, urlQuery), {}, {
|
|
54
|
+
[name]: (_values$ = values[1]) !== null && _values$ !== void 0 ? _values$ : fallbackValue // SECOND value is the new one
|
|
55
|
+
});
|
|
56
|
+
history.push({
|
|
57
|
+
pathname: location.pathname,
|
|
58
|
+
search: "?".concat(_queryString.default.stringify(newQuery))
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
(0, _react.useEffect)(() => {
|
|
62
|
+
if (!param) {
|
|
63
|
+
const newQuery = _objectSpread(_objectSpread({}, urlQuery), {}, {
|
|
64
|
+
[name]: defaultValue
|
|
65
|
+
});
|
|
66
|
+
history.push({
|
|
67
|
+
pathname: location.pathname,
|
|
68
|
+
search: "?".concat(_queryString.default.stringify(newQuery))
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}, [defaultValue, history, location.pathname, name, param, urlQuery]);
|
|
72
|
+
return {
|
|
73
|
+
handler,
|
|
74
|
+
param
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
var _default = exports.default = useStandaloneSASQQueryParameter;
|
|
@@ -82,6 +82,29 @@ const generateKiwtQueryParams = function (options, nsValues) {
|
|
|
82
82
|
} = nsValues;
|
|
83
83
|
const {
|
|
84
84
|
searchKey = '',
|
|
85
|
+
/*
|
|
86
|
+
* Array of objects to configure how filters coming from `nsValues.filters` are mapped into KIWT filter strings.
|
|
87
|
+
*
|
|
88
|
+
* Example structure:
|
|
89
|
+
* [
|
|
90
|
+
* {
|
|
91
|
+
* name: 'status', // Matches filter key in URL (e.g., filters=status.active)
|
|
92
|
+
* filterPrefix: 'filters=', // Optional, defaults to 'filters='
|
|
93
|
+
* // Optional function to entirely customize how the array of values is mapped to a string.
|
|
94
|
+
* // (e.g., ['active', 'cancelled'] => 'is:active and is:cancelled')
|
|
95
|
+
* // Defaults to constructing from `values` map below
|
|
96
|
+
* // valuesMapping: (filterValues) => string,
|
|
97
|
+
* values: [ // Optional: Specific configuration for individual filter values
|
|
98
|
+
* {
|
|
99
|
+
* name: 'active', // Matches filter value in URL
|
|
100
|
+
* value: 'activeValue', // Actual value to use in the KIWT query (defaults to name)
|
|
101
|
+
* comparator: '==' // Optional comparator override (defaults to '==')
|
|
102
|
+
* },
|
|
103
|
+
* // ... other values
|
|
104
|
+
* ]
|
|
105
|
+
* }
|
|
106
|
+
* ]
|
|
107
|
+
*/
|
|
85
108
|
filterConfig = [],
|
|
86
109
|
/* Assumtion made that if no filterKey is provided then the given filterValues for that key are standalaone, ie require no comparator or key */
|
|
87
110
|
filterKeys = {},
|
|
@@ -153,8 +176,11 @@ const generateKiwtQueryParams = function (options, nsValues) {
|
|
|
153
176
|
const filterConfigEntry = filterConfig.find(conf => conf.name === filterName);
|
|
154
177
|
const filterKey = filterKeys[filterName];
|
|
155
178
|
if (filterConfigEntry) {
|
|
179
|
+
var _filterConfigEntry$fi;
|
|
156
180
|
// We have a direct mapping instruction, use it
|
|
157
|
-
|
|
181
|
+
|
|
182
|
+
// Do we have a specific way to map values to a string?
|
|
183
|
+
const filterString = filterConfigEntry.valuesMapping ? filterConfigEntry.valuesMapping(filterValues) : filterValues.map(v => {
|
|
158
184
|
var _filterConfigEntry$va, _filterConfigEntry$va2, _fcValueEntry$value, _fcValueEntry$compara;
|
|
159
185
|
const fcValueEntry = (_filterConfigEntry$va = filterConfigEntry === null || filterConfigEntry === void 0 || (_filterConfigEntry$va2 = filterConfigEntry.values) === null || _filterConfigEntry$va2 === void 0 ? void 0 : _filterConfigEntry$va2.find(fce => fce.name === v)) !== null && _filterConfigEntry$va !== void 0 ? _filterConfigEntry$va : {};
|
|
160
186
|
const fceValue = (_fcValueEntry$value = fcValueEntry.value) !== null && _fcValueEntry$value !== void 0 ? _fcValueEntry$value : v;
|
|
@@ -162,7 +188,10 @@ const generateKiwtQueryParams = function (options, nsValues) {
|
|
|
162
188
|
const fceComparator = (_fcValueEntry$compara = fcValueEntry.comparator) !== null && _fcValueEntry$compara !== void 0 ? _fcValueEntry$compara : '==';
|
|
163
189
|
return "".concat(filterKey !== null && filterKey !== void 0 ? filterKey : filterName).concat(fceComparator).concat(fceValue !== null && fceValue !== void 0 ? fceValue : v);
|
|
164
190
|
}).join('||');
|
|
165
|
-
|
|
191
|
+
|
|
192
|
+
// This will NOT be url encoded by this component
|
|
193
|
+
const filterPrefix = (_filterConfigEntry$fi = filterConfigEntry.filterPrefix) !== null && _filterConfigEntry$fi !== void 0 ? _filterConfigEntry$fi : 'filters=';
|
|
194
|
+
paramsArray.push("".concat(filterPrefix).concat(conditionalEncodeURIComponent(filterString, encode)));
|
|
166
195
|
} else if (!filterKey) {
|
|
167
196
|
// These filters have no key mapping so we just pass the values to the backend as-is.
|
|
168
197
|
paramsArray.push(...(filterValues !== null && filterValues !== void 0 ? filterValues : []).map(f => "filters=".concat(conditionalEncodeURIComponent(f, encode))));
|
package/package.json
CHANGED
package/src/lib/hooks/index.js
CHANGED
|
@@ -19,5 +19,6 @@ export { default as useMutateCustomProperties } from './useMutateCustomPropertie
|
|
|
19
19
|
export { default as useMutateModConfigEntry } from './useMutateModConfigEntry';
|
|
20
20
|
|
|
21
21
|
export { default as usePrevNextPagination } from './usePrevNextPagination';
|
|
22
|
+
export { default as useStandaloneSASQQueryParameter } from './useStandaloneSASQQueryParameter';
|
|
22
23
|
|
|
23
24
|
export * from './intlHooks';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './useStandaloneSASQQueryParameter';
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { useHistory, useLocation } from 'react-router';
|
|
3
|
+
import queryString from 'query-string';
|
|
4
|
+
|
|
5
|
+
// !WARNING! This pattern is not recommended
|
|
6
|
+
// You likely want to make use of the filterConfig valuesMapping/filterPrefix
|
|
7
|
+
// instead so SASQ filters can be used natively
|
|
8
|
+
/**
|
|
9
|
+
* Custom hook for managing a single, standalone URL query parameter.
|
|
10
|
+
*
|
|
11
|
+
* This hook automatically reads a specified query parameter from the URL. If the
|
|
12
|
+
* parameter is missing on the initial load, it uses `defaultValue` and updates
|
|
13
|
+
* the URL to include it. It provides a `handler` function to update the
|
|
14
|
+
* parameter's value in the URL, which defaults to `fallbackValue` if no new
|
|
15
|
+
* value is explicitly provided to the handler.
|
|
16
|
+
*
|
|
17
|
+
* @param {object} props - The properties object.
|
|
18
|
+
* @param {string} props.name - The name of the query parameter to manage (e.g., 'showDetails').
|
|
19
|
+
* @param {string} [props.defaultValue='true'] - The value to set in the URL if the parameter is missing on initial load.
|
|
20
|
+
* @param {string} [props.fallbackValue='false'] - The value to set when the `handler` is called without a new value.
|
|
21
|
+
* @returns {{ handler: function, param: string }} An object containing the update handler and the current parameter value.
|
|
22
|
+
*/
|
|
23
|
+
const useStandaloneSASQQueryParameter = ({
|
|
24
|
+
name,
|
|
25
|
+
defaultValue, // This is the value that will be spun up if no value is present in the url
|
|
26
|
+
fallbackValue, // This is the value that will be set if there is no value passed to handler (values[0])
|
|
27
|
+
}) => {
|
|
28
|
+
const location = useLocation();
|
|
29
|
+
const history = useHistory();
|
|
30
|
+
|
|
31
|
+
// Special URL management for includeTerminal
|
|
32
|
+
const urlQuery = queryString.parse(location.search);
|
|
33
|
+
const param = urlQuery[name];
|
|
34
|
+
|
|
35
|
+
const handler = ({ name: _name, values }) => {
|
|
36
|
+
const newQuery = {
|
|
37
|
+
...urlQuery,
|
|
38
|
+
[name]: values[1] ?? fallbackValue // SECOND value is the new one
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
history.push({
|
|
42
|
+
pathname: location.pathname,
|
|
43
|
+
search: `?${queryString.stringify(newQuery)}`
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (!param) {
|
|
49
|
+
const newQuery = {
|
|
50
|
+
...urlQuery,
|
|
51
|
+
[name]: defaultValue
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
history.push({
|
|
55
|
+
pathname: location.pathname,
|
|
56
|
+
search: `?${queryString.stringify(newQuery)}`
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}, [defaultValue, history, location.pathname, name, param, urlQuery]);
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
handler,
|
|
63
|
+
param
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export default useStandaloneSASQQueryParameter;
|
|
@@ -67,6 +67,29 @@ const generateKiwtQueryParams = (options, nsValues, encode = true) => {
|
|
|
67
67
|
const { qindex, query, filters, sort } = nsValues;
|
|
68
68
|
const {
|
|
69
69
|
searchKey = '',
|
|
70
|
+
/*
|
|
71
|
+
* Array of objects to configure how filters coming from `nsValues.filters` are mapped into KIWT filter strings.
|
|
72
|
+
*
|
|
73
|
+
* Example structure:
|
|
74
|
+
* [
|
|
75
|
+
* {
|
|
76
|
+
* name: 'status', // Matches filter key in URL (e.g., filters=status.active)
|
|
77
|
+
* filterPrefix: 'filters=', // Optional, defaults to 'filters='
|
|
78
|
+
* // Optional function to entirely customize how the array of values is mapped to a string.
|
|
79
|
+
* // (e.g., ['active', 'cancelled'] => 'is:active and is:cancelled')
|
|
80
|
+
* // Defaults to constructing from `values` map below
|
|
81
|
+
* // valuesMapping: (filterValues) => string,
|
|
82
|
+
* values: [ // Optional: Specific configuration for individual filter values
|
|
83
|
+
* {
|
|
84
|
+
* name: 'active', // Matches filter value in URL
|
|
85
|
+
* value: 'activeValue', // Actual value to use in the KIWT query (defaults to name)
|
|
86
|
+
* comparator: '==' // Optional comparator override (defaults to '==')
|
|
87
|
+
* },
|
|
88
|
+
* // ... other values
|
|
89
|
+
* ]
|
|
90
|
+
* }
|
|
91
|
+
* ]
|
|
92
|
+
*/
|
|
70
93
|
filterConfig = [],
|
|
71
94
|
/* Assumtion made that if no filterKey is provided then the given filterValues for that key are standalaone, ie require no comparator or key */
|
|
72
95
|
filterKeys = {},
|
|
@@ -140,15 +163,22 @@ const generateKiwtQueryParams = (options, nsValues, encode = true) => {
|
|
|
140
163
|
const filterKey = filterKeys[filterName];
|
|
141
164
|
if (filterConfigEntry) {
|
|
142
165
|
// We have a direct mapping instruction, use it
|
|
143
|
-
const filterString = filterValues.map(v => {
|
|
144
|
-
const fcValueEntry = filterConfigEntry?.values?.find(fce => fce.name === v) ?? {};
|
|
145
|
-
const fceValue = fcValueEntry.value ?? v;
|
|
146
|
-
// This is especially useful where comparator acts strangely for a single value, such as `filters=foo isNotSet`
|
|
147
|
-
const fceComparator = fcValueEntry.comparator ?? '==';
|
|
148
|
-
return `${filterKey ?? filterName}${fceComparator}${fceValue ?? v}`;
|
|
149
|
-
}).join('||');
|
|
150
166
|
|
|
151
|
-
|
|
167
|
+
// Do we have a specific way to map values to a string?
|
|
168
|
+
const filterString = filterConfigEntry.valuesMapping ?
|
|
169
|
+
filterConfigEntry.valuesMapping(filterValues) :
|
|
170
|
+
filterValues.map(v => {
|
|
171
|
+
const fcValueEntry = filterConfigEntry?.values?.find(fce => fce.name === v) ?? {};
|
|
172
|
+
const fceValue = fcValueEntry.value ?? v;
|
|
173
|
+
// This is especially useful where comparator acts strangely for a single value, such as `filters=foo isNotSet`
|
|
174
|
+
const fceComparator = fcValueEntry.comparator ?? '==';
|
|
175
|
+
return `${filterKey ?? filterName}${fceComparator}${fceValue ?? v}`;
|
|
176
|
+
}).join('||');
|
|
177
|
+
|
|
178
|
+
// This will NOT be url encoded by this component
|
|
179
|
+
const filterPrefix = filterConfigEntry.filterPrefix ?? 'filters=';
|
|
180
|
+
|
|
181
|
+
paramsArray.push(`${filterPrefix}${conditionalEncodeURIComponent(filterString, encode)}`);
|
|
152
182
|
} else if (!filterKey) {
|
|
153
183
|
// These filters have no key mapping so we just pass the values to the backend as-is.
|
|
154
184
|
paramsArray.push(...(filterValues ?? []).map(f => `filters=${conditionalEncodeURIComponent(f, encode)}`));
|