@applica-software-guru/react-admin 1.2.120 → 1.2.121

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.2.120",
3
+ "version": "1.2.121",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -62,8 +62,12 @@ function reducer(state: IState, action: IAction): IState {
62
62
  return _.includes(getItemsIds(state.items), payload) ? _.extend(newState, { activeItem: payload }) : newState;
63
63
  case ActionType.ADD_ITEM: {
64
64
  const id = payload.id,
65
- items = _.reject(newState.items, (item: IItem) => item.id === id);
66
- items.push(payload);
65
+ items = _.chain(newState.items)
66
+ .clone()
67
+ .reject((item: IItem) => item.id === id)
68
+ .concat([payload])
69
+ .orderBy((item) => item.index)
70
+ .value();
67
71
  _.extend(newState, { items: items });
68
72
  if (newState.activeItem === undefined) {
69
73
  _.extend(newState, { activeItem: payload.id });
@@ -72,7 +76,10 @@ function reducer(state: IState, action: IAction): IState {
72
76
  }
73
77
  case ActionType.REMOVE_ITEM: {
74
78
  const id = _.isString(payload) ? payload : payload.id,
75
- items = _.reject(newState.items, (item: IItem) => item.id === id);
79
+ items = _.chain(newState.items)
80
+ .clone()
81
+ .reject((item: IItem) => item.id === id)
82
+ .value();
76
83
  _.extend(newState, { items: items });
77
84
  if (newState.activeItem === id) {
78
85
  _.extend(newState, { activeItem: _.first(items)?.id ?? undefined });
@@ -7,12 +7,12 @@ import { IItem } from './types';
7
7
  import { useIsActive } from './hooks';
8
8
  import { getId } from './utils';
9
9
 
10
- type IBaseItemProps = React.PropsWithChildren<Optional<IItem, 'id'>>;
10
+ type IBaseItemProps = React.PropsWithChildren<Optional<IItem, 'id' | 'index'>>;
11
11
  type ITabProps = IBaseItemProps;
12
12
  type IGroupProps = IBaseItemProps;
13
13
 
14
14
  function BaseItem(props: IBaseItemProps) {
15
- const { label, icon, badge } = props,
15
+ const { label, icon, badge, index = 0 } = props,
16
16
  id = getId(props),
17
17
  addItem = useAddItem(),
18
18
  removeItem = useRemoveItem(),
@@ -21,6 +21,7 @@ function BaseItem(props: IBaseItemProps) {
21
21
  useEffect(() => {
22
22
  addItem({
23
23
  id: id,
24
+ index: index,
24
25
  label: label,
25
26
  icon: icon,
26
27
  badge: badge
@@ -28,7 +29,7 @@ function BaseItem(props: IBaseItemProps) {
28
29
  return () => {
29
30
  removeItem(id);
30
31
  };
31
- }, [addItem, removeItem, label, icon, id, badge]);
32
+ }, [addItem, removeItem, label, icon, id, badge, index]);
32
33
 
33
34
  /* All tabs are rendered (not only the one in focus), to allow validation
34
35
  on tabs not in focus. The tabs receive a `hidden` property, which they'll
@@ -57,8 +58,12 @@ function Tab(props: ITabProps) {
57
58
  function useBaseItemChildren(props: React.PropsWithChildren): Array<React.FunctionComponentElement<IBaseItemProps>> {
58
59
  const { children } = props,
59
60
  result = useMemo<Array<React.FunctionComponentElement<IBaseItemProps>>>(
60
- //@ts-ignore
61
- () => _.filter(Children.toArray(children), (Child) => isValidElement(Child) && (Child?.type === Tab || Child?.type === Group)),
61
+ () =>
62
+ //@ts-ignore
63
+ _.chain(Children.toArray(children))
64
+ .filter((Child) => isValidElement(Child) && (Child?.type === Tab || Child?.type === Group))
65
+ .map((Child: React.FunctionComponentElement<IBaseItemProps>, index) => cloneElement(Child, { index: index }))
66
+ .value(),
62
67
  [children]
63
68
  );
64
69
  return result;
@@ -8,6 +8,7 @@ type Disposition = {
8
8
 
9
9
  type IItem = {
10
10
  id: string;
11
+ index: number;
11
12
  label: string;
12
13
  icon?: React.ReactNode;
13
14
  badge?: {