diff --git a/packages/ui/src/components/metrics-table-title/metrics-table-title.jsx b/packages/ui/src/components/metrics-table-title/metrics-table-title.jsx index ac389fbab7..8e27622996 100644 --- a/packages/ui/src/components/metrics-table-title/metrics-table-title.jsx +++ b/packages/ui/src/components/metrics-table-title/metrics-table-title.jsx @@ -14,7 +14,7 @@ export const MetricsTableTitle = (props) => { const rootClassName = cx(css.root, className); return ( - + {title} diff --git a/packages/ui/src/components/metrics-table-title/metrics-table-title.module.css b/packages/ui/src/components/metrics-table-title/metrics-table-title.module.css index 268a0507d1..ce9e01afc6 100644 --- a/packages/ui/src/components/metrics-table-title/metrics-table-title.module.css +++ b/packages/ui/src/components/metrics-table-title/metrics-table-title.module.css @@ -18,8 +18,10 @@ } .info { + color: var(--color-text-light); + font-family: var(--font-family-fixed); font-size: var(--size-xsmall); - font-weight: normal; + font-weight: bold; } .readMoreLink { diff --git a/packages/ui/src/components/metrics-table/metrics-table.jsx b/packages/ui/src/components/metrics-table/metrics-table.jsx index 7226578de3..f65f9755cc 100644 --- a/packages/ui/src/components/metrics-table/metrics-table.jsx +++ b/packages/ui/src/components/metrics-table/metrics-table.jsx @@ -1,4 +1,4 @@ -import React, { useMemo } from 'react'; +import React from 'react'; import PropTypes from 'prop-types'; import cx from 'classnames'; import isEmpty from 'lodash/isEmpty'; @@ -15,98 +15,68 @@ import styles from './metrics-table.module.css'; const METRIC_TYPE_DATA = getGlobalMetricType(null, METRIC_TYPE_FILE_SIZE); const VISIBLE_COUNT = 500; +const BASELINE_COLUMN_SPAN = 1; +const CURRENT_COLUMN_SPAN = 3; +const BASELINE_TITLE = 'Baseline'; +const CURRENT_TITLE = 'Current'; const getRowsRunTotal = (rows, runIndex) => sum(rows.map((row) => row?.runs?.[runIndex]?.value || 0)); -const getHeaderLabelCells = (rows) => (run, runIndex, runs) => { - const isBaseline = runIndex === runs.length - 1; - const className = cx(styles.value, isBaseline ? styles.baseline : styles.current); +const ColumnJob = ({ run, isBaseline }) => { + const colSpan = isBaseline ? BASELINE_COLUMN_SPAN : CURRENT_COLUMN_SPAN; if (!run) { - return [ - { children: '-', className }, - ...(!isBaseline ? [{ children: ' ', className: styles.delta }] : []), - ]; + return ( + - + ); } const { label, internalBuildNumber } = run; - const jobName = ( - - {label} - + return ( + + + {label} + + ); - - return [ - // Value column - { children: jobName, className }, - // Delta column - ...(!isBaseline ? [{ children: ' ', className: cx(styles.delta) }] : []), - ]; }; -const getHeaderTotalCells = (rows) => (run, runIndex, runs) => { - const isBaseline = runIndex === runs.length - 1; - const className = cx(styles.value, isBaseline ? styles.baseline : styles.current); - +const ColumnSum = ({ rows, isBaseline, runIndex }) => { const currentRunTotal = getRowsRunTotal(rows, runIndex); const baselineRunTotal = !isBaseline && getRowsRunTotal(rows, runIndex + 1); const infoTotal = getMetricRunInfo(METRIC_TYPE_DATA, currentRunTotal, baselineRunTotal); - return [ - // Value column - { - children: , - className, - }, - - // Delta column - ...(!isBaseline - ? [ - { - children: ( - - ), - className: styles.delta, - }, - ] - : []), - ]; + return ( + <> + + + + {!isBaseline && ( + <> + + + + + + + + )} + + ); }; -const getHeaderRows = (runs, items, showHeaderSum, title) => [ - { - className: styles.headerRowColumns, - cells: [ - // Metric name column - one empty strying to render the column - { - children: title || ' ', - className: styles.metricName, - rowSpan: showHeaderSum ? 2 : 1, - }, - - // Runs - ...runs.map(getHeaderLabelCells(items)).flat(), - ], - }, - ...(showHeaderSum - ? [ - { - className: styles.headerRowTotals, - cells: runs.map(getHeaderTotalCells(items)).flat(), - }, - ] - : []), -]; - -const MetricsTableRow = ({ item, renderRowHeader }) => ( +const Row = ({ item, renderRowHeader }) => ( {renderRowHeader(item)} @@ -120,11 +90,12 @@ const MetricsTableRow = ({ item, renderRowHeader }) => ( <> - {!isBaseline && } + {!isBaseline && } ); } - const { displayValue, deltaPercentage, displayDeltaPercentage, deltaType } = run; + const { displayValue, deltaPercentage, displayDelta, displayDeltaPercentage, deltaType } = run; return ( <> @@ -132,9 +103,14 @@ const MetricsTableRow = ({ item, renderRowHeader }) => ( {!isBaseline && typeof deltaPercentage === 'number' && ( - - - + <> + + + + + + + )} ); @@ -142,7 +118,7 @@ const MetricsTableRow = ({ item, renderRowHeader }) => ( ); -MetricsTableRow.propTypes = { +Row.propTypes = { item: PropTypes.shape({ changed: PropTypes.bool, runs: PropTypes.arrayOf( @@ -165,21 +141,12 @@ export const MetricsTable = ({ items, emptyMessage, showHeaderSum, - headerRows, title, showAllItems, setShowAllItems, ...restProps }) => { - const { headers, columnClassNames } = useMemo(() => { - const headerColumns = getHeaderRows(runs, items, showHeaderSum, title); - - return { - headers: [...headerRows, ...headerColumns], - // First header row has the column class names - columnClassNames: headerColumns[0].cells.map((headerColumn) => headerColumn.className), - }; - }, [headerRows, runs, items, showHeaderSum, title]); + const columnCount = (runs.length - 1) * CURRENT_COLUMN_SPAN + BASELINE_COLUMN_SPAN + 1; const rootClassName = cx( styles.root, @@ -196,24 +163,22 @@ export const MetricsTable = ({ return ( - {headers.map((headerRow) => { - const { cells, className: rowClassName } = headerRow.cells - ? headerRow - : { cells: headerRow }; - - return ( - - {cells.map((header) => ( - - ))} - - ); - })} + + + {title || ' '} + + {runs.map((run, runIndex) => )} + + {showHeaderSum && ( + + {runs.map((run, runIndex) => )} + + )} {showEmpty && ( - +
@@ -227,12 +192,12 @@ export const MetricsTable = ({ {showItems && ( <> {visibleItems.map((item) => ( - + ))} {hasHiddenItems && ( - + {showAllItems ? (