@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axinom/mosaic-ui",
3
- "version": "0.52.0-rc.8",
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-rc.8",
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": "f307889eea9c4a4e4f196af828da5549f1a723c8"
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 = (filters: FilterValues<T>): void => {
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
- filters: activeFilters,
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 = (data: T): ActionData[] =>
359
- (inlineMenuActions?.(data) ?? []).map((action) =>
360
- isContextAction(action)
361
- ? {
362
- ...action,
363
- onActionSelected: async () => {
364
- try {
365
- const result = await action.onActionSelected();
366
- if (result) {
367
- setStationMessage(errMsg(result));
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
- } catch (error) {
370
- setStationMessage(errMsg(error, errAction));
371
- }
372
- },
373
- }
374
- : action,
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
- filters?: FilterValues<T>;
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
- filters,
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>>(filters || {});
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
- const onSortChanged = useCallback(
134
- (sort: SortData<T>): void => {
132
+ useEffect(() => {
133
+ if (activeFilters !== filterValues.current) {
135
134
  // Re-enable more data requests
136
135
  hasMoreData.current = true;
137
- // Set new sorting order.
138
- sorting.current = sort;
136
+ // Set new filters.
137
+ filterValues.current = activeFilters ?? {};
139
138
  loadData();
140
- },
141
- [loadData],
142
- );
139
+ }
140
+ }, [activeFilters, loadData]);
143
141
 
144
- const onFiltersChange = useCallback(
145
- (filters: FilterValues<T>): void => {
142
+ const onSortChanged = useCallback(
143
+ (sort: SortData<T>): void => {
146
144
  // Re-enable more data requests
147
145
  hasMoreData.current = true;
148
- // Set new filters.
149
- filterValues.current = filters;
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,
@@ -67,6 +67,7 @@ export const useFilters = <T extends Data>({
67
67
  )}
68
68
  </>
69
69
  );
70
+
70
71
  return {
71
72
  Filters: FilterComponent,
72
73
  activeFilters,
@@ -21,7 +21,7 @@
21
21
  grid: 1fr / 1fr;
22
22
 
23
23
  &.hasMessage {
24
- grid: min-content 1fr / 1fr;
24
+ grid: min-content 1fr / minmax(740px, 1fr);
25
25
  }
26
26
  }
27
27
  }
@@ -1,5 +1,5 @@
1
1
  import { useFormikContext } from 'formik';
2
- import { useEffect, useState } from 'react';
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 [canSubmit, setCanSubmit] = useState<boolean>(true);
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
- setCanSubmit(false);
33
+ if (!isSubmitting && canSubmit.current) {
34
+ canSubmit.current = false;
35
35
  await submitForm();
36
+ canSubmit.current = true;
36
37
  }
37
38
  } catch (error) {
38
- setCanSubmit(true);
39
+ canSubmit.current = true;
39
40
  throw error;
40
41
  }
41
42
  };