Skip to content

Commit dceec75

Browse files
atrakhConvex, Inc.
authored and
Convex, Inc.
committed
dashboard: fix conversion of index filter value to jsonvalue (#37321)
GitOrigin-RevId: 3f93725ada5faf27ca712b525781f7a7dc09e2da
1 parent fe549b8 commit dceec75

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

npm-packages/dashboard-common/src/features/data/components/DataFilters/IndexFilterEditor.tsx

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { JSONValue, ValidatorJSON, Value } from "convex/values";
1+
import { ValidatorJSON, Value, convexToJson } from "convex/values";
22
import React, { useCallback, useState } from "react";
33
import {
44
FilterByIndex,
@@ -103,7 +103,7 @@ export function IndexFilterEditor({
103103
const regularFilter: FilterByIndex = {
104104
type: "indexEq",
105105
enabled: filter.enabled,
106-
value: newValue,
106+
value: convexToJson(newValue),
107107
};
108108
onChange(regularFilter, idx);
109109
}
@@ -167,7 +167,13 @@ export function IndexFilterEditor({
167167
if (filter.type !== "indexEq") {
168168
throw new Error("Called handleValueChange for non-equals filter");
169169
}
170-
onChange({ ...filter, value }, idx);
170+
onChange(
171+
{
172+
...filter,
173+
value: value === undefined ? undefined : convexToJson(value),
174+
},
175+
idx,
176+
);
171177
},
172178
[filter, idx, onChange],
173179
);
@@ -238,23 +244,23 @@ export function IndexFilterEditor({
238244
const handleLowerValueChange = useCallback(
239245
(value?: Value) => {
240246
if ("lowerValue" in filter) {
241-
// Convert Value to JSONValue to ensure compatibility
242-
const jsonValue: JSONValue | undefined =
243-
value === undefined
244-
? null
245-
: typeof value === "bigint"
246-
? Number(value)
247-
: (value as JSONValue);
248-
onChange({ ...filter, lowerValue: jsonValue }, idx);
247+
onChange(
248+
{
249+
...filter,
250+
lowerValue: value === undefined ? undefined : convexToJson(value),
251+
},
252+
idx,
253+
);
249254

250255
// Check if lowerValue is greater than upperValue
251256
if (
252257
filter.type === "indexRange" &&
253-
jsonValue !== null &&
258+
value !== null &&
259+
value !== undefined &&
254260
filter.upperValue !== null &&
255261
filter.upperValue !== undefined &&
256-
typeof jsonValue === typeof filter.upperValue &&
257-
jsonValue > filter.upperValue
262+
typeof value === typeof filter.upperValue &&
263+
value > filter.upperValue
258264
) {
259265
onError(idx, [RANGE_ERROR_MESSAGE]);
260266
}
@@ -266,23 +272,23 @@ export function IndexFilterEditor({
266272
const handleUpperValueChange = useCallback(
267273
(value?: Value) => {
268274
if ("upperValue" in filter) {
269-
// Convert Value to JSONValue to ensure compatibility
270-
const jsonValue: JSONValue | undefined =
271-
value === undefined
272-
? null
273-
: typeof value === "bigint"
274-
? Number(value)
275-
: (value as JSONValue);
276-
onChange({ ...filter, upperValue: jsonValue }, idx);
275+
onChange(
276+
{
277+
...filter,
278+
upperValue: value === undefined ? undefined : convexToJson(value),
279+
},
280+
idx,
281+
);
277282

278283
// Check if upperValue is less than lowerValue
279284
if (
280285
filter.type === "indexRange" &&
281-
jsonValue !== null &&
286+
value !== null &&
287+
value !== undefined &&
282288
filter.lowerValue !== null &&
283289
filter.lowerValue !== undefined &&
284-
typeof jsonValue === typeof filter.lowerValue &&
285-
jsonValue < filter.lowerValue
290+
typeof value === typeof filter.lowerValue &&
291+
value < filter.lowerValue
286292
) {
287293
onError(idx, [RANGE_ERROR_MESSAGE]);
288294
}

0 commit comments

Comments
 (0)