pcm-shared-components 0.0.86 → 0.0.87

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.
@@ -60,6 +60,25 @@ export const GenericDialogWindow = props => {
60
60
  } catch (error) {}
61
61
 
62
62
  return return_value;
63
+ }; //?-------------------------------------------------------
64
+ //? Children on click callback override, updates the onclick for a given menu
65
+ //?-------------------------------------------------------
66
+
67
+
68
+ const updateObjectByID = (obj, id, onClick) => {
69
+ if (!obj) return;
70
+
71
+ if (obj.id && obj.id === id) {
72
+ obj.onClick = onClick;
73
+ } else if (typeof obj === 'object' && Array.isArray(obj)) {
74
+ for (var i = 0; i < obj.length; i++) {
75
+ updateObjectByID(obj[i], id, onClick);
76
+ }
77
+ } else if (obj.subMenu) {
78
+ updateObjectByID(obj.subMenu, id, onClick);
79
+ }
80
+
81
+ return obj;
63
82
  };
64
83
 
65
84
  const setMenuOnClickCallback = useCallback((id, onClick) => {
@@ -75,7 +94,7 @@ export const GenericDialogWindow = props => {
75
94
  }];
76
95
  });
77
96
  }
78
- }, []);
97
+ }, [appBarMenu]);
79
98
 
80
99
  const setOverrides = () => {
81
100
  try {
@@ -83,15 +102,7 @@ export const GenericDialogWindow = props => {
83
102
  onClickOverride.forEach(item => {
84
103
  setManagedAppBarMenu(previousState => {
85
104
  return { ...previousState,
86
- mainMenu: [...previousState.mainMenu.map(mm => {
87
- if (mm.id.toLowerCase() === item.id.toLowerCase()) {
88
- return { ...mm,
89
- onClick: item.onClick
90
- };
91
- } else {
92
- return mm;
93
- }
94
- })]
105
+ mainMenu: updateObjectByID(previousState.mainMenu, item.id, item.onClick)
95
106
  };
96
107
  });
97
108
  });
@@ -106,7 +117,6 @@ export const GenericDialogWindow = props => {
106
117
  }, [onClickOverride]);
107
118
  useEffect(() => {
108
119
  if (appBarMenu && appBarMenu.mainMenu) {
109
- // If we have a mainMenu item with the id='save' then override the onClick event to use the onSave function which reaches into the child ref
110
120
  setManagedAppBarMenu({ ...appBarMenu,
111
121
  mainMenu: [...appBarMenu.mainMenu.map(mm => {
112
122
  if (mm.id === 'save') {
@@ -119,7 +129,8 @@ export const GenericDialogWindow = props => {
119
129
  return mm;
120
130
  }
121
131
  })]
122
- }); //Need to re-apply any onClick override to ensure they are still properly set by what was overridden from the child component.
132
+ }); // If we have a mainMenu item with the id='save' then override the onClick event to use the onSave function which reaches into the child ref
133
+ //Need to re-apply any onClick override to ensure they are still properly set by what was overridden from the child component.
123
134
 
124
135
  setOverrides();
125
136
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pcm-shared-components",
3
- "version": "0.0.86",
3
+ "version": "0.0.87",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "babel": {