// Copyright (C) The Arvados Authors. All rights reserved. // // SPDX-License-Identifier: AGPL-3.0 import React from 'react'; import { connect } from 'react-redux'; import { Grid, Card, Chip, CardContent, TableBody, TableCell, TableHead, TableRow, Table, Tooltip, IconButton } from '@mui/material'; import { CustomStyleRulesCallback } from 'common/custom-theme'; import { WithStyles } from '@mui/styles'; import withStyles from '@mui/styles/withStyles'; import { ArvadosTheme } from 'common/custom-theme'; import { compose, Dispatch } from 'redux'; import { loadVirtualMachinesAdminData, openAddVirtualMachineLoginDialog, openRemoveVirtualMachineLoginDialog, openEditVirtualMachineLoginDialog } from 'store/virtual-machines/virtual-machines-actions'; import { RootState } from 'store/store'; import { ListResults } from 'services/common-service/common-service'; import { MoreVerticalIcon, AddUserIcon } from 'components/icon/icon'; import { VirtualMachineLogins, VirtualMachinesResource } from 'models/virtual-machines'; import { openVirtualMachinesContextMenu } from 'store/context-menu/context-menu-actions'; import { ResourceUuid, VirtualMachineHostname, VirtualMachineLogin } from 'views-components/data-explorer/renderers'; type CssRules = 'moreOptionsButton' | 'moreOptions' | 'chipsRoot' | 'vmTableWrapper'; const styles: CustomStyleRulesCallback = (theme: ArvadosTheme) => ({ moreOptionsButton: { padding: 0 }, moreOptions: { textAlign: 'right', '&:last-child': { paddingRight: 0 } }, chipsRoot: { margin: `0px -calc(${theme.spacing(1)} / 2)`, }, vmTableWrapper: { overflowX: 'auto', }, }); const mapStateToProps = (state: RootState) => { return { userUuid: state.auth.user!.uuid, ...state.virtualMachines }; }; const mapDispatchToProps = (dispatch: Dispatch): Pick => ({ loadVirtualMachinesData: () => dispatch(loadVirtualMachinesAdminData()), onOptionsMenuOpen: (event, virtualMachine) => { dispatch(openVirtualMachinesContextMenu(event, virtualMachine)); }, onAddLogin: (uuid: string) => { dispatch(openAddVirtualMachineLoginDialog(uuid)); }, onDeleteLogin: (uuid: string) => { dispatch(openRemoveVirtualMachineLoginDialog(uuid)); }, onLoginEdit: (uuid: string) => { dispatch(openEditVirtualMachineLoginDialog(uuid)); }, }); interface VirtualMachinesPanelDataProps { virtualMachines: ListResults; logins: VirtualMachineLogins; links: ListResults; userUuid: string; } interface VirtualMachinesPanelActionProps { loadVirtualMachinesData: () => string; onOptionsMenuOpen: (event: React.MouseEvent, virtualMachine: VirtualMachinesResource) => void; onAddLogin: (uuid: string) => void; onDeleteLogin: (uuid: string) => void; onLoginEdit: (uuid: string) => void; } type VirtualMachineProps = VirtualMachinesPanelActionProps & VirtualMachinesPanelDataProps & WithStyles; export const VirtualMachineAdminPanel = compose( withStyles(styles), connect(mapStateToProps, mapDispatchToProps))( class extends React.Component { componentDidMount() { this.props.loadVirtualMachinesData(); } render() { const { virtualMachines } = this.props; return ( {virtualMachines.itemsAvailable > 0 && } ); } } ); const CardContentWithVirtualMachines = (props: VirtualMachineProps) => {virtualMachinesTable(props)} ; const virtualMachinesTable = (props: VirtualMachineProps) => Uuid Host name Logins {props.virtualMachines.items.map((machine, index) => {props.links.items.filter((link) => (link.headUuid === machine.uuid)).map((permission, i) => ( } onDelete={event => props.onDeleteLogin(permission.uuid)} onClick={event => props.onLoginEdit(permission.uuid)} /> ))} props.onAddLogin(machine.uuid)} className={props.classes.moreOptionsButton} size="large"> props.onOptionsMenuOpen(event, machine)} className={props.classes.moreOptionsButton} size="large"> )}
;