@k-int/stripes-kint-components 5.20.1 → 5.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/CHANGELOG.md +12 -0
- package/es/lib/hooks/useKiwtSASQuery.js +12 -3
- package/es/lib/hooks/usePrevNextPagination.js +3 -1
- package/es/lib/settingsHooks/useSettingSection/useSettingSection.js +11 -7
- package/package.json +1 -1
- package/src/lib/hooks/useKiwtSASQuery.js +13 -5
- package/src/lib/hooks/usePrevNextPagination.js +2 -1
- package/src/lib/settingsHooks/useSettingSection/README.md +16 -15
- package/src/lib/settingsHooks/useSettingSection/useSettingSection.js +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
# [5.21.0](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/compare/v5.20.1...v5.21.0) (2025-06-06)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* useKiwtSASQuery use state ([7e4f89c](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/commit/7e4f89c6fb4b0a7a64331f55a4647c5c6a9c3464))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* useSettingSection configurability ([8e7b724](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/commit/8e7b724f442c440b1a3d5b36b95300e4417b4d4e))
|
|
12
|
+
|
|
1
13
|
## [5.20.1](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/compare/v5.20.0...v5.20.1) (2025-05-14)
|
|
2
14
|
|
|
3
15
|
|
|
@@ -13,7 +13,8 @@ const locationQuerySetter = _ref => {
|
|
|
13
13
|
let {
|
|
14
14
|
location,
|
|
15
15
|
history,
|
|
16
|
-
nsValues
|
|
16
|
+
nsValues,
|
|
17
|
+
state
|
|
17
18
|
} = _ref;
|
|
18
19
|
const {
|
|
19
20
|
pathname,
|
|
@@ -24,7 +25,13 @@ const locationQuerySetter = _ref => {
|
|
|
24
25
|
// Do not push to history if the url didn't change
|
|
25
26
|
// https://issues.folio.org/browse/STSMACOM-637
|
|
26
27
|
if (`${pathname}${search}` !== url) {
|
|
27
|
-
history
|
|
28
|
+
// Only PUSH to history if we're not doing an initialisation OR changing from external-location
|
|
29
|
+
// This is the SASQ state being used here
|
|
30
|
+
if (['external-location', 'init.reset'].includes(state?.changeType)) {
|
|
31
|
+
history.replace(url);
|
|
32
|
+
} else {
|
|
33
|
+
history.push(url);
|
|
34
|
+
}
|
|
28
35
|
}
|
|
29
36
|
};
|
|
30
37
|
const useKiwtSASQuery = () => {
|
|
@@ -42,7 +49,8 @@ const useKiwtSASQuery = () => {
|
|
|
42
49
|
}
|
|
43
50
|
const querySetter = _ref2 => {
|
|
44
51
|
let {
|
|
45
|
-
nsValues
|
|
52
|
+
nsValues,
|
|
53
|
+
...rest
|
|
46
54
|
} = _ref2;
|
|
47
55
|
setQuery({
|
|
48
56
|
...query,
|
|
@@ -50,6 +58,7 @@ const useKiwtSASQuery = () => {
|
|
|
50
58
|
qindex
|
|
51
59
|
});
|
|
52
60
|
locationQuerySetter({
|
|
61
|
+
...rest,
|
|
53
62
|
location,
|
|
54
63
|
history,
|
|
55
64
|
nsValues
|
|
@@ -101,7 +101,9 @@ const usePrevNextPagination = function () {
|
|
|
101
101
|
...urlQuery,
|
|
102
102
|
page: 1
|
|
103
103
|
};
|
|
104
|
-
|
|
104
|
+
|
|
105
|
+
// We use replace instead of push for the defaulting so we don't add unnecessary history entries
|
|
106
|
+
history.replace({
|
|
105
107
|
pathname: location.pathname,
|
|
106
108
|
search: `?${_queryString.default.stringify(newQuery)}`
|
|
107
109
|
});
|
|
@@ -15,9 +15,9 @@ const useSettingSection = _ref => {
|
|
|
15
15
|
let {
|
|
16
16
|
queryParams
|
|
17
17
|
} = _ref2;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
return ['stripes-kint-components', 'useSetting', 'appSettings', queryParams, sectionName];
|
|
19
|
+
},
|
|
20
|
+
getMutateNamespaceGenerator = () => ['stripes-kint-components', 'useSetting', 'putSetting', sectionName]
|
|
21
21
|
} = _ref;
|
|
22
22
|
const ky = (0, _core.useOkapiKy)();
|
|
23
23
|
const queryParams = (0, _utils.generateKiwtQueryParams)({
|
|
@@ -32,18 +32,22 @@ const useSettingSection = _ref => {
|
|
|
32
32
|
stats: false
|
|
33
33
|
}, {});
|
|
34
34
|
const {
|
|
35
|
-
data: settings = []
|
|
35
|
+
data: settings = [],
|
|
36
|
+
...settingsQuery
|
|
36
37
|
} = (0, _reactQuery.useQuery)(getQueryNamespaceGenerator({
|
|
37
38
|
queryParams
|
|
38
39
|
}), () => ky(`${settingEndpoint}?${queryParams?.join('&')}`).json());
|
|
39
40
|
const {
|
|
40
|
-
mutateAsync: putSetting
|
|
41
|
-
|
|
41
|
+
mutateAsync: putSetting,
|
|
42
|
+
...settingsMutate
|
|
43
|
+
} = (0, _reactQuery.useMutation)(getMutateNamespaceGenerator(), data => ky.put(`${settingEndpoint}${data.id ? '/' + data.id : ''}`, {
|
|
42
44
|
json: data
|
|
43
45
|
}));
|
|
44
46
|
return {
|
|
45
47
|
handleSubmit: putSetting,
|
|
46
|
-
settings
|
|
48
|
+
settings,
|
|
49
|
+
settingsQuery,
|
|
50
|
+
settingsMutate
|
|
47
51
|
};
|
|
48
52
|
};
|
|
49
53
|
var _default = exports.default = useSettingSection;
|
package/package.json
CHANGED
|
@@ -4,14 +4,22 @@ import { useLocation, useHistory } from 'react-router-dom';
|
|
|
4
4
|
import buildUrl from '../utils/buildUrl';
|
|
5
5
|
import useQindex from './useQIndex';
|
|
6
6
|
|
|
7
|
-
const locationQuerySetter = ({ location, history, nsValues }) => {
|
|
7
|
+
const locationQuerySetter = ({ location, history, nsValues, state }) => {
|
|
8
8
|
const { pathname, search } = location;
|
|
9
9
|
const url = buildUrl(location, nsValues);
|
|
10
10
|
|
|
11
11
|
// Do not push to history if the url didn't change
|
|
12
12
|
// https://issues.folio.org/browse/STSMACOM-637
|
|
13
|
-
if (
|
|
14
|
-
|
|
13
|
+
if (
|
|
14
|
+
`${pathname}${search}` !== url
|
|
15
|
+
) {
|
|
16
|
+
// Only PUSH to history if we're not doing an initialisation OR changing from external-location
|
|
17
|
+
// This is the SASQ state being used here
|
|
18
|
+
if (['external-location', 'init.reset'].includes(state?.changeType)) {
|
|
19
|
+
history.replace(url);
|
|
20
|
+
} else {
|
|
21
|
+
history.push(url);
|
|
22
|
+
}
|
|
15
23
|
}
|
|
16
24
|
};
|
|
17
25
|
|
|
@@ -27,9 +35,9 @@ const useKiwtSASQuery = () => {
|
|
|
27
35
|
setQuery({ ...query, qindex });
|
|
28
36
|
}
|
|
29
37
|
|
|
30
|
-
const querySetter = ({ nsValues }) => {
|
|
38
|
+
const querySetter = ({ nsValues, ...rest }) => {
|
|
31
39
|
setQuery({ ...query, ...nsValues, qindex });
|
|
32
|
-
locationQuerySetter({ location, history, nsValues });
|
|
40
|
+
locationQuerySetter({ ...rest, location, history, nsValues });
|
|
33
41
|
};
|
|
34
42
|
return { query, queryGetter, querySetter };
|
|
35
43
|
};
|
|
@@ -115,7 +115,8 @@ const usePrevNextPagination = ({
|
|
|
115
115
|
page: 1
|
|
116
116
|
};
|
|
117
117
|
|
|
118
|
-
history
|
|
118
|
+
// We use replace instead of push for the defaulting so we don't add unnecessary history entries
|
|
119
|
+
history.replace({
|
|
119
120
|
pathname: location.pathname,
|
|
120
121
|
search: `?${queryString.stringify(newQuery)}`
|
|
121
122
|
});
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# useSettingSection
|
|
2
2
|
|
|
3
|
-
A custom hook
|
|
3
|
+
A custom React hook designed for fetching and updating settings data from an API. It leverages `react-query` for robust asynchronous data management and provides flexible control over query and mutation keys.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
`useSettingSection`
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
`useSettingSection` simplifies interaction with a settings API by:
|
|
8
|
+
|
|
9
|
+
* **Fetching Settings:** It retrieves settings for a specific `sectionName`, automatically filtering and sorting the results. Data is cached and managed efficiently by `react-query`.
|
|
10
|
+
* **Updating Settings:** It provides a mutation handler (`handleSubmit`) to send updates for individual settings, performing an HTTP PUT request to your specified endpoint.
|
|
11
|
+
* **Flexible Key Generation:** Offers optional functions to customize the `react-query` keys for both data fetching and mutations, allowing for fine-grained cache control and query invalidation.
|
|
12
12
|
|
|
13
13
|
## Basic Usage
|
|
14
14
|
|
|
@@ -38,17 +38,18 @@ const SettingsEditor = ({ sectionName, settingEndpoint }) => {
|
|
|
38
38
|
|
|
39
39
|
## Parameters
|
|
40
40
|
|
|
41
|
-
| Name
|
|
42
|
-
|
|
43
|
-
| `sectionName`
|
|
44
|
-
| `settingEndpoint
|
|
41
|
+
| Name | Type | Description | Required | Default Value |
|
|
42
|
+
| :----------------------------- | :--------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
43
|
+
| `sectionName` | `string` | The name of the settings section to fetch. This is used in the `generateKiwtQueryParams` call to filter settings by their `section` property. | ✓ | None |
|
|
44
|
+
| `settingEndpoint` | `string` | The base URL endpoint for the settings API (e.g., `/settings-storage/settings`). The hook appends query parameters for fetching and, in the case of an update, the setting's ID for PUT requests. | ✓ | None |
|
|
45
|
+
| `getQueryNamespaceGenerator` | `function` | An optional function that generates the `react-query` key for the settings query. It receives an object `{ queryParams }` as an argument, where `queryParams` is the array of generated Kiwt query parameters. **Customize this for specific caching behaviors or if you need to append additional identifiers to your query key.** | ✕ | `({ queryParams }) => ['stripes-kint-components', 'useSetting', 'appSettings', queryParams, sectionName]` |
|
|
46
|
+
| `getMutateNamespaceGenerator` | `function` | An optional function that generates the `react-query` key for the mutation. **Customize this if you need a specific key for your mutation, for example, to differentiate it from other mutations or target specific invalidations.** | ✕ | `() => ['stripes-kint-components', 'useSetting', 'putSetting', sectionName]` |
|
|
45
47
|
|
|
46
48
|
## Returns
|
|
47
49
|
|
|
48
50
|
An object containing:
|
|
49
51
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
A mutation function that accepts a settings data object and performs an HTTP PUT request to update the setting.
|
|
52
|
+
* **`settings`** (`array`): The array of settings retrieved from the API. Defaults to an empty array if the query has not completed or returns no data.
|
|
53
|
+
* **`handleSubmit`** (`function`): A `react-query` mutation function (`mutateAsync`) that accepts a settings data object (e.g., `{ id: 'uuid', key: 'mySetting', value: 'newValue' }`) and performs an HTTP PUT request to update the setting.
|
|
54
|
+
* **`settingsQuery`** (`object`): The `react-query` result object from the `useQuery` hook. This provides detailed query status (e.g., `isLoading`, `isFetching`, `isError`, `data`, `error`).
|
|
55
|
+
* **`settingsMutate`** (`object`): The `react-query` result object from the `useMutation` hook. This provides detailed mutation status (e.g., `isLoading`, `isError`, `isSuccess`, `data`, `error`).
|
|
@@ -5,10 +5,8 @@ import { generateKiwtQueryParams } from '../../utils';
|
|
|
5
5
|
const useSettingSection = ({
|
|
6
6
|
sectionName,
|
|
7
7
|
settingEndpoint,
|
|
8
|
-
getQueryNamespaceGenerator = ({ queryParams }) =>
|
|
9
|
-
|
|
10
|
-
return queryNamespace;
|
|
11
|
-
},
|
|
8
|
+
getQueryNamespaceGenerator = ({ queryParams }) => ['stripes-kint-components', 'useSetting', 'appSettings', queryParams, sectionName],
|
|
9
|
+
getMutateNamespaceGenerator = () => ['stripes-kint-components', 'useSetting', 'putSetting', sectionName]
|
|
12
10
|
}) => {
|
|
13
11
|
const ky = useOkapiKy();
|
|
14
12
|
const queryParams = generateKiwtQueryParams({
|
|
@@ -27,19 +25,21 @@ const useSettingSection = ({
|
|
|
27
25
|
stats: false
|
|
28
26
|
}, {});
|
|
29
27
|
|
|
30
|
-
const { data: settings = [] } = useQuery(
|
|
28
|
+
const { data: settings = [], ...settingsQuery } = useQuery(
|
|
31
29
|
getQueryNamespaceGenerator({ queryParams }),
|
|
32
30
|
() => ky(`${settingEndpoint}?${queryParams?.join('&')}`).json()
|
|
33
31
|
);
|
|
34
32
|
|
|
35
|
-
const { mutateAsync: putSetting } = useMutation(
|
|
36
|
-
|
|
33
|
+
const { mutateAsync: putSetting, ...settingsMutate } = useMutation(
|
|
34
|
+
getMutateNamespaceGenerator(),
|
|
37
35
|
(data) => ky.put(`${settingEndpoint}${data.id ? '/' + data.id : ''}`, { json: data })
|
|
38
36
|
);
|
|
39
37
|
|
|
40
38
|
return ({
|
|
41
39
|
handleSubmit: putSetting,
|
|
42
|
-
settings
|
|
40
|
+
settings,
|
|
41
|
+
settingsQuery,
|
|
42
|
+
settingsMutate
|
|
43
43
|
});
|
|
44
44
|
};
|
|
45
45
|
|