changed components structure

master
Tudor Stanciu 2023-03-21 18:31:58 +02:00
parent 3cc5d8f6f3
commit 94f2138bc7
4 changed files with 43 additions and 38 deletions

View File

@ -5,13 +5,13 @@ import {
TableRow, TableRow,
IconButton, IconButton,
Collapse, Collapse,
Tooltip,
Menu Menu
} from "@material-ui/core"; } from "@material-ui/core";
import { KeyboardArrowDown, KeyboardArrowUp } from "@material-ui/icons"; import { KeyboardArrowDown, KeyboardArrowUp } from "@material-ui/icons";
import { makeStyles } from "@material-ui/core/styles"; import { makeStyles } from "@material-ui/core/styles";
import MachineLog from "./MachineLog"; import MachineLog from "./common/MachineLog";
import WakeComponent from "./WakeComponent"; import WakeComponent from "./common/WakeComponent";
import ActionButton from "./common/ActionButton";
import { useSensitiveInfo } from "../../../hooks"; import { useSensitiveInfo } from "../../../hooks";
const useRowStyles = makeStyles({ const useRowStyles = makeStyles({
@ -22,38 +22,6 @@ const useRowStyles = makeStyles({
} }
}); });
const ActionButton = React.forwardRef((props, _ref) => {
const { action, machine } = props;
return (
<Tooltip
id={`machine-item-${machine.machineId}-${action.code}-tooltip`}
title={action.tooltip}
>
<span>
<IconButton
id={`machine-item-${machine.machineId}-${action.code}`}
size={"small"}
onClick={action.system ? action.effect : action.effect(machine)}
>
<action.icon />
</IconButton>
</span>
</Tooltip>
);
});
ActionButton.propTypes = {
machine: PropTypes.shape({
machineId: PropTypes.number.isRequired
}).isRequired,
action: PropTypes.shape({
code: PropTypes.string.isRequired,
tooltip: PropTypes.string.isRequired,
system: PropTypes.bool,
effect: PropTypes.func.isRequired
}).isRequired
};
const Machine = ({ const Machine = ({
machine, machine,
actions, actions,

View File

@ -0,0 +1,37 @@
import React from "react";
import PropTypes from "prop-types";
import { IconButton, Tooltip } from "@material-ui/core";
const ActionButton = React.forwardRef((props, _ref) => {
const { action, machine } = props;
return (
<Tooltip
id={`machine-item-${machine.machineId}-${action.code}-tooltip`}
title={action.tooltip}
>
<span>
<IconButton
id={`machine-item-${machine.machineId}-${action.code}`}
size={"small"}
onClick={action.system ? action.effect : action.effect(machine)}
>
<action.icon />
</IconButton>
</span>
</Tooltip>
);
});
ActionButton.propTypes = {
machine: PropTypes.shape({
machineId: PropTypes.number.isRequired
}).isRequired,
action: PropTypes.shape({
code: PropTypes.string.isRequired,
tooltip: PropTypes.string.isRequired,
system: PropTypes.bool,
effect: PropTypes.func.isRequired
}).isRequired
};
export default ActionButton;

View File

@ -3,9 +3,9 @@ import PropTypes from "prop-types";
import { IconButton, Tooltip } from "@material-ui/core"; import { IconButton, Tooltip } from "@material-ui/core";
import { PowerSettingsNew } from "@material-ui/icons"; import { PowerSettingsNew } from "@material-ui/icons";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useToast } from "../../../hooks"; import { useToast } from "../../../../hooks";
import { msToMinAndSec } from "../../../utils/time"; import { msToMinAndSec } from "../../../../utils/time";
import useApi from "../../../api"; import useApi from "../../../../api";
const initialState = { on: false }; const initialState = { on: false };
const defaultPingInterval = 1200000; //20 minutes const defaultPingInterval = 1200000; //20 minutes