@k-int/stripes-kint-components 5.16.0 → 5.18.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 +20 -0
- package/LICENSE +1 -1
- package/es/index.js +24 -12
- package/es/lib/EditableSettingsList/EditableSettingsList.js +4 -3
- package/es/lib/EditableSettingsList/EditableSettingsListFieldArray/EditableSettingsListFieldArray.js +110 -0
- package/es/lib/EditableSettingsList/{EditableSettingsListFieldArray.test.js → EditableSettingsListFieldArray/EditableSettingsListFieldArray.test.js} +3 -4
- package/es/lib/EditableSettingsList/EditableSettingsListFieldArray/index.js +13 -0
- package/es/lib/EditableSettingsList/SettingField/{EditSettingValue.js → EditSettingValue/EditSettingValue.js} +2 -2
- package/es/lib/EditableSettingsList/SettingField/{EditSettingValue.test.js → EditSettingValue/EditSettingValue.test.js} +2 -3
- package/es/lib/EditableSettingsList/SettingField/EditSettingValue/index.js +13 -0
- package/es/lib/EditableSettingsList/SettingField/{RenderSettingValue.js → RenderSettingValue/RenderSettingValue.js} +1 -1
- package/es/lib/EditableSettingsList/SettingField/{RenderSettingValue.test.js → RenderSettingValue/RenderSettingValue.test.js} +2 -2
- package/es/lib/EditableSettingsList/SettingField/RenderSettingValue/index.js +13 -0
- package/es/lib/EditableSettingsList/SettingField/SettingField.js +5 -5
- package/es/lib/EditableSettingsList/SettingField/SettingField.test.js +54 -44
- package/es/lib/EditableSettingsList/index.js +12 -0
- package/es/lib/SASQLookupComponent/SASQLookupComponent.js +26 -9
- package/es/lib/SASQViewComponent/SASQViewComponent.js +21 -7
- package/es/lib/SettingPage/SettingPage.js +3 -1
- package/es/lib/SettingPage/{SettingPagePane.js → SettingPagePane/SettingPagePane.js} +2 -2
- package/es/lib/SettingPage/SettingPagePane/index.js +13 -0
- package/es/lib/settingsHooks/useAppSettings/index.js +13 -0
- package/es/lib/settingsHooks/{useAppSettings.js → useAppSettings/useAppSettings.js} +1 -1
- package/es/lib/settingsHooks/useSettingSection/index.js +13 -0
- package/es/lib/settingsHooks/{useSettingSection.js → useSettingSection/useSettingSection.js} +1 -1
- package/es/lib/settingsHooks/useSettings/index.js +13 -0
- package/es/lib/settingsHooks/{useSettings.js → useSettings/useSettings.js} +10 -9
- package/package.json +1 -1
- package/src/index.js +4 -3
- package/src/lib/ActionList/README.md +18 -18
- package/src/lib/EditableSettingsList/EditableSettingsList.js +3 -2
- package/src/lib/EditableSettingsList/EditableSettingsListFieldArray/EditableSettingsListFieldArray.js +118 -0
- package/src/lib/EditableSettingsList/{EditableSettingsListFieldArray.test.js → EditableSettingsListFieldArray/EditableSettingsListFieldArray.test.js} +3 -5
- package/src/lib/EditableSettingsList/EditableSettingsListFieldArray/README.md +68 -0
- package/src/lib/EditableSettingsList/EditableSettingsListFieldArray/index.js +1 -0
- package/src/lib/EditableSettingsList/README.md +74 -0
- package/src/lib/EditableSettingsList/SettingField/{EditSettingValue.js → EditSettingValue/EditSettingValue.js} +2 -2
- package/src/lib/EditableSettingsList/SettingField/{EditSettingValue.test.js → EditSettingValue/EditSettingValue.test.js} +2 -5
- package/src/lib/EditableSettingsList/SettingField/EditSettingValue/README.md +63 -0
- package/src/lib/EditableSettingsList/SettingField/EditSettingValue/index.js +1 -0
- package/src/lib/EditableSettingsList/SettingField/README.md +61 -0
- package/src/lib/EditableSettingsList/SettingField/{RenderSettingValue.js → RenderSettingValue/RenderSettingValue.js} +1 -1
- package/src/lib/EditableSettingsList/SettingField/{RenderSettingValue.test.js → RenderSettingValue/RenderSettingValue.test.js} +2 -2
- package/src/lib/EditableSettingsList/SettingField/RenderSettingValue/index.js +1 -0
- package/src/lib/EditableSettingsList/SettingField/SettingField.js +5 -3
- package/src/lib/EditableSettingsList/SettingField/SettingField.test.js +65 -44
- package/src/lib/EditableSettingsList/index.js +1 -1
- package/src/lib/SASQLookupComponent/SASQLookupComponent.js +21 -10
- package/src/lib/SASQViewComponent/SASQViewComponent.js +17 -8
- package/src/lib/SettingPage/README.md +66 -0
- package/src/lib/SettingPage/SettingPage.js +3 -1
- package/src/lib/SettingPage/SettingPagePane/README.md +31 -0
- package/src/lib/SettingPage/{SettingPagePane.js → SettingPagePane/SettingPagePane.js} +2 -2
- package/src/lib/SettingPage/SettingPagePane/index.js +1 -0
- package/src/lib/settingsHooks/useAppSettings/index.js +1 -0
- package/src/lib/settingsHooks/{useAppSettings.js → useAppSettings/useAppSettings.js} +1 -1
- package/src/lib/settingsHooks/useSettingSection/README.md +54 -0
- package/src/lib/settingsHooks/useSettingSection/index.js +1 -0
- package/src/lib/settingsHooks/{useSettingSection.js → useSettingSection/useSettingSection.js} +1 -1
- package/src/lib/settingsHooks/useSettings/README.md +84 -0
- package/src/lib/settingsHooks/useSettings/index.js +1 -0
- package/src/lib/settingsHooks/{useSettings.js → useSettings/useSettings.js} +10 -7
- package/es/lib/EditableSettingsList/EditableSettingsListFieldArray.js +0 -57
- package/src/lib/EditableSettingsList/EditableSettingsListFieldArray.js +0 -58
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# useSettings
|
|
2
|
+
|
|
3
|
+
A comprehensive hook that manages the retrieval and configuration of settings data for one or multiple sections. It orchestrates multiple queries with `react-query`, constructs dynamic pages for each settings section, and returns a pre-configured `SettingsComponent` for rendering the settings UI.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
`useSettings` serves several purposes:
|
|
8
|
+
|
|
9
|
+
- **Multi-Section Querying:**
|
|
10
|
+
It supports both single and multiple settings sections. Depending on the provided props, it dynamically generates query parameters and uses `useQueries` to fetch data for each section.
|
|
11
|
+
|
|
12
|
+
- **Dynamic Page Generation:**
|
|
13
|
+
When queries return data, it extracts unique section names to create dynamic pages. Each page includes a route, localized label, and a component that wraps a `SettingPage` in a `SettingPagePane`.
|
|
14
|
+
|
|
15
|
+
- **Context and Configuration:**
|
|
16
|
+
The hook creates a `SettingsContextProvider` to pass down configuration details (like API endpoints and internationalization keys) to its children. This ensures that each section or page has the necessary context for rendering.
|
|
17
|
+
|
|
18
|
+
- **Final Settings Component:**
|
|
19
|
+
It returns a `SettingsComponent` that wraps the list of pages or sections using the `Settings` component from `@folio/stripes/smart-components`. This component can then be directly rendered in the application.
|
|
20
|
+
|
|
21
|
+
## Basic Usage
|
|
22
|
+
|
|
23
|
+
```jsx
|
|
24
|
+
const SettingsContainer = () => {
|
|
25
|
+
const {
|
|
26
|
+
isLoading,
|
|
27
|
+
SettingsComponent,
|
|
28
|
+
pageList,
|
|
29
|
+
sections,
|
|
30
|
+
SettingsContextProvider,
|
|
31
|
+
} = useSettings({
|
|
32
|
+
sectionName: 'general',
|
|
33
|
+
settingEndpoint: '/settings',
|
|
34
|
+
refdataEndpoint: '/refdata',
|
|
35
|
+
// Other optional props for customization...
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (isLoading) return <div>Loading settings...</div>;
|
|
39
|
+
|
|
40
|
+
return <SettingsComponent />;
|
|
41
|
+
};
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Parameters
|
|
45
|
+
|
|
46
|
+
`useSettings` accepts an optional settings props object (`settingsProps`) that may include the following properties:
|
|
47
|
+
|
|
48
|
+
| Name | Type | Description | Required |
|
|
49
|
+
|------------------------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|
|
|
50
|
+
| `allowGlobalEdit` | `boolean`| Global flag to enable or disable editing of settings. Defaults to `true`. | ✕ |
|
|
51
|
+
| `dynamicPageExclusions`| `array` | Array of section names to be excluded from dynamic page generation. | ✕ |
|
|
52
|
+
| `intlKey` | `string` | Base internationalization key for resolving labels. | ✕ |
|
|
53
|
+
| `intlNS` | `string` | Internationalization namespace. | ✕ |
|
|
54
|
+
| `labelOverrides` | `object` | Custom label overrides for specific settings keys. | ✕ |
|
|
55
|
+
| `pages` | `array` | If provided, acts as a passthrough configuration for either sections or standalone pages, disabling query execution. | ✕ |
|
|
56
|
+
| `persistentPages` | `array` | Array of pages that persist regardless of dynamic query results. | ✕ |
|
|
57
|
+
| `preventQueries` | `boolean`| Flag to disable querying if settings data is provided externally. | ✕ |
|
|
58
|
+
| `refdataEndpoint` | `string` | The API endpoint to retrieve reference data for settings. | ✕ |
|
|
59
|
+
| `renderSingleSection` | `boolean`| When only one section is available, determines if it should be rendered as a single section with its own label. | ✕ |
|
|
60
|
+
| `sectionPermission` | `string` | Permission string that, if provided, restricts the rendering of a section unless the current user has the specified permission. | ✕ |
|
|
61
|
+
| `sectionRoute` | `string` | Base route path to be used when constructing dynamic page routes for settings sections. | ✕ |
|
|
62
|
+
| `sections` | `array` | Array of section configuration objects. Each object can override or extend the global settings props for that specific section. This means that the shape here matches more or less the shape for the props of `useSettings` itself. | ✕ |
|
|
63
|
+
| `settingEndpoint` | `string` | The base URL endpoint for fetching and updating settings. | ✕ |
|
|
64
|
+
| `templateEndpoint` | `string` | The endpoint for retrieving settings templates (if applicable). | ✕ |
|
|
65
|
+
| `render` | `func` | A custom render function for rendering individual setting fields. This function is passed down to the underlying settings components for specialized display logic. See `EditableSettingsList` for more information on how render is used. | ✕ |
|
|
66
|
+
|
|
67
|
+
## Returns
|
|
68
|
+
|
|
69
|
+
The hook returns an object containing:
|
|
70
|
+
|
|
71
|
+
- **`isLoading`** (`boolean`):
|
|
72
|
+
Indicates if any of the settings queries are still loading.
|
|
73
|
+
|
|
74
|
+
- **`pageList`** (`array`):
|
|
75
|
+
An array of pages to be rendered by the `Settings` component. This is the final list of pages for a single section, if applicable.
|
|
76
|
+
|
|
77
|
+
- **`sections`** (`array`):
|
|
78
|
+
An array of fully configured sections. Each section includes its own `SettingsContextProvider`, dynamic pages, and additional configuration data.
|
|
79
|
+
|
|
80
|
+
- **`SettingsComponent`** (`React Component`):
|
|
81
|
+
A component pre-configured with the pages and sections that renders the settings UI. This component wraps the settings in the required `Settings` component from `@folio/stripes/smart-components`.
|
|
82
|
+
|
|
83
|
+
- **`SettingsContextProvider`** (`React Component`):
|
|
84
|
+
A context provider component for settings configuration. If only one section is available, it is provided directly; otherwise, it defaults to a pass-through provider.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './useSettings';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
|
|
4
4
|
import { useQueries } from 'react-query';
|
|
@@ -6,11 +6,11 @@ import { useOkapiKy, useStripes } from '@folio/stripes/core';
|
|
|
6
6
|
|
|
7
7
|
import { Settings } from '@folio/stripes/smart-components';
|
|
8
8
|
|
|
9
|
-
import { SettingPage, SettingPagePane } from '
|
|
10
|
-
import { SettingsContext } from '
|
|
9
|
+
import { SettingPage, SettingPagePane } from '../../SettingPage';
|
|
10
|
+
import { SettingsContext } from '../../contexts';
|
|
11
11
|
|
|
12
|
-
import { generateKiwtQueryParams, sortByLabel, toCamelCase } from '
|
|
13
|
-
import { useKintIntl, useIntlKey } from '
|
|
12
|
+
import { generateKiwtQueryParams, sortByLabel, toCamelCase } from '../../utils';
|
|
13
|
+
import { useKintIntl, useIntlKey } from '../../hooks';
|
|
14
14
|
|
|
15
15
|
// TODO work underway to make the settings hook more useful when trying to render multiple sections at a time
|
|
16
16
|
const useSettings = (settingsProps = {}) => {
|
|
@@ -30,7 +30,8 @@ const useSettings = (settingsProps = {}) => {
|
|
|
30
30
|
sections, // if present, should be an array of objects with the SAME shape as the overall props here.
|
|
31
31
|
// If a prop isn't present it can fall back to the "global" prop.
|
|
32
32
|
settingEndpoint,
|
|
33
|
-
templateEndpoint
|
|
33
|
+
templateEndpoint,
|
|
34
|
+
render, // Allow setting-by-setting rendering of fields, to allow for special treatment for a given setting key etc
|
|
34
35
|
} = settingsProps;
|
|
35
36
|
|
|
36
37
|
const ky = useOkapiKy();
|
|
@@ -100,6 +101,7 @@ const useSettings = (settingsProps = {}) => {
|
|
|
100
101
|
const getDynamicPages = useCallback((qra, sma) => {
|
|
101
102
|
const pagesFromQueryReturn = [...new Set(qra.data?.map(s => s.section))];
|
|
102
103
|
const dynamic = pagesFromQueryReturn.map(page => {
|
|
104
|
+
const finalRender = sma.render ?? render;
|
|
103
105
|
const finalSectionRoute = sma.sectionRoute ?? sectionRoute;
|
|
104
106
|
const pageRoute = (finalSectionRoute ? `${finalSectionRoute}/` : '') + page;
|
|
105
107
|
return (
|
|
@@ -120,6 +122,7 @@ const useSettings = (settingsProps = {}) => {
|
|
|
120
122
|
intlKey={passedIntlKey}
|
|
121
123
|
intlNS={passedIntlNS}
|
|
122
124
|
labelOverrides={labelOverrides}
|
|
125
|
+
render={finalRender}
|
|
123
126
|
sectionName={page}
|
|
124
127
|
{...props}
|
|
125
128
|
/>
|
|
@@ -133,7 +136,7 @@ const useSettings = (settingsProps = {}) => {
|
|
|
133
136
|
pages: pagesFromQueryReturn,
|
|
134
137
|
dynamic,
|
|
135
138
|
};
|
|
136
|
-
}, [allowGlobalEdit, kintIntl, labelOverrides, passedIntlKey, passedIntlNS, sectionRoute]);
|
|
139
|
+
}, [allowGlobalEdit, kintIntl, labelOverrides, passedIntlKey, passedIntlNS, render, sectionRoute]);
|
|
137
140
|
|
|
138
141
|
useEffect(() => {
|
|
139
142
|
// Handle loading
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _react = _interopRequireDefault(require("react"));
|
|
8
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
-
var _reactFinalForm = require("react-final-form");
|
|
10
|
-
var _SettingField = require("./SettingField");
|
|
11
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
-
const EditableSettingsListFieldArray = _ref => {
|
|
14
|
-
let {
|
|
15
|
-
allowEdit = true,
|
|
16
|
-
data,
|
|
17
|
-
fields,
|
|
18
|
-
intlKey: passedIntlKey,
|
|
19
|
-
intlNS: passedIntlNS,
|
|
20
|
-
labelOverrides = {},
|
|
21
|
-
onSave
|
|
22
|
-
} = _ref;
|
|
23
|
-
const handleSave = index => {
|
|
24
|
-
const setting = fields.value[index];
|
|
25
|
-
return onSave(setting);
|
|
26
|
-
};
|
|
27
|
-
return fields.map((setting, i) => {
|
|
28
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFinalForm.Field, {
|
|
29
|
-
allowEdit: allowEdit,
|
|
30
|
-
component: _SettingField.SettingField,
|
|
31
|
-
"data-testid": `editableSettingsListFieldArray[${i}]`,
|
|
32
|
-
intlKey: passedIntlKey,
|
|
33
|
-
intlNS: passedIntlNS,
|
|
34
|
-
labelOverrides: labelOverrides,
|
|
35
|
-
name: setting,
|
|
36
|
-
onSave: () => handleSave(i),
|
|
37
|
-
settingData: {
|
|
38
|
-
currentSetting: fields.value[i],
|
|
39
|
-
...data
|
|
40
|
-
}
|
|
41
|
-
}, setting);
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
EditableSettingsListFieldArray.propTypes = {
|
|
45
|
-
allowEdit: _propTypes.default.bool,
|
|
46
|
-
fields: _propTypes.default.object,
|
|
47
|
-
intlKey: _propTypes.default.string,
|
|
48
|
-
intlNS: _propTypes.default.string,
|
|
49
|
-
labelOverrides: _propTypes.default.object,
|
|
50
|
-
onSave: _propTypes.default.func,
|
|
51
|
-
data: _propTypes.default.shape({
|
|
52
|
-
refdatavalues: _propTypes.default.arrayOf(_propTypes.default.object)
|
|
53
|
-
}),
|
|
54
|
-
mutators: _propTypes.default.object,
|
|
55
|
-
initialValues: _propTypes.default.object
|
|
56
|
-
};
|
|
57
|
-
var _default = exports.default = EditableSettingsListFieldArray;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { Field } from 'react-final-form';
|
|
4
|
-
|
|
5
|
-
import { SettingField } from './SettingField';
|
|
6
|
-
|
|
7
|
-
const EditableSettingsListFieldArray = ({
|
|
8
|
-
allowEdit = true,
|
|
9
|
-
data,
|
|
10
|
-
fields,
|
|
11
|
-
intlKey: passedIntlKey,
|
|
12
|
-
intlNS: passedIntlNS,
|
|
13
|
-
labelOverrides = {},
|
|
14
|
-
onSave
|
|
15
|
-
}) => {
|
|
16
|
-
const handleSave = (index) => {
|
|
17
|
-
const setting = fields.value[index];
|
|
18
|
-
return onSave(setting);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
return (
|
|
22
|
-
fields.map((setting, i) => {
|
|
23
|
-
return (
|
|
24
|
-
<Field
|
|
25
|
-
key={setting}
|
|
26
|
-
allowEdit={allowEdit}
|
|
27
|
-
component={SettingField}
|
|
28
|
-
data-testid={`editableSettingsListFieldArray[${i}]`}
|
|
29
|
-
intlKey={passedIntlKey}
|
|
30
|
-
intlNS={passedIntlNS}
|
|
31
|
-
labelOverrides={labelOverrides}
|
|
32
|
-
name={setting}
|
|
33
|
-
onSave={() => handleSave(i)}
|
|
34
|
-
settingData={{
|
|
35
|
-
currentSetting: fields.value[i],
|
|
36
|
-
...data
|
|
37
|
-
}}
|
|
38
|
-
/>
|
|
39
|
-
);
|
|
40
|
-
})
|
|
41
|
-
);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
EditableSettingsListFieldArray.propTypes = {
|
|
45
|
-
allowEdit: PropTypes.bool,
|
|
46
|
-
fields: PropTypes.object,
|
|
47
|
-
intlKey: PropTypes.string,
|
|
48
|
-
intlNS: PropTypes.string,
|
|
49
|
-
labelOverrides: PropTypes.object,
|
|
50
|
-
onSave: PropTypes.func,
|
|
51
|
-
data: PropTypes.shape({
|
|
52
|
-
refdatavalues: PropTypes.arrayOf(PropTypes.object)
|
|
53
|
-
}),
|
|
54
|
-
mutators: PropTypes.object,
|
|
55
|
-
initialValues: PropTypes.object
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export default EditableSettingsListFieldArray;
|