removed secondaryActionsMenuProps

master
Tudor Stanciu 2023-03-24 01:30:49 +02:00
parent 64684674ba
commit 4195456227
5 changed files with 53 additions and 87 deletions

View File

@ -42,13 +42,7 @@ GridCell.propTypes = {
value: PropTypes.string.isRequired value: PropTypes.string.isRequired
}; };
const MachineAccordion = ({ const MachineAccordion = ({ machine, actions, logs, addLog }) => {
machine,
actions,
logs,
addLog,
secondaryActionsMenuProps
}) => {
const { t } = useTranslation(); const { t } = useTranslation();
const classes = useStyles(); const classes = useStyles();
return ( return (
@ -78,7 +72,6 @@ const MachineAccordion = ({
machine={machine} machine={machine}
actions={actions} actions={actions}
addLog={addLog} addLog={addLog}
secondaryActionsMenuProps={secondaryActionsMenuProps}
/> />
</Grid> </Grid>
</Grid> </Grid>
@ -101,8 +94,7 @@ MachineAccordion.propTypes = {
}).isRequired, }).isRequired,
actions: PropTypes.array.isRequired, actions: PropTypes.array.isRequired,
logs: PropTypes.array.isRequired, logs: PropTypes.array.isRequired,
addLog: PropTypes.func.isRequired, addLog: PropTypes.func.isRequired
secondaryActionsMenuProps: PropTypes.object.isRequired
}; };
export default MachineAccordion; export default MachineAccordion;

View File

@ -4,20 +4,12 @@ import MachineTableRow from "./MachineTableRow";
import MachineAccordion from "./MachineAccordion"; import MachineAccordion from "./MachineAccordion";
import { ViewModes } from "./ViewModeSelection"; import { ViewModes } from "./ViewModeSelection";
import { useToast } from "../../../hooks"; import { useToast } from "../../../hooks";
import { import { LastPage, RotateLeft, Launch, Stop } from "@material-ui/icons";
LastPage,
MoreHoriz,
RotateLeft,
Launch,
Stop
} from "@material-ui/icons";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import useApi from "../../../api"; import useApi from "../../../api";
const MachineContainer = ({ machine, viewMode }) => { const MachineContainer = ({ machine, viewMode }) => {
const [logs, setLogs] = useState([]); const [logs, setLogs] = useState([]);
const [secondaryActionsAnchor, setSecondaryActionsAnchor] =
React.useState(null);
const { success, error } = useToast(); const { success, error } = useToast();
const { t } = useTranslation(); const { t } = useTranslation();
@ -44,7 +36,7 @@ const MachineContainer = ({ machine, viewMode }) => {
); );
const pingMachine = useCallback( const pingMachine = useCallback(
machine => async () => { async machine => {
await api.pingMachine(machine.machineId, { await api.pingMachine(machine.machineId, {
onCompleted: manageActionResponse onCompleted: manageActionResponse
}); });
@ -52,35 +44,20 @@ const MachineContainer = ({ machine, viewMode }) => {
[manageActionResponse, api] [manageActionResponse, api]
); );
const handleOpenSecondaryActions = event => {
setSecondaryActionsAnchor(event.currentTarget);
};
const handleCloseSecondaryActions = () => {
setSecondaryActionsAnchor(null);
};
const secondaryActionsMenuProps = {
anchor: secondaryActionsAnchor,
onCloseSecondaryActions: handleCloseSecondaryActions
};
const shutdownMachine = useCallback( const shutdownMachine = useCallback(
machine => async () => { async machine => {
await api.shutdownMachine(machine.machineId, 0, false, { await api.shutdownMachine(machine.machineId, 0, false, {
onCompleted: manageActionResponse onCompleted: manageActionResponse
}); });
handleCloseSecondaryActions();
}, },
[manageActionResponse, api] [manageActionResponse, api]
); );
const restartMachine = useCallback( const restartMachine = useCallback(
machine => async () => { async machine => {
await api.restartMachine(machine.machineId, 0, false, { await api.restartMachine(machine.machineId, 0, false, {
onCompleted: manageActionResponse onCompleted: manageActionResponse
}); });
handleCloseSecondaryActions();
}, },
[manageActionResponse, api] [manageActionResponse, api]
); );
@ -91,36 +68,28 @@ const MachineContainer = ({ machine, viewMode }) => {
effect: pingMachine, effect: pingMachine,
icon: LastPage, icon: LastPage,
tooltip: t("Machine.Actions.Ping"), tooltip: t("Machine.Actions.Ping"),
top: true main: true
},
{
code: "more",
effect: handleOpenSecondaryActions,
icon: MoreHoriz,
tooltip: t("Machine.Actions.More"),
top: true,
system: true
}, },
{ {
code: "shutdown", code: "shutdown",
effect: shutdownMachine, effect: shutdownMachine,
icon: Stop, icon: Stop,
tooltip: t("Machine.Actions.Shutdown"), tooltip: t("Machine.Actions.Shutdown"),
top: false main: false
}, },
{ {
code: "restart", code: "restart",
effect: restartMachine, effect: restartMachine,
icon: RotateLeft, icon: RotateLeft,
tooltip: t("Machine.Actions.Restart"), tooltip: t("Machine.Actions.Restart"),
top: false main: false
}, },
{ {
code: "advanced", code: "advanced",
effect: () => {}, effect: () => {},
icon: Launch, icon: Launch,
tooltip: t("Machine.Actions.Advanced"), tooltip: t("Machine.Actions.Advanced"),
top: false main: false
} }
]; ];
@ -132,7 +101,6 @@ const MachineContainer = ({ machine, viewMode }) => {
actions={actions} actions={actions}
logs={logs} logs={logs}
addLog={addLog} addLog={addLog}
secondaryActionsMenuProps={secondaryActionsMenuProps}
/> />
)} )}
{viewMode === ViewModes.ACCORDION && ( {viewMode === ViewModes.ACCORDION && (
@ -141,7 +109,6 @@ const MachineContainer = ({ machine, viewMode }) => {
actions={actions} actions={actions}
logs={logs} logs={logs}
addLog={addLog} addLog={addLog}
secondaryActionsMenuProps={secondaryActionsMenuProps}
/> />
)} )}
</> </>

View File

@ -15,13 +15,7 @@ const useRowStyles = makeStyles({
} }
}); });
const MachineTableRow = ({ const MachineTableRow = ({ machine, actions, logs, addLog }) => {
machine,
actions,
logs,
addLog,
secondaryActionsMenuProps
}) => {
const [open, setOpen] = React.useState(false); const [open, setOpen] = React.useState(false);
const classes = useRowStyles(); const classes = useRowStyles();
const { mask } = useSensitiveInfo(); const { mask } = useSensitiveInfo();
@ -45,12 +39,7 @@ const MachineTableRow = ({
<TableCell>{mask(machine.iPv4Address)}</TableCell> <TableCell>{mask(machine.iPv4Address)}</TableCell>
<TableCell>{mask(machine.macAddress)}</TableCell> <TableCell>{mask(machine.macAddress)}</TableCell>
<TableCell align="right"> <TableCell align="right">
<ActionsGroup <ActionsGroup machine={machine} actions={actions} addLog={addLog} />
machine={machine}
actions={actions}
addLog={addLog}
secondaryActionsMenuProps={secondaryActionsMenuProps}
/>
</TableCell> </TableCell>
</TableRow> </TableRow>
<TableRow> <TableRow>
@ -75,8 +64,7 @@ MachineTableRow.propTypes = {
}).isRequired, }).isRequired,
actions: PropTypes.array.isRequired, actions: PropTypes.array.isRequired,
logs: PropTypes.array.isRequired, logs: PropTypes.array.isRequired,
addLog: PropTypes.func.isRequired, addLog: PropTypes.func.isRequired
secondaryActionsMenuProps: PropTypes.object.isRequired
}; };
export default MachineTableRow; export default MachineTableRow;

View File

@ -3,11 +3,11 @@ import PropTypes from "prop-types";
import { IconButton, Tooltip } from "@material-ui/core"; import { IconButton, Tooltip } from "@material-ui/core";
const ActionButton = React.forwardRef((props, _ref) => { const ActionButton = React.forwardRef((props, _ref) => {
const { action, machine } = props; const { action, machine, callback } = props;
const id = `machine-item-${machine.machineId}-${action.code}`; const id = `machine-item-${machine.machineId}-${action.code}`;
const handleActionClick = event => { const handleActionClick = event => {
if (action.system) action.effect(); action.effect(machine, event);
else action.effect(machine); callback && callback(machine);
event.stopPropagation(); event.stopPropagation();
}; };
@ -37,9 +37,9 @@ ActionButton.propTypes = {
action: PropTypes.shape({ action: PropTypes.shape({
code: PropTypes.string.isRequired, code: PropTypes.string.isRequired,
tooltip: PropTypes.string.isRequired, tooltip: PropTypes.string.isRequired,
system: PropTypes.bool,
effect: PropTypes.func.isRequired effect: PropTypes.func.isRequired
}).isRequired }).isRequired,
callback: PropTypes.func
}; };
export default ActionButton; export default ActionButton;

View File

@ -1,47 +1,67 @@
import React, { useMemo } from "react"; import React, { useMemo, useState } from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import WakeComponent from "./WakeComponent"; import WakeComponent from "./WakeComponent";
import ActionButton from "./ActionButton"; import ActionButton from "./ActionButton";
import { Menu } from "@material-ui/core"; import { Menu } from "@material-ui/core";
import { MoreHoriz } from "@material-ui/icons";
import { useTranslation } from "react-i18next";
const ActionsGroup = ({ const ActionsGroup = ({ machine, actions, addLog }) => {
machine, const [menuAnchor, setMenuAnchor] = useState(null);
actions,
addLog, const { t } = useTranslation();
secondaryActionsMenuProps
}) => { const mainActions = useMemo(
const topActions = useMemo( () => actions.filter(a => a.main === true),
() => actions.filter(a => a.top === true),
[actions] [actions]
); );
const secondaryActions = useMemo( const secondaryActions = useMemo(
() => actions.filter(a => a.top === false), () => actions.filter(a => a.main === false),
[actions] [actions]
); );
const handleMenuOpen = (_, event) => {
setMenuAnchor(event.currentTarget);
};
const handleMenuClose = () => {
setMenuAnchor(null);
};
return ( return (
<> <>
<WakeComponent machine={machine} addLog={addLog} /> <WakeComponent machine={machine} addLog={addLog} />
{topActions.map(action => ( {mainActions.map(action => (
<ActionButton <ActionButton
key={`machine-item-${machine.machineId}-${action.code}`} key={`machine-item-${machine.machineId}-${action.code}`}
action={action} action={action}
machine={machine} machine={machine}
/> />
))} ))}
<ActionButton
action={{
code: "more",
effect: handleMenuOpen,
icon: MoreHoriz,
tooltip: t("Machine.Actions.More")
}}
machine={machine}
/>
<Menu <Menu
id="secondary-actions-menu" id="secondary-actions-menu"
anchorEl={secondaryActionsMenuProps.anchor} anchorEl={menuAnchor}
keepMounted keepMounted
open={Boolean(secondaryActionsMenuProps.anchor)} open={Boolean(menuAnchor)}
onClose={secondaryActionsMenuProps.onCloseSecondaryActions} onClose={handleMenuClose}
> >
{secondaryActions.map(action => ( {secondaryActions.map(action => (
<ActionButton <ActionButton
key={`machine-item-${machine.machineId}-${action.code}`} key={`machine-item-${machine.machineId}-${action.code}`}
action={action} action={action}
machine={machine} machine={machine}
callback={handleMenuClose}
/> />
))} ))}
</Menu> </Menu>
@ -59,8 +79,7 @@ ActionsGroup.propTypes = {
description: PropTypes.string description: PropTypes.string
}).isRequired, }).isRequired,
actions: PropTypes.array.isRequired, actions: PropTypes.array.isRequired,
addLog: PropTypes.func.isRequired, addLog: PropTypes.func.isRequired
secondaryActionsMenuProps: PropTypes.object.isRequired
}; };
export default ActionsGroup; export default ActionsGroup;