From c6433f310b821b4e8b3cb55df1e9ccadda7d97f4 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Thu, 16 May 2024 20:11:20 +0800 Subject: [PATCH] feat: add server docker expend view --- reporter/utils/utils.go | 34 ++-- src/client/components/DataTable.tsx | 46 +++++- src/client/components/server/ServerList.tsx | 74 ++++++--- .../components/server/ServerRowExpendView.tsx | 151 ++++++++++++++++++ src/types/server.ts | 30 ++++ 5 files changed, 295 insertions(+), 40 deletions(-) create mode 100644 src/client/components/server/ServerRowExpendView.tsx diff --git a/reporter/utils/utils.go b/reporter/utils/utils.go index 4cb013e..4b36425 100644 --- a/reporter/utils/utils.go +++ b/reporter/utils/utils.go @@ -43,22 +43,23 @@ type ReportDataPayload struct { } type DockerDataPayload struct { - ID string `json:"id"` - Image string `json:"image"` - ImageID string `json:"imageId"` - CreatedAt int64 `json:"createdAt"` - State string `json:"state"` - Status string `json:"status"` - CpuPercent float64 `json:"cpuPercent"` - Memory float64 `json:"memory"` - MemLimit uint64 `json:"memLimit"` - MemPercent float64 `json:"memPercent"` - StorageWriteSize uint64 `json:"storageWriteSize"` - StorageReadSize uint64 `json:"storageReadSize"` - NetworkRx float64 `json:"networkRx"` - NetworkTx float64 `json:"networkTx"` - IORead uint64 `json:"ioRead"` - IOWrite uint64 `json:"ioWrite"` + ID string `json:"id"` + Image string `json:"image"` + ImageID string `json:"imageId"` + Ports []dockerTypes.Port `json:"ports"` + CreatedAt int64 `json:"createdAt"` + State string `json:"state"` + Status string `json:"status"` + CpuPercent float64 `json:"cpuPercent"` + Memory float64 `json:"memory"` + MemLimit uint64 `json:"memLimit"` + MemPercent float64 `json:"memPercent"` + StorageWriteSize uint64 `json:"storageWriteSize"` + StorageReadSize uint64 `json:"storageReadSize"` + NetworkRx float64 `json:"networkRx"` + NetworkTx float64 `json:"networkTx"` + IORead uint64 `json:"ioRead"` + IOWrite uint64 `json:"ioWrite"` } var checkIP int @@ -303,6 +304,7 @@ func GetDockerStat() ([]DockerDataPayload, error) { ID: container.ID[:10], Image: container.Image, ImageID: container.ImageID, + Ports: container.Ports, CreatedAt: container.Created, State: container.State, Status: container.Status, diff --git a/src/client/components/DataTable.tsx b/src/client/components/DataTable.tsx index 614e22d..bdc45d3 100644 --- a/src/client/components/DataTable.tsx +++ b/src/client/components/DataTable.tsx @@ -5,6 +5,7 @@ import { useReactTable, createColumnHelper, getExpandedRowModel, + ExpandedState, } from '@tanstack/react-table'; import { @@ -17,6 +18,9 @@ import { } from '@/components/ui/table'; import { Empty } from 'antd'; import React from 'react'; +import { Button } from './ui/button'; +import { LuArrowRight } from 'react-icons/lu'; +import { cn } from '@/utils/style'; export type { ColumnDef }; export { createColumnHelper }; @@ -32,10 +36,18 @@ export function DataTable({ data, ExpandComponent, }: DataTableProps) { + const [expanded, setExpanded] = React.useState({}); + const canExpand = Boolean(ExpandComponent); + const table = useReactTable({ data, columns, + state: { + expanded, + }, + onExpandedChange: setExpanded, getCoreRowModel: getCoreRowModel(), + getRowCanExpand: () => canExpand, }); return ( @@ -44,6 +56,21 @@ export function DataTable({ {table.getHeaderGroups().map((headerGroup) => ( + {canExpand && ( + +