@k-int/stripes-kint-components 5.8.3 → 5.10.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 +19 -0
- package/es/lib/ActionList/ActionListFieldArray.js +6 -6
- package/es/lib/CustomProperties/Config/CustomPropertiesSettings.js +3 -0
- package/es/lib/CustomProperties/Edit/CustomPropertyField.js +1 -1
- package/es/lib/EditableRefdataList/EditableRefdataList.js +2 -0
- package/es/lib/NumberField/NumberField.test.js +16 -24
- package/es/lib/Typedown/Typedown.js +12 -2
- package/es/lib/hooks/index.js +11 -4
- package/es/lib/hooks/typedownHooks/useTypedown.js +15 -2
- package/es/lib/hooks/useMutateCustomProperties.js +13 -35
- package/es/lib/hooks/useMutateGeneric.js +91 -0
- package/es/lib/hooks/useMutateRefdataCategory.js +38 -29
- package/es/lib/hooks/useMutateRefdataValue.js +54 -37
- package/package.json +1 -1
- package/src/lib/ActionList/ActionListFieldArray.js +5 -6
- package/src/lib/CustomProperties/Config/CustomPropertiesSettings.js +2 -0
- package/src/lib/CustomProperties/Edit/CustomPropertyField.js +1 -1
- package/src/lib/EditableRefdataList/EditableRefdataList.js +2 -0
- package/src/lib/FormModal/README.md +91 -0
- package/src/lib/NumberField/NumberField.test.js +18 -28
- package/src/lib/QueryTypedown/README.md +72 -0
- package/src/lib/Typedown/EXAMPLE.md +115 -0
- package/src/lib/Typedown/README.md +45 -113
- package/src/lib/Typedown/Typedown.js +16 -3
- package/src/lib/hooks/README.md +48 -13
- package/src/lib/hooks/index.js +6 -4
- package/src/lib/hooks/typedownHooks/useTypedown.js +17 -3
- package/src/lib/hooks/useMutateCustomProperties.js +12 -58
- package/src/lib/hooks/useMutateGeneric.js +103 -0
- package/src/lib/hooks/useMutateRefdataCategory.js +38 -49
- package/src/lib/hooks/useMutateRefdataValue.js +70 -65
- package/src/lib/utils/README.md +126 -56
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
# [5.10.0](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/compare/v5.9.0...v5.10.0) (2025-02-04)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* Typedown delay ([c736865](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/commit/c736865cec8f4b5cbe2ad473393452fd7ec34dc8))
|
|
7
|
+
|
|
8
|
+
# [5.9.0](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/compare/v5.8.3...v5.9.0) (2025-01-31)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* Ensure first field always gets focus ([144624e](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/commit/144624e290e5f11db558e6345a979979ee84af34))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* useMutateGeneric ([7e9a1e6](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/commit/7e9a1e6ceaef4157adf5ffe08da03269006d86f9))
|
|
19
|
+
|
|
1
20
|
## [5.8.3](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/compare/v5.8.2...v5.8.3) (2024-10-23)
|
|
2
21
|
|
|
3
22
|
|
|
@@ -327,13 +327,14 @@ const ActionListFieldArray = /*#__PURE__*/(0, _react.forwardRef)((_ref2, ref) =>
|
|
|
327
327
|
formatter,
|
|
328
328
|
...restOfMclProps
|
|
329
329
|
} = mclProps; // Destructure formatter part of mclProps
|
|
330
|
+
|
|
330
331
|
const fieldAwareFormatter = () => {
|
|
331
332
|
const returnObj = {};
|
|
332
333
|
// For each visible field, if it's being edited then ignore passed formatters, else use them
|
|
333
334
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
335
|
+
visibleFields.forEach((key, index) => {
|
|
336
|
+
// Work out now whether or not to autofocus, so that gets cemented into the returnObj function
|
|
337
|
+
const shouldAutoFocus = index === 0;
|
|
337
338
|
returnObj[key] = cd => {
|
|
338
339
|
// Row is being edited if it has no id, or its id is in the editing string
|
|
339
340
|
const editingRow = cd.id === editing || !cd.id;
|
|
@@ -368,15 +369,14 @@ const ActionListFieldArray = /*#__PURE__*/(0, _react.forwardRef)((_ref2, ref) =>
|
|
|
368
369
|
returnValue = fieldComponents[key] ? fieldComponents[key](passedObject) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFinalForm.Field, {
|
|
369
370
|
ariaLabel: key // TODO at the moment the only way to override this is passing in an entire fieldComponent.
|
|
370
371
|
,
|
|
371
|
-
autoFocus:
|
|
372
|
+
autoFocus: shouldAutoFocus // TODO at the moment this will always be the first field, even if it's not editable
|
|
373
|
+
,
|
|
372
374
|
component: _components.TextField,
|
|
373
375
|
marginBottom0: true,
|
|
374
376
|
name: `${cd.fieldName}.${key}`,
|
|
375
377
|
parse: v => v,
|
|
376
378
|
validate: validateFunction
|
|
377
379
|
});
|
|
378
|
-
// After first field, every other field should not autofocus
|
|
379
|
-
autoFocus = false;
|
|
380
380
|
}
|
|
381
381
|
}
|
|
382
382
|
return returnValue;
|
|
@@ -72,6 +72,9 @@ const CustomPropertiesSettings = _ref => {
|
|
|
72
72
|
})
|
|
73
73
|
}];
|
|
74
74
|
}
|
|
75
|
+
|
|
76
|
+
// TODO consider moving some of the invalidations etc into the useMutateCustomProperties hook?
|
|
77
|
+
// Also all around patterns for defaulting afterQueryCalls etc are not ideal
|
|
75
78
|
const {
|
|
76
79
|
post: createCustprop,
|
|
77
80
|
put: editCustProp,
|
|
@@ -162,7 +162,7 @@ const CustomPropertyField = _ref => {
|
|
|
162
162
|
component: _components.MultiSelection,
|
|
163
163
|
// The "not set" value is not relevant for a multi select
|
|
164
164
|
dataOptions: (0, _orderBy.default)(customProperty.options?.filter(opt => !!opt?.value), 'label'),
|
|
165
|
-
renderToOverlay: true
|
|
165
|
+
renderToOverlay: true // FIXME Switch to usePortal for stripes v10
|
|
166
166
|
};
|
|
167
167
|
// MultiSelection passes the changed array as a value not an event
|
|
168
168
|
handleChange = refdataArray => {
|
|
@@ -92,6 +92,7 @@ const EditableRefdataList = _ref => {
|
|
|
92
92
|
}, [isRefdataLoading, refdata]);
|
|
93
93
|
|
|
94
94
|
// Edit and Create will use the same PUT mutation
|
|
95
|
+
// TODO I believe after the changes to refactor to useMutateGeneric, we can now use POST separately to get differing callouts etc
|
|
95
96
|
const {
|
|
96
97
|
delete: deleteRefdataValue,
|
|
97
98
|
put: editRefdataValue
|
|
@@ -115,6 +116,7 @@ const EditableRefdataList = _ref => {
|
|
|
115
116
|
// or one provided in labelOverrides, which is passed the error message and refdata in question
|
|
116
117
|
delete: async err => {
|
|
117
118
|
const errorResp = await (0, _utils.parseErrorResponse)(err.response);
|
|
119
|
+
console.log("ERRORRESP: %o", errorResp);
|
|
118
120
|
callout.sendCallout({
|
|
119
121
|
message: kintIntl.formatKintMessage({
|
|
120
122
|
id: 'refdata.deleteRefdataValue.errorMessage',
|
|
@@ -24,9 +24,18 @@ const getTextField = () => {
|
|
|
24
24
|
name: NUMBER_FIELD_LABEL
|
|
25
25
|
});
|
|
26
26
|
};
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const testSubmitValues = expectedValues => {
|
|
28
|
+
describe('submitting the form', () => {
|
|
29
|
+
beforeEach(async () => {
|
|
30
|
+
await (0, _react2.waitFor)(async () => {
|
|
31
|
+
await (0, _stripesErmTesting.Button)('Submit').click();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
it('submits with expected values', async () => {
|
|
35
|
+
await (0, _react2.waitFor)(() => {
|
|
36
|
+
expect(onSubmit.mock.calls?.[0]?.[0]).toEqual(expectedValues);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
30
39
|
});
|
|
31
40
|
};
|
|
32
41
|
const SpecialResetButton = () => {
|
|
@@ -95,12 +104,7 @@ describe.each([['Non-Controlled', /*#__PURE__*/(0, _jsxRuntime.jsx)(NonControlle
|
|
|
95
104
|
it('does not render typed characters', async () => {
|
|
96
105
|
expect(textField).toHaveDisplayValue(expectedDisplay);
|
|
97
106
|
});
|
|
98
|
-
|
|
99
|
-
beforeEach(submitForm);
|
|
100
|
-
it('submits with expected values', () => {
|
|
101
|
-
expect(onSubmit.mock.calls[0][0]).toEqual(expectedSubmit);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
107
|
+
testSubmitValues(expectedSubmit);
|
|
104
108
|
});
|
|
105
109
|
});
|
|
106
110
|
});
|
|
@@ -116,7 +120,7 @@ describe.each([['Non-Controlled', /*#__PURE__*/(0, _jsxRuntime.jsx)(NonControlle
|
|
|
116
120
|
[NUMBER_FIELD_INPUT_ID]: '-100'
|
|
117
121
|
}, '-100', {
|
|
118
122
|
[NUMBER_FIELD_INPUT_ID]: '-100'
|
|
119
|
-
}]])(`Initial values (${controlType})`, (describeTitle, initialValues, displayValue,
|
|
123
|
+
}]])(`Initial values (${controlType})`, (describeTitle, initialValues, displayValue, expectedSubmit) => {
|
|
120
124
|
describe(describeTitle, () => {
|
|
121
125
|
beforeEach(async () => {
|
|
122
126
|
onSubmit.mockClear();
|
|
@@ -130,12 +134,7 @@ describe.each([['Non-Controlled', /*#__PURE__*/(0, _jsxRuntime.jsx)(NonControlle
|
|
|
130
134
|
it('renders initial value', async () => {
|
|
131
135
|
expect(textField).toHaveDisplayValue(displayValue);
|
|
132
136
|
});
|
|
133
|
-
|
|
134
|
-
beforeEach(submitForm);
|
|
135
|
-
it('submits with expected values', () => {
|
|
136
|
-
expect(onSubmit.mock.calls[0][0]).toEqual(submitValue);
|
|
137
|
-
});
|
|
138
|
-
});
|
|
137
|
+
testSubmitValues(expectedSubmit);
|
|
139
138
|
});
|
|
140
139
|
});
|
|
141
140
|
describe.each([['Clear after typing', async () => {
|
|
@@ -185,14 +184,7 @@ describe.each([['Non-Controlled', /*#__PURE__*/(0, _jsxRuntime.jsx)(NonControlle
|
|
|
185
184
|
expect(textField).toHaveDisplayValue(expectedValue);
|
|
186
185
|
});
|
|
187
186
|
});
|
|
188
|
-
|
|
189
|
-
describe('submitting the form', () => {
|
|
190
|
-
beforeEach(submitForm);
|
|
191
|
-
it('submits with expected values', () => {
|
|
192
|
-
expect(onSubmit.mock.calls[0][0]).toEqual(expectedSubmit);
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
});
|
|
187
|
+
testSubmitValues(expectedSubmit);
|
|
196
188
|
});
|
|
197
189
|
});
|
|
198
190
|
});
|
|
@@ -22,8 +22,11 @@ const Typedown = _ref => {
|
|
|
22
22
|
className,
|
|
23
23
|
dataOptions,
|
|
24
24
|
displayClearItem = true,
|
|
25
|
+
displayValueWhileOpen = true,
|
|
25
26
|
endOfList,
|
|
26
27
|
id,
|
|
28
|
+
initialOpenDelay = 800,
|
|
29
|
+
// Initial opening delay of 800ms (handles any stripes animations)
|
|
27
30
|
input,
|
|
28
31
|
isSelected,
|
|
29
32
|
filterPath,
|
|
@@ -89,7 +92,9 @@ const Typedown = _ref => {
|
|
|
89
92
|
resizeRef,
|
|
90
93
|
searchWidth
|
|
91
94
|
}
|
|
92
|
-
} = (0, _typedownHooks.useTypedown)(input.name
|
|
95
|
+
} = (0, _typedownHooks.useTypedown)(input.name, {
|
|
96
|
+
timeout: initialOpenDelay
|
|
97
|
+
});
|
|
93
98
|
const renderItem = (0, _react.useCallback)(function (option) {
|
|
94
99
|
let optionIsSelected = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
95
100
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
@@ -157,6 +162,9 @@ const Typedown = _ref => {
|
|
|
157
162
|
})
|
|
158
163
|
});
|
|
159
164
|
};
|
|
165
|
+
const displayValue = (0, _react.useMemo)(() => {
|
|
166
|
+
return !!selectedUniqueId && (!open || displayValueWhileOpen);
|
|
167
|
+
}, [displayValueWhileOpen, open, selectedUniqueId]);
|
|
160
168
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
161
169
|
ref: resizeRef,
|
|
162
170
|
className: (0, _classnames.default)(_TypeDown.default.typedown, className),
|
|
@@ -185,7 +193,7 @@ const Typedown = _ref => {
|
|
|
185
193
|
overlayRef: overlayRef,
|
|
186
194
|
portal: portal,
|
|
187
195
|
children: dropDown()
|
|
188
|
-
}, "typedown-menu-toggle"),
|
|
196
|
+
}, "typedown-menu-toggle"), displayValue && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
189
197
|
className: (0, _classnames.default)(_TypeDown.default.selectedDisplay),
|
|
190
198
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
191
199
|
className: _TypeDown.default.selectedItem,
|
|
@@ -202,9 +210,11 @@ Typedown.propTypes = {
|
|
|
202
210
|
className: _propTypes.default.string,
|
|
203
211
|
dataOptions: _propTypes.default.arrayOf(_propTypes.default.object),
|
|
204
212
|
displayClearItem: _propTypes.default.bool,
|
|
213
|
+
displayValueWhileOpen: _propTypes.default.bool,
|
|
205
214
|
endOfList: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.node, _propTypes.default.element]),
|
|
206
215
|
filterPath: _propTypes.default.string,
|
|
207
216
|
id: _propTypes.default.string,
|
|
217
|
+
initialOpenDelay: _propTypes.default.number,
|
|
208
218
|
input: _propTypes.default.object,
|
|
209
219
|
isSelected: _propTypes.default.func,
|
|
210
220
|
label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.element]),
|
package/es/lib/hooks/index.js
CHANGED
|
@@ -81,6 +81,12 @@ Object.defineProperty(exports, "useMutateCustomProperties", {
|
|
|
81
81
|
return _useMutateCustomProperties.default;
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
|
+
Object.defineProperty(exports, "useMutateGeneric", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function () {
|
|
87
|
+
return _useMutateGeneric.default;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
84
90
|
Object.defineProperty(exports, "useMutateModConfigEntry", {
|
|
85
91
|
enumerable: true,
|
|
86
92
|
get: function () {
|
|
@@ -125,7 +131,6 @@ Object.defineProperty(exports, "useTemplates", {
|
|
|
125
131
|
});
|
|
126
132
|
var _useRefdata = _interopRequireDefault(require("./useRefdata"));
|
|
127
133
|
var _useTemplates = _interopRequireDefault(require("./useTemplates"));
|
|
128
|
-
var _useMutateRefdataValue = _interopRequireDefault(require("./useMutateRefdataValue"));
|
|
129
134
|
var _useActiveElement = _interopRequireDefault(require("./useActiveElement"));
|
|
130
135
|
var _useKiwtSASQuery = _interopRequireDefault(require("./useKiwtSASQuery"));
|
|
131
136
|
var _useHelperApp = _interopRequireDefault(require("./useHelperApp"));
|
|
@@ -133,14 +138,16 @@ var _useLocalStorageState = _interopRequireDefault(require("./useLocalStorageSta
|
|
|
133
138
|
var _useQIndex = _interopRequireDefault(require("./useQIndex"));
|
|
134
139
|
var _useKiwtFieldArray = _interopRequireDefault(require("./useKiwtFieldArray"));
|
|
135
140
|
var _useCustomProperties = _interopRequireDefault(require("./useCustomProperties"));
|
|
136
|
-
var _useMutateCustomProperties = _interopRequireDefault(require("./useMutateCustomProperties"));
|
|
137
141
|
var _useInvalidateRefdata = _interopRequireDefault(require("./useInvalidateRefdata"));
|
|
138
|
-
var _useMutateRefdataCategory = _interopRequireDefault(require("./useMutateRefdataCategory"));
|
|
139
142
|
var _useKintIntl = _interopRequireDefault(require("./useKintIntl"));
|
|
140
143
|
var _useIntlKeyStore = _interopRequireDefault(require("./useIntlKeyStore"));
|
|
141
144
|
var _useIntlKey = _interopRequireDefault(require("./useIntlKey"));
|
|
142
145
|
var _useSASQQueryMeta = _interopRequireDefault(require("./useSASQQueryMeta"));
|
|
143
146
|
var _useModConfigEntries = _interopRequireDefault(require("./useModConfigEntries"));
|
|
144
|
-
var _useMutateModConfigEntry = _interopRequireDefault(require("./useMutateModConfigEntry"));
|
|
145
147
|
var _useActionListRef = _interopRequireDefault(require("./useActionListRef"));
|
|
148
|
+
var _useMutateGeneric = _interopRequireDefault(require("./useMutateGeneric"));
|
|
149
|
+
var _useMutateRefdataValue = _interopRequireDefault(require("./useMutateRefdataValue"));
|
|
150
|
+
var _useMutateRefdataCategory = _interopRequireDefault(require("./useMutateRefdataCategory"));
|
|
151
|
+
var _useMutateCustomProperties = _interopRequireDefault(require("./useMutateCustomProperties"));
|
|
152
|
+
var _useMutateModConfigEntry = _interopRequireDefault(require("./useMutateModConfigEntry"));
|
|
146
153
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -11,7 +11,10 @@ var _eventCodes = require("../../constants/eventCodes");
|
|
|
11
11
|
var _selectorSafe = _interopRequireDefault(require("../../utils/selectorSafe"));
|
|
12
12
|
var _useTypedownToggle = _interopRequireDefault(require("./useTypedownToggle"));
|
|
13
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
-
const useTypedown = name
|
|
14
|
+
const useTypedown = function (name) {
|
|
15
|
+
let {
|
|
16
|
+
timeout = 800
|
|
17
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
15
18
|
// SEARCHFIELD COMPONENT
|
|
16
19
|
const searchFieldComponent = document.getElementById(`typedown-searchField-${(0, _selectorSafe.default)(name)}`);
|
|
17
20
|
|
|
@@ -101,6 +104,16 @@ const useTypedown = name => {
|
|
|
101
104
|
const {
|
|
102
105
|
open
|
|
103
106
|
} = (0, _useTypedownToggle.default)(name);
|
|
107
|
+
const [useOpen, setUseOpen] = (0, _react.useState)(false);
|
|
108
|
+
(0, _react.useEffect)(() => {
|
|
109
|
+
// Use setTimeout to update the message after 2000 milliseconds (2 seconds)
|
|
110
|
+
const timeoutId = setTimeout(() => {
|
|
111
|
+
setUseOpen(true);
|
|
112
|
+
}, timeout); // Wait 0.8 seconds for open prop to get used
|
|
113
|
+
|
|
114
|
+
// Cleanup function to clear the timeout if the component unmounts
|
|
115
|
+
return () => clearTimeout(timeoutId);
|
|
116
|
+
}, [timeout]);
|
|
104
117
|
|
|
105
118
|
// RESIZE STUFF
|
|
106
119
|
const {
|
|
@@ -123,7 +136,7 @@ const useTypedown = name => {
|
|
|
123
136
|
searchFieldKeyDownHandler
|
|
124
137
|
},
|
|
125
138
|
variables: {
|
|
126
|
-
open,
|
|
139
|
+
open: useOpen ? open : false,
|
|
127
140
|
portal,
|
|
128
141
|
resizeRef,
|
|
129
142
|
searchWidth
|
|
@@ -4,45 +4,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var
|
|
8
|
-
|
|
7
|
+
var _useMutateGeneric = _interopRequireDefault(require("./useMutateGeneric"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
9
|
const useMutateCustomProperties = _ref => {
|
|
10
10
|
let {
|
|
11
|
-
afterQueryCalls,
|
|
12
|
-
catchQueryCalls,
|
|
13
11
|
endpoint,
|
|
14
12
|
id,
|
|
15
|
-
|
|
16
|
-
returnQueryObject = {
|
|
17
|
-
post: false,
|
|
18
|
-
put: false,
|
|
19
|
-
delete: false
|
|
20
|
-
}
|
|
13
|
+
...mutateGenericProps
|
|
21
14
|
} = _ref;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
returnObj.delete = deleteQueryObject;
|
|
33
|
-
} else {
|
|
34
|
-
returnObj.delete = deleteQueryObject.mutateAsync;
|
|
35
|
-
}
|
|
36
|
-
if (returnQueryObject?.put) {
|
|
37
|
-
returnObj.put = putQueryObject;
|
|
38
|
-
} else {
|
|
39
|
-
returnObj.put = putQueryObject.mutateAsync;
|
|
40
|
-
}
|
|
41
|
-
if (returnQueryObject?.post) {
|
|
42
|
-
returnObj.post = postQueryObject;
|
|
43
|
-
} else {
|
|
44
|
-
returnObj.post = postQueryObject.mutateAsync;
|
|
45
|
-
}
|
|
46
|
-
return returnObj;
|
|
15
|
+
return (0, _useMutateGeneric.default)({
|
|
16
|
+
endpoint,
|
|
17
|
+
endpointMutators: {
|
|
18
|
+
delete: () => `${endpoint}/${id}`,
|
|
19
|
+
put: () => `${endpoint}/${id}`
|
|
20
|
+
},
|
|
21
|
+
id,
|
|
22
|
+
queryKey: ['stripes-kint-components', 'useMutateCustomProperties', id],
|
|
23
|
+
...mutateGenericProps
|
|
24
|
+
});
|
|
47
25
|
};
|
|
48
26
|
var _default = exports.default = useMutateCustomProperties;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _reactQuery = require("react-query");
|
|
8
|
+
var _noop = _interopRequireDefault(require("lodash/noop"));
|
|
9
|
+
var _core = require("@folio/stripes/core");
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
// DEFAULT ASSUMES PUT/POST goes to ENDPOINT/id and that POST goes to ENDPOINT
|
|
12
|
+
// A utility function to provide this all-in-one functionality used in various places
|
|
13
|
+
|
|
14
|
+
const useMutateGeneric = function () {
|
|
15
|
+
let {
|
|
16
|
+
afterQueryCalls: {
|
|
17
|
+
delete: afterQueryDelete = _noop.default,
|
|
18
|
+
post: afterQueryPost = _noop.default,
|
|
19
|
+
put: afterQueryPut = _noop.default
|
|
20
|
+
} = {},
|
|
21
|
+
catchQueryCalls: {
|
|
22
|
+
delete: catchQueryDelete = _noop.default,
|
|
23
|
+
post: catchQueryPost = _noop.default,
|
|
24
|
+
put: catchQueryPut = _noop.default
|
|
25
|
+
} = {},
|
|
26
|
+
endpoint,
|
|
27
|
+
endpointMutators: {
|
|
28
|
+
delete: endpointMutatorDelete = id => `${endpoint}/${id}`,
|
|
29
|
+
post: endpointMutatorPost = () => endpoint,
|
|
30
|
+
put: endpointMutatorPut = data => `${endpoint}/${data.id}`
|
|
31
|
+
} = {},
|
|
32
|
+
payloadMutators: {
|
|
33
|
+
post: payloadMutatorPost = data => ({
|
|
34
|
+
json: data
|
|
35
|
+
}),
|
|
36
|
+
put: payloadMutatorPut = data => ({
|
|
37
|
+
json: data
|
|
38
|
+
})
|
|
39
|
+
} = {},
|
|
40
|
+
promiseReturns: {
|
|
41
|
+
delete: promiseReturnDelete = (id, ky) => ky.delete(endpointMutatorDelete(id)).json(),
|
|
42
|
+
post: promiseReturnPost = (data, ky) => ky.post(endpointMutatorPost(data), payloadMutatorPost(data)).json(),
|
|
43
|
+
put: promiseReturnPut = (data, ky) => ky.put(endpointMutatorPut(data), payloadMutatorPut(data)).json()
|
|
44
|
+
} = {},
|
|
45
|
+
queryKey = [],
|
|
46
|
+
// Must be type: array
|
|
47
|
+
queryKeyMutators: {
|
|
48
|
+
delete: queryKeyMutatorDelete = () => [...queryKey, 'delete'],
|
|
49
|
+
post: queryKeyMutatorPost = () => [...queryKey, 'create'],
|
|
50
|
+
put: queryKeyMutatorPut = () => [...queryKey, 'edit']
|
|
51
|
+
} = {},
|
|
52
|
+
queryParams: {
|
|
53
|
+
delete: queryParamsDelete = {},
|
|
54
|
+
post: queryParamsPost = {},
|
|
55
|
+
put: queryParamsPut = {}
|
|
56
|
+
} = {},
|
|
57
|
+
returnQueryObject: {
|
|
58
|
+
delete: returnQueryObjectDelete = false,
|
|
59
|
+
post: returnQueryObjectPost = false,
|
|
60
|
+
put: returnQueryObjectPut = false
|
|
61
|
+
} = {}
|
|
62
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
63
|
+
const ky = (0, _core.useOkapiKy)();
|
|
64
|
+
|
|
65
|
+
// DELETE Object
|
|
66
|
+
const deleteQueryObject = (0, _reactQuery.useMutation)(queryKeyMutatorDelete(), async id => promiseReturnDelete(id, ky).then(res => afterQueryDelete(res)).catch(catchQueryDelete), queryParamsDelete);
|
|
67
|
+
|
|
68
|
+
// Edit Object
|
|
69
|
+
const putQueryObject = (0, _reactQuery.useMutation)(queryKeyMutatorPut(), async data => promiseReturnPut(data, ky).then(afterQueryPut).catch(catchQueryPut), queryParamsPut);
|
|
70
|
+
|
|
71
|
+
// Create Object
|
|
72
|
+
const postQueryObject = (0, _reactQuery.useMutation)(queryKeyMutatorPost(), async data => promiseReturnPost(data, ky).then(afterQueryPost).catch(catchQueryPost), queryParamsPost);
|
|
73
|
+
const returnObj = {};
|
|
74
|
+
if (returnQueryObjectDelete) {
|
|
75
|
+
returnObj.delete = deleteQueryObject;
|
|
76
|
+
} else {
|
|
77
|
+
returnObj.delete = deleteQueryObject.mutateAsync;
|
|
78
|
+
}
|
|
79
|
+
if (returnQueryObjectPut) {
|
|
80
|
+
returnObj.put = putQueryObject;
|
|
81
|
+
} else {
|
|
82
|
+
returnObj.put = putQueryObject.mutateAsync;
|
|
83
|
+
}
|
|
84
|
+
if (returnQueryObjectPost) {
|
|
85
|
+
returnObj.post = postQueryObject;
|
|
86
|
+
} else {
|
|
87
|
+
returnObj.post = postQueryObject.mutateAsync;
|
|
88
|
+
}
|
|
89
|
+
return returnObj;
|
|
90
|
+
};
|
|
91
|
+
var _default = exports.default = useMutateGeneric;
|
|
@@ -4,41 +4,50 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var
|
|
8
|
-
var _core = require("@folio/stripes/core");
|
|
7
|
+
var _noop = _interopRequireDefault(require("lodash/noop"));
|
|
9
8
|
var _useInvalidateRefdata = _interopRequireDefault(require("./useInvalidateRefdata"));
|
|
9
|
+
var _useMutateGeneric = _interopRequireDefault(require("./useMutateGeneric"));
|
|
10
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
11
|
const useMutateRefdataCategory = _ref => {
|
|
12
12
|
let {
|
|
13
|
-
afterQueryCalls
|
|
14
|
-
|
|
13
|
+
afterQueryCalls: {
|
|
14
|
+
delete: afterQueryDelete = _noop.default,
|
|
15
|
+
post: afterQueryPost = _noop.default,
|
|
16
|
+
put: afterQueryPut = _noop.default
|
|
17
|
+
} = {},
|
|
15
18
|
endpoint,
|
|
16
|
-
|
|
17
|
-
returnQueryObject = {
|
|
18
|
-
post: false,
|
|
19
|
-
delete: false
|
|
20
|
-
}
|
|
19
|
+
...mutateGenericProps
|
|
21
20
|
} = _ref;
|
|
22
|
-
const returnObj = {};
|
|
23
|
-
const ky = (0, _core.useOkapiKy)();
|
|
24
21
|
const invalidateRefdata = (0, _useInvalidateRefdata.default)();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
22
|
+
return (0, _useMutateGeneric.default)({
|
|
23
|
+
afterQueryCalls: {
|
|
24
|
+
delete: res => {
|
|
25
|
+
invalidateRefdata().then(() => {
|
|
26
|
+
afterQueryDelete(res);
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
post: res => {
|
|
30
|
+
invalidateRefdata().then(() => {
|
|
31
|
+
afterQueryPost(res);
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
put: res => {
|
|
35
|
+
invalidateRefdata().then(() => {
|
|
36
|
+
afterQueryPut(res);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
endpoint,
|
|
41
|
+
payloadMutators: {
|
|
42
|
+
post: data => ({
|
|
43
|
+
json: {
|
|
44
|
+
...data,
|
|
45
|
+
values: []
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
},
|
|
49
|
+
queryKey: ['stripes-kint-components', 'useMutateRefdataCategory'],
|
|
50
|
+
...mutateGenericProps
|
|
51
|
+
});
|
|
43
52
|
};
|
|
44
53
|
var _default = exports.default = useMutateRefdataCategory;
|
|
@@ -4,50 +4,67 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var
|
|
8
|
-
var _core = require("@folio/stripes/core");
|
|
7
|
+
var _noop = _interopRequireDefault(require("lodash/noop"));
|
|
9
8
|
var _useInvalidateRefdata = _interopRequireDefault(require("./useInvalidateRefdata"));
|
|
9
|
+
var _useMutateGeneric = _interopRequireDefault(require("./useMutateGeneric"));
|
|
10
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
11
|
const useMutateRefdataValue = _ref => {
|
|
12
12
|
let {
|
|
13
|
-
afterQueryCalls
|
|
14
|
-
|
|
13
|
+
afterQueryCalls: {
|
|
14
|
+
delete: afterQueryDelete = _noop.default,
|
|
15
|
+
post: afterQueryPost = _noop.default,
|
|
16
|
+
put: afterQueryPut = _noop.default
|
|
17
|
+
} = {},
|
|
15
18
|
endpoint,
|
|
16
19
|
id,
|
|
17
|
-
|
|
18
|
-
returnQueryObject = {
|
|
19
|
-
put: false,
|
|
20
|
-
delete: false
|
|
21
|
-
}
|
|
20
|
+
...mutateGenericProps
|
|
22
21
|
} = _ref;
|
|
23
|
-
const returnObj = {};
|
|
24
|
-
const ky = (0, _core.useOkapiKy)();
|
|
25
22
|
const invalidateRefdata = (0, _useInvalidateRefdata.default)();
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
23
|
+
return (0, _useMutateGeneric.default)({
|
|
24
|
+
afterQueryCalls: {
|
|
25
|
+
delete: res => {
|
|
26
|
+
invalidateRefdata().then(() => {
|
|
27
|
+
afterQueryDelete(res);
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
post: res => {
|
|
31
|
+
invalidateRefdata().then(() => {
|
|
32
|
+
afterQueryPost(res);
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
put: res => {
|
|
36
|
+
invalidateRefdata().then(() => {
|
|
37
|
+
afterQueryPut(res);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
endpoint,
|
|
42
|
+
id,
|
|
43
|
+
promiseReturns: {
|
|
44
|
+
delete: (delId, ky) => ky.put(`${endpoint}/${id}`, {
|
|
45
|
+
json: {
|
|
46
|
+
id,
|
|
47
|
+
values: [{
|
|
48
|
+
id: delId,
|
|
49
|
+
_delete: true
|
|
50
|
+
}]
|
|
51
|
+
}
|
|
52
|
+
}).json(),
|
|
53
|
+
post: (data, ky) => ky.put(`${endpoint}/${id}`, {
|
|
54
|
+
json: {
|
|
55
|
+
id,
|
|
56
|
+
values: [data]
|
|
57
|
+
}
|
|
58
|
+
}).json(),
|
|
59
|
+
put: (data, ky) => ky.put(`${endpoint}/${id}`, {
|
|
60
|
+
json: {
|
|
61
|
+
id,
|
|
62
|
+
values: [data]
|
|
63
|
+
}
|
|
64
|
+
}).json()
|
|
65
|
+
},
|
|
66
|
+
queryKey: ['stripes-kint-components', 'useMutateRefdataValue', id],
|
|
67
|
+
...mutateGenericProps
|
|
68
|
+
});
|
|
52
69
|
};
|
|
53
70
|
var _default = exports.default = useMutateRefdataValue;
|