Files
pgadmin4/web/pgadmin/static/js/components/Menu.jsx
Aditya Toshniwal 9c30d983bd Fixed following issues for query tool after react porting:
1) Add New Server Connection > Server options keep loading(For empty Server group).
 2) After clicking indent/Unindent(for all operations) for large query option left as it is till operation completes
 3) Check sign beside options in Execute Option/Copy Header is little bit big
 4) In explain > Analysis tab does not show ROWS column
 5) In explain > Explain > analysis previous explain output is NOT cleared. New rows are appended. Same applies to the statistics tab.
 6) Update new query tool connection tool tip. Fixes #7289
 7) Explain-Analyze > Loops column is empty.
 8) Explain-Analyze with Verbose & Costs > in ROW X columns upward arrows are missing.
 9) Explain-Analyze with all option checked > background colors are missing for timing.
 10) Explain-Analyze > Additional bullet is added before Hash Cond.
 11) Browser Tree > Filtered rows icon is not working.
 12) Create table with timestamp and default value as function now() > Add new row > Enter mandatory columns except column where default value is function(now()) > Click Save > New row added but column with default value has value [default]. not updated to actual value. / Default values are not considered for any column while adding a new entry.
 13) Disable execute options in View/Edit data.
 14) The Boolean column always shows null.
 15) In Query history Remove & Remove all buttons are stuck to each other.
 16) On Remove all, the right panel is empty.
 17) Create a column with boolean[]/ text[], Try to add a new entry from data grid, enter “” quotes > Click Ok > Now try edit cell > You can not change value.
 18) In query history - Select queries are suffixed by ’Save Data’ icon
 19) Edit any table with PK > Try to insert duplicate PK > Error thrown > Correct pK value > Still old error shown > Not able to add new entry (This works when focus is moved from edited cell)
 20) Clicking arrows after opening dropdown options, does not collapse dropdown.

refs #6131
2022-04-18 12:50:51 +05:30

119 lines
3.2 KiB
JavaScript

import { makeStyles } from '@material-ui/styles';
import React, { useRef } from 'react';
import CheckIcon from '@material-ui/icons/Check';
import PropTypes from 'prop-types';
import {
MenuItem,
ControlledMenu,
applyStatics,
} from '@szhsin/react-menu';
export {MenuDivider as PgMenuDivider} from '@szhsin/react-menu';
import { shortcutToString } from './ShortcutTitle';
import clsx from 'clsx';
import CustomPropTypes from '../custom_prop_types';
const useStyles = makeStyles((theme)=>({
menu: {
'& .szh-menu': {
padding: '4px 0px',
zIndex: 1000,
backgroundColor: theme.palette.background.default,
color: theme.palette.text.primary,
border: `1px solid ${theme.otherVars.borderColor}`
},
'& .szh-menu__divider': {
margin: 0,
}
},
menuItem: {
display: 'flex',
padding: '4px 8px',
'&.szh-menu__item--active, &.szh-menu__item--hover': {
backgroundColor: theme.palette.primary.main,
color: theme.palette.primary.contrastText,
}
},
checkIcon: {
width: '1.3rem',
},
hideCheck: {
visibility: 'hidden',
},
shortcut: {
marginLeft: 'auto',
fontSize: '0.8em',
paddingLeft: '12px',
}
}));
export function PgMenu({open, className, ...props}) {
const classes = useStyles();
return (
<ControlledMenu
state={open ? 'open' : 'closed'}
{...props}
className={clsx(classes.menu, className)}
/>
);
}
PgMenu.propTypes = {
open: PropTypes.bool,
className: CustomPropTypes.className,
};
export const PgMenuItem = applyStatics(MenuItem)(({hasCheck=false, checked=false, accesskey, shortcut, children, ...props})=>{
const classes = useStyles();
let onClick = props.onClick;
if(hasCheck) {
onClick = (e)=>{
e.keepOpen = true;
props.onClick(e);
};
}
return <MenuItem {...props} onClick={onClick} className={classes.menuItem}>
{hasCheck && <CheckIcon className={classes.checkIcon} style={checked ? {} : {visibility: 'hidden'}} />}
{children}
{(shortcut || accesskey) && <div className={classes.shortcut}>({shortcutToString(shortcut, accesskey)})</div>}
</MenuItem>;
});
PgMenuItem.propTypes = {
hasCheck: PropTypes.bool,
checked: PropTypes.bool,
accesskey: PropTypes.string,
shortcut: CustomPropTypes.shortcut,
children: CustomPropTypes.children,
onClick: PropTypes.func,
};
export function usePgMenuGroup() {
const [openMenuName, setOpenMenuName] = React.useState(null);
const prevMenuOpenIdRef = useRef(null);
const toggleMenu = React.useCallback((e)=>{
setOpenMenuName(()=>{
return prevMenuOpenIdRef.current == e.currentTarget?.name ? null : e.currentTarget?.name;
});
prevMenuOpenIdRef.current = null;
}, []);
const handleMenuClose = React.useCallback(()=>{
/* We have no way here to know if the menu was closed using menu button or not
We will keep the last menu name ref for sometime so that the menu does not
open again if menu button is clicked to close the menu */
prevMenuOpenIdRef.current = openMenuName;
setTimeout(()=>{
prevMenuOpenIdRef.current = null;
}, 300);
setOpenMenuName(null);
}, [openMenuName]);
return {
openMenuName: openMenuName,
toggleMenu: toggleMenu,
onMenuClose: handleMenuClose,
};
}