@k-int/stripes-kint-components 5.5.2 → 5.6.1

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 CHANGED
@@ -1,3 +1,17 @@
1
+ ## [5.6.1](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/compare/v5.6.0...v5.6.1) (2024-04-16)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * ERM-3194 Always display error message if delete of picklist value unsuccessful ([f58d971](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/commit/f58d9710238730d6d65b3f348106892daec0d54e))
7
+
8
+ # [5.6.0](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/compare/v5.5.2...v5.6.0) (2024-04-04)
9
+
10
+
11
+ ### Features
12
+
13
+ * 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))
14
+
1
15
  ## [5.5.2](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/compare/v5.5.1...v5.5.2) (2024-03-25)
2
16
 
3
17
 
@@ -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
- handleSubmit(...arguments);
46
- restart();
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
- onSubmit: _propTypes.default.func
152
+ onError: _propTypes.default.func,
153
+ onSubmit: _propTypes.default.func,
154
+ onSuccess: _propTypes.default.func
104
155
  };
105
156
  var _default = exports.default = FormModal;
@@ -6,7 +6,12 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  const parseErrorResponse = async responseObj => {
8
8
  var _ref;
9
- let errorResp;
9
+ let errorResp = {
10
+ message: 'something went wrong'
11
+ };
12
+ if (!responseObj) {
13
+ return errorResp;
14
+ }
10
15
  const code = responseObj === null || responseObj === void 0 ? void 0 : responseObj.status;
11
16
  const contentType = (_ref = [...(responseObj === null || responseObj === void 0 ? void 0 : responseObj.headers)]) === null || _ref === void 0 || (_ref = _ref.find(header => header[0] === 'content-type')) === null || _ref === void 0 ? void 0 : _ref[1];
12
17
  if (contentType.includes('json')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k-int/stripes-kint-components",
3
- "version": "5.5.2",
3
+ "version": "5.6.1",
4
4
  "description": "Stripes Component library for K-Int specific applications",
5
5
  "sideEffects": [
6
6
  "*.css"
@@ -59,7 +59,7 @@
59
59
  "core-js": "^3.6.1",
60
60
  "eslint": "^8.0.0",
61
61
  "eslint-plugin-import": "^2.26.0",
62
- "eslint-plugin-jest": "^27.4.2",
62
+ "eslint-plugin-jest": "^28.0.0",
63
63
  "graphql": "^16.0.0",
64
64
  "identity-obj-proxy": "^3.0.0",
65
65
  "moment": "^2.29.4",
@@ -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
- handleSubmit(...onSaveProps);
32
- restart();
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({ formState, handleSubmit: handleSaveAndClear, handleClose, handleSubmitNoRestart: handleSubmit });
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
- onSubmit: PropTypes.func
147
+ onError: PropTypes.func,
148
+ onSubmit: PropTypes.func,
149
+ onSuccess: PropTypes.func
97
150
  };
98
151
 
99
152
  export default FormModal;
@@ -1,5 +1,8 @@
1
1
  const parseErrorResponse = async (responseObj) => {
2
- let errorResp;
2
+ let errorResp = { message: 'something went wrong' };
3
+ if (!responseObj) {
4
+ return errorResp;
5
+ }
3
6
  const code = responseObj?.status;
4
7
  const contentType = [...responseObj?.headers]?.find(header => header[0] === 'content-type')?.[1];
5
8