@k-int/stripes-kint-components 5.27.0 → 5.28.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 +10 -0
- package/es/index.js +9 -68
- package/es/lib/FieldLabel/FieldLabel.js +34 -0
- package/es/lib/FieldLabel/index.js +13 -0
- package/es/lib/RefdataButtons/RefdataButtons.js +5 -2
- package/es/lib/{EditableRefdataCategoryList → Settings/EditableRefdataCategoryList}/EditableRefdataCategoryList.js +6 -6
- package/es/lib/{EditableRefdataList → Settings/EditableRefdataList}/EditableRefdataList.js +4 -4
- package/es/lib/{EditableSettingsList → Settings/EditableSettingsList}/EditableSettingsListFieldArray/EditableSettingsListFieldArray.test.js +1 -1
- package/es/lib/Settings/EditableSettingsList/SettingField/EditSettingValue/EditSettingValue.js +60 -0
- package/es/lib/{EditableSettingsList → Settings/EditableSettingsList}/SettingField/EditSettingValue/EditSettingValue.test.js +10 -10
- package/es/lib/{EditableSettingsList → Settings/EditableSettingsList}/SettingField/RenderSettingValue/RenderSettingValue.js +1 -1
- package/es/lib/{EditableSettingsList → Settings/EditableSettingsList}/SettingField/RenderSettingValue/RenderSettingValue.test.js +2 -2
- package/es/lib/{EditableSettingsList → Settings/EditableSettingsList}/SettingField/SettingField.js +3 -3
- package/es/lib/{EditableSettingsList → Settings/EditableSettingsList}/SettingField/SettingField.test.js +2 -2
- package/es/lib/{RefdataCategoriesSettings → Settings/RefdataCategoriesSettings}/RefdataCategoriesSettings.js +2 -2
- package/es/lib/{SettingPage → Settings/SettingPage}/SettingPage.js +1 -1
- package/es/lib/{SettingPage → Settings/SettingPage}/SettingPagePane/SettingPagePane.js +2 -2
- package/es/lib/{SettingsFormContainer → Settings/SettingsFormContainer}/SettingsFormContainer.js +1 -1
- package/es/lib/Settings/StaticSettingsField/StaticSettingsField.js +89 -0
- package/es/lib/Settings/StaticSettingsField/index.js +13 -0
- package/es/lib/Settings/constants/index.js +16 -0
- package/es/lib/Settings/constants/queryKeys.js +12 -0
- package/es/lib/{settingsHooks → Settings/hooks}/index.js +17 -0
- package/es/lib/Settings/hooks/staticSettingsPages/index.js +27 -0
- package/es/lib/Settings/hooks/staticSettingsPages/useSettingCallout/index.js +13 -0
- package/es/lib/Settings/hooks/staticSettingsPages/useSettingCallout/useSettingCallout.js +59 -0
- package/es/lib/Settings/hooks/staticSettingsPages/useSettingsSectionInitalValues/index.js +13 -0
- package/es/lib/Settings/hooks/staticSettingsPages/useSettingsSectionInitalValues/useSettingsSectionInitalValues.js +33 -0
- package/es/lib/Settings/hooks/staticSettingsPages/useStaticSettingsSection.js +121 -0
- package/es/lib/{settingsHooks → Settings/hooks}/useAppSettings/useAppSettings.js +1 -1
- package/es/lib/{settingsHooks → Settings/hooks}/useSettingSection/useSettingSection.js +4 -3
- package/es/lib/{settingsHooks → Settings/hooks}/useSettings/useSettings.js +2 -2
- package/es/lib/Settings/index.js +107 -0
- package/package.json +1 -1
- package/src/index.js +5 -21
- package/src/lib/FieldLabel/FieldLabel.js +26 -0
- package/src/lib/FieldLabel/README.md +26 -0
- package/src/lib/FieldLabel/index.js +1 -0
- package/src/lib/RefdataButtons/RefdataButtons.js +5 -1
- package/src/lib/{EditableRefdataCategoryList → Settings/EditableRefdataCategoryList}/EditableRefdataCategoryList.js +6 -6
- package/src/lib/{EditableRefdataList → Settings/EditableRefdataList}/EditableRefdataList.js +4 -4
- package/src/lib/Settings/EditableRefdataList/README.md +26 -0
- package/src/lib/{EditableSettingsList → Settings/EditableSettingsList}/EditableSettingsListFieldArray/EditableSettingsListFieldArray.test.js +1 -1
- package/src/lib/Settings/EditableSettingsList/SettingField/EditSettingValue/EditSettingValue.js +50 -0
- package/src/lib/{EditableSettingsList → Settings/EditableSettingsList}/SettingField/EditSettingValue/EditSettingValue.test.js +10 -10
- package/src/lib/{EditableSettingsList → Settings/EditableSettingsList}/SettingField/RenderSettingValue/RenderSettingValue.js +1 -1
- package/src/lib/{EditableSettingsList → Settings/EditableSettingsList}/SettingField/RenderSettingValue/RenderSettingValue.test.js +2 -2
- package/src/lib/{EditableSettingsList → Settings/EditableSettingsList}/SettingField/SettingField.js +3 -3
- package/src/lib/{EditableSettingsList → Settings/EditableSettingsList}/SettingField/SettingField.test.js +2 -2
- package/src/lib/{RefdataCategoriesSettings → Settings/RefdataCategoriesSettings}/RefdataCategoriesSettings.js +2 -2
- package/src/lib/{SettingPage → Settings/SettingPage}/SettingPage.js +1 -1
- package/src/lib/{SettingPage → Settings/SettingPage}/SettingPagePane/SettingPagePane.js +2 -2
- package/src/lib/{SettingsFormContainer → Settings/SettingsFormContainer}/SettingsFormContainer.js +1 -1
- package/src/lib/{EditableSettingsList/SettingField/EditSettingValue/EditSettingValue.js → Settings/StaticSettingsField/StaticSettingsField.js} +18 -40
- package/src/lib/Settings/StaticSettingsField/index.js +1 -0
- package/src/lib/Settings/constants/index.js +1 -0
- package/src/lib/Settings/constants/queryKeys.js +5 -0
- package/src/lib/{settingsHooks → Settings/hooks}/index.js +1 -0
- package/src/lib/Settings/hooks/staticSettingsPages/README.md +187 -0
- package/src/lib/Settings/hooks/staticSettingsPages/index.js +3 -0
- package/src/lib/Settings/hooks/staticSettingsPages/useSettingCallout/index.js +1 -0
- package/src/lib/Settings/hooks/staticSettingsPages/useSettingCallout/useSettingCallout.js +52 -0
- package/src/lib/Settings/hooks/staticSettingsPages/useSettingsSectionInitalValues/index.js +1 -0
- package/src/lib/Settings/hooks/staticSettingsPages/useSettingsSectionInitalValues/useSettingsSectionInitalValues.js +27 -0
- package/src/lib/Settings/hooks/staticSettingsPages/useStaticSettingsSection.js +100 -0
- package/src/lib/{settingsHooks → Settings/hooks}/useAppSettings/README.md +1 -1
- package/src/lib/{settingsHooks → Settings/hooks}/useAppSettings/useAppSettings.js +1 -1
- package/src/lib/{settingsHooks → Settings/hooks}/useSettingSection/useSettingSection.js +5 -3
- package/src/lib/{settingsHooks → Settings/hooks}/useSettings/useSettings.js +2 -2
- package/src/lib/Settings/index.js +28 -0
- package/test/jest/helpers/KintHarness.js +1 -1
- package/es/lib/EditableSettingsList/SettingField/EditSettingValue/EditSettingValue.js +0 -107
- package/src/lib/EditableRefdataList/README.md +0 -26
- /package/es/lib/{EditableRefdataCategoryList → Settings/EditableRefdataCategoryList}/index.js +0 -0
- /package/es/lib/{EditableRefdataList → Settings/EditableRefdataList}/index.js +0 -0
- /package/es/lib/{EditableSettingsList → Settings/EditableSettingsList}/EditableSettingsList.js +0 -0
- /package/es/lib/{EditableSettingsList → Settings/EditableSettingsList}/EditableSettingsListFieldArray/EditableSettingsListFieldArray.js +0 -0
- /package/es/lib/{EditableSettingsList → Settings/EditableSettingsList}/EditableSettingsListFieldArray/index.js +0 -0
- /package/es/lib/{EditableSettingsList → Settings/EditableSettingsList}/SettingField/EditSettingValue/index.js +0 -0
- /package/es/lib/{EditableSettingsList → Settings/EditableSettingsList}/SettingField/RenderSettingValue/index.js +0 -0
- /package/es/lib/{EditableSettingsList → Settings/EditableSettingsList}/SettingField/index.js +0 -0
- /package/es/lib/{EditableSettingsList → Settings/EditableSettingsList}/index.js +0 -0
- /package/es/lib/{RefdataCategoriesSettings → Settings/RefdataCategoriesSettings}/index.js +0 -0
- /package/es/lib/{SettingPage → Settings/SettingPage}/SettingPagePane/index.js +0 -0
- /package/es/lib/{SettingPage → Settings/SettingPage}/index.js +0 -0
- /package/es/lib/{SettingsFormContainer → Settings/SettingsFormContainer}/index.js +0 -0
- /package/es/lib/{contexts → Settings/contexts}/SettingsContext.js +0 -0
- /package/es/lib/{contexts → Settings/contexts}/index.js +0 -0
- /package/es/lib/{settingsHooks → Settings/hooks}/useAppSettings/index.js +0 -0
- /package/es/lib/{settingsHooks → Settings/hooks}/useSettingSection/index.js +0 -0
- /package/es/lib/{settingsHooks → Settings/hooks}/useSettings/index.js +0 -0
- /package/src/lib/{EditableRefdataCategoryList → Settings/EditableRefdataCategoryList}/index.js +0 -0
- /package/src/lib/{EditableRefdataList → Settings/EditableRefdataList}/index.js +0 -0
- /package/src/lib/{EditableSettingsList → Settings/EditableSettingsList}/EditableSettingsList.js +0 -0
- /package/src/lib/{EditableSettingsList → Settings/EditableSettingsList}/EditableSettingsListFieldArray/EditableSettingsListFieldArray.js +0 -0
- /package/src/lib/{EditableSettingsList → Settings/EditableSettingsList}/EditableSettingsListFieldArray/README.md +0 -0
- /package/src/lib/{EditableSettingsList → Settings/EditableSettingsList}/EditableSettingsListFieldArray/index.js +0 -0
- /package/src/lib/{EditableSettingsList → Settings/EditableSettingsList}/README.md +0 -0
- /package/src/lib/{EditableSettingsList → Settings/EditableSettingsList}/SettingField/EditSettingValue/README.md +0 -0
- /package/src/lib/{EditableSettingsList → Settings/EditableSettingsList}/SettingField/EditSettingValue/index.js +0 -0
- /package/src/lib/{EditableSettingsList → Settings/EditableSettingsList}/SettingField/README.md +0 -0
- /package/src/lib/{EditableSettingsList → Settings/EditableSettingsList}/SettingField/RenderSettingValue/index.js +0 -0
- /package/src/lib/{EditableSettingsList → Settings/EditableSettingsList}/SettingField/index.js +0 -0
- /package/src/lib/{EditableSettingsList → Settings/EditableSettingsList}/index.js +0 -0
- /package/src/lib/{RefdataCategoriesSettings → Settings/RefdataCategoriesSettings}/index.js +0 -0
- /package/src/lib/{SettingPage → Settings/SettingPage}/README.md +0 -0
- /package/src/lib/{SettingPage → Settings/SettingPage}/SettingPagePane/README.md +0 -0
- /package/src/lib/{SettingPage → Settings/SettingPage}/SettingPagePane/index.js +0 -0
- /package/src/lib/{SettingPage → Settings/SettingPage}/index.js +0 -0
- /package/src/lib/{SettingsFormContainer → Settings/SettingsFormContainer}/index.js +0 -0
- /package/src/lib/{contexts → Settings/contexts}/SettingsContext.js +0 -0
- /package/src/lib/{contexts → Settings/contexts}/index.js +0 -0
- /package/src/lib/{settingsHooks → Settings/hooks}/useAppSettings/index.js +0 -0
- /package/src/lib/{settingsHooks → Settings/hooks}/useSettingSection/README.md +0 -0
- /package/src/lib/{settingsHooks → Settings/hooks}/useSettingSection/index.js +0 -0
- /package/src/lib/{settingsHooks → Settings/hooks}/useSettings/README.md +0 -0
- /package/src/lib/{settingsHooks → Settings/hooks}/useSettings/index.js +0 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# EditableRefdataList
|
|
2
|
+
A component designed to render an editable list of refdata, which is editable if the refdata has property `internal: false`.
|
|
3
|
+
This will create an `ActionList` complete with `edit`, `delete` and `create` actions, and allow the user to edit the `value` and `label` of refdataValues.
|
|
4
|
+
|
|
5
|
+
## Basic Usage
|
|
6
|
+
```
|
|
7
|
+
import { EditableRefdataList } from '@k-int/stripes-kint-components';
|
|
8
|
+
|
|
9
|
+
...
|
|
10
|
+
<EditableRefdataList
|
|
11
|
+
desc="PublicationRequest.RequestStatus"
|
|
12
|
+
refdataEndpoint="oa/refdata"
|
|
13
|
+
/>
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Props
|
|
17
|
+
|
|
18
|
+
| Name | Type | Description | default | required |
|
|
19
|
+
|-------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------|----------------|
|
|
20
|
+
| afterQueryCalls | object | An object of the form `{delete: func1, put: func2}` where `func1`/`func2` are functions to be called after the `delete`/`put`. | | ✕ |
|
|
21
|
+
| allowSpecial | boolean | A boolean to turn off/on the stripping out of special characters and replacing them with `_`. Generally turning this on will cause problems with queries to KIWT endpoints and internally with Stripes filters, where a refdata value includes `&&`, ` | | `, `\` or `"`. | false | ✕ |
|
|
22
|
+
| catchQueryCalls | object | An object of the form `{delete: func1, put: func2}` where `func1`/`func2` are functions to be called with a HTTPError object when the `delete`/`put` calls fail. | `{delete: <Fires a callout of the format "<strong>Error: {label}</strong> was not deleted. {error}">}` | | ✕ |
|
|
23
|
+
| desc | String | A string corresponding to the refdataValue category, usually of the form `DomainClass.Field`. See `useRefdata` for more information. | | ✕ |
|
|
24
|
+
| displayConditions | object | An object of the form `{delete: false, edit: true, create: true}`, with keys `delete`, `edit` and `create`, and a boolean value. These will each default to true if not specified. These booleans will act as an additional check before rendering the actions for create/delete/edit, as well as whether or not to render the actions column at all. | `{delete: true, edit: true, create: true}` | ✕ |
|
|
25
|
+
| endpoint | String | A string containing the path to the endpoint for refdata | | ✓ |
|
|
26
|
+
| labelOverrides | object | An object containing translation overrides. Currently accepts: `deleteError: (err, object) => { ... output a callout message }`. | | ✕ |
|
|
@@ -2,7 +2,7 @@ import { TestForm } from '@folio/stripes-erm-testing';
|
|
|
2
2
|
import { FieldArray } from 'react-final-form-arrays';
|
|
3
3
|
import EditableSettingsListFieldArray from './EditableSettingsListFieldArray';
|
|
4
4
|
|
|
5
|
-
import { renderWithKintHarness } from '
|
|
5
|
+
import { renderWithKintHarness } from '../../../../../test/jest/helpers';
|
|
6
6
|
|
|
7
7
|
const onSubmit = jest.fn();
|
|
8
8
|
jest.mock('../SettingField', () => ({ SettingField: () => <div>SettingField</div> }));
|
package/src/lib/Settings/EditableSettingsList/SettingField/EditSettingValue/EditSettingValue.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
|
|
3
|
+
import { useKintIntl } from '../../../../hooks';
|
|
4
|
+
import StaticSettingsField from '../../../StaticSettingsField';
|
|
5
|
+
|
|
6
|
+
const EditSettingValue = ({
|
|
7
|
+
currentSetting: setting,
|
|
8
|
+
input,
|
|
9
|
+
intlKey: passedIntlKey,
|
|
10
|
+
intlNS: passedIntlNS,
|
|
11
|
+
labelOverrides = {},
|
|
12
|
+
...props
|
|
13
|
+
}) => {
|
|
14
|
+
const kintIntl = useKintIntl(passedIntlKey, passedIntlNS);
|
|
15
|
+
|
|
16
|
+
const fieldLabel = kintIntl.formatKintMessage({
|
|
17
|
+
id: 'settings.valueFor',
|
|
18
|
+
overrideValue: labelOverrides?.valueFor
|
|
19
|
+
}, { name: setting.key });
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<StaticSettingsField
|
|
23
|
+
aria-label={fieldLabel}
|
|
24
|
+
autofocus
|
|
25
|
+
name={`${input.name}.value`}
|
|
26
|
+
setting={setting}
|
|
27
|
+
{...props}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
EditSettingValue.propTypes = {
|
|
33
|
+
currentSetting: PropTypes.shape({
|
|
34
|
+
settingType: PropTypes.string,
|
|
35
|
+
key: PropTypes.string,
|
|
36
|
+
}),
|
|
37
|
+
input: PropTypes.shape({
|
|
38
|
+
name: PropTypes.string
|
|
39
|
+
}),
|
|
40
|
+
intlKey: PropTypes.string,
|
|
41
|
+
intlNS: PropTypes.string,
|
|
42
|
+
labelOverrides: PropTypes.object,
|
|
43
|
+
refdata: PropTypes.arrayOf(PropTypes.object),
|
|
44
|
+
templates: PropTypes.arrayOf(PropTypes.shape({
|
|
45
|
+
name: PropTypes.string,
|
|
46
|
+
id: PropTypes.string
|
|
47
|
+
}))
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default EditSettingValue;
|
|
@@ -2,10 +2,10 @@ import { TestForm } from '@folio/stripes-erm-testing';
|
|
|
2
2
|
|
|
3
3
|
import EditSettingValue from './EditSettingValue';
|
|
4
4
|
|
|
5
|
-
import { renderWithKintHarness } from '
|
|
5
|
+
import { renderWithKintHarness } from '../../../../../../test/jest/helpers';
|
|
6
6
|
|
|
7
7
|
const onSubmit = jest.fn();
|
|
8
|
-
jest.mock('
|
|
8
|
+
jest.mock('../../../../hooks');
|
|
9
9
|
|
|
10
10
|
const stringSetting = {
|
|
11
11
|
id: '12345',
|
|
@@ -317,14 +317,14 @@ describe('EditSettingValue', () => {
|
|
|
317
317
|
});
|
|
318
318
|
test('renders the edit field', () => {
|
|
319
319
|
const { getByRole } = renderComponent;
|
|
320
|
-
expect(getByRole('combobox', { name: 'Value for setting testSettingKey' }));
|
|
320
|
+
expect(getByRole('combobox', { name: 'Value for setting testSettingKey' })).toBeInTheDocument();
|
|
321
321
|
});
|
|
322
322
|
|
|
323
323
|
test('renders the expected template options', () => {
|
|
324
324
|
const { getByRole } = renderComponent;
|
|
325
|
-
expect(getByRole('option', { name: '' })); // empty option
|
|
326
|
-
expect(getByRole('option', { name: 'Test template' }));
|
|
327
|
-
expect(getByRole('option', { name: 'Red herring template' }));
|
|
325
|
+
expect(getByRole('option', { name: '' })).toBeInTheDocument(); // empty option
|
|
326
|
+
expect(getByRole('option', { name: 'Test template' })).toBeInTheDocument();
|
|
327
|
+
expect(getByRole('option', { name: 'Red herring template' })).toBeInTheDocument();
|
|
328
328
|
});
|
|
329
329
|
|
|
330
330
|
test('renders expected display item in template dropdown', () => {
|
|
@@ -358,14 +358,14 @@ describe('EditSettingValue', () => {
|
|
|
358
358
|
|
|
359
359
|
test('renders the edit field', () => {
|
|
360
360
|
const { getByRole } = renderComponent;
|
|
361
|
-
expect(getByRole('combobox', { name: 'Value for setting testSettingKey' }));
|
|
361
|
+
expect(getByRole('combobox', { name: 'Value for setting testSettingKey' })).toBeInTheDocument();
|
|
362
362
|
});
|
|
363
363
|
|
|
364
364
|
test('renders the expected template options', () => {
|
|
365
365
|
const { getByRole } = renderComponent;
|
|
366
|
-
expect(getByRole('option', { name: '' })); // empty option
|
|
367
|
-
expect(getByRole('option', { name: 'Test template' }));
|
|
368
|
-
expect(getByRole('option', { name: 'Red herring template' }));
|
|
366
|
+
expect(getByRole('option', { name: '' })).toBeInTheDocument(); // empty option
|
|
367
|
+
expect(getByRole('option', { name: 'Test template' })).toBeInTheDocument();
|
|
368
|
+
expect(getByRole('option', { name: 'Red herring template' })).toBeInTheDocument();
|
|
369
369
|
});
|
|
370
370
|
|
|
371
371
|
test('renders expected display item in template dropdown', () => {
|
|
@@ -2,9 +2,9 @@ import React from 'react';
|
|
|
2
2
|
|
|
3
3
|
import RenderSettingValue from './RenderSettingValue';
|
|
4
4
|
|
|
5
|
-
import { renderWithKintHarness } from '
|
|
5
|
+
import { renderWithKintHarness } from '../../../../../../test/jest/helpers';
|
|
6
6
|
|
|
7
|
-
jest.mock('
|
|
7
|
+
jest.mock('../../../../hooks');
|
|
8
8
|
|
|
9
9
|
const stringSetting = {
|
|
10
10
|
id: '12345',
|
package/src/lib/{EditableSettingsList → Settings/EditableSettingsList}/SettingField/SettingField.js
RENAMED
|
@@ -10,10 +10,10 @@ import {
|
|
|
10
10
|
import EditSettingValue from './EditSettingValue';
|
|
11
11
|
import RenderSettingValue from './RenderSettingValue';
|
|
12
12
|
import { SettingsContext } from '../../contexts';
|
|
13
|
-
import { useKintIntl, useRefdata, useTemplates } from '
|
|
14
|
-
import { toCamelCase } from '
|
|
13
|
+
import { useKintIntl, useRefdata, useTemplates } from '../../../hooks';
|
|
14
|
+
import { toCamelCase } from '../../../utils';
|
|
15
15
|
|
|
16
|
-
import renderHelpTextCSS from '
|
|
16
|
+
import renderHelpTextCSS from '../../../../../styles/renderHelpText.css';
|
|
17
17
|
|
|
18
18
|
const SettingField = (settingFieldProps) => {
|
|
19
19
|
const {
|
|
@@ -6,7 +6,7 @@ import { Button, TestForm } from '@folio/stripes-erm-testing';
|
|
|
6
6
|
import { Field } from 'react-final-form';
|
|
7
7
|
import SettingField from './SettingField';
|
|
8
8
|
|
|
9
|
-
import { renderWithKintHarness } from '
|
|
9
|
+
import { renderWithKintHarness } from '../../../../../test/jest/helpers';
|
|
10
10
|
|
|
11
11
|
const onSubmit = jest.fn();
|
|
12
12
|
const onSave = jest.fn().mockResolvedValue();
|
|
@@ -14,7 +14,7 @@ const onSave = jest.fn().mockResolvedValue();
|
|
|
14
14
|
jest.mock('./EditSettingValue', () => () => <div>EditSettingValue</div>);
|
|
15
15
|
jest.mock('./RenderSettingValue', () => () => <div>RenderSettingValue</div>);
|
|
16
16
|
|
|
17
|
-
jest.mock('
|
|
17
|
+
jest.mock('../../../hooks');
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
const setting = {
|
|
@@ -3,11 +3,11 @@ import PropTypes from 'prop-types';
|
|
|
3
3
|
|
|
4
4
|
import { Button, Col, KeyValue, Pane, PaneHeader, PaneMenu, Row } from '@folio/stripes/components';
|
|
5
5
|
|
|
6
|
-
import { useActionListRef, useKintIntl } from '
|
|
6
|
+
import { useActionListRef, useKintIntl } from '../../hooks';
|
|
7
7
|
|
|
8
8
|
import EditableRefdataCategoryList from '../EditableRefdataCategoryList';
|
|
9
9
|
import EditableRefdataList from '../EditableRefdataList';
|
|
10
|
-
import FormattedKintMessage from '
|
|
10
|
+
import FormattedKintMessage from '../../FormattedKintMessage';
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
const propTypes = {
|
|
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
|
|
|
4
4
|
import { EditableSettingsList } from '../EditableSettingsList';
|
|
5
5
|
import { SettingsContext } from '../contexts';
|
|
6
6
|
// Importing directly here to avoid cyclic dependency
|
|
7
|
-
import useSettingSection from '../
|
|
7
|
+
import useSettingSection from '../hooks/useSettingSection';
|
|
8
8
|
|
|
9
9
|
const SettingPage = ({
|
|
10
10
|
allowEdit = true,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import PropTypes from 'prop-types';
|
|
2
2
|
|
|
3
3
|
import { Pane } from '@folio/stripes/components';
|
|
4
|
-
import { toCamelCase } from '
|
|
5
|
-
import { useKintIntl } from '
|
|
4
|
+
import { toCamelCase } from '../../../utils';
|
|
5
|
+
import { useKintIntl } from '../../../hooks';
|
|
6
6
|
|
|
7
7
|
const SettingPagePane = ({
|
|
8
8
|
children,
|
package/src/lib/{SettingsFormContainer → Settings/SettingsFormContainer}/SettingsFormContainer.js
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import PropTypes from 'prop-types';
|
|
2
2
|
|
|
3
3
|
import { useCallout } from '@folio/stripes/core';
|
|
4
|
-
import { useKintIntl, useModConfigEntries, useMutateModConfigEntry } from '
|
|
4
|
+
import { useKintIntl, useModConfigEntries, useMutateModConfigEntry } from '../../hooks';
|
|
5
5
|
|
|
6
6
|
/*
|
|
7
7
|
* API is similar to ConfigManager
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import PropTypes from 'prop-types';
|
|
3
2
|
|
|
4
3
|
import { Field } from 'react-final-form';
|
|
@@ -6,27 +5,17 @@ import {
|
|
|
6
5
|
Select,
|
|
7
6
|
TextField,
|
|
8
7
|
} from '@folio/stripes/components';
|
|
9
|
-
import RefdataButtons from '../../../RefdataButtons';
|
|
10
|
-
import { useKintIntl } from '../../../hooks';
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
const {
|
|
14
|
-
currentSetting: setting,
|
|
15
|
-
input,
|
|
16
|
-
intlKey: passedIntlKey,
|
|
17
|
-
intlNS: passedIntlNS,
|
|
18
|
-
labelOverrides = {},
|
|
19
|
-
refdata,
|
|
20
|
-
templates
|
|
21
|
-
} = props;
|
|
22
|
-
|
|
23
|
-
const kintIntl = useKintIntl(passedIntlKey, passedIntlNS);
|
|
24
|
-
|
|
25
|
-
const fieldLabel = kintIntl.formatKintMessage({
|
|
26
|
-
id: 'settings.valueFor',
|
|
27
|
-
overrideValue: labelOverrides?.valueFor
|
|
28
|
-
}, { name: setting.key });
|
|
9
|
+
import RefdataButtons from '../../RefdataButtons';
|
|
29
10
|
|
|
11
|
+
// This is pretty much EXACTLY equivalent to the EditSettingValue in EditableSettingsList,
|
|
12
|
+
// but slightly tweaked to be more accommodating
|
|
13
|
+
const StaticSettingsField = ({
|
|
14
|
+
refdata,
|
|
15
|
+
setting = {},
|
|
16
|
+
templates,
|
|
17
|
+
...fieldProps // Anything else will be passed directly onto the <Field> component
|
|
18
|
+
}) => {
|
|
30
19
|
// Adding default sort to refdata object in ascending order by label
|
|
31
20
|
const sortByLabel = (a, b) => (a.label.localeCompare(b.label));
|
|
32
21
|
const sortedRefdata = refdata?.sort(sortByLabel);
|
|
@@ -42,26 +31,23 @@ const EditSettingValue = (props) => {
|
|
|
42
31
|
|
|
43
32
|
return (
|
|
44
33
|
<Field
|
|
45
|
-
aria-label={fieldLabel}
|
|
46
34
|
component={RefdataComponent}
|
|
47
35
|
dataOptions={sortedRefdata}
|
|
48
|
-
|
|
36
|
+
{...fieldProps}
|
|
49
37
|
/>
|
|
50
38
|
);
|
|
51
39
|
|
|
52
40
|
case 'Password':
|
|
53
41
|
return (
|
|
54
42
|
<Field
|
|
55
|
-
aria-label={fieldLabel}
|
|
56
|
-
autoFocus
|
|
57
43
|
component={TextField}
|
|
58
|
-
name={`${input.name}.value`}
|
|
59
44
|
parse={v => v} // Lets us send an empty string instead of 'undefined'
|
|
60
45
|
type="password"
|
|
46
|
+
{...fieldProps}
|
|
61
47
|
/>
|
|
62
48
|
);
|
|
63
49
|
case 'Template': {
|
|
64
|
-
// Grab
|
|
50
|
+
// Grab template values corresponding to setting
|
|
65
51
|
// eslint-disable-next-line no-case-declarations
|
|
66
52
|
const selectTemplateValues = [
|
|
67
53
|
{ value: '', label: '' },
|
|
@@ -70,11 +56,10 @@ const EditSettingValue = (props) => {
|
|
|
70
56
|
|
|
71
57
|
return (
|
|
72
58
|
<Field
|
|
73
|
-
aria-label={fieldLabel}
|
|
74
59
|
component={Select}
|
|
75
60
|
dataOptions={selectTemplateValues}
|
|
76
|
-
name={`${input.name}.value`}
|
|
77
61
|
parse={v => v}
|
|
62
|
+
{...fieldProps}
|
|
78
63
|
/>
|
|
79
64
|
);
|
|
80
65
|
}
|
|
@@ -82,27 +67,20 @@ const EditSettingValue = (props) => {
|
|
|
82
67
|
// If in doubt, go with String
|
|
83
68
|
return (
|
|
84
69
|
<Field
|
|
85
|
-
aria-label={fieldLabel}
|
|
86
|
-
autoFocus
|
|
87
70
|
component={TextField}
|
|
88
|
-
name={`${input.name}.value`}
|
|
89
71
|
parse={v => v} // Lets us send an empty string instead of 'undefined'
|
|
72
|
+
{...fieldProps}
|
|
90
73
|
/>
|
|
91
74
|
);
|
|
92
75
|
}
|
|
93
76
|
};
|
|
94
77
|
|
|
95
|
-
|
|
96
|
-
|
|
78
|
+
StaticSettingsField.propTypes = {
|
|
79
|
+
setting: PropTypes.shape({
|
|
97
80
|
settingType: PropTypes.string,
|
|
98
81
|
key: PropTypes.string,
|
|
99
82
|
}),
|
|
100
|
-
|
|
101
|
-
name: PropTypes.string
|
|
102
|
-
}),
|
|
103
|
-
intlKey: PropTypes.string,
|
|
104
|
-
intlNS: PropTypes.string,
|
|
105
|
-
labelOverrides: PropTypes.object,
|
|
83
|
+
name: PropTypes.string.isRequired,
|
|
106
84
|
refdata: PropTypes.arrayOf(PropTypes.object),
|
|
107
85
|
templates: PropTypes.arrayOf(PropTypes.shape({
|
|
108
86
|
name: PropTypes.string,
|
|
@@ -110,4 +88,4 @@ EditSettingValue.propTypes = {
|
|
|
110
88
|
}))
|
|
111
89
|
};
|
|
112
90
|
|
|
113
|
-
export default
|
|
91
|
+
export default StaticSettingsField;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './StaticSettingsField';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './queryKeys';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const BASE_APP_SETTING_QUERY_KEY = ['stripes-kint-components', 'useSetting', 'appSettings'];
|
|
2
|
+
export const GET_SETTING_SECTION_QUERY_KEY = (queryParams, sectionName) => [...BASE_APP_SETTING_QUERY_KEY, sectionName, queryParams];
|
|
3
|
+
|
|
4
|
+
export const BASE_APP_SETTING_MUTATE_KEY = ['stripes-kint-components', 'useSetting', 'putSetting'];
|
|
5
|
+
export const GET_SETTING_SECTION_MUTATE_KEY = (sectionName) => [...BASE_APP_SETTING_MUTATE_KEY, sectionName];
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# Static settings pages
|
|
2
|
+
|
|
3
|
+
## Premise
|
|
4
|
+
A set of hooks and utilities for use in static settings pages.
|
|
5
|
+
The dynamic AppSettings pages are great for getting a system up and running, but lack any design, and have pretty poor UX.
|
|
6
|
+
|
|
7
|
+
Instead we often wish to replace these modular dynamic pages with ones statically designed and rendered.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
In the example below, one can see how the user might make use of the initialValues and onSubmit from the useStaticSettingsSection
|
|
11
|
+
in order to set up everything needed to handle a static settings section form
|
|
12
|
+
```javascript
|
|
13
|
+
import { Form, Field } from 'react-final-form';
|
|
14
|
+
import { FormattedMessage } from 'react-intl';
|
|
15
|
+
import { useQueryClient } from 'react-query';
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
Button,
|
|
19
|
+
Label,
|
|
20
|
+
RadioButton,
|
|
21
|
+
RadioButtonGroup,
|
|
22
|
+
Tooltip,
|
|
23
|
+
IconButton,
|
|
24
|
+
TextField,
|
|
25
|
+
Pane,
|
|
26
|
+
Row,
|
|
27
|
+
Col
|
|
28
|
+
} from '@folio/stripes/components';
|
|
29
|
+
|
|
30
|
+
import {
|
|
31
|
+
useStaticSettingsSection
|
|
32
|
+
} from '@k-int/stripes-kint-components';
|
|
33
|
+
import { SETTINGS_INSTITUTION_ENDPOINT, useILLRefdata } from '@k-int/stripes-ill';
|
|
34
|
+
|
|
35
|
+
// Some constants for refdata vocab names
|
|
36
|
+
const AUTO_RESPONDER = 'AutoResponder';
|
|
37
|
+
const AUTO_RESPONDER_LOCAL = 'AutoResponder_Local';
|
|
38
|
+
const AUTO_RESPONDER_CANCEL = 'AutoResponder_Cancel';
|
|
39
|
+
const YES_NO = 'YesNo';
|
|
40
|
+
|
|
41
|
+
const AutoResponderSettings = () => {
|
|
42
|
+
const queryClient = useQueryClient();
|
|
43
|
+
const refdataValues = useILLRefdata([AUTO_RESPONDER, AUTO_RESPONDER_LOCAL, AUTO_RESPONDER_CANCEL, YES_NO]);
|
|
44
|
+
const queryNamespaceBase = ['ILL', 'Settings', 'AutoResponderSettings'];
|
|
45
|
+
|
|
46
|
+
const {
|
|
47
|
+
initialValues,
|
|
48
|
+
onSubmit,
|
|
49
|
+
} = useStaticSettingsSection({
|
|
50
|
+
intlKey: 'ui-ill-ui', // FIXME it's kind of crazy that this isn't set up above in the main App...
|
|
51
|
+
onSubmitComplete: () => queryClient.invalidateQueries(queryNamespaceBase), // Ensure it updates fields after submits
|
|
52
|
+
sectionName: 'autoResponder',
|
|
53
|
+
settingEndpoint: SETTINGS_INSTITUTION_ENDPOINT,
|
|
54
|
+
getQueryNamespaceGenerator: ({ queryParams }) => [...queryNamespaceBase, queryParams]
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const renderRefdataSetting = ({
|
|
58
|
+
helpText,
|
|
59
|
+
label,
|
|
60
|
+
name,
|
|
61
|
+
fieldRefdataValues = [],
|
|
62
|
+
}) => (
|
|
63
|
+
<Field
|
|
64
|
+
component={RadioButtonGroup}
|
|
65
|
+
label={
|
|
66
|
+
<Label>
|
|
67
|
+
{label}
|
|
68
|
+
{helpText ?
|
|
69
|
+
<Tooltip text={helpText}>
|
|
70
|
+
{({ ref, ariaIds }) => (
|
|
71
|
+
<IconButton
|
|
72
|
+
ref={ref}
|
|
73
|
+
aria-describedby={ariaIds.sub}
|
|
74
|
+
aria-labelledby={ariaIds.text}
|
|
75
|
+
icon="info"
|
|
76
|
+
/>
|
|
77
|
+
)}
|
|
78
|
+
</Tooltip> :
|
|
79
|
+
null
|
|
80
|
+
}
|
|
81
|
+
</Label>
|
|
82
|
+
}
|
|
83
|
+
name={name}
|
|
84
|
+
>
|
|
85
|
+
{
|
|
86
|
+
fieldRefdataValues.map(rdv => (
|
|
87
|
+
<RadioButton
|
|
88
|
+
key={`${name}-option-${rdv.value}`}
|
|
89
|
+
label={rdv.label}
|
|
90
|
+
value={rdv.value}
|
|
91
|
+
/>
|
|
92
|
+
))
|
|
93
|
+
}
|
|
94
|
+
</Field>
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<Form
|
|
99
|
+
initialValues={initialValues}
|
|
100
|
+
onSubmit={onSubmit}
|
|
101
|
+
render={({ handleSubmit, submitting, pristine, invalid }) => (
|
|
102
|
+
<form onSubmit={handleSubmit}>
|
|
103
|
+
<Pane
|
|
104
|
+
defaultWidth="fill"
|
|
105
|
+
lastMenu={
|
|
106
|
+
<Button
|
|
107
|
+
buttonStyle="primary"
|
|
108
|
+
disabled={submitting || pristine || invalid}
|
|
109
|
+
marginBottom0
|
|
110
|
+
onClick={handleSubmit}
|
|
111
|
+
>
|
|
112
|
+
<FormattedMessage id="ui-ill-ui.save" />
|
|
113
|
+
</Button>
|
|
114
|
+
}
|
|
115
|
+
paneTitle={<FormattedMessage id="ui-ill-ui.settings.settingsSection.autoResponder" />}
|
|
116
|
+
>
|
|
117
|
+
<Row>
|
|
118
|
+
<Col xs={6}>
|
|
119
|
+
{renderRefdataSetting({
|
|
120
|
+
helpText: <FormattedMessage id="ui-ill-ui.settings.autoResponder.autoResponderCancel.help" />,
|
|
121
|
+
label: <FormattedMessage id="ui-ill-ui.settings.autoResponder.autoResponderCancel" />,
|
|
122
|
+
name: 'auto_responder_cancel',
|
|
123
|
+
fieldRefdataValues: refdataValues.find(rdc => rdc.desc === AUTO_RESPONDER_CANCEL)?.values ?? []
|
|
124
|
+
})}
|
|
125
|
+
</Col>
|
|
126
|
+
<Col xs={6}>
|
|
127
|
+
{renderRefdataSetting({
|
|
128
|
+
helpText: <FormattedMessage id="ui-ill-ui.settings.autoResponder.autoResponderLocal.help" />,
|
|
129
|
+
label: <FormattedMessage id="ui-ill-ui.settings.autoResponder.autoResponderLocal" />,
|
|
130
|
+
name: 'auto_responder_local',
|
|
131
|
+
fieldRefdataValues: refdataValues.find(rdc => rdc.desc === AUTO_RESPONDER_LOCAL)?.values ?? []
|
|
132
|
+
})}
|
|
133
|
+
</Col>
|
|
134
|
+
</Row>
|
|
135
|
+
<Row>
|
|
136
|
+
<Col xs={6}>
|
|
137
|
+
{renderRefdataSetting({
|
|
138
|
+
helpText: <FormattedMessage id="ui-ill-ui.settings.autoResponder.autoResponderStatus.help" />,
|
|
139
|
+
label: <FormattedMessage id="ui-ill-ui.settings.autoResponder.autoResponderStatus" />,
|
|
140
|
+
name: 'auto_responder_status',
|
|
141
|
+
fieldRefdataValues: refdataValues.find(rdc => rdc.desc === AUTO_RESPONDER)?.values ?? []
|
|
142
|
+
})}
|
|
143
|
+
</Col>
|
|
144
|
+
<Col xs={6}>
|
|
145
|
+
{renderRefdataSetting({
|
|
146
|
+
label: <FormattedMessage id="ui-ill-ui.settings.autoResponder.enableLocalAvailabilityCheck" />,
|
|
147
|
+
name: 'enable_local_availability_check',
|
|
148
|
+
fieldRefdataValues: refdataValues.find(rdc => rdc.desc === YES_NO)?.values ?? []
|
|
149
|
+
})}
|
|
150
|
+
</Col>
|
|
151
|
+
</Row>
|
|
152
|
+
<Row>
|
|
153
|
+
<Col xs={6}>
|
|
154
|
+
<Field
|
|
155
|
+
component={TextField}
|
|
156
|
+
label={<FormattedMessage id="ui-ill-ui.settings.autoResponder.staleAfter" />}
|
|
157
|
+
name="stale_request_2_days"
|
|
158
|
+
/>
|
|
159
|
+
</Col>
|
|
160
|
+
<Col xs={6}>
|
|
161
|
+
{renderRefdataSetting({
|
|
162
|
+
helpText: <FormattedMessage id="ui-ill-ui.settings.autoResponder.staleRequest3ExcludeWeekend.help" />,
|
|
163
|
+
label: <FormattedMessage id="ui-ill-ui.settings.autoResponder.staleRequest3ExcludeWeekend" />,
|
|
164
|
+
name: 'stale_request_3_exclude_weekend',
|
|
165
|
+
fieldRefdataValues: refdataValues.find(rdc => rdc.desc === YES_NO)?.values ?? []
|
|
166
|
+
})}
|
|
167
|
+
</Col>
|
|
168
|
+
</Row>
|
|
169
|
+
<Row>
|
|
170
|
+
<Col xs={6}>
|
|
171
|
+
{renderRefdataSetting({
|
|
172
|
+
helpText: <FormattedMessage id="ui-ill-ui.settings.autoResponder.staleRequest1Enabled.help" />,
|
|
173
|
+
label: <FormattedMessage id="ui-ill-ui.settings.autoResponder.staleRequest1Enabled" />,
|
|
174
|
+
name: 'stale_request_1_enabled',
|
|
175
|
+
fieldRefdataValues: refdataValues.find(rdc => rdc.desc === YES_NO)?.values ?? []
|
|
176
|
+
})}
|
|
177
|
+
</Col>
|
|
178
|
+
</Row>
|
|
179
|
+
</Pane>
|
|
180
|
+
</form>
|
|
181
|
+
)}
|
|
182
|
+
/>
|
|
183
|
+
);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export default AutoResponderSettings;
|
|
187
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './useSettingCallout';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useCallout } from '@folio/stripes/core';
|
|
4
|
+
import { useKintIntl } from '../../../../hooks';
|
|
5
|
+
import { toCamelCase } from '../../../../utils';
|
|
6
|
+
|
|
7
|
+
// A hook which can take an array of settings objects and return a
|
|
8
|
+
const useSettingCallout = ({
|
|
9
|
+
labelOverrides = [],
|
|
10
|
+
intlKey: passedIntlKey,
|
|
11
|
+
intlNS: passedIntlNS,
|
|
12
|
+
} = {}) => {
|
|
13
|
+
const callout = useCallout();
|
|
14
|
+
const kintIntl = useKintIntl(passedIntlKey, passedIntlNS);
|
|
15
|
+
|
|
16
|
+
return useCallback(({
|
|
17
|
+
settings,
|
|
18
|
+
type
|
|
19
|
+
}) => {
|
|
20
|
+
callout.sendCallout({
|
|
21
|
+
type,
|
|
22
|
+
timeout: 10000,
|
|
23
|
+
message: (
|
|
24
|
+
<ul>
|
|
25
|
+
{settings.map(({ setting, error: _error }) => {
|
|
26
|
+
// error will obviously be null for successful updates.
|
|
27
|
+
// We can choose to surface the errors to the user should we wish
|
|
28
|
+
const settingLabel = kintIntl.formatKintMessage({
|
|
29
|
+
id: `settings.${setting.section}.${toCamelCase(setting.key)}`, // Camelcasing to keep in line with how we translate the dynamic settings
|
|
30
|
+
overrideValue: labelOverrides[setting.key],
|
|
31
|
+
fallbackMessage: setting.key
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const message = kintIntl.formatKintMessage({
|
|
35
|
+
id: `settings.update.${type}`,
|
|
36
|
+
overrideValue: labelOverrides[type],
|
|
37
|
+
fallbackMessage: setting.key
|
|
38
|
+
}, { settingLabel, newValue: setting.value });
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<li key={setting.id || setting.key}>
|
|
42
|
+
{message}
|
|
43
|
+
</li>
|
|
44
|
+
);
|
|
45
|
+
})}
|
|
46
|
+
</ul>
|
|
47
|
+
)
|
|
48
|
+
});
|
|
49
|
+
}, [callout, kintIntl, labelOverrides]);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default useSettingCallout;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './useSettingsSectionInitalValues';
|