From 964ceb937273875275a54640db4b8deb99a34772 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sat, 17 Apr 2021 03:05:52 +0300 Subject: [PATCH] actions --- .../machines/components/MachineItem.js | 54 +++++++------------ .../machines/components/MachineLog.js | 1 - .../machines/components/MachinesContainer.js | 29 ++++++++-- .../machines/components/MachinesList.js | 6 ++- 4 files changed, 46 insertions(+), 44 deletions(-) diff --git a/src/features/machines/components/MachineItem.js b/src/features/machines/components/MachineItem.js index ecd5f7e..2e924b6 100644 --- a/src/features/machines/components/MachineItem.js +++ b/src/features/machines/components/MachineItem.js @@ -7,12 +7,7 @@ import { Collapse, Tooltip } from "@material-ui/core"; -import { - KeyboardArrowDown, - KeyboardArrowUp, - PowerSettingsNew, - LastPage -} from "@material-ui/icons"; +import { KeyboardArrowDown, KeyboardArrowUp } from "@material-ui/icons"; import { makeStyles } from "@material-ui/core/styles"; import MachineLog from "./MachineLog"; import { useTranslation } from "react-i18next"; @@ -25,15 +20,11 @@ const useRowStyles = makeStyles({ } }); -const MachineItem = ({ machine }) => { +const MachineItem = ({ machine, actions }) => { const [open, setOpen] = React.useState(false); const classes = useRowStyles(); const { t } = useTranslation(); - const handleClick = event => { - alert("asdasd"); - }; - return ( @@ -53,30 +44,20 @@ const MachineItem = ({ machine }) => { {machine.iPv4Address} <> - - - - - - - - - - - - - - + {actions.map(action => ( + + + + + + + + ))} @@ -99,7 +80,8 @@ MachineItem.propTypes = { macAddress: PropTypes.string.isRequired, iPv4Address: PropTypes.string, description: PropTypes.string - }).isRequired + }).isRequired, + actions: PropTypes.array.isRequired }; export default MachineItem; diff --git a/src/features/machines/components/MachineLog.js b/src/features/machines/components/MachineLog.js index 6303931..773a871 100644 --- a/src/features/machines/components/MachineLog.js +++ b/src/features/machines/components/MachineLog.js @@ -1,5 +1,4 @@ import React from "react"; -import PropTypes from "prop-types"; import { Table, TableBody, diff --git a/src/features/machines/components/MachinesContainer.js b/src/features/machines/components/MachinesContainer.js index e944182..395d0c2 100644 --- a/src/features/machines/components/MachinesContainer.js +++ b/src/features/machines/components/MachinesContainer.js @@ -5,28 +5,47 @@ import { } from "../../../state/ApplicationContexts"; import { readMachines } from "../api"; import MachinesList from "./MachinesList"; +import { PowerSettingsNew, LastPage } from "@material-ui/icons"; const MachinesContainer = () => { const state = useContext(ApplicationStateContext); const dispatchActions = useContext(ApplicationDispatchContext); - const handleChange = prop => event => { - dispatchActions.onNetworkChange(prop, event.target.value); - }; - const handleReadMachines = useCallback(async () => { const machines = await readMachines(); const data = Object.assign(machines, { loaded: true }); dispatchActions.onNetworkChange("machines", data); }, [dispatchActions]); + const onClick = machine => () => alert(machine); + const actions = [ + { + code: "wake", + effect: onClick, + icon: PowerSettingsNew, + tooltip: "Wake" + }, + { + code: "ping", + effect: onClick, + icon: LastPage, + tooltip: "Ping" + } + ]; + useEffect(() => { if (!state.network.machines.loaded) { handleReadMachines(); } }, [handleReadMachines, state.network.machines.loaded]); - return ; + return ( + + ); }; export default MachinesContainer; diff --git a/src/features/machines/components/MachinesList.js b/src/features/machines/components/MachinesList.js index 1b35a78..505ba53 100644 --- a/src/features/machines/components/MachinesList.js +++ b/src/features/machines/components/MachinesList.js @@ -11,7 +11,7 @@ import { import Paper from "@material-ui/core/Paper"; import MachineItem from "./MachineItem"; -const MachinesList = ({ dense, machines }) => { +const MachinesList = ({ dense, machines, actions }) => { return ( @@ -29,6 +29,7 @@ const MachinesList = ({ dense, machines }) => { ))} @@ -39,7 +40,8 @@ const MachinesList = ({ dense, machines }) => { MachinesList.propTypes = { dense: PropTypes.bool.isRequired, - machines: PropTypes.array.isRequired + machines: PropTypes.array.isRequired, + actions: PropTypes.array.isRequired }; export default MachinesList;