Skip to content

Commit

Permalink
Update Query type
Browse files Browse the repository at this point in the history
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.

¹ <https://nodejs.org/docs/latest-v22.x/api/querystring.html#querystringparsestr-sep-eq-options>
  • Loading branch information
joverlee521 committed Dec 7, 2024
1 parent 728682d commit de428f1
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/actions/measurements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
}

/**
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit de428f1

Please sign in to comment.