MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / usePgMenuGroup

Function usePgMenuGroup

web/pgadmin/static/js/components/Menu.jsx:122–150  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

120};
121
122export function usePgMenuGroup() {
123 const [openMenuName, setOpenMenuName] = React.useState(null);
124 const prevMenuOpenIdRef = useRef(null);
125
126 const toggleMenu = React.useCallback((e)=>{
127 const name = e.currentTarget?.getAttribute?.('name') || e.currentTarget?.name;
128 setOpenMenuName(()=>{
129 return prevMenuOpenIdRef.current == name ? null : name;
130 });
131 prevMenuOpenIdRef.current = null;
132 }, []);
133
134 const handleMenuClose = React.useCallback(()=>{
135 /* We have no way here to know if the menu was closed using menu button or not
136 We will keep the last menu name ref for sometime so that the menu does not
137 open again if menu button is clicked to close the menu */
138 prevMenuOpenIdRef.current = openMenuName;
139 setTimeout(()=>{
140 prevMenuOpenIdRef.current = null;
141 }, 300);
142 setOpenMenuName(null);
143 }, [openMenuName]);
144
145 return {
146 openMenuName: openMenuName,
147 toggleMenu: toggleMenu,
148 onMenuClose: handleMenuClose,
149 };
150}

Callers 5

MainToolBarFunction · 0.90
StatusBarFunction · 0.90
MainToolBarFunction · 0.90
FileManagerFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected