diff --git a/horreum-web/src/domain/runs/DatasetComparison.tsx b/horreum-web/src/domain/runs/DatasetComparison.tsx index 7a6c894fa..7cb75e000 100644 --- a/horreum-web/src/domain/runs/DatasetComparison.tsx +++ b/horreum-web/src/domain/runs/DatasetComparison.tsx @@ -1,4 +1,4 @@ -import {useContext, useEffect, useMemo, useRef, useState} from "react" +import { SetStateAction, useContext, useEffect, useMemo, useRef, useState } from "react" import { useSelector } from "react-redux" import { ActionGroup, @@ -8,18 +8,23 @@ import { EmptyState, EmptyStateBody, PageSection, - Spinner, Tooltip, + Spinner, } from "@patternfly/react-core" import { - expandable, - ICell, - IRow + Caption, + expandable, + ExpandableRowContent, + ICell, + InnerScrollContainer, + IRow, + IRowCell, + Table, + Tbody, + Td, + Th, + Thead, + Tr, } from '@patternfly/react-table'; -import { - Table, - TableHeader, - TableBody -} from '@patternfly/react-table/deprecated'; import { NavLink } from "react-router-dom" import { Bar, BarChart, CartesianGrid, ResponsiveContainer, YAxis } from "recharts" @@ -126,6 +131,43 @@ type LabelsComparisonProps = { alerting: AlertContextType } +function renderTableHead(headers: ICell[]) { + return + + + {headers.map((header, index) => + {header.title} + )} + + +} + +function renderTableBody(rows: IRow[], setRows: { (v: SetStateAction): void }) { + return + {rows.map((row, index) => + + { + rows[index + 1].isOpen = !rows[index + 1].isOpen + setRows([...rows]) + }, + expandId: 'expandable-' + index + } + }/> + {row.cells?.map((cell, index) => + + {(cell as IRowCell).title} + + )} + + )} + +} + function LabelsComparison({headers, datasets, alerting}: LabelsComparisonProps) { const [loading, setLoading] = useState(false) const [rows, setRows] = useState([]) @@ -152,16 +194,18 @@ function LabelsComparison({headers, datasets, alerting}: LabelsComparisonProps) rows.forEach(row => { const numeric = row.every((value, i) => i === 0 || typeof value === "number") renderRows.push({ - isOpen: numeric ? false : undefined, cells: row.map(value => ({ title: typeof value === "object" ? JSON.stringify(value) : value, })), }) if (numeric) { renderRows.push({ + isOpen: false, parent: renderRows.length - 1, cells: [ - "", + { + title: "" + }, { title: ( - { - rows[rowIndex].isOpen = isOpen - setRows([...rows]) - }} - > - - - + + + Label(s) Comparison + {renderTableHead(headers)} + {renderTableBody(rows, setRows)} + + > ) @@ -246,7 +282,6 @@ function ViewComparison({headers, view, datasets, alerting}: ViewComparisonProps rowsData.forEach((rd, index) => { const isNum = rd.every((data, rdIndex ) => rdIndex === 0 || typeof rd[rdIndex] === 'number' ) allRows.push({ - isOpen: isNum ? false: undefined, cells: rd.map( (r, index) => ({ title: typeof r === "object" ? JSON.stringify(r) : r }) @@ -254,9 +289,12 @@ function ViewComparison({headers, view, datasets, alerting}: ViewComparisonProps }) if (isNum){ allRows.push({ + isOpen: false, parent: allRows.length - 1, cells: [ - "", + { + title: "" + }, { title: ( - { - rows[rowIndex].isOpen = isOpen - setRows([...rows]) - }} - > - - - + + + View Component(s) Comparison + {renderTableHead(headers)} + {renderTableBody(rows, setRows)} + + > )