Skip to content

Commit

Permalink
Refactor frontend subject table row to prepare for #6578.
Browse files Browse the repository at this point in the history
  • Loading branch information
fniessink committed Jul 15, 2024
1 parent 768c569 commit 2b8f981
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions components/frontend/src/subject/SubjectTableRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { TrendSparkline } from "../measurement/TrendSparkline"
import { MetricDetails } from "../metric/MetricDetails"
import { Label, Popup, Table } from "../semantic_ui_react_wrappers"
import {
dataModelPropType,
datePropType,
datesPropType,
directionPropType,
measurementsPropType,
Expand Down Expand Up @@ -153,6 +155,35 @@ DeltaCell.propTypes = {
status: string,
}

function measurementOnDate(metric_uuid, measurements, date) {
const isoDateString = date.toISOString().split("T")[0]
return measurements?.find((m) => {
return (
m.metric_uuid === metric_uuid &&
m.start.split("T")[0] <= isoDateString &&
isoDateString <= m.end.split("T")[0]
)
})
}
measurementOnDate.propTypes = {
metric_uuid: string,
measurements: measurementsPropType,
date: datePropType,
}

function metricValueAndStatusOnDate(dataModel, metric, metric_uuid, measurements, date) {
const measurement = measurementOnDate(metric_uuid, measurements, date)
const scale = getMetricScale(metric, dataModel)
return [measurement?.[scale]?.value ?? "?", measurement?.[scale]?.status ?? "unknown"]
}
metricValueAndStatusOnDate.propTypes = {
dataModel: dataModelPropType,
metric: metricPropType,
metric_uuid: string,
measurements: measurementsPropType,
date: datePropType,
}

function MeasurementCells({ dates, metric, metric_uuid, measurements, settings }) {
const dataModel = useContext(DataModel)
const showDeltaColumns = settings.hiddenColumns.excludes("delta")
Expand All @@ -161,16 +192,7 @@ function MeasurementCells({ dates, metric, metric_uuid, measurements, settings }
const cells = []
let previousValue = "?"
dates.forEach((date, index) => {
const isoDateString = date.toISOString().split("T")[0]
const measurement = measurements?.find((m) => {
return (
m.metric_uuid === metric_uuid &&
m.start.split("T")[0] <= isoDateString &&
isoDateString <= m.end.split("T")[0]
)
})
let metricValue = measurement?.[scale]?.value ?? "?"
const status = measurement?.[scale]?.status ?? "unknown"
const [metricValue, status] = metricValueAndStatusOnDate(dataModel, metric, metric_uuid, measurements, date)
if (showDeltaColumns && index > 0) {
cells.push(
<DeltaCell
Expand Down

0 comments on commit 2b8f981

Please sign in to comment.