pcm-shared-components 0.0.85 → 0.0.88
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.
|
@@ -2,6 +2,7 @@ import React, { Fragment, useState, useEffect } from "react";
|
|
|
2
2
|
import { Typography, Button, Tooltip, IconButton, Toolbar, MenuItem, Menu, AppBar, Badge } from "@mui/material";
|
|
3
3
|
import { makeStyles } from '@mui/styles';
|
|
4
4
|
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
|
|
5
|
+
import Divider from '@mui/material/Divider';
|
|
5
6
|
import { ThemeProvider } from '@mui/system';
|
|
6
7
|
import { createTheme, useTheme } from '@mui/material/styles';
|
|
7
8
|
import MoreIcon from "@mui/icons-material/MoreVert";
|
|
@@ -98,7 +99,7 @@ export const GenericAppBar = props => {
|
|
|
98
99
|
borderLeft: "0.1em solid #aeaeae",
|
|
99
100
|
padding: "0.5em",
|
|
100
101
|
margin: "10px 10px 10px 10px",
|
|
101
|
-
height:
|
|
102
|
+
height: 5
|
|
102
103
|
},
|
|
103
104
|
mobile_divider: {
|
|
104
105
|
borderBottom: "0.1em solid #aeaeae",
|
|
@@ -217,10 +218,7 @@ export const GenericAppBar = props => {
|
|
|
217
218
|
}), menu.display_divider ? menu_divider : /*#__PURE__*/React.createElement("div", {
|
|
218
219
|
className: "mr-12"
|
|
219
220
|
})) : /*#__PURE__*/React.createElement("div", {
|
|
220
|
-
|
|
221
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
222
|
-
className: "flex flex-row",
|
|
223
|
-
key: `main_sub_items_${new Date()}`
|
|
221
|
+
className: "flex flex-row "
|
|
224
222
|
}, /*#__PURE__*/React.createElement(Tooltip, {
|
|
225
223
|
title: menu.name
|
|
226
224
|
}, menu.isButton ? /*#__PURE__*/React.createElement(Button // className={classes.menuButton}
|
|
@@ -238,9 +236,18 @@ export const GenericAppBar = props => {
|
|
|
238
236
|
onClick: () => {
|
|
239
237
|
menu.onClick();
|
|
240
238
|
}
|
|
241
|
-
}, menu.icon)), menu.display_divider ?
|
|
242
|
-
|
|
243
|
-
|
|
239
|
+
}, menu.icon)), menu.display_divider ? /*#__PURE__*/React.createElement(Divider, {
|
|
240
|
+
style: {
|
|
241
|
+
marginRight: 24,
|
|
242
|
+
marginLeft: 6
|
|
243
|
+
},
|
|
244
|
+
orientation: "vertical",
|
|
245
|
+
flexItem: true
|
|
246
|
+
}) : /*#__PURE__*/React.createElement("div", {
|
|
247
|
+
style: {
|
|
248
|
+
marginRight: 24
|
|
249
|
+
}
|
|
250
|
+
}))); //? ------------------------------------------------
|
|
244
251
|
//! Mobile menu
|
|
245
252
|
//? ------------------------------------------------
|
|
246
253
|
|
|
@@ -270,10 +277,7 @@ export const GenericAppBar = props => {
|
|
|
270
277
|
//? ------------------------------------------------
|
|
271
278
|
|
|
272
279
|
const MainItems = () => {
|
|
273
|
-
return /*#__PURE__*/React.createElement(
|
|
274
|
-
className: "flex flex-row",
|
|
275
|
-
key: `main_items_${new Date()}`
|
|
276
|
-
}, (appBarMenu.mainMenu || []).filter(mn => !(mn.hideMenu && mn.hideMenu === true)).map((menu, idx) => /*#__PURE__*/React.createElement(DesktopItemMenu, {
|
|
280
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, (appBarMenu.mainMenu || []).filter(mn => !(mn.hideMenu && mn.hideMenu === true)).map((menu, idx) => /*#__PURE__*/React.createElement(DesktopItemMenu, {
|
|
277
281
|
key: `desktop_item_menu_${idx}`,
|
|
278
282
|
menu: menu,
|
|
279
283
|
idx: idx
|
|
@@ -27,6 +27,7 @@ export const GenericDialogWindow = props => {
|
|
|
27
27
|
const [is_loading, setIsLoading] = useState(false);
|
|
28
28
|
const [managedAppBarMenu, setManagedAppBarMenu] = useState(undefined);
|
|
29
29
|
const [save_button_label, setSaveButtonLabel] = useState(undefined);
|
|
30
|
+
const [onClickOverride, setOnClickOverride] = useState([]);
|
|
30
31
|
const childRef = useRef();
|
|
31
32
|
|
|
32
33
|
const onSave = () => {
|
|
@@ -47,7 +48,7 @@ export const GenericDialogWindow = props => {
|
|
|
47
48
|
};
|
|
48
49
|
|
|
49
50
|
const getSaveButtonLabel = () => {
|
|
50
|
-
let return_value = 'Save
|
|
51
|
+
let return_value = 'Save'; //returns the save label for the save button in the bottom right of the dialog.
|
|
51
52
|
// The save label is taken from the mainMenu name item having an id='save'
|
|
52
53
|
|
|
53
54
|
try {
|
|
@@ -59,11 +60,63 @@ export const GenericDialogWindow = props => {
|
|
|
59
60
|
} catch (error) {}
|
|
60
61
|
|
|
61
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;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const setMenuOnClickCallback = useCallback((id, onClick) => {
|
|
85
|
+
//Used to set the onClick callback on a specific menu matching the id provided.
|
|
86
|
+
//Example: Used by the children component to set the onClick of a menu.
|
|
87
|
+
// A menu must have a unique id object matching the id on which we are searching for and a callback function must be provided
|
|
88
|
+
if (!onClickOverride.find(oco => oco.id.toLowerCase() === id.toLowerCase())) {
|
|
89
|
+
//Nice this override doesn't exist. Add it
|
|
90
|
+
setOnClickOverride(previousState => {
|
|
91
|
+
return [...previousState, {
|
|
92
|
+
id: id,
|
|
93
|
+
onClick: onClick
|
|
94
|
+
}];
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}, [appBarMenu]);
|
|
98
|
+
|
|
99
|
+
const setOverrides = () => {
|
|
100
|
+
try {
|
|
101
|
+
//Loop over all our on click overrides and apply the onClick callback for each id found in the onClickOverride state
|
|
102
|
+
onClickOverride.forEach(item => {
|
|
103
|
+
setManagedAppBarMenu(previousState => {
|
|
104
|
+
return { ...previousState,
|
|
105
|
+
mainMenu: updateObjectByID(previousState.mainMenu, item.id, item.onClick)
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.error('Error in setMenuOnClickCallback: ', error);
|
|
111
|
+
}
|
|
62
112
|
};
|
|
63
113
|
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
//Wait for the state to be updated then loop over the overrides to ensure they are properly applied
|
|
116
|
+
setOverrides();
|
|
117
|
+
}, [onClickOverride]);
|
|
64
118
|
useEffect(() => {
|
|
65
119
|
if (appBarMenu && appBarMenu.mainMenu) {
|
|
66
|
-
// 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
|
|
67
120
|
setManagedAppBarMenu({ ...appBarMenu,
|
|
68
121
|
mainMenu: [...appBarMenu.mainMenu.map(mm => {
|
|
69
122
|
if (mm.id === 'save') {
|
|
@@ -76,7 +129,10 @@ export const GenericDialogWindow = props => {
|
|
|
76
129
|
return mm;
|
|
77
130
|
}
|
|
78
131
|
})]
|
|
79
|
-
});
|
|
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.
|
|
134
|
+
|
|
135
|
+
setOverrides();
|
|
80
136
|
}
|
|
81
137
|
}, [appBarMenu, can_save, showSaveButton, save_button_label]); // -----------------------------------------
|
|
82
138
|
// Note make sure to include disableEnforceFocus or else I'll have infinite error/warnings on Uncaught RangeError.
|
|
@@ -109,7 +165,8 @@ export const GenericDialogWindow = props => {
|
|
|
109
165
|
setIsLoading,
|
|
110
166
|
setSaveButtonLabel,
|
|
111
167
|
closeDialog,
|
|
112
|
-
data: data
|
|
168
|
+
data: data,
|
|
169
|
+
setMenuOnClickCallback
|
|
113
170
|
},
|
|
114
171
|
ref: childRef
|
|
115
172
|
}) : /*#__PURE__*/React.createElement(React.Fragment, null)))), /*#__PURE__*/React.createElement(DialogActions, {
|