From b6916de0b44fd69673f0e68e2312263fbdea9206 Mon Sep 17 00:00:00 2001 From: Sergio Betanzos Date: Tue, 22 Jun 2021 09:19:40 +0200 Subject: [PATCH] F OpenNebula/one#5422: Add hosts table --- .../client/components/Tables/Hosts/index.js | 9 +-- .../src/client/components/Tables/Hosts/row.js | 68 +++++++++++++++++++ src/fireedge/src/client/models/Host.js | 2 +- 3 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 src/fireedge/src/client/components/Tables/Hosts/row.js diff --git a/src/fireedge/src/client/components/Tables/Hosts/index.js b/src/fireedge/src/client/components/Tables/Hosts/index.js index d55c565734..ec46853faa 100644 --- a/src/fireedge/src/client/components/Tables/Hosts/index.js +++ b/src/fireedge/src/client/components/Tables/Hosts/index.js @@ -5,11 +5,11 @@ import { useFetch } from 'client/hooks' import { useHost, useHostApi } from 'client/features/One' import { EnhancedTable } from 'client/components/Tables' -import { HostCard } from 'client/components/Cards' -import Columns from 'client/components/Tables/Hosts/columns' +import HostColumns from 'client/components/Tables/Hosts/columns' +import HostRow from 'client/components/Tables/Hosts/row' const HostsTable = () => { - const columns = React.useMemo(() => Columns, []) + const columns = React.useMemo(() => HostColumns, []) const hosts = useHost() const { getHosts } = useHostApi() @@ -24,7 +24,8 @@ const HostsTable = () => { columns={columns} data={hosts} isLoading={loading || reloading} - MobileComponentRow={HostCard} + getRowId={row => String(row.ID)} + RowComponent={HostRow} /> ) } diff --git a/src/fireedge/src/client/components/Tables/Hosts/row.js b/src/fireedge/src/client/components/Tables/Hosts/row.js new file mode 100644 index 0000000000..b3764e1a90 --- /dev/null +++ b/src/fireedge/src/client/components/Tables/Hosts/row.js @@ -0,0 +1,68 @@ +import * as React from 'react' +import PropTypes from 'prop-types' + +import { Server, ModernTv } from 'iconoir-react' +import { Typography } from '@material-ui/core' + +import { StatusCircle, LinearProgressWithLabel, StatusChip } from 'client/components/Status' +import { rowStyles } from 'client/components/Tables/styles' + +import * as HostModel from 'client/models/Host' + +const Row = ({ value, ...props }) => { + const classes = rowStyles() + const { ID, NAME, IM_MAD, VM_MAD, VMS, CLUSTER } = value + + const { + percentCpuUsed, + percentCpuLabel, + percentMemUsed, + percentMemLabel + } = HostModel.getAllocatedInfo(value) + + const state = HostModel.getState(value) + const runningVms = [VMS?.ID ?? []].flat().length || 0 + + const labels = [...new Set([IM_MAD, VM_MAD])] + + return ( +
+
+ +
+
+ + {NAME} + + {labels.map(label => ( + + ))} + + +
+ {`#${ID}`} + + + {` ${CLUSTER}`} + + + + {` ${runningVms}`} + +
+
+
+ + +
+
+ ) +} + +Row.propTypes = { + value: PropTypes.object, + isSelected: PropTypes.bool, + handleClick: PropTypes.func +} + +export default Row diff --git a/src/fireedge/src/client/models/Host.js b/src/fireedge/src/client/models/Host.js index 61e9ccc418..20bdfc510f 100644 --- a/src/fireedge/src/client/models/Host.js +++ b/src/fireedge/src/client/models/Host.js @@ -3,7 +3,7 @@ import { HOST_STATES } from 'client/constants' export const getState = ({ STATE } = {}) => HOST_STATES[STATE] -export const getAllocatedInfo = ({ HOST_SHARE } = {}) => { +export const getAllocatedInfo = ({ HOST_SHARE = {} } = {}) => { const { CPU_USAGE, TOTAL_CPU, MEM_USAGE, TOTAL_MEM } = HOST_SHARE const percentCpuUsed = +CPU_USAGE * 100 / +TOTAL_CPU || 0