@axinom/mosaic-ui 0.52.0-rc.8 → 0.52.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/dist/components/Explorer/Explorer.d.ts.map +1 -1
- package/dist/components/Explorer/helpers/useDataProvider.d.ts +2 -3
- package/dist/components/Explorer/helpers/useDataProvider.d.ts.map +1 -1
- package/dist/components/Explorer/helpers/useFilters.d.ts.map +1 -1
- package/dist/components/FormStation/SaveOnDemand/SaveOnDemand.d.ts.map +1 -1
- package/dist/index.es.js +4 -4
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/Explorer/Explorer.tsx +23 -22
- package/src/components/Explorer/QuickEdit/useQuickEdit.spec.tsx +0 -12
- package/src/components/Explorer/helpers/useDataProvider.tsx +13 -16
- package/src/components/Explorer/helpers/useFilters.tsx +1 -0
- package/src/components/FormStation/FormStationContentWrapper/FormStationContentWrapper.scss +1 -1
- package/src/components/FormStation/SaveOnDemand/SaveOnDemand.tsx +6 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axinom/mosaic-ui",
|
|
3
|
-
"version": "0.52.
|
|
3
|
+
"version": "0.52.1",
|
|
4
4
|
"description": "UI components for building Axinom Mosaic applications",
|
|
5
5
|
"author": "Axinom",
|
|
6
6
|
"license": "PROPRIETARY",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"build-storybook": "storybook build"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@axinom/mosaic-core": "^0.4.25
|
|
35
|
+
"@axinom/mosaic-core": "^0.4.25",
|
|
36
36
|
"@faker-js/faker": "^7.4.0",
|
|
37
37
|
"@geoffcox/react-splitter": "^2.1.2",
|
|
38
38
|
"@popperjs/core": "^2.11.8",
|
|
@@ -106,5 +106,5 @@
|
|
|
106
106
|
"publishConfig": {
|
|
107
107
|
"access": "public"
|
|
108
108
|
},
|
|
109
|
-
"gitHead": "
|
|
109
|
+
"gitHead": "ac91e5639b80b0ad2fa95a1df3f2a899afab5b3c"
|
|
110
110
|
}
|
|
@@ -242,10 +242,9 @@ export const Explorer = React.forwardRef(function Explorer<T extends Data>(
|
|
|
242
242
|
}
|
|
243
243
|
}, [defaultSortOrder, globalStateOptions.sort, sortOrder, stationKey]);
|
|
244
244
|
|
|
245
|
-
const onFilterChangedHandler = (
|
|
246
|
-
onFiltersChange(filters);
|
|
245
|
+
const onFilterChangedHandler = useCallback(() => {
|
|
247
246
|
listRef.current?.resetSelection();
|
|
248
|
-
};
|
|
247
|
+
}, []);
|
|
249
248
|
|
|
250
249
|
const {
|
|
251
250
|
activeFilters,
|
|
@@ -268,14 +267,13 @@ export const Explorer = React.forwardRef(function Explorer<T extends Data>(
|
|
|
268
267
|
hasMoreData,
|
|
269
268
|
onReloadData,
|
|
270
269
|
onRequestMoreData,
|
|
271
|
-
onFiltersChange,
|
|
272
270
|
onSortChanged,
|
|
273
271
|
} = useDataProvider<T>({
|
|
274
272
|
dataProvider,
|
|
275
273
|
explorerRef,
|
|
276
274
|
setStationMessage,
|
|
277
275
|
defaultSortOrder: sortOrder,
|
|
278
|
-
|
|
276
|
+
activeFilters,
|
|
279
277
|
keyProperty,
|
|
280
278
|
});
|
|
281
279
|
|
|
@@ -355,24 +353,27 @@ export const Explorer = React.forwardRef(function Explorer<T extends Data>(
|
|
|
355
353
|
|
|
356
354
|
const errAction = 'An error occurred when trying to execute the operation.';
|
|
357
355
|
|
|
358
|
-
const inlineMenuActionsHandler = (
|
|
359
|
-
(
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
356
|
+
const inlineMenuActionsHandler = useCallback(
|
|
357
|
+
(data: T): ActionData[] =>
|
|
358
|
+
(inlineMenuActions?.(data) ?? []).map((action) =>
|
|
359
|
+
isContextAction(action)
|
|
360
|
+
? {
|
|
361
|
+
...action,
|
|
362
|
+
onActionSelected: async () => {
|
|
363
|
+
try {
|
|
364
|
+
const result = await action.onActionSelected();
|
|
365
|
+
if (result) {
|
|
366
|
+
setStationMessage(errMsg(result));
|
|
367
|
+
}
|
|
368
|
+
} catch (error) {
|
|
369
|
+
setStationMessage(errMsg(error, errAction));
|
|
368
370
|
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
);
|
|
371
|
+
},
|
|
372
|
+
}
|
|
373
|
+
: action,
|
|
374
|
+
),
|
|
375
|
+
[inlineMenuActions, setStationMessage],
|
|
376
|
+
);
|
|
376
377
|
|
|
377
378
|
const { actions: pageHeaderActions } = useActions<T>({
|
|
378
379
|
actions,
|
|
@@ -229,7 +229,6 @@ describe('useQuickEdit', () => {
|
|
|
229
229
|
wrapper.update();
|
|
230
230
|
|
|
231
231
|
const { ContextConsumer, ref: contextRef } = getContextConsumer();
|
|
232
|
-
|
|
233
232
|
mount(
|
|
234
233
|
<ref.current.QuickEditContextProvider>
|
|
235
234
|
<ContextConsumer contextRef={contextRef} />
|
|
@@ -249,14 +248,12 @@ describe('useQuickEdit', () => {
|
|
|
249
248
|
await act(async () => {
|
|
250
249
|
ref.current.quickEditAction?.kind === 'group' &&
|
|
251
250
|
(await ref.current.quickEditAction?.onActionsGroupToggled?.(true));
|
|
252
|
-
|
|
253
251
|
ref.current.changeSelectedItem({ id: 1 });
|
|
254
252
|
});
|
|
255
253
|
|
|
256
254
|
wrapper.update();
|
|
257
255
|
|
|
258
256
|
const { ContextConsumer, ref: contextRef } = getContextConsumer();
|
|
259
|
-
|
|
260
257
|
mount(
|
|
261
258
|
<ref.current.QuickEditContextProvider>
|
|
262
259
|
<ContextConsumer contextRef={contextRef} />
|
|
@@ -276,14 +273,12 @@ describe('useQuickEdit', () => {
|
|
|
276
273
|
await act(async () => {
|
|
277
274
|
ref.current.quickEditAction?.kind === 'group' &&
|
|
278
275
|
(await ref.current.quickEditAction?.onActionsGroupToggled?.(true));
|
|
279
|
-
|
|
280
276
|
ref.current.changeSelectedItem({ id: 1 });
|
|
281
277
|
});
|
|
282
278
|
|
|
283
279
|
wrapper.update();
|
|
284
280
|
|
|
285
281
|
const { ContextConsumer, ref: contextRef } = getContextConsumer();
|
|
286
|
-
|
|
287
282
|
mount(
|
|
288
283
|
<ref.current.QuickEditContextProvider>
|
|
289
284
|
<ContextConsumer contextRef={contextRef} />
|
|
@@ -294,7 +289,6 @@ describe('useQuickEdit', () => {
|
|
|
294
289
|
|
|
295
290
|
await act(async () => {
|
|
296
291
|
contextRef.current.registerSaveCallback?.(saveCallbackSpy);
|
|
297
|
-
|
|
298
292
|
ref.current.changeSelectedItem({ id: 1 });
|
|
299
293
|
});
|
|
300
294
|
|
|
@@ -309,14 +303,12 @@ describe('useQuickEdit', () => {
|
|
|
309
303
|
await act(async () => {
|
|
310
304
|
ref.current.quickEditAction?.kind === 'group' &&
|
|
311
305
|
(await ref.current.quickEditAction?.onActionsGroupToggled?.(true));
|
|
312
|
-
|
|
313
306
|
ref.current.changeSelectedItem({ id: 1 });
|
|
314
307
|
});
|
|
315
308
|
|
|
316
309
|
wrapper.update();
|
|
317
310
|
|
|
318
311
|
const { ContextConsumer, ref: contextRef } = getContextConsumer();
|
|
319
|
-
|
|
320
312
|
mount(
|
|
321
313
|
<ref.current.QuickEditContextProvider>
|
|
322
314
|
<ContextConsumer contextRef={contextRef} />
|
|
@@ -327,7 +319,6 @@ describe('useQuickEdit', () => {
|
|
|
327
319
|
|
|
328
320
|
await act(async () => {
|
|
329
321
|
contextRef.current.registerSaveCallback?.(saveCallbackSpy);
|
|
330
|
-
|
|
331
322
|
contextRef.current.refresh?.();
|
|
332
323
|
});
|
|
333
324
|
|
|
@@ -352,7 +343,6 @@ describe('useQuickEdit', () => {
|
|
|
352
343
|
wrapper.update();
|
|
353
344
|
|
|
354
345
|
const { ContextConsumer, ref: contextRef } = getContextConsumer();
|
|
355
|
-
|
|
356
346
|
mount(
|
|
357
347
|
<ref.current.QuickEditContextProvider>
|
|
358
348
|
<ContextConsumer contextRef={contextRef} />
|
|
@@ -381,7 +371,6 @@ describe('useQuickEdit', () => {
|
|
|
381
371
|
});
|
|
382
372
|
|
|
383
373
|
wrapper.update();
|
|
384
|
-
|
|
385
374
|
const { ContextConsumer, ref: contextRef } = getContextConsumer();
|
|
386
375
|
|
|
387
376
|
mount(
|
|
@@ -411,7 +400,6 @@ describe('useQuickEdit', () => {
|
|
|
411
400
|
wrapper.update();
|
|
412
401
|
|
|
413
402
|
const { ContextConsumer, ref: contextRef } = getContextConsumer();
|
|
414
|
-
|
|
415
403
|
mount(
|
|
416
404
|
<ref.current.QuickEditContextProvider>
|
|
417
405
|
<ContextConsumer contextRef={contextRef} />
|
|
@@ -26,7 +26,6 @@ interface DataProviderReturnType<T> {
|
|
|
26
26
|
readonly hasMoreData: boolean;
|
|
27
27
|
readonly onReloadData: () => void;
|
|
28
28
|
readonly onSortChanged: (sort: SortData<T>) => void;
|
|
29
|
-
readonly onFiltersChange: (filters: FilterValues<T>) => void;
|
|
30
29
|
readonly onRequestMoreData: () => void;
|
|
31
30
|
}
|
|
32
31
|
|
|
@@ -39,7 +38,7 @@ interface DataProviderArgumentType<T extends Data> {
|
|
|
39
38
|
dataProvider: ExplorerDataProvider<T>;
|
|
40
39
|
explorerRef: React.ForwardedRef<ExplorerDataProviderConnection<T>>;
|
|
41
40
|
defaultSortOrder?: SortData<T>;
|
|
42
|
-
|
|
41
|
+
activeFilters?: FilterValues<T>;
|
|
43
42
|
keyProperty?: keyof T;
|
|
44
43
|
setStationMessage: React.Dispatch<
|
|
45
44
|
React.SetStateAction<StationMessage | undefined>
|
|
@@ -51,7 +50,7 @@ export function useDataProvider<T extends Data>({
|
|
|
51
50
|
explorerRef,
|
|
52
51
|
setStationMessage,
|
|
53
52
|
defaultSortOrder,
|
|
54
|
-
|
|
53
|
+
activeFilters,
|
|
55
54
|
keyProperty,
|
|
56
55
|
}: DataProviderArgumentType<T>): DataProviderReturnType<T> {
|
|
57
56
|
const dataProviderRef = useUpdatingRef(dataProvider);
|
|
@@ -67,7 +66,7 @@ export function useDataProvider<T extends Data>({
|
|
|
67
66
|
const lastAttemptedPagingInfo = useRef<unknown>();
|
|
68
67
|
|
|
69
68
|
const sorting = useRef<SortData<T> | undefined>(defaultSortOrder);
|
|
70
|
-
const filterValues = useRef<FilterValues<T>>(
|
|
69
|
+
const filterValues = useRef<FilterValues<T>>(activeFilters || {});
|
|
71
70
|
|
|
72
71
|
const loadData = useCallback(
|
|
73
72
|
async (
|
|
@@ -130,23 +129,22 @@ export function useDataProvider<T extends Data>({
|
|
|
130
129
|
[dataProviderRef, setStationMessage],
|
|
131
130
|
);
|
|
132
131
|
|
|
133
|
-
|
|
134
|
-
(
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
if (activeFilters !== filterValues.current) {
|
|
135
134
|
// Re-enable more data requests
|
|
136
135
|
hasMoreData.current = true;
|
|
137
|
-
// Set new
|
|
138
|
-
|
|
136
|
+
// Set new filters.
|
|
137
|
+
filterValues.current = activeFilters ?? {};
|
|
139
138
|
loadData();
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
);
|
|
139
|
+
}
|
|
140
|
+
}, [activeFilters, loadData]);
|
|
143
141
|
|
|
144
|
-
const
|
|
145
|
-
(
|
|
142
|
+
const onSortChanged = useCallback(
|
|
143
|
+
(sort: SortData<T>): void => {
|
|
146
144
|
// Re-enable more data requests
|
|
147
145
|
hasMoreData.current = true;
|
|
148
|
-
// Set new
|
|
149
|
-
|
|
146
|
+
// Set new sorting order.
|
|
147
|
+
sorting.current = sort;
|
|
150
148
|
loadData();
|
|
151
149
|
},
|
|
152
150
|
[loadData],
|
|
@@ -182,7 +180,6 @@ export function useDataProvider<T extends Data>({
|
|
|
182
180
|
resultCount,
|
|
183
181
|
onReloadData,
|
|
184
182
|
onSortChanged,
|
|
185
|
-
onFiltersChange,
|
|
186
183
|
onRequestMoreData,
|
|
187
184
|
data,
|
|
188
185
|
hasMoreData: hasMoreData.current,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useFormikContext } from 'formik';
|
|
2
|
-
import { useEffect,
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
3
|
|
|
4
4
|
interface SaveOnDemandProps {
|
|
5
5
|
/** If set to true, will prevent form submission when navigating away. (default: false) */
|
|
@@ -16,7 +16,7 @@ export const SaveOnDemand: React.FC<SaveOnDemandProps> = ({
|
|
|
16
16
|
registerSaveCallback,
|
|
17
17
|
}) => {
|
|
18
18
|
const { submitForm, dirty, isValid } = useFormikContext();
|
|
19
|
-
const
|
|
19
|
+
const canSubmit = useRef(true);
|
|
20
20
|
|
|
21
21
|
useEffect(() => {
|
|
22
22
|
const saveCallback = async (): Promise<void> => {
|
|
@@ -30,12 +30,13 @@ export const SaveOnDemand: React.FC<SaveOnDemandProps> = ({
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
try {
|
|
33
|
-
if (!isSubmitting && canSubmit) {
|
|
34
|
-
|
|
33
|
+
if (!isSubmitting && canSubmit.current) {
|
|
34
|
+
canSubmit.current = false;
|
|
35
35
|
await submitForm();
|
|
36
|
+
canSubmit.current = true;
|
|
36
37
|
}
|
|
37
38
|
} catch (error) {
|
|
38
|
-
|
|
39
|
+
canSubmit.current = true;
|
|
39
40
|
throw error;
|
|
40
41
|
}
|
|
41
42
|
};
|