Fix dialog action filtering

This commit is contained in:
Paulo Gustavo Veiga 2021-02-06 08:27:37 -08:00
parent 5f41821f00
commit d2a4fa0365
2 changed files with 8 additions and 7 deletions

View File

@ -11,17 +11,18 @@ import PrintOutlinedIcon from '@material-ui/icons/PrintOutlined';
import ShareOutlinedIcon from '@material-ui/icons/ShareOutlined';
import { FormattedMessage } from 'react-intl';
import { LabelOutlined } from '@material-ui/icons';
import { fetchMapById } from '../action-dispatcher';
export type ActionType = 'open' | 'share' | 'import' | 'delete' | 'info' | 'create' | 'duplicate' | 'export' | 'label' | 'rename' | 'print' | 'info' | 'publish' | 'history' | undefined;
interface ActionProps {
onClose: (action: ActionType) => void;
anchor: undefined | HTMLElement;
role: 'owner' | 'editor' | 'viewer'
anchor?: HTMLElement;
mapId?: number
}
const ActionChooser = (props: ActionProps) => {
const { anchor, onClose, role } = props;
const { anchor, onClose, mapId } = props;
const handleOnClose = (action: ActionType): ((event: React.MouseEvent<HTMLLIElement>) => void) => {
return (event): void => {
@ -30,8 +31,8 @@ const ActionChooser = (props: ActionProps) => {
};
}
const role = mapId ? fetchMapById(mapId)?.map?.role : undefined;
return (
<Menu
anchorEl={anchor}
keepMounted
@ -45,7 +46,7 @@ const ActionChooser = (props: ActionProps) => {
</ListItemIcon>
<FormattedMessage id="action.open" defaultMessage="Open" />
</MenuItem>
<Divider />
<MenuItem onClick={handleOnClose('duplicate')}>

View File

@ -319,6 +319,8 @@ export const MapsList = (props: MapsListProps) => {
const isSelected = (id: number) => selected.indexOf(id) !== -1;
return (
<div className={classes.root}>
<ActionChooser anchor={activeRowAction?.el} onClose={handleActionMenuClose} mapId={activeRowAction?.mapId} />
<Paper className={classes.paper} elevation={0}>
<Toolbar className={classes.toolbar} variant="dense">
@ -467,7 +469,6 @@ export const MapsList = (props: MapsListProps) => {
<MoreHorizIcon color="action" />
</IconButton>
</Tooltip>
<ActionChooser anchor={activeRowAction?.el} onClose={handleActionMenuClose} role={row.role} />
</TableCell>
</TableRow>
);
@ -478,7 +479,6 @@ export const MapsList = (props: MapsListProps) => {
</Paper>
{/* Action Dialog */}
<ActionDispatcher action={activeDialog?.actionType} onClose={() => setActiveDialog(undefined)} mapId={activeDialog ? activeDialog.mapId : -1} />
</div >
);