Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion crates/bindings-typescript/src/react/useTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { type EventContextInterface } from '../sdk/db_connection_impl';
import type { ConnectionState } from './connection_state';
import type { UntypedRemoteModule } from '../sdk/spacetime_module';
import type { RowType, UntypedTableDef } from '../lib/table';
import { Uuid } from '../lib/uuid';
import type { Prettify } from '../lib/type_util';

export interface UseTableCallbacks<RowType> {
Expand All @@ -18,7 +19,7 @@ export interface UseTableCallbacks<RowType> {
onUpdate?: (oldRow: RowType, newRow: RowType) => void;
}

export type Value = string | number | boolean;
export type Value = string | number | boolean | Uuid;

export type Expr<Column extends string> =
| { type: 'eq'; key: Column; value: Value }
Expand Down Expand Up @@ -76,6 +77,7 @@ export function evaluate<Column extends string>(
): boolean {
switch (expr.type) {
case 'eq': {
// The actual value of the Column
const v = row[expr.key];
if (
typeof v === 'string' ||
Expand All @@ -84,6 +86,16 @@ export function evaluate<Column extends string>(
) {
return v === expr.value;
}
if (typeof v === 'object') {
// Value of the Column and passed Value are both a Uuid so do an integer comparison.
if (v instanceof Uuid && expr.value instanceof Uuid) {
return v.asBigInt() === expr.value.asBigInt();
}
// Value of the Column is a Uuid but passed Value is a String so compare them via string.
if (v instanceof Uuid && typeof expr.value === 'string') {
return v.toString() === expr.value;
}
}
return false;
}
case 'and':
Expand All @@ -105,6 +117,13 @@ function formatValue(v: Value): string {
return Number.isFinite(v) ? String(v) : `'${String(v)}'`;
case 'boolean':
return v ? 'TRUE' : 'FALSE';
case 'object': {
if (v instanceof Uuid) {
return `'${v.toString()}'`;
}

return '';
}
}
}

Expand Down
Loading