@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,27 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
const useSettingsSectionInitalValues = ({
|
|
4
|
+
settings: rawSettings, // A settingsSection return of EXACTLY the shape defined in useSettingsSection
|
|
5
|
+
}) => {
|
|
6
|
+
const initialValues = useMemo(() => {
|
|
7
|
+
const settingsKeyValue = rawSettings.map(setting => {
|
|
8
|
+
const { key, value, settingType } = setting;
|
|
9
|
+
let parsedValue;
|
|
10
|
+
if (settingType === 'Boolean') {
|
|
11
|
+
parsedValue = value === 'true';
|
|
12
|
+
} else if (settingType === 'Integer') {
|
|
13
|
+
parsedValue = Number(value);
|
|
14
|
+
} else {
|
|
15
|
+
parsedValue = value;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return [key, parsedValue];
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return Object.fromEntries(settingsKeyValue);
|
|
22
|
+
}, [rawSettings]);
|
|
23
|
+
|
|
24
|
+
return initialValues;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default useSettingsSectionInitalValues;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
import useSettingSection from '../useSettingSection';
|
|
4
|
+
import useSettingsSectionInitalValues from './useSettingsSectionInitalValues';
|
|
5
|
+
import useSettingCallout from './useSettingCallout';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A helper hook which collates several hooks useful in the setup and operation of static setting pages, in which
|
|
9
|
+
* an entire section of AppSetting objects needs to be submitted at once
|
|
10
|
+
*/
|
|
11
|
+
const useStaticSettingsSection = ({
|
|
12
|
+
intlKey: passedIntlKey,
|
|
13
|
+
intlNS: passedIntlNS,
|
|
14
|
+
onSubmitComplete = () => null, // Callback which runs after all promises have completed
|
|
15
|
+
onSettingsSuccess = () => null, // Specifically logic to handle a list of successful settings calls
|
|
16
|
+
onSettingsFailure = () => null, // Specifically logic to handle a list of failed settings calls
|
|
17
|
+
sectionName,
|
|
18
|
+
settingEndpoint,
|
|
19
|
+
getQueryNamespaceGenerator
|
|
20
|
+
}) => {
|
|
21
|
+
// Following example in agreements for useAgreementsDisplaySettings
|
|
22
|
+
const settingsSection = useSettingSection({
|
|
23
|
+
sectionName,
|
|
24
|
+
settingEndpoint,
|
|
25
|
+
getQueryNamespaceGenerator
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const { handleSubmit, settings: rawSettings } = settingsSection;
|
|
29
|
+
|
|
30
|
+
// We should ONLY change initial values when autoResponderValues updates
|
|
31
|
+
// initialValues should take a KIWT AppSetting object and turn it into key/value for the Form
|
|
32
|
+
const initialValues = useSettingsSectionInitalValues({ settings: rawSettings });
|
|
33
|
+
const sendSettingsCallout = useSettingCallout({
|
|
34
|
+
intlKey: passedIntlKey,
|
|
35
|
+
intlNS: passedIntlNS,
|
|
36
|
+
}); // Translations will need to be set up here for this to work
|
|
37
|
+
|
|
38
|
+
const onSubmit = useCallback((values) => {
|
|
39
|
+
const updates = [];
|
|
40
|
+
|
|
41
|
+
rawSettings.forEach(setting => {
|
|
42
|
+
const originalValue = initialValues[setting.key];
|
|
43
|
+
const formValue = values[setting.key];
|
|
44
|
+
if (formValue !== originalValue) {
|
|
45
|
+
updates.push({
|
|
46
|
+
...setting,
|
|
47
|
+
value: formValue.toString()
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
if (updates.length > 0) {
|
|
53
|
+
const successful = [];
|
|
54
|
+
const failed = [];
|
|
55
|
+
|
|
56
|
+
// type MUST be 'success' or 'error'
|
|
57
|
+
|
|
58
|
+
// We catch any failed requests and stick them in an array for us to deal with later
|
|
59
|
+
const updatePromises = updates.map(update => handleSubmit(update)
|
|
60
|
+
.then(() => {
|
|
61
|
+
// Ensure same shape for these objects in failure AND success
|
|
62
|
+
successful.push({ setting: update });
|
|
63
|
+
})
|
|
64
|
+
.catch((error) => {
|
|
65
|
+
failed.push({ setting: update, error });
|
|
66
|
+
}));
|
|
67
|
+
|
|
68
|
+
return Promise.all(updatePromises)
|
|
69
|
+
.then(() => {
|
|
70
|
+
if (successful.length > 0) {
|
|
71
|
+
sendSettingsCallout({ type: 'success', settings: successful });
|
|
72
|
+
onSettingsSuccess({ settings: successful });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (failed.length > 0) {
|
|
76
|
+
sendSettingsCallout({ type: 'error', settings: failed });
|
|
77
|
+
onSettingsFailure({ settings: failed });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
onSubmitComplete();
|
|
81
|
+
return true;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
// In case we somehow called this with no updates
|
|
85
|
+
// (Shouldn't be possible because of the disabled save button),
|
|
86
|
+
// return an empty promise
|
|
87
|
+
return Promise.resolve(true);
|
|
88
|
+
}, [rawSettings, initialValues, handleSubmit, onSubmitComplete, sendSettingsCallout, onSettingsSuccess, onSettingsFailure]);
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
return ({
|
|
92
|
+
rawSettings,
|
|
93
|
+
initialValues,
|
|
94
|
+
onSubmit,
|
|
95
|
+
sendSettingsCallout,
|
|
96
|
+
settingsSection
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export default useStaticSettingsSection;
|
|
@@ -3,7 +3,7 @@ A hook for fetching AppSetting values
|
|
|
3
3
|
|
|
4
4
|
## Basic usage
|
|
5
5
|
```javascript
|
|
6
|
-
import { useAppSettings } from '@k-int/stripes-kint-components'
|
|
6
|
+
import { useAppSettings } from '@k-int/stripes-kint-components';
|
|
7
7
|
...
|
|
8
8
|
const data = useAppSettings({
|
|
9
9
|
endpoint: 'oa/settings/appSettings'
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { useMutation, useQuery } from 'react-query';
|
|
2
2
|
import { useOkapiKy } from '@folio/stripes/core';
|
|
3
|
-
import { generateKiwtQueryParams } from '
|
|
3
|
+
import { generateKiwtQueryParams } from '../../../utils';
|
|
4
|
+
|
|
5
|
+
import { GET_SETTING_SECTION_MUTATE_KEY, GET_SETTING_SECTION_QUERY_KEY } from '../../constants';
|
|
4
6
|
|
|
5
7
|
const useSettingSection = ({
|
|
6
8
|
sectionName,
|
|
7
9
|
settingEndpoint,
|
|
8
|
-
getQueryNamespaceGenerator = ({ queryParams }) =>
|
|
9
|
-
getMutateNamespaceGenerator = () =>
|
|
10
|
+
getQueryNamespaceGenerator = ({ queryParams }) => GET_SETTING_SECTION_QUERY_KEY(queryParams, sectionName),
|
|
11
|
+
getMutateNamespaceGenerator = () => GET_SETTING_SECTION_MUTATE_KEY(sectionName)
|
|
10
12
|
}) => {
|
|
11
13
|
const ky = useOkapiKy();
|
|
12
14
|
const queryParams = generateKiwtQueryParams({
|
|
@@ -9,8 +9,8 @@ import { Settings } from '@folio/stripes/smart-components';
|
|
|
9
9
|
import { SettingPage, SettingPagePane } from '../../SettingPage';
|
|
10
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 = {}) => {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { default as SettingsFormContainer } from './SettingsFormContainer';
|
|
2
|
+
|
|
3
|
+
// Settings hooks
|
|
4
|
+
export * from './hooks';
|
|
5
|
+
|
|
6
|
+
// Setting Page Components
|
|
7
|
+
export {
|
|
8
|
+
SettingPage,
|
|
9
|
+
SettingPagePane,
|
|
10
|
+
} from './SettingPage';
|
|
11
|
+
|
|
12
|
+
// EditableSettingsList
|
|
13
|
+
export * from './EditableSettingsList';
|
|
14
|
+
|
|
15
|
+
// Refdata categories
|
|
16
|
+
export { default as RefdataCategoriesSettings } from './RefdataCategoriesSettings';
|
|
17
|
+
|
|
18
|
+
export { default as EditableRefdataList } from './EditableRefdataList';
|
|
19
|
+
export { default as EditableRefdataCategoryList } from './EditableRefdataCategoryList';
|
|
20
|
+
|
|
21
|
+
export { default as StaticSettingsField } from './StaticSettingsField';
|
|
22
|
+
|
|
23
|
+
// Contexts
|
|
24
|
+
export {
|
|
25
|
+
SettingsContext,
|
|
26
|
+
} from './contexts';
|
|
27
|
+
|
|
28
|
+
export * from './constants';
|
|
@@ -4,7 +4,7 @@ import { BaseHarness } from '@folio/stripes-erm-testing';
|
|
|
4
4
|
|
|
5
5
|
import { useIntlKeyStore } from '../../../src';
|
|
6
6
|
|
|
7
|
-
import { SettingsContext } from '../../../src/lib/
|
|
7
|
+
import { SettingsContext } from '../../../src/lib/Settings';
|
|
8
8
|
import translationsProperties from '../../helpers';
|
|
9
9
|
|
|
10
10
|
const InternalKintIntlHarness = ({ children, intlKey, moduleName }) => {
|
|
@@ -1,107 +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 _components = require("@folio/stripes/components");
|
|
11
|
-
var _RefdataButtons = _interopRequireDefault(require("../../../RefdataButtons"));
|
|
12
|
-
var _hooks = require("../../../hooks");
|
|
13
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
-
const EditSettingValue = props => {
|
|
16
|
-
const {
|
|
17
|
-
currentSetting: setting,
|
|
18
|
-
input,
|
|
19
|
-
intlKey: passedIntlKey,
|
|
20
|
-
intlNS: passedIntlNS,
|
|
21
|
-
labelOverrides = {},
|
|
22
|
-
refdata,
|
|
23
|
-
templates
|
|
24
|
-
} = props;
|
|
25
|
-
const kintIntl = (0, _hooks.useKintIntl)(passedIntlKey, passedIntlNS);
|
|
26
|
-
const fieldLabel = kintIntl.formatKintMessage({
|
|
27
|
-
id: 'settings.valueFor',
|
|
28
|
-
overrideValue: labelOverrides === null || labelOverrides === void 0 ? void 0 : labelOverrides.valueFor
|
|
29
|
-
}, {
|
|
30
|
-
name: setting.key
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
// Adding default sort to refdata object in ascending order by label
|
|
34
|
-
const sortByLabel = (a, b) => a.label.localeCompare(b.label);
|
|
35
|
-
const sortedRefdata = refdata === null || refdata === void 0 ? void 0 : refdata.sort(sortByLabel);
|
|
36
|
-
switch (setting.settingType) {
|
|
37
|
-
case 'Refdata':
|
|
38
|
-
// Grab refdata values corresponding to setting
|
|
39
|
-
// eslint-disable-next-line no-case-declarations
|
|
40
|
-
let RefdataComponent = _components.Select;
|
|
41
|
-
if (refdata.length > 0 && refdata.length <= 4) {
|
|
42
|
-
RefdataComponent = _RefdataButtons.default;
|
|
43
|
-
}
|
|
44
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFinalForm.Field, {
|
|
45
|
-
"aria-label": fieldLabel,
|
|
46
|
-
component: RefdataComponent,
|
|
47
|
-
dataOptions: sortedRefdata,
|
|
48
|
-
name: "".concat(input.name, ".value")
|
|
49
|
-
});
|
|
50
|
-
case 'Password':
|
|
51
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFinalForm.Field, {
|
|
52
|
-
"aria-label": fieldLabel,
|
|
53
|
-
autoFocus: true,
|
|
54
|
-
component: _components.TextField,
|
|
55
|
-
name: "".concat(input.name, ".value"),
|
|
56
|
-
parse: v => v // Lets us send an empty string instead of 'undefined'
|
|
57
|
-
,
|
|
58
|
-
type: "password"
|
|
59
|
-
});
|
|
60
|
-
case 'Template':
|
|
61
|
-
{
|
|
62
|
-
// Grab refdata values corresponding to setting
|
|
63
|
-
// eslint-disable-next-line no-case-declarations
|
|
64
|
-
const selectTemplateValues = [{
|
|
65
|
-
value: '',
|
|
66
|
-
label: ''
|
|
67
|
-
}, ...templates.map(t => ({
|
|
68
|
-
value: t.id,
|
|
69
|
-
label: t.name
|
|
70
|
-
}))];
|
|
71
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFinalForm.Field, {
|
|
72
|
-
"aria-label": fieldLabel,
|
|
73
|
-
component: _components.Select,
|
|
74
|
-
dataOptions: selectTemplateValues,
|
|
75
|
-
name: "".concat(input.name, ".value"),
|
|
76
|
-
parse: v => v
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
default:
|
|
80
|
-
// If in doubt, go with String
|
|
81
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFinalForm.Field, {
|
|
82
|
-
"aria-label": fieldLabel,
|
|
83
|
-
autoFocus: true,
|
|
84
|
-
component: _components.TextField,
|
|
85
|
-
name: "".concat(input.name, ".value"),
|
|
86
|
-
parse: v => v // Lets us send an empty string instead of 'undefined'
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
EditSettingValue.propTypes = {
|
|
91
|
-
currentSetting: _propTypes.default.shape({
|
|
92
|
-
settingType: _propTypes.default.string,
|
|
93
|
-
key: _propTypes.default.string
|
|
94
|
-
}),
|
|
95
|
-
input: _propTypes.default.shape({
|
|
96
|
-
name: _propTypes.default.string
|
|
97
|
-
}),
|
|
98
|
-
intlKey: _propTypes.default.string,
|
|
99
|
-
intlNS: _propTypes.default.string,
|
|
100
|
-
labelOverrides: _propTypes.default.object,
|
|
101
|
-
refdata: _propTypes.default.arrayOf(_propTypes.default.object),
|
|
102
|
-
templates: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
103
|
-
name: _propTypes.default.string,
|
|
104
|
-
id: _propTypes.default.string
|
|
105
|
-
}))
|
|
106
|
-
};
|
|
107
|
-
var _default = exports.default = EditSettingValue;
|
|
@@ -1,26 +0,0 @@
|
|
|
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 }`. | | ✕ |
|
/package/es/lib/{EditableRefdataCategoryList → Settings/EditableRefdataCategoryList}/index.js
RENAMED
|
File without changes
|
|
File without changes
|
/package/es/lib/{EditableSettingsList → Settings/EditableSettingsList}/EditableSettingsList.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/es/lib/{EditableSettingsList → Settings/EditableSettingsList}/SettingField/index.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/src/lib/{EditableRefdataCategoryList → Settings/EditableRefdataCategoryList}/index.js
RENAMED
|
File without changes
|
|
File without changes
|
/package/src/lib/{EditableSettingsList → Settings/EditableSettingsList}/EditableSettingsList.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/src/lib/{EditableSettingsList → Settings/EditableSettingsList}/SettingField/README.md
RENAMED
|
File without changes
|
|
File without changes
|
/package/src/lib/{EditableSettingsList → Settings/EditableSettingsList}/SettingField/index.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|