Skip to content

Commit

Permalink
Consolidate measurements display values with MeasurementsDisplay type
Browse files Browse the repository at this point in the history
  • Loading branch information
joverlee521 committed Nov 19, 2024
1 parent cb77d9c commit f2fe21d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/actions/measurements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
Collection,
isCollection,
isMeasurement,
isMeasurementsDisplay,
measurementsDisplayValues,
Measurement,
MeasurementsDisplay,
MeasurementsJson,
Expand Down Expand Up @@ -111,9 +113,8 @@ function getCollectionDefaultControl(
break;
}
case 'measurementsDisplay': {
const expectedValues = ["mean", "raw"];
if (defaultControl !== undefined && !expectedValues.includes(defaultControl)) {
console.error(`Ignoring invalid ${displayDefaultKey} value ${defaultControl}, must be one of ${expectedValues}`)
if (defaultControl !== undefined && isMeasurementsDisplay(defaultControl)) {
console.error(`Ignoring invalid ${displayDefaultKey} value ${defaultControl}, must be one of ${measurementsDisplayValues}`)
defaultControl = undefined;
}
break;
Expand Down Expand Up @@ -648,7 +649,7 @@ export const combineMeasurementsControlsAndQuery = (
let newControlState = undefined;
switch(queryKey) {
case "m_display":
if (queryValue === "mean" || queryValue === "raw") {
if (isMeasurementsDisplay(queryValue)) {
newControlState = queryValue;
}
break;
Expand Down
5 changes: 4 additions & 1 deletion src/reducers/measurements/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { measurementIdSymbol } from "../../util/globals";
* <https://github.com/nextstrain/augur/blob/3f72c40897a80132099729d5d00a6718e76e0e9e/augur/data/schema-measurements.json#L152>
*/
type MeasurementMetadata = string | number | boolean
export type MeasurementsDisplay = 'raw' | 'mean'

export const measurementsDisplayValues = ["raw", "mean"];
export type MeasurementsDisplay = (typeof measurementsDisplayValues)[number]
export const isMeasurementsDisplay = (x: any): x is MeasurementsDisplay => measurementsDisplayValues.includes(x);

interface JsonMeasurement {
readonly strain: string
Expand Down

0 comments on commit f2fe21d

Please sign in to comment.