@applica-software-guru/react-admin 1.3.129 → 1.3.131

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": "@applica-software-guru/react-admin",
3
- "version": "1.3.129",
3
+ "version": "1.3.131",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -163,7 +163,7 @@ const ApplicaAdmin = ({
163
163
  useErrorEventCatcher({
164
164
  apiUrl,
165
165
  errorHandler,
166
- catcherFn: (error: any): CatchResult => {
166
+ catcherFn: (error: ErrorEvent | string): CatchResult => {
167
167
  const errorMessage = error?.toString();
168
168
  const knownErrors = [
169
169
  // @see https://github.com/marmelab/react-admin/pull/8884
@@ -177,7 +177,7 @@ const ApplicaAdmin = ({
177
177
  catch: isKnowBug,
178
178
  display: !isKnowBug,
179
179
  log: !isKnowBug,
180
- error
180
+ error: errorMessage
181
181
  });
182
182
  return result;
183
183
  }
@@ -3,7 +3,7 @@ import { Avatar } from '../../@extended';
3
3
  import { Card, Collapse, List, ListItem, ListItemProps, ListItemIcon, ListItemText, ListItemButton, ListItemAvatar } from '@mui/material';
4
4
  import { useSetActiveItem, useSyncWithLocation } from './Provider';
5
5
  import { IItem } from './types';
6
- import { useCallback, useMemo, useState } from 'react';
6
+ import { useCallback, useEffect, useMemo, useState } from 'react';
7
7
  import { useChildren, useIsActive, useNavigateForm } from './hooks';
8
8
  import { ExpandLess, ExpandMore } from '@mui/icons-material';
9
9
  import { getLevel } from './utils';
@@ -57,6 +57,12 @@ function NavMenuItem(props: INavMenuItemProps) {
57
57
  hasIcon = icon !== undefined,
58
58
  listItemProps = _.omit(props, ['label', 'icon', 'selected', 'badge']);
59
59
 
60
+ useEffect(() => {
61
+ if (selected && !open) {
62
+ setOpen(selected);
63
+ }
64
+ }, [selected, open, setOpen]);
65
+
60
66
  return (
61
67
  <>
62
68
  <ListItem {...listItemProps} disablePadding>
@@ -61,18 +61,15 @@ function reducer(state: IState, action: IAction): IState {
61
61
  case ActionType.SET_ACTIVE_ITEM:
62
62
  return _.includes(getItemsIds(state.items), payload) ? _.extend(newState, { activeItem: payload }) : newState;
63
63
  case ActionType.ADD_ITEM: {
64
- const id = payload.id,
65
- items = _.chain(newState.items)
64
+ const { id } = payload;
65
+ return _.extend(newState, {
66
+ items: _.chain(newState.items)
66
67
  .clone()
67
68
  .reject((item: IItem) => item.id === id)
68
69
  .concat([payload])
69
70
  .orderBy((item) => item.index)
70
- .value();
71
- _.extend(newState, { items: items });
72
- if (newState.activeItem === undefined) {
73
- _.extend(newState, { activeItem: payload.id });
74
- }
75
- return newState;
71
+ .value()
72
+ });
76
73
  }
77
74
  case ActionType.REMOVE_ITEM: {
78
75
  const id = _.isString(payload) ? payload : payload.id,
@@ -6,7 +6,11 @@ import { useNavigate } from 'react-router';
6
6
 
7
7
  function useIsActive(id: string): boolean {
8
8
  const activeItem = useActiveItem();
9
- return id === activeItem || isChild(id, activeItem ?? '');
9
+ if (activeItem === undefined) {
10
+ return false;
11
+ } else {
12
+ return id === activeItem || isChild(id, activeItem);
13
+ }
10
14
  }
11
15
 
12
16
  function useChildren(id?: string): Array<IItem> {
@@ -26,23 +26,34 @@ const useErrorEventCatcher = ({
26
26
  }
27
27
  return new ErrorEventHandler({ apiUrl });
28
28
  }, [apiUrl, props.errorHandler]);
29
+ const consoleError = console.error;
29
30
  const handleError = React.useCallback(
30
- function (event: ErrorEvent) {
31
- const catchResult = catcherFn(event);
32
-
31
+ function (event: ErrorEvent | string, ...args: any[]) {
32
+ const catchResult = catcherFn(event instanceof ErrorEvent ? event : event.replace(/%s/g, () => args.shift()));
33
+ if (catchResult.isCatched()) {
34
+ return false;
35
+ }
33
36
  if (catchResult.logError()) {
34
- errorHandler.handle(event);
37
+ if (event instanceof ErrorEvent) {
38
+ errorHandler.handle(event);
39
+ } else {
40
+ errorHandler.handle(new ErrorEvent('window.onerror', { error: event, message: event.toString() }));
41
+ }
35
42
  }
36
43
 
37
- return !catchResult.isCatched() || catchResult.displayError();
44
+ if (catchResult.displayError()) {
45
+ consoleError.apply(console, arguments as any);
46
+ }
38
47
  },
39
48
  [apiUrl, loading, catcherFn, enabled, errorHandler]
40
49
  );
41
50
  React.useEffect(() => {
42
51
  window.removeEventListener('error', handleError);
43
52
  window.addEventListener('error', handleError);
53
+ console.error = handleError;
44
54
  return () => {
45
55
  window.removeEventListener('error', handleError);
56
+ console.error = consoleError;
46
57
  };
47
58
  }, [handleError]);
48
59
  return true;
@@ -36,10 +36,6 @@ function createI18nProvider(data: ICreateI18nProviderData): Promise<any> {
36
36
  getLanguages = (): Promise<Locale> => {
37
37
  return fetch(`${apiUrl}/i18n/languages`, { headers: headers, method: 'get' })
38
38
  .then((response) => response.json())
39
- .then((response) => {
40
- const { responseCode, locales } = response;
41
- return responseCode !== 'ok' ? defaultLanguages : locales;
42
- })
43
39
  .catch(() => {
44
40
  return Promise.resolve(defaultLanguages);
45
41
  });