@k-int/stripes-kint-components 1.3.0 → 1.7.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 +34 -2
- package/es/artifacts/coverage-jest/lcov-report/block-navigation.js +109 -0
- package/es/artifacts/coverage-jest/lcov-report/prettify.js +998 -0
- package/es/artifacts/coverage-jest/lcov-report/sorter.js +238 -0
- package/es/index.js +69 -17
- package/es/lib/ActionList/ActionList.js +63 -24
- package/es/lib/ActionList/ActionListFieldArray.js +158 -96
- package/es/lib/ActionList/index.js +7 -3
- package/es/lib/EditableRefdataList/EditableRefdataList.js +69 -24
- package/es/lib/EditableRefdataList/index.js +7 -3
- package/es/lib/EditableSettingsList/EditableSettingsList.js +90 -0
- package/es/lib/EditableSettingsList/EditableSettingsListFieldArray.js +90 -0
- package/es/lib/EditableSettingsList/EditableSettingsListFieldArray.test.js +181 -0
- package/es/lib/{Settings → EditableSettingsList/SettingField}/EditSettingValue.js +72 -9
- package/es/lib/EditableSettingsList/SettingField/EditSettingValue.test.js +447 -0
- package/es/lib/{Settings → EditableSettingsList/SettingField}/RenderSettingValue.js +45 -7
- package/es/lib/EditableSettingsList/SettingField/RenderSettingValue.test.js +495 -0
- package/es/lib/EditableSettingsList/SettingField/SettingField.js +187 -0
- package/es/lib/EditableSettingsList/SettingField/SettingField.test.js +180 -0
- package/es/lib/EditableSettingsList/SettingField/index.js +35 -0
- package/es/lib/EditableSettingsList/index.js +35 -0
- package/es/lib/NoResultsMessage/NoResultsMessage.js +122 -0
- package/es/lib/NoResultsMessage/index.js +19 -0
- package/es/lib/QueryTypedown/QueryTypedown.js +48 -9
- package/es/lib/QueryTypedown/index.js +6 -2
- package/es/lib/RefdataButtons/RefdataButtons.js +143 -0
- package/es/lib/RefdataButtons/index.js +19 -0
- package/es/lib/SASQLookupComponent/SASQLookupComponent.js +202 -131
- package/es/lib/SASQLookupComponent/index.js +6 -2
- package/es/lib/SASQRoute/SASQRoute.js +55 -18
- package/es/lib/SASQRoute/index.js +6 -2
- package/es/lib/SASQViewComponent/SASQViewComponent.js +50 -11
- package/es/lib/SASQViewComponent/index.js +6 -2
- package/es/lib/SearchField/SearchField.js +48 -13
- package/es/lib/SearchField/index.js +6 -2
- package/es/lib/SettingPage/SettingPage.js +99 -0
- package/es/lib/SettingPage/SettingPagePane.js +83 -0
- package/es/lib/SettingPage/index.js +27 -0
- package/es/lib/TypeDown/TypeDown.js +143 -101
- package/es/lib/TypeDown/index.js +6 -2
- package/es/lib/Typedown/Typedown.js +140 -96
- package/es/lib/Typedown/index.js +6 -2
- package/es/lib/constants/eventCodes.js +31 -1
- package/es/lib/contexts/SettingsContext.js +41 -0
- package/es/lib/contexts/index.js +19 -0
- package/es/lib/hooks/index.js +42 -8
- package/es/lib/hooks/settingsHooks/index.js +27 -0
- package/es/lib/hooks/settingsHooks/useSettingSection.js +74 -0
- package/es/lib/hooks/settingsHooks/useSettings.js +175 -0
- package/es/lib/hooks/typedownHooks/index.js +8 -28
- package/es/lib/hooks/typedownHooks/useTypedown.js +129 -12
- package/es/lib/hooks/typedownHooks/useTypedownData.js +35 -2
- package/es/lib/hooks/typedownHooks/useTypedownToggle.js +39 -6
- package/es/lib/hooks/useActiveElement.js +33 -2
- package/es/lib/hooks/useHelperApp.js +51 -12
- package/es/lib/hooks/useKiwtFieldArray.js +142 -0
- package/es/lib/hooks/useKiwtSASQuery.js +62 -7
- package/es/lib/hooks/useLocalStorageState.js +37 -4
- package/es/lib/hooks/useMutateRefdataValue.js +42 -9
- package/es/lib/hooks/useQIndex.js +108 -0
- package/es/lib/hooks/useRefdata.js +56 -12
- package/es/lib/hooks/useTemplates.js +36 -3
- package/es/lib/utils/buildUrl.js +43 -10
- package/es/lib/utils/generateKiwtQuery.js +31 -108
- package/es/lib/utils/generateKiwtQueryParams.js +154 -0
- package/es/lib/utils/index.js +55 -3
- package/es/lib/utils/refdataOptions.js +43 -0
- package/es/lib/utils/renderHelpText.js +109 -0
- package/es/lib/utils/selectorSafe.js +31 -2
- package/es/lib/utils/sortByLabel.js +55 -0
- package/es/lib/utils/toCamelCase.js +48 -0
- package/jest.config.js +15 -1
- package/junit.xml +79 -0
- package/package.json +17 -10
- package/src/artifacts/coverage-jest/lcov-report/ActionList/ActionList.js.html +256 -0
- package/src/artifacts/coverage-jest/lcov-report/ActionList/ActionListFieldArray.js.html +799 -0
- package/src/artifacts/coverage-jest/lcov-report/ActionList/index.html +146 -0
- package/src/artifacts/coverage-jest/lcov-report/ActionList/index.js.html +88 -0
- package/src/artifacts/coverage-jest/lcov-report/EditableRefdataList/EditableRefdataList.js.html +376 -0
- package/src/artifacts/coverage-jest/lcov-report/EditableRefdataList/index.html +131 -0
- package/src/artifacts/coverage-jest/lcov-report/EditableRefdataList/index.js.html +88 -0
- package/src/artifacts/coverage-jest/lcov-report/EditableSettingsList/EditableSettingsList.js.html +223 -0
- package/src/artifacts/coverage-jest/lcov-report/EditableSettingsList/EditableSettingsListFieldArray.js.html +211 -0
- package/src/artifacts/coverage-jest/lcov-report/EditableSettingsList/SettingField/EditSettingValue.js.html +376 -0
- package/src/artifacts/coverage-jest/lcov-report/EditableSettingsList/SettingField/RenderSettingValue.js.html +262 -0
- package/src/artifacts/coverage-jest/lcov-report/EditableSettingsList/SettingField/SettingField.js.html +436 -0
- package/src/artifacts/coverage-jest/lcov-report/EditableSettingsList/SettingField/index.html +161 -0
- package/src/artifacts/coverage-jest/lcov-report/EditableSettingsList/SettingField/index.js.html +94 -0
- package/src/artifacts/coverage-jest/lcov-report/EditableSettingsList/index.html +146 -0
- package/src/artifacts/coverage-jest/lcov-report/EditableSettingsList/index.js.html +94 -0
- package/src/artifacts/coverage-jest/lcov-report/NoResultsMessage/NoResultsMessage.js.html +319 -0
- package/src/artifacts/coverage-jest/lcov-report/NoResultsMessage/index.html +131 -0
- package/src/artifacts/coverage-jest/lcov-report/NoResultsMessage/index.js.html +88 -0
- package/src/artifacts/coverage-jest/lcov-report/QueryTypedown/QueryTypedown.js.html +184 -0
- package/src/artifacts/coverage-jest/lcov-report/QueryTypedown/index.html +131 -0
- package/src/artifacts/coverage-jest/lcov-report/QueryTypedown/index.js.html +88 -0
- package/src/artifacts/coverage-jest/lcov-report/RefdataButtons/RefdataButtons.js.html +370 -0
- package/src/artifacts/coverage-jest/lcov-report/RefdataButtons/index.html +131 -0
- package/src/artifacts/coverage-jest/lcov-report/RefdataButtons/index.js.html +88 -0
- package/src/artifacts/coverage-jest/lcov-report/SASQLookupComponent/SASQLookupComponent.js.html +949 -0
- package/src/artifacts/coverage-jest/lcov-report/SASQLookupComponent/index.html +131 -0
- package/src/artifacts/coverage-jest/lcov-report/SASQLookupComponent/index.js.html +88 -0
- package/src/artifacts/coverage-jest/lcov-report/SASQRoute/SASQRoute.js.html +274 -0
- package/src/artifacts/coverage-jest/lcov-report/SASQRoute/index.html +131 -0
- package/src/artifacts/coverage-jest/lcov-report/SASQRoute/index.js.html +88 -0
- package/src/artifacts/coverage-jest/lcov-report/SASQViewComponent/SASQViewComponent.js.html +250 -0
- package/src/artifacts/coverage-jest/lcov-report/SASQViewComponent/index.html +131 -0
- package/src/artifacts/coverage-jest/lcov-report/SASQViewComponent/index.js.html +88 -0
- package/src/artifacts/coverage-jest/lcov-report/SearchField/SearchField.js.html +214 -0
- package/src/artifacts/coverage-jest/lcov-report/SearchField/index.html +131 -0
- package/src/artifacts/coverage-jest/lcov-report/SearchField/index.js.html +88 -0
- package/src/artifacts/coverage-jest/lcov-report/SettingPage/SettingPage.js.html +211 -0
- package/src/artifacts/coverage-jest/lcov-report/SettingPage/SettingPagePane.js.html +178 -0
- package/src/artifacts/coverage-jest/lcov-report/SettingPage/index.html +146 -0
- package/src/artifacts/coverage-jest/lcov-report/SettingPage/index.js.html +91 -0
- package/src/artifacts/coverage-jest/lcov-report/TypeDown/TypeDown.js.html +769 -0
- package/src/artifacts/coverage-jest/lcov-report/TypeDown/index.html +131 -0
- package/src/artifacts/coverage-jest/lcov-report/TypeDown/index.js.html +88 -0
- package/src/artifacts/coverage-jest/lcov-report/Typedown/Typedown.js.html +790 -0
- package/src/artifacts/coverage-jest/lcov-report/Typedown/index.html +131 -0
- package/src/artifacts/coverage-jest/lcov-report/Typedown/index.js.html +88 -0
- package/src/artifacts/coverage-jest/lcov-report/base.css +224 -0
- package/src/artifacts/coverage-jest/lcov-report/block-navigation.js +87 -0
- package/src/artifacts/coverage-jest/lcov-report/constants/eventCodes.js.html +94 -0
- package/src/artifacts/coverage-jest/lcov-report/constants/index.html +116 -0
- package/src/artifacts/coverage-jest/lcov-report/contexts/SettingsContext.js.html +97 -0
- package/src/artifacts/coverage-jest/lcov-report/contexts/index.html +131 -0
- package/src/artifacts/coverage-jest/lcov-report/contexts/index.js.html +91 -0
- package/src/artifacts/coverage-jest/lcov-report/favicon.png +0 -0
- package/src/artifacts/coverage-jest/lcov-report/hooks/index.html +251 -0
- package/src/artifacts/coverage-jest/lcov-report/hooks/index.js.html +115 -0
- package/src/artifacts/coverage-jest/lcov-report/hooks/settingsHooks/index.html +146 -0
- package/src/artifacts/coverage-jest/lcov-report/hooks/settingsHooks/index.js.html +91 -0
- package/src/artifacts/coverage-jest/lcov-report/hooks/settingsHooks/useSettingSection.js.html +163 -0
- package/src/artifacts/coverage-jest/lcov-report/hooks/settingsHooks/useSettings.js.html +403 -0
- package/src/artifacts/coverage-jest/lcov-report/hooks/typedownHooks/index.html +161 -0
- package/src/artifacts/coverage-jest/lcov-report/hooks/typedownHooks/index.js.html +94 -0
- package/src/artifacts/coverage-jest/lcov-report/hooks/typedownHooks/useTypedown.js.html +520 -0
- package/src/artifacts/coverage-jest/lcov-report/hooks/typedownHooks/useTypedownData.js.html +163 -0
- package/src/artifacts/coverage-jest/lcov-report/hooks/typedownHooks/useTypedownToggle.js.html +163 -0
- package/src/artifacts/coverage-jest/lcov-report/hooks/useActiveElement.js.html +157 -0
- package/src/artifacts/coverage-jest/lcov-report/hooks/useHelperApp.js.html +283 -0
- package/src/artifacts/coverage-jest/lcov-report/hooks/useKiwtFieldArray.js.html +274 -0
- package/src/artifacts/coverage-jest/lcov-report/hooks/useKiwtSASQuery.js.html +178 -0
- package/src/artifacts/coverage-jest/lcov-report/hooks/useLocalStorageState.js.html +136 -0
- package/src/artifacts/coverage-jest/lcov-report/hooks/useMutateRefdataValue.js.html +301 -0
- package/src/artifacts/coverage-jest/lcov-report/hooks/useQIndex.js.html +208 -0
- package/src/artifacts/coverage-jest/lcov-report/hooks/useRefdata.js.html +268 -0
- package/src/artifacts/coverage-jest/lcov-report/hooks/useTemplates.js.html +166 -0
- package/src/artifacts/coverage-jest/lcov-report/index.html +401 -0
- package/src/artifacts/coverage-jest/lcov-report/prettify.css +1 -0
- package/src/artifacts/coverage-jest/lcov-report/prettify.js +2 -0
- package/src/artifacts/coverage-jest/lcov-report/sort-arrow-sprite.png +0 -0
- package/src/artifacts/coverage-jest/lcov-report/sorter.js +196 -0
- package/src/artifacts/coverage-jest/lcov-report/utils/buildUrl.js.html +193 -0
- package/src/artifacts/coverage-jest/lcov-report/utils/generateKiwtQuery.js.html +109 -0
- package/src/artifacts/coverage-jest/lcov-report/utils/generateKiwtQueryParams.js.html +286 -0
- package/src/artifacts/coverage-jest/lcov-report/utils/index.html +236 -0
- package/src/artifacts/coverage-jest/lcov-report/utils/index.js.html +121 -0
- package/src/artifacts/coverage-jest/lcov-report/utils/refdataOptions.js.html +106 -0
- package/src/artifacts/coverage-jest/lcov-report/utils/renderHelpText.js.html +166 -0
- package/src/artifacts/coverage-jest/lcov-report/utils/selectorSafe.js.html +103 -0
- package/src/artifacts/coverage-jest/lcov-report/utils/sortByLabel.js.html +130 -0
- package/src/artifacts/coverage-jest/lcov-report/utils/toCamelCase.js.html +127 -0
- package/src/artifacts/coverage-jest/lcov.info +1999 -0
- package/src/index.js +21 -6
- package/src/lib/ActionList/ActionList.js +5 -2
- package/src/lib/ActionList/ActionListFieldArray.js +20 -8
- package/src/lib/ActionList/README.md +1 -0
- package/src/lib/ActionList/index.js +1 -1
- package/src/lib/EditableRefdataList/EditableRefdataList.js +10 -5
- package/src/lib/EditableRefdataList/index.js +1 -1
- package/src/lib/{Settings → EditableSettingsList}/EditableSettingsList.js +0 -0
- package/src/lib/{Settings → EditableSettingsList}/EditableSettingsListFieldArray.js +2 -2
- package/src/lib/EditableSettingsList/EditableSettingsListFieldArray.test.js +111 -0
- package/src/lib/{Settings → EditableSettingsList/SettingField}/EditSettingValue.js +24 -1
- package/src/lib/EditableSettingsList/SettingField/EditSettingValue.test.js +379 -0
- package/src/lib/{Settings → EditableSettingsList/SettingField}/RenderSettingValue.js +2 -1
- package/src/lib/EditableSettingsList/SettingField/RenderSettingValue.test.js +368 -0
- package/src/lib/{Settings → EditableSettingsList/SettingField}/SettingField.js +7 -7
- package/src/lib/EditableSettingsList/SettingField/SettingField.test.js +80 -0
- package/src/lib/EditableSettingsList/SettingField/index.js +3 -0
- package/src/lib/EditableSettingsList/index.js +3 -0
- package/src/lib/NoResultsMessage/NoResultsMessage.js +78 -0
- package/src/lib/NoResultsMessage/index.js +1 -0
- package/src/lib/{Settings → RefdataButtons}/RefdataButtons.js +1 -1
- package/src/lib/RefdataButtons/index.js +1 -0
- package/src/lib/SASQLookupComponent/SASQLookupComponent.js +36 -8
- package/src/lib/SASQRoute/README.md +1 -1
- package/src/lib/{Settings → SettingPage}/SettingPage.js +5 -5
- package/src/lib/{Settings → SettingPage}/SettingPagePane.js +12 -2
- package/src/lib/SettingPage/index.js +2 -0
- package/src/lib/TypeDown/README.md +1 -115
- package/src/lib/TypeDown/TypeDown.js +4 -2
- package/src/lib/Typedown/Typedown.js +2 -1
- package/src/lib/{Settings → contexts}/SettingsContext.js +1 -1
- package/src/lib/contexts/index.js +2 -0
- package/src/lib/hooks/README.md +107 -0
- package/src/lib/hooks/index.js +3 -0
- package/src/lib/hooks/settingsHooks/index.js +2 -0
- package/src/lib/{Settings → hooks/settingsHooks}/useSettingSection.js +0 -0
- package/src/lib/{Settings → hooks/settingsHooks}/useSettings.js +14 -6
- package/src/lib/hooks/typedownHooks/index.js +0 -3
- package/src/lib/hooks/typedownHooks/useTypedown.js +93 -11
- package/src/lib/hooks/useHelperApp.js +5 -1
- package/src/lib/hooks/useKiwtFieldArray.js +63 -0
- package/src/lib/hooks/useKiwtSASQuery.js +9 -1
- package/src/lib/hooks/useQIndex.js +41 -0
- package/src/lib/hooks/useRefdata.js +17 -6
- package/src/lib/utils/README.md +39 -1
- package/src/lib/utils/generateKiwtQuery.js +3 -62
- package/src/lib/utils/generateKiwtQueryParams.js +67 -0
- package/src/lib/utils/index.js +10 -0
- package/src/lib/utils/refdataOptions.js +7 -0
- package/src/lib/{Settings/utils → utils}/renderHelpText.js +1 -1
- package/src/lib/{Settings/utils → utils}/sortByLabel.js +1 -1
- package/src/lib/{Settings/utils → utils}/toCamelCase.js +0 -0
- package/styles/NoResultsMessage.css +38 -0
- package/test/helpers/index.js +1 -0
- package/test/helpers/translationsProperties.js +40 -0
- package/test/jest/helpers/KintHarness.js +36 -0
- package/test/jest/helpers/index.js +2 -0
- package/test/jest/helpers/renderWithKintHarness.js +15 -0
- package/test/jest/jest-transformer.js +4 -0
- package/test/jest/setupTests.js +1 -0
- package/translations/stripes-kint-components/en.json +4 -1
- package/babelOptions.js +0 -30
- package/es/lib/Settings/EditableSettingsList.js +0 -57
- package/es/lib/Settings/EditableSettingsListFieldArray.js +0 -59
- package/es/lib/Settings/RefdataButtons.js +0 -100
- package/es/lib/Settings/SettingField.js +0 -144
- package/es/lib/Settings/SettingPage.js +0 -64
- package/es/lib/Settings/SettingPagePane.js +0 -43
- package/es/lib/Settings/SettingsContext.js +0 -18
- package/es/lib/Settings/index.js +0 -71
- package/es/lib/Settings/useSettingSection.js +0 -41
- package/es/lib/Settings/useSettings.js +0 -126
- package/es/lib/Settings/utils/index.js +0 -31
- package/es/lib/Settings/utils/renderHelpText.js +0 -57
- package/es/lib/Settings/utils/sortByLabel.js +0 -26
- package/es/lib/Settings/utils/toCamelCase.js +0 -19
- package/es/lib/hooks/typedownHooks/useTypedownFooter.js +0 -47
- package/es/lib/hooks/typedownHooks/useTypedownList.js +0 -45
- package/es/lib/hooks/typedownHooks/useTypedownSearchField.js +0 -47
- package/es/lib/utils/getFocusableElements.js +0 -132
- package/src/lib/Settings/index.js +0 -8
- package/src/lib/Settings/utils/index.js +0 -3
- package/src/lib/hooks/typedownHooks/useTypedownFooter.js +0 -43
- package/src/lib/hooks/typedownHooks/useTypedownList.js +0 -36
- package/src/lib/hooks/typedownHooks/useTypedownSearchField.js +0 -39
- package/src/lib/utils/getFocusableElements.js +0 -99
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React, { useContext } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
|
|
4
|
-
import EditableSettingsList from '
|
|
5
|
-
import SettingsContext from '
|
|
6
|
-
import useSettingSection from '
|
|
4
|
+
import { EditableSettingsList } from '../EditableSettingsList';
|
|
5
|
+
import { SettingsContext } from '../contexts';
|
|
6
|
+
import { useSettingSection } from '../hooks';
|
|
7
7
|
|
|
8
8
|
const SettingPage = ({ sectionName }) => {
|
|
9
9
|
const { settingEndpoint } = useContext(SettingsContext);
|
|
@@ -31,10 +31,10 @@ SettingPage.propTypes = {
|
|
|
31
31
|
sectionName: PropTypes.string,
|
|
32
32
|
resources: PropTypes.shape({
|
|
33
33
|
settings: PropTypes.shape({
|
|
34
|
-
records: PropTypes.
|
|
34
|
+
records: PropTypes.arrayOf(PropTypes.object)
|
|
35
35
|
}),
|
|
36
36
|
refdatavalues: PropTypes.shape({
|
|
37
|
-
records: PropTypes.
|
|
37
|
+
records: PropTypes.arrayOf(PropTypes.object)
|
|
38
38
|
})
|
|
39
39
|
})
|
|
40
40
|
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import React, { useContext } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
2
4
|
import { Pane } from '@folio/stripes/components';
|
|
3
5
|
import { FormattedMessage } from 'react-intl';
|
|
4
|
-
import SettingsContext from '
|
|
5
|
-
import { toCamelCase } from '
|
|
6
|
+
import { SettingsContext } from '../contexts';
|
|
7
|
+
import { toCamelCase } from '../utils';
|
|
6
8
|
|
|
7
9
|
const SettingPagePane = ({ sectionName, children }) => {
|
|
8
10
|
const { intlKey } = useContext(SettingsContext);
|
|
@@ -18,4 +20,12 @@ const SettingPagePane = ({ sectionName, children }) => {
|
|
|
18
20
|
);
|
|
19
21
|
};
|
|
20
22
|
|
|
23
|
+
SettingPagePane.propTypes = {
|
|
24
|
+
sectionName: PropTypes.string,
|
|
25
|
+
children: PropTypes.oneOfType([
|
|
26
|
+
PropTypes.func,
|
|
27
|
+
PropTypes.node
|
|
28
|
+
])
|
|
29
|
+
};
|
|
30
|
+
|
|
21
31
|
export default SettingPagePane;
|
|
@@ -1,115 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import React from 'react';
|
|
3
|
-
|
|
4
|
-
import { Button, Col, Pane, Row, TextField } from '@folio/stripes/components';
|
|
5
|
-
import { AppIcon } from '@folio/stripes/core';
|
|
6
|
-
import { generateKiwtQuery, TypeDown } from '@k-int/stripes-kint-components';
|
|
7
|
-
|
|
8
|
-
import { Form, Field, useFormState } from 'react-final-form';
|
|
9
|
-
|
|
10
|
-
const TestField = () => {
|
|
11
|
-
const pathMutator = (input, path) => {
|
|
12
|
-
const query = generateKiwtQuery(
|
|
13
|
-
{
|
|
14
|
-
searchKey: 'name,alternateNames.name',
|
|
15
|
-
stats: false
|
|
16
|
-
}, {
|
|
17
|
-
sort: 'name',
|
|
18
|
-
query: input,
|
|
19
|
-
}
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
return `${path}${query}`;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
console.log("Current values: %o", useFormState()?.values)
|
|
26
|
-
return (
|
|
27
|
-
<Field
|
|
28
|
-
component={TypeDown}
|
|
29
|
-
name="test"
|
|
30
|
-
path="erm/sas"
|
|
31
|
-
pathMutator={pathMutator}
|
|
32
|
-
renderFooter={() => (
|
|
33
|
-
<>
|
|
34
|
-
<Button
|
|
35
|
-
id="footer button 1"
|
|
36
|
-
marginBottom0
|
|
37
|
-
onClick={() => {
|
|
38
|
-
alert('sup')
|
|
39
|
-
}}
|
|
40
|
-
type="button"
|
|
41
|
-
>
|
|
42
|
-
Hello 1
|
|
43
|
-
</Button>
|
|
44
|
-
<Button
|
|
45
|
-
id="footer button 2"
|
|
46
|
-
marginBottom0
|
|
47
|
-
onClick={() => {
|
|
48
|
-
alert('sup 2')
|
|
49
|
-
}}
|
|
50
|
-
type="button"
|
|
51
|
-
>
|
|
52
|
-
Hello 2
|
|
53
|
-
</Button>
|
|
54
|
-
</>
|
|
55
|
-
)}
|
|
56
|
-
renderListItem={agreement => {
|
|
57
|
-
return (
|
|
58
|
-
<>
|
|
59
|
-
<AppIcon
|
|
60
|
-
app="agreements"
|
|
61
|
-
size="small"
|
|
62
|
-
>
|
|
63
|
-
{agreement.name}
|
|
64
|
-
</AppIcon>
|
|
65
|
-
</>
|
|
66
|
-
);
|
|
67
|
-
}}
|
|
68
|
-
/>
|
|
69
|
-
);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const TestComponent = () => {
|
|
74
|
-
return (
|
|
75
|
-
<Pane
|
|
76
|
-
defaultWidth="fill"
|
|
77
|
-
dismissible
|
|
78
|
-
id="test-typedown"
|
|
79
|
-
paneTitle={"Test typedown"}
|
|
80
|
-
>
|
|
81
|
-
<Form
|
|
82
|
-
enableReinitialize
|
|
83
|
-
navigationCheck
|
|
84
|
-
onSubmit={(values) => console.log("submitting: %o", values)}
|
|
85
|
-
subscription={{ values: true }}
|
|
86
|
-
>
|
|
87
|
-
{({ handleSubmit }) => {
|
|
88
|
-
return (
|
|
89
|
-
<form onSubmit={handleSubmit}>
|
|
90
|
-
<Row>
|
|
91
|
-
<Col xs={6}>
|
|
92
|
-
<TestField />
|
|
93
|
-
</Col>
|
|
94
|
-
<Col xs={6}>
|
|
95
|
-
<Field
|
|
96
|
-
component={TextField}
|
|
97
|
-
name="test2"
|
|
98
|
-
/>
|
|
99
|
-
</Col>
|
|
100
|
-
</Row>
|
|
101
|
-
<Button
|
|
102
|
-
type="submit"
|
|
103
|
-
>
|
|
104
|
-
submit
|
|
105
|
-
</Button>
|
|
106
|
-
</form>
|
|
107
|
-
);
|
|
108
|
-
}}
|
|
109
|
-
</Form>
|
|
110
|
-
</Pane>
|
|
111
|
-
);
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
export default TestComponent;
|
|
115
|
-
```
|
|
1
|
+
DEPRECATED - DO NOT USE. You probably want Typedown
|
|
@@ -30,6 +30,7 @@ const TypeDown = ({
|
|
|
30
30
|
}) => {
|
|
31
31
|
useEffect(() => {
|
|
32
32
|
if (process.env.NODE_ENV === 'development') {
|
|
33
|
+
// eslint-disable-next-line no-console
|
|
33
34
|
console.warn('TypeDown component is deprecated, you likely want either Typedown or QueryTypedown');
|
|
34
35
|
}
|
|
35
36
|
}, []);
|
|
@@ -71,13 +72,13 @@ const TypeDown = ({
|
|
|
71
72
|
</div>
|
|
72
73
|
), [renderListItem, uniqueIdentificationPath]);
|
|
73
74
|
|
|
74
|
-
const handleChange = value => {
|
|
75
|
+
const handleChange = useCallback(value => {
|
|
75
76
|
input.onChange(value);
|
|
76
77
|
|
|
77
78
|
if (typeof onChange === 'function') {
|
|
78
79
|
onChange(value);
|
|
79
80
|
}
|
|
80
|
-
};
|
|
81
|
+
}, [input, onChange]);
|
|
81
82
|
|
|
82
83
|
const dropDown = useCallback(() => {
|
|
83
84
|
return (
|
|
@@ -132,6 +133,7 @@ const TypeDown = ({
|
|
|
132
133
|
}, [
|
|
133
134
|
data,
|
|
134
135
|
footerRef,
|
|
136
|
+
handleChange,
|
|
135
137
|
handleNextFocus,
|
|
136
138
|
input,
|
|
137
139
|
listKeyDownHandler,
|
|
@@ -131,7 +131,7 @@ const Typedown = ({
|
|
|
131
131
|
<div
|
|
132
132
|
ref={footerRef}
|
|
133
133
|
className={css.footer}
|
|
134
|
-
id=
|
|
134
|
+
id={`typedown-footer-${selectorSafe(input.name)}`}
|
|
135
135
|
>
|
|
136
136
|
{renderFooter()}
|
|
137
137
|
</div>
|
|
@@ -222,6 +222,7 @@ const Typedown = ({
|
|
|
222
222
|
|
|
223
223
|
Typedown.propTypes = {
|
|
224
224
|
dataOptions: PropTypes.arrayOf(PropTypes.object),
|
|
225
|
+
filterPath: PropTypes.string,
|
|
225
226
|
input: PropTypes.object,
|
|
226
227
|
meta: PropTypes.object,
|
|
227
228
|
onChange: PropTypes.func,
|
package/src/lib/hooks/README.md
CHANGED
|
@@ -21,6 +21,7 @@ endpoint | string | The endpoint to fetch refdataValues from | | ✓ |
|
|
|
21
21
|
desc | string | The refdataCategory (usually of the form `DomainClass.Field`) | | ✕ |
|
|
22
22
|
queryParams | object | A set of queryParameters to hand to react-query's `useQuery` | | ✕ |
|
|
23
23
|
returnQueryObject | bool | A switch to return the entirety of the queryObject from useQuery. If `false`, the data will be destructured, if `true` the return will be the full object returned by react-query's `useQuery` | false | ✕ |
|
|
24
|
+
options | object | An object of the shape SASQ_MAP (See generateKiwtQuery) to pass to the generateKiwtQuery inside. Any passed desc "d" will be passed as a filter `DescKey.${d}`, with DescKey acting as FilterName, assuming `filterKeys: { DescKey: "desc" }` in options, so `desc==${d}` is passed directly to the backend. | `{filterKeys: {DescKey: "desc" }, stats: false, max: 100}` | ✕ |
|
|
24
25
|
|
|
25
26
|
## useMutateRefdataValue
|
|
26
27
|
A hook for mutations (Create/Delete/Edit) of refdataValues.
|
|
@@ -117,6 +118,8 @@ A hook which takes an object containing various helper components to render, and
|
|
|
117
118
|
When the url contains a query of the form `helper={name}`, this hook will check the helpers object it was handed for a key matching `{name}`, and if there is one it will return the component value for that key.
|
|
118
119
|
|
|
119
120
|
The hook also returns an object `helperToggleFunctions`, which will have the same keys as were handed to the hook, and values corresponding to "toggle" functions for that key. These functions are a simple way to change the helper query in the url.
|
|
121
|
+
|
|
122
|
+
Finally the hook also returns an ease-of-use function `isOpen`, which takes a string input and returns a boolean if the current helper in the URL matches that string or not.
|
|
120
123
|
### Basic usage
|
|
121
124
|
```
|
|
122
125
|
import { useHelperApp } from '@k-int/stripes-kint-components'
|
|
@@ -181,3 +184,107 @@ import { useQuery } from 'react-query';
|
|
|
181
184
|
</SearchAndSortQuery>
|
|
182
185
|
|
|
183
186
|
```
|
|
187
|
+
|
|
188
|
+
## useQIndex
|
|
189
|
+
A hook with a similar API to setState, but instead stores a value in the `qindex` parameter in the URL.
|
|
190
|
+
Returns an array `[qindex, setQindex]`. There is no way to set an initialValue with the hook, as the state is derived from the URL rather than the other way around. This means that multiple `useQIndex` hooks can exist at once.
|
|
191
|
+
|
|
192
|
+
### BasicUsage
|
|
193
|
+
```
|
|
194
|
+
import {
|
|
195
|
+
Button,
|
|
196
|
+
} from '@folio/stripes/components';
|
|
197
|
+
import useQindex from '../../../../stripes-kint-components/src/lib/hooks/useQIndex';
|
|
198
|
+
|
|
199
|
+
const Test() {
|
|
200
|
+
const [qindex, setQindex] = useQindex();
|
|
201
|
+
|
|
202
|
+
return (
|
|
203
|
+
<>
|
|
204
|
+
<Button
|
|
205
|
+
onClick={() => setQindex(qindex + "1")}
|
|
206
|
+
>
|
|
207
|
+
change the qindex
|
|
208
|
+
</Button>
|
|
209
|
+
<div>
|
|
210
|
+
{`The current qindex is: ${qindex}`
|
|
211
|
+
</div>
|
|
212
|
+
</>
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export default Test;
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## useKiwtFieldArray
|
|
220
|
+
A hook to replace `withKiwtFieldArray` [from stripes-erm-components](https://github.com/folio-org/stripes-erm-components/tree/master/lib/withKiwtFieldArray). Provides functions for adding and deleting items in a way which the backend endpoints will understand, as well as an "items" array to track the current set of valid items in the form.
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
### BasicUsage
|
|
224
|
+
```
|
|
225
|
+
...
|
|
226
|
+
import useKiwtFieldArray from '../../../util/useKiwtFieldArray';
|
|
227
|
+
...
|
|
228
|
+
|
|
229
|
+
const TestFieldArray = () => {
|
|
230
|
+
const {
|
|
231
|
+
items,
|
|
232
|
+
onAddField,
|
|
233
|
+
onDeleteField
|
|
234
|
+
} = useKiwtFieldArray(name, true);
|
|
235
|
+
|
|
236
|
+
return (
|
|
237
|
+
<>
|
|
238
|
+
{items.map((item, index) => {
|
|
239
|
+
return (
|
|
240
|
+
<Row>
|
|
241
|
+
<Col xs={3}>
|
|
242
|
+
<Field
|
|
243
|
+
name={`${name}[${index}].name`}
|
|
244
|
+
component={TextField}
|
|
245
|
+
required
|
|
246
|
+
validate={requiredValidator}
|
|
247
|
+
/>
|
|
248
|
+
</Col>
|
|
249
|
+
<Col xs={1}>
|
|
250
|
+
<IconButton
|
|
251
|
+
icon="trash"
|
|
252
|
+
id="remove-volume-button"
|
|
253
|
+
onClick={() => onDeleteField(index, volume)}
|
|
254
|
+
/>
|
|
255
|
+
</Col>
|
|
256
|
+
</Row>
|
|
257
|
+
);
|
|
258
|
+
})}
|
|
259
|
+
<Button
|
|
260
|
+
onClick={() => onAddField({}})}
|
|
261
|
+
>
|
|
262
|
+
ADD NEW
|
|
263
|
+
</Button>
|
|
264
|
+
</>
|
|
265
|
+
);
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
const Test = ({}) => {
|
|
269
|
+
return (
|
|
270
|
+
<Form
|
|
271
|
+
...
|
|
272
|
+
render={({ handleSubmit, submitting, form }) => (
|
|
273
|
+
<form onSubmit={handleSubmit}>
|
|
274
|
+
<FieldArray
|
|
275
|
+
name="test"
|
|
276
|
+
component={TestFieldArray}
|
|
277
|
+
/>
|
|
278
|
+
</form>
|
|
279
|
+
)}
|
|
280
|
+
/>
|
|
281
|
+
);
|
|
282
|
+
};
|
|
283
|
+
export default Test
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Props
|
|
287
|
+
Name | Type | Description | default | required
|
|
288
|
+
--- | --- | --- | --- | ---
|
|
289
|
+
name | String | The name of the fieldArray, used to hook into the final form state for that field. | | ✓ |
|
|
290
|
+
submitWholeDeletedObject | bool | a boolean flag to ensure that a deleted object is sent whole to the backend, rather than just as an id. | false | ✕ |
|
package/src/lib/hooks/index.js
CHANGED
|
@@ -5,3 +5,6 @@ export { default as useActiveElement } from './useActiveElement';
|
|
|
5
5
|
export { default as useKiwtSASQuery } from './useKiwtSASQuery';
|
|
6
6
|
export { default as useHelperApp } from './useHelperApp';
|
|
7
7
|
export { default as useLocalStorageState } from './useLocalStorageState';
|
|
8
|
+
export { default as useQIndex } from './useQIndex';
|
|
9
|
+
export { useSettings, useSettingSection } from './settingsHooks';
|
|
10
|
+
export { default as useKiwtFieldArray } from './useKiwtFieldArray';
|
|
File without changes
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import React, { useContext } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
2
4
|
import { useQuery } from 'react-query';
|
|
3
5
|
import { FormattedMessage, useIntl } from 'react-intl';
|
|
4
6
|
import { useOkapiKy } from '@folio/stripes/core';
|
|
5
7
|
|
|
6
8
|
import { Settings } from '@folio/stripes/smart-components';
|
|
7
9
|
|
|
8
|
-
import SettingPage from '
|
|
9
|
-
import
|
|
10
|
-
import SettingsContext from './SettingsContext';
|
|
10
|
+
import { SettingPage, SettingPagePane } from '../../SettingPage';
|
|
11
|
+
import { SettingsContext } from '../../contexts';
|
|
11
12
|
|
|
12
|
-
import { sortByLabel, toCamelCase } from '
|
|
13
|
+
import { sortByLabel, toCamelCase } from '../../utils';
|
|
13
14
|
|
|
14
15
|
const useSettings = ({
|
|
15
16
|
dynamicPageExclusions,
|
|
@@ -21,7 +22,7 @@ const useSettings = ({
|
|
|
21
22
|
}) => {
|
|
22
23
|
const ky = useOkapiKy();
|
|
23
24
|
const intl = useIntl();
|
|
24
|
-
const extraPathItems = dynamicPageExclusions.map(dpe => `filters=section!=${dpe}`)
|
|
25
|
+
const extraPathItems = dynamicPageExclusions.map(dpe => `filters=section!=${dpe}`);
|
|
25
26
|
extraPathItems.push('max=500');
|
|
26
27
|
|
|
27
28
|
const { data: appSettings = [], isLoading } = useQuery(
|
|
@@ -50,7 +51,7 @@ const useSettings = ({
|
|
|
50
51
|
);
|
|
51
52
|
});
|
|
52
53
|
|
|
53
|
-
const pageList = persistentPages.concat(dynamic).sort(sortByLabel)
|
|
54
|
+
const pageList = persistentPages.concat(dynamic).sort(sortByLabel);
|
|
54
55
|
|
|
55
56
|
const SettingsContextProvider = ({ children }) => {
|
|
56
57
|
return (
|
|
@@ -67,6 +68,13 @@ const useSettings = ({
|
|
|
67
68
|
);
|
|
68
69
|
};
|
|
69
70
|
|
|
71
|
+
SettingsContextProvider.propTypes = {
|
|
72
|
+
children: PropTypes.oneOfType([
|
|
73
|
+
PropTypes.func,
|
|
74
|
+
PropTypes.node
|
|
75
|
+
])
|
|
76
|
+
};
|
|
77
|
+
|
|
70
78
|
const SettingsComponent = (props) => {
|
|
71
79
|
const settingsData = useContext(SettingsContext);
|
|
72
80
|
|
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
export { default as useTypedown } from './useTypedown';
|
|
2
|
-
export { default as useTypedownFooter } from './useTypedownFooter';
|
|
3
|
-
export { default as useTypedownList } from './useTypedownList';
|
|
4
|
-
export { default as useTypedownSearchField } from './useTypedownSearchField';
|
|
5
2
|
export { default as useTypedownToggle } from './useTypedownToggle';
|
|
6
3
|
export { default as useTypedownData } from './useTypedownData';
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { useRef } from 'react';
|
|
2
2
|
import { useResizeDetector } from 'react-resize-detector';
|
|
3
3
|
|
|
4
|
-
// TODO swap to stripes-components export once available (Will need <= peer dep bump)
|
|
5
4
|
import {
|
|
5
|
+
getFirstFocusable,
|
|
6
|
+
getLastFocusable,
|
|
6
7
|
getNextFocusable,
|
|
7
|
-
|
|
8
|
+
getPreviousFocusable,
|
|
9
|
+
} from '@folio/stripes/components';
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
DOWN_ARROW,
|
|
13
|
+
TAB,
|
|
14
|
+
UP_ARROW
|
|
15
|
+
} from '../../constants/eventCodes';
|
|
8
16
|
|
|
9
17
|
import selectorSafe from '../../utils/selectorSafe';
|
|
10
18
|
|
|
11
|
-
import
|
|
12
|
-
useTypedownToggle,
|
|
13
|
-
useTypedownFooter,
|
|
14
|
-
useTypedownSearchField,
|
|
15
|
-
useTypedownList
|
|
16
|
-
} from '.';
|
|
19
|
+
import useTypedownToggle from './useTypedownToggle';
|
|
17
20
|
|
|
18
21
|
const useTypedown = (name) => {
|
|
19
22
|
// SEARCHFIELD COMPONENT
|
|
@@ -23,11 +26,90 @@ const useTypedown = (name) => {
|
|
|
23
26
|
const listRef = useRef();
|
|
24
27
|
const triggerRef = useRef();
|
|
25
28
|
const overlayRef = useRef();
|
|
26
|
-
const footerRef =
|
|
29
|
+
const footerRef = useRef();
|
|
30
|
+
|
|
31
|
+
const footer = document.getElementById(`typedown-footer-${selectorSafe(name)}`);
|
|
32
|
+
// Add an event listener to the footer, so that we can control tab behaviour between footer elements
|
|
33
|
+
|
|
34
|
+
if (footer && footer.getAttribute('hasListener') !== 'true') {
|
|
35
|
+
footer.addEventListener('keydown', e => {
|
|
36
|
+
// We want special behaviour on tab
|
|
37
|
+
if (e.code === TAB) {
|
|
38
|
+
// Prevent the default behaviour
|
|
39
|
+
e.preventDefault();
|
|
40
|
+
const focusFunc = e.shiftKey ? getPreviousFocusable : getNextFocusable;
|
|
41
|
+
const elem = focusFunc(footerRef.current, true, true, false, true);
|
|
42
|
+
|
|
43
|
+
if (elem) {
|
|
44
|
+
// Focus on next focusable element
|
|
45
|
+
elem.focus();
|
|
46
|
+
} else if (e.shiftKey) {
|
|
47
|
+
// We are at the beginning of the list, refocus on search bar
|
|
48
|
+
searchFieldComponent.focus();
|
|
49
|
+
} else {
|
|
50
|
+
// We are at the end of the list, move onto next focusable element in page
|
|
51
|
+
getNextFocusable(searchFieldComponent, false).focus();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
footer.setAttribute('hasListener', 'true');
|
|
57
|
+
}
|
|
27
58
|
|
|
28
59
|
// SET UP HANDLERS
|
|
29
|
-
const searchFieldKeyDownHandler =
|
|
30
|
-
|
|
60
|
+
const searchFieldKeyDownHandler = e => {
|
|
61
|
+
if (e.code === UP_ARROW) {
|
|
62
|
+
const elem = getLastFocusable(listRef.current, true, true);
|
|
63
|
+
if (elem) {
|
|
64
|
+
elem.focus();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (e.code === DOWN_ARROW) {
|
|
69
|
+
const elem = getFirstFocusable(listRef.current, true, true);
|
|
70
|
+
if (elem) {
|
|
71
|
+
elem.focus();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Tab key (But not while shifting)
|
|
76
|
+
if (e.code === TAB && !e.shiftKey) {
|
|
77
|
+
e.preventDefault();
|
|
78
|
+
// If we have focusable elements in the footer, then focus on them, else unfocus searchbar
|
|
79
|
+
const elem = getNextFocusable(footerRef.current, true, true, true, true);
|
|
80
|
+
if (elem) {
|
|
81
|
+
elem.focus();
|
|
82
|
+
} else {
|
|
83
|
+
getNextFocusable(searchFieldComponent, false).focus();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const listKeyDownHandler = e => {
|
|
89
|
+
if (e.code === DOWN_ARROW) {
|
|
90
|
+
const elem = getNextFocusable(listRef.current, true, true);
|
|
91
|
+
elem.focus();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (e.code === UP_ARROW) {
|
|
95
|
+
const elem = getPreviousFocusable(listRef.current, true, true);
|
|
96
|
+
elem.focus();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (e.code === TAB) {
|
|
100
|
+
e.preventDefault();
|
|
101
|
+
let elem;
|
|
102
|
+
if (!e.shiftKey && !footerRef.current) {
|
|
103
|
+
elem = getNextFocusable(searchFieldComponent, false);
|
|
104
|
+
} else if (!e.shiftKey) {
|
|
105
|
+
elem = getNextFocusable(footerRef.current, true, true, true, true);
|
|
106
|
+
} else {
|
|
107
|
+
elem = searchFieldComponent;
|
|
108
|
+
}
|
|
109
|
+
elem.focus();
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
31
113
|
const handleNextFocus = () => getNextFocusable(searchFieldComponent, false).focus();
|
|
32
114
|
|
|
33
115
|
// SET UP VARIABLES
|
|
@@ -13,6 +13,10 @@ const useHelperApp = (helpers) => {
|
|
|
13
13
|
setCurrentHelper(helper !== currentHelper ? helper : undefined);
|
|
14
14
|
}, [currentHelper]);
|
|
15
15
|
|
|
16
|
+
const isOpen = (hlp) => {
|
|
17
|
+
return currentHelper === hlp;
|
|
18
|
+
};
|
|
19
|
+
|
|
16
20
|
useEffect(() => {
|
|
17
21
|
if (currentHelper !== query?.helper) {
|
|
18
22
|
const newQuery = {
|
|
@@ -56,7 +60,7 @@ const useHelperApp = (helpers) => {
|
|
|
56
60
|
helperToggleFunctions[h] = () => handleToggleHelper(h);
|
|
57
61
|
});
|
|
58
62
|
|
|
59
|
-
return { HelperComponent, helperToggleFunctions };
|
|
63
|
+
return { HelperComponent, helperToggleFunctions, isOpen };
|
|
60
64
|
};
|
|
61
65
|
|
|
62
66
|
export default useHelperApp;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { useFieldArray } from 'react-final-form-arrays';
|
|
3
|
+
|
|
4
|
+
const useKiwtFieldArray = (name, submitWholeDeletedObject = false) => {
|
|
5
|
+
const { fields } = useFieldArray(name);
|
|
6
|
+
const { value: values = [] } = fields;
|
|
7
|
+
const [endOfList, setEndOfList] = useState(0);
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const i = values.filter(line => !line._delete);
|
|
11
|
+
setEndOfList(i.length);
|
|
12
|
+
}, [values]);
|
|
13
|
+
|
|
14
|
+
const onAddField = (field = { _delete: false }) => {
|
|
15
|
+
fields.insert(endOfList, field);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const onMarkForDeletion = (field) => {
|
|
19
|
+
if (field && field.id) {
|
|
20
|
+
if (submitWholeDeletedObject) {
|
|
21
|
+
fields.push({ ...field, _delete: true });
|
|
22
|
+
} else {
|
|
23
|
+
fields.push({ id: field.id, _delete: true });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const onDeleteField = (index, field) => {
|
|
29
|
+
fields.remove(index);
|
|
30
|
+
onMarkForDeletion(field);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const onPrependField = (field = { _delete: false }) => {
|
|
34
|
+
fields.unshift(field);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const onReplaceField = (index, field) => {
|
|
38
|
+
if (fields.update) { // react-final-form-arrays
|
|
39
|
+
fields.update(index, field);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const onUpdateField = (index, field) => {
|
|
44
|
+
fields.update(index, {
|
|
45
|
+
...fields.value[index],
|
|
46
|
+
...field,
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const items = values.slice(0, endOfList);
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
items,
|
|
54
|
+
onAddField,
|
|
55
|
+
onDeleteField,
|
|
56
|
+
onMarkForDeletion,
|
|
57
|
+
onPrependField,
|
|
58
|
+
onReplaceField,
|
|
59
|
+
onUpdateField,
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export default useKiwtFieldArray;
|
|
@@ -2,6 +2,7 @@ import React, { useState } from 'react';
|
|
|
2
2
|
import { useLocation, useHistory } from 'react-router-dom';
|
|
3
3
|
|
|
4
4
|
import buildUrl from '../utils/buildUrl';
|
|
5
|
+
import useQindex from './useQIndex';
|
|
5
6
|
|
|
6
7
|
const locationQuerySetter = ({ location, history, nsValues }) => {
|
|
7
8
|
const url = buildUrl(location, nsValues);
|
|
@@ -13,8 +14,15 @@ const useKiwtSASQuery = () => {
|
|
|
13
14
|
const location = useLocation();
|
|
14
15
|
const [query, setQuery] = useState({});
|
|
15
16
|
const queryGetter = () => query;
|
|
17
|
+
|
|
18
|
+
const [qindex] = useQindex();
|
|
19
|
+
// Ensure we update the query along with the querySetter
|
|
20
|
+
if (query.qindex !== qindex) {
|
|
21
|
+
setQuery({ ...query, qindex });
|
|
22
|
+
}
|
|
23
|
+
|
|
16
24
|
const querySetter = ({ nsValues }) => {
|
|
17
|
-
setQuery(nsValues);
|
|
25
|
+
setQuery({ ...query, ...nsValues, qindex });
|
|
18
26
|
locationQuerySetter({ location, history, nsValues });
|
|
19
27
|
};
|
|
20
28
|
return { query, queryGetter, querySetter };
|