From de428f17a8669159c31118daf425f5da75c137c2 Mon Sep 17 00:00:00 2001 From: Jover Lee Date: Mon, 18 Nov 2024 13:56:52 -0800 Subject: [PATCH] Update `Query` type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update the `Query` type to reflect the returned type of `querystring.parse`.¹ This led me to realize that there's a currently a bug in the measurement filter query param matching when filtering using values that are _not_ a string the raw measurement metadata. This will be fixed in the following commit. ¹ --- src/actions/measurements.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/actions/measurements.ts b/src/actions/measurements.ts index 25021e64a..0aa29bfbc 100644 --- a/src/actions/measurements.ts +++ b/src/actions/measurements.ts @@ -43,9 +43,13 @@ interface MeasurementsQuery { m_threshold?: QueryBoolean [key: MeasurementsFilterQuery]: string[] } -/* Central Query type placeholder! */ +/** + * Central Query type placeholder! + * Expected to be the returned object from querystring.parse() + * https://nodejs.org/docs/latest-v22.x/api/querystring.html#querystringparsestr-sep-eq-options + */ interface Query extends MeasurementsQuery { - [key: string]: unknown + [key: string]: string | string[] } /** @@ -658,8 +662,11 @@ export const combineMeasurementsControlsAndQuery = ( } // Remove and ignore query for invalid field values + let filterValues = updatedQuery[filterKey]; + if (typeof filterValues === "string") { + filterValues = Array(filterValues); + } const collectionFieldValues = collectionToDisplay.filters.get(field).values; - const filterValues = Array.isArray(updatedQuery[filterKey]) ? updatedQuery[filterKey] : [updatedQuery[filterKey]]; const validFilterValues = filterValues.filter((value) => collectionFieldValues.has(value)); if (!validFilterValues.length) { delete updatedQuery[filterKey];