// This file is part of MinIO Console Server // Copyright (c) 2020 MinIO, Inc. // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . import React from "react"; import isString from "lodash/isString"; import { IconButton } from "@material-ui/core"; import ViewIcon from "./TableActionIcons/ViewIcon"; import PencilIcon from "./TableActionIcons/PencilIcon"; import DeleteIcon from "./TableActionIcons/DeleteIcon"; import DescriptionIcon from "./TableActionIcons/DescriptionIcon"; import CloudIcon from "./TableActionIcons/CloudIcon"; import ConsoleIcon from "./TableActionIcons/ConsoleIcon"; import GetAppIcon from "@material-ui/icons/GetApp"; import SvgIcon from "@material-ui/core/SvgIcon"; import { Link } from "react-router-dom"; interface IActionButton { type: string; onClick?: (id: string) => any; to?: string; valueToSend: any; selected: boolean; sendOnlyId?: boolean; idField: string; } const defineIcon = (type: string, selected: boolean) => { switch (type) { case "view": return ; case "edit": return ; case "delete": return ; case "description": return ; case "cloud": return ; case "console": return ; case "download": return ( ); } return null; }; const TableActionButton = ({ type, onClick, valueToSend, idField, selected, to, sendOnlyId = false, }: IActionButton) => { const valueClick = sendOnlyId ? valueToSend[idField] : valueToSend; const buttonElement = ( { e.stopPropagation(); onClick(valueClick); } : () => null } > {defineIcon(type, selected)} ); if (onClick) { return buttonElement; } if (isString(to)) { return ( { e.stopPropagation(); }} > {buttonElement} ); } return null; }; export default TableActionButton;