// Copyright (C) The Arvados Authors. All rights reserved. // // SPDX-License-Identifier: AGPL-3.0 import * as React from 'react'; import { connect } from 'react-redux'; import { Grid, Card, CardContent, TableBody, TableCell, TableHead, TableRow, Table, Tooltip, IconButton } from '@material-ui/core'; import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles'; import { ArvadosTheme } from '~/common/custom-theme'; import { compose, Dispatch } from 'redux'; import { loadVirtualMachinesAdminData } from '~/store/virtual-machines/virtual-machines-actions'; import { RootState } from '~/store/store'; import { ListResults } from '~/services/common-service/common-service'; import { MoreOptionsIcon } from '~/components/icon/icon'; import { VirtualMachineLogins, VirtualMachinesResource } from '~/models/virtual-machines'; import { openVirtualMachinesContextMenu } from '~/store/context-menu/context-menu-actions'; type CssRules = 'moreOptionsButton' | 'moreOptions'; const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ moreOptionsButton: { padding: 0 }, moreOptions: { textAlign: 'right', '&:last-child': { paddingRight: 0 } }, }); const mapStateToProps = (state: RootState) => { return { logins: state.virtualMachines.logins, userUuid: state.auth.user!.uuid, ...state.virtualMachines }; }; const mapDispatchToProps = (dispatch: Dispatch): Pick => ({ loadVirtualMachinesData: () => dispatch(loadVirtualMachinesAdminData()), onOptionsMenuOpen: (event, virtualMachine) => { dispatch(openVirtualMachinesContextMenu(event, virtualMachine)); }, }); interface VirtualMachinesPanelDataProps { virtualMachines: ListResults; logins: VirtualMachineLogins; userUuid: string; } interface VirtualMachinesPanelActionProps { loadVirtualMachinesData: () => string; onOptionsMenuOpen: (event: React.MouseEvent, virtualMachine: VirtualMachinesResource) => 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.logins.items.length > 0 && props.virtualMachines.items.map((it, index) => {it.uuid} {it.hostname} ["{props.logins.items.map(it => it.userUuid === props.userUuid ? it.username : '')}"] props.onOptionsMenuOpen(event, it)} className={props.classes.moreOptionsButton}> )}
;