@k-int/stripes-kint-components 5.5.1 → 5.6.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 +14 -0
- package/README.md +6 -6
- package/es/lib/FormModal/FormModal.js +55 -4
- package/package.json +3 -4
- package/src/lib/FormModal/FormModal.js +57 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [5.6.0](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/compare/v5.5.2...v5.6.0) (2024-04-04)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* FormModal default now handles async and sync submit handlers differently, and implementor can hook into those with onError and onSuccess props. ([822882c](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/commit/822882cfa428e8785c2f04541776526b5846e5f3))
|
|
7
|
+
|
|
8
|
+
## [5.5.2](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/compare/v5.5.1...v5.5.2) (2024-03-25)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **deps:** update dependency react-resize-detector to v10 ([407e388](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/commit/407e388de33b42cfb9c02a4c1d37bb1940eb4a65))
|
|
14
|
+
|
|
1
15
|
## [5.5.1](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/compare/v5.5.0...v5.5.1) (2024-03-19)
|
|
2
16
|
|
|
3
17
|
|
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ In the case where components from this repository require translations, it will
|
|
|
14
14
|
In order to develop this module within a stripes workspace, a couple of steps are needed
|
|
15
15
|
- An environment variable must be set up (See https://chlee.co/how-to-setup-environment-variables-for-windows-mac-and-linux/), `STRIPES_TRANSPILE_TOKENS="@k-int"`
|
|
16
16
|
- Clone this repository `git clone git@gitlab.com:knowledge-integration/folio/stripes-kint-components.git`
|
|
17
|
-
-
|
|
17
|
+
- Ensure your branch's `kint-components` version is at least in line with, or higher than the latest released artifact version (THIS SHOULD NOT BE MERGED TO MAIN: Release versions are controlled by the semantic releases plugin at release time.)
|
|
18
18
|
- Nuke your workspace node_modules and rebuild
|
|
19
19
|
|
|
20
20
|
### What went wrong
|
|
@@ -40,9 +40,9 @@ If the compatibility chart below states compatible with a certain flower release
|
|
|
40
40
|
|
|
41
41
|
Release major | Latest release | Flower releases present in (ERM) | Flower compatibility
|
|
42
42
|
--- | --- | --- | --- |
|
|
43
|
-
v1 | 1.7.
|
|
44
|
-
v2 | 2.8.
|
|
45
|
-
v3 | 3.2.
|
|
46
|
-
v4 | 4.7.
|
|
47
|
-
v5 | 5.
|
|
43
|
+
v1 | 1.7.x | Lotus | Kiwi - Morning Glory |
|
|
44
|
+
v2 | 2.8.x | Morning Glory | Kiwi - Morning Glory |
|
|
45
|
+
v3 | 3.2.x | Nolana | Morning Glory - Nolana |
|
|
46
|
+
v4 | 4.7.x | Orchid | Morning Glory - Orchid |
|
|
47
|
+
v5 | 5.5.x | Poppy, Quesnalia | Morning Glory - Quesnalia+ |
|
|
48
48
|
|
|
@@ -21,7 +21,11 @@ const FormModal = _ref => {
|
|
|
21
21
|
onClose,
|
|
22
22
|
...modalProps
|
|
23
23
|
},
|
|
24
|
+
onError,
|
|
25
|
+
// Optional handler to run onSuccess for default handleSaveAndClear
|
|
24
26
|
onSubmit,
|
|
27
|
+
onSuccess,
|
|
28
|
+
// Optional handler to run onSuccess for default handleSaveAndClear
|
|
25
29
|
...formProps
|
|
26
30
|
} = _ref;
|
|
27
31
|
const kintIntl = (0, _hooks.useKintIntl)(passedIntlKey, passedIntlNS);
|
|
@@ -41,9 +45,52 @@ const FormModal = _ref => {
|
|
|
41
45
|
onClose(e);
|
|
42
46
|
restart();
|
|
43
47
|
};
|
|
48
|
+
|
|
49
|
+
// Handle asynchronous submit functions differently to synchronous ones
|
|
44
50
|
const handleSaveAndClear = function () {
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
try {
|
|
52
|
+
const submitReturn = handleSubmit(...arguments);
|
|
53
|
+
|
|
54
|
+
// Figure out if we're in an async or sync submit function
|
|
55
|
+
if (typeof submitReturn === 'object' && typeof submitReturn.then === 'function') {
|
|
56
|
+
// Async function
|
|
57
|
+
return submitReturn.then(incomingParams => {
|
|
58
|
+
restart();
|
|
59
|
+
return incomingParams;
|
|
60
|
+
}).then(incomingParams => {
|
|
61
|
+
if (onSuccess && typeof onSuccess === 'function') {
|
|
62
|
+
// Allow onSuccess to dictate what continues downstream
|
|
63
|
+
return onSuccess(incomingParams);
|
|
64
|
+
}
|
|
65
|
+
return incomingParams;
|
|
66
|
+
}).catch(incomingParams => {
|
|
67
|
+
if (onError && typeof onError === 'function') {
|
|
68
|
+
// Allow onError to dictate what continues downstream
|
|
69
|
+
return onError(incomingParams);
|
|
70
|
+
}
|
|
71
|
+
return incomingParams;
|
|
72
|
+
});
|
|
73
|
+
} else if (onSuccess && typeof onSuccess === 'function') {
|
|
74
|
+
// Sync function and we have an onSuccess handler
|
|
75
|
+
|
|
76
|
+
// onSuccess dictates return
|
|
77
|
+
const returnShape = onSuccess(submitReturn);
|
|
78
|
+
restart();
|
|
79
|
+
return returnShape;
|
|
80
|
+
} else {
|
|
81
|
+
// Sync function and we have no onSuccess handler
|
|
82
|
+
|
|
83
|
+
restart();
|
|
84
|
+
return submitReturn;
|
|
85
|
+
}
|
|
86
|
+
} catch (err) {
|
|
87
|
+
// Sync function catch
|
|
88
|
+
if (onError && typeof onError === 'function') {
|
|
89
|
+
// Allow onError to dictate what continues downstream
|
|
90
|
+
return onError(err);
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
47
94
|
};
|
|
48
95
|
const renderFooter = () => {
|
|
49
96
|
if (footer) {
|
|
@@ -51,7 +98,9 @@ const FormModal = _ref => {
|
|
|
51
98
|
formState,
|
|
52
99
|
handleSubmit: handleSaveAndClear,
|
|
53
100
|
handleClose,
|
|
54
|
-
handleSubmitNoRestart: handleSubmit
|
|
101
|
+
handleSubmitNoRestart: handleSubmit,
|
|
102
|
+
// DEPRECATED -- should use handleSubmitRaw
|
|
103
|
+
handleSubmitRaw: handleSubmit
|
|
55
104
|
});
|
|
56
105
|
}
|
|
57
106
|
const {
|
|
@@ -100,6 +149,8 @@ FormModal.propTypes = {
|
|
|
100
149
|
footer: _propTypes.default.func,
|
|
101
150
|
onClose: _propTypes.default.func
|
|
102
151
|
}),
|
|
103
|
-
|
|
152
|
+
onError: _propTypes.default.func,
|
|
153
|
+
onSubmit: _propTypes.default.func,
|
|
154
|
+
onSuccess: _propTypes.default.func
|
|
104
155
|
};
|
|
105
156
|
var _default = exports.default = FormModal;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@k-int/stripes-kint-components",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.0",
|
|
4
4
|
"description": "Stripes Component library for K-Int specific applications",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"*.css"
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@rehooks/local-storage": "^2.4.4",
|
|
25
25
|
"compose-function": "^3.0.3",
|
|
26
|
-
"react-resize-detector": "^
|
|
26
|
+
"react-resize-detector": "^10.0.0",
|
|
27
27
|
"zustand": "^4.0.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
@@ -76,8 +76,7 @@
|
|
|
76
76
|
"regenerator-runtime": "^0.14.0",
|
|
77
77
|
"rxjs": "^7.0.0",
|
|
78
78
|
"semantic-release": "^22.0.6",
|
|
79
|
-
"sinon": "^17.0.0"
|
|
80
|
-
"typescript": "^2.8.0"
|
|
79
|
+
"sinon": "^17.0.0"
|
|
81
80
|
},
|
|
82
81
|
"peerDependencies": {
|
|
83
82
|
"@folio/stripes": ">=9.0.0",
|
|
@@ -10,7 +10,9 @@ const FormModal = ({
|
|
|
10
10
|
intlNS: passedIntlNS,
|
|
11
11
|
labelOverrides = {},
|
|
12
12
|
modalProps: { footer, onClose, ...modalProps },
|
|
13
|
+
onError, // Optional handler to run onSuccess for default handleSaveAndClear
|
|
13
14
|
onSubmit,
|
|
15
|
+
onSuccess, // Optional handler to run onSuccess for default handleSaveAndClear
|
|
14
16
|
...formProps
|
|
15
17
|
}) => {
|
|
16
18
|
const kintIntl = useKintIntl(passedIntlKey, passedIntlNS);
|
|
@@ -27,14 +29,63 @@ const FormModal = ({
|
|
|
27
29
|
restart();
|
|
28
30
|
};
|
|
29
31
|
|
|
32
|
+
// Handle asynchronous submit functions differently to synchronous ones
|
|
30
33
|
const handleSaveAndClear = (...onSaveProps) => {
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
try {
|
|
35
|
+
const submitReturn = handleSubmit(...onSaveProps);
|
|
36
|
+
|
|
37
|
+
// Figure out if we're in an async or sync submit function
|
|
38
|
+
if (typeof submitReturn === 'object' && typeof submitReturn.then === 'function') {
|
|
39
|
+
// Async function
|
|
40
|
+
return submitReturn.then((incomingParams) => {
|
|
41
|
+
restart();
|
|
42
|
+
return incomingParams;
|
|
43
|
+
}).then((incomingParams) => {
|
|
44
|
+
if (onSuccess && typeof onSuccess === 'function') {
|
|
45
|
+
// Allow onSuccess to dictate what continues downstream
|
|
46
|
+
return onSuccess(incomingParams);
|
|
47
|
+
}
|
|
48
|
+
return incomingParams;
|
|
49
|
+
}).catch((incomingParams) => {
|
|
50
|
+
if (onError && typeof onError === 'function') {
|
|
51
|
+
// Allow onError to dictate what continues downstream
|
|
52
|
+
return onError(incomingParams);
|
|
53
|
+
}
|
|
54
|
+
return incomingParams;
|
|
55
|
+
});
|
|
56
|
+
} else if (onSuccess && typeof onSuccess === 'function') {
|
|
57
|
+
// Sync function and we have an onSuccess handler
|
|
58
|
+
|
|
59
|
+
// onSuccess dictates return
|
|
60
|
+
const returnShape = onSuccess(submitReturn);
|
|
61
|
+
restart();
|
|
62
|
+
return returnShape;
|
|
63
|
+
} else {
|
|
64
|
+
// Sync function and we have no onSuccess handler
|
|
65
|
+
|
|
66
|
+
restart();
|
|
67
|
+
return submitReturn;
|
|
68
|
+
}
|
|
69
|
+
} catch (err) {
|
|
70
|
+
// Sync function catch
|
|
71
|
+
if (onError && typeof onError === 'function') {
|
|
72
|
+
// Allow onError to dictate what continues downstream
|
|
73
|
+
return onError(err);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
33
78
|
};
|
|
34
79
|
|
|
35
80
|
const renderFooter = () => {
|
|
36
81
|
if (footer) {
|
|
37
|
-
return footer({
|
|
82
|
+
return footer({
|
|
83
|
+
formState,
|
|
84
|
+
handleSubmit: handleSaveAndClear,
|
|
85
|
+
handleClose,
|
|
86
|
+
handleSubmitNoRestart: handleSubmit, // DEPRECATED -- should use handleSubmitRaw
|
|
87
|
+
handleSubmitRaw: handleSubmit
|
|
88
|
+
});
|
|
38
89
|
}
|
|
39
90
|
|
|
40
91
|
const { invalid, pristine, submitting, validating } = formState;
|
|
@@ -93,7 +144,9 @@ FormModal.propTypes = {
|
|
|
93
144
|
footer: PropTypes.func,
|
|
94
145
|
onClose: PropTypes.func,
|
|
95
146
|
}),
|
|
96
|
-
|
|
147
|
+
onError: PropTypes.func,
|
|
148
|
+
onSubmit: PropTypes.func,
|
|
149
|
+
onSuccess: PropTypes.func
|
|
97
150
|
};
|
|
98
151
|
|
|
99
152
|
export default FormModal;
|