From cb77d9cc787b5be628db0bc28cbb1fd475348a05 Mon Sep 17 00:00:00 2001 From: Jover Lee Date: Mon, 18 Nov 2024 16:23:06 -0800 Subject: [PATCH] Consolidate query boolean checks in `isQueryBoolean` --- src/actions/measurements.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/actions/measurements.ts b/src/actions/measurements.ts index bae8cb8bc..5a1591986 100644 --- a/src/actions/measurements.ts +++ b/src/actions/measurements.ts @@ -34,7 +34,10 @@ interface GroupingValues { /* mf_ correspond to active measurements filters */ const filterQueryPrefix = "mf_"; type MeasurementsFilterQuery = `mf_${string}` -type QueryBoolean = "show" | "hide" + +const queryBooleanValues = ["show", "hide"] as const; +type QueryBoolean = (typeof queryBooleanValues)[number] +export const isQueryBoolean = (x: any): x is QueryBoolean => queryBooleanValues.includes(x) /* Measurements query parameters that are constructed and/or parsed here. */ interface MeasurementsQuery { m_collection?: string @@ -656,13 +659,12 @@ export const combineMeasurementsControlsAndQuery = ( } break; case "m_overallMean": - if (queryValue === "show" || queryValue === "hide") { + if (isQueryBoolean(queryValue)) { newControlState = queryValue === "show"; } break; case "m_threshold": - if (collectionToDisplay.thresholds && - (queryValue === "show" || queryValue === "hide")) { + if (collectionToDisplay.thresholds && isQueryBoolean(queryValue)) { newControlState = queryValue === "show"; } break;