Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

improvement: add global text search to filters table, sticky header (#1265)

Myles Scolnickf51cc471ec09
diff --git a/frontend/src/components/ui/input.tsx b/frontend/src/components/ui/input.tsx
index 3213c917ec..e0aa3e2d41 100644
--- a/frontend/src/components/ui/input.tsx
+++ b/frontend/src/components/ui/input.tsx
@@ -5,7 +5,7 @@ import { cn } from "@/utils/cn";
import { useDebounceControlledState } from "@/hooks/useDebounce";
import { Events } from "@/utils/events";
import { NumberField, NumberFieldProps } from "@/components/ui/number-field";
-import { SearchIcon } from "lucide-react";
+import { SearchIcon, XIcon } from "lucide-react";
export type InputProps = React.InputHTMLAttributes<HTMLInputElement> & {
icon?: React.ReactNode;
@@ -108,14 +108,17 @@ export const SearchInput = React.forwardRef<
InputProps & {
rootClassName?: string;
icon?: React.ReactNode | null;
+ clearable?: boolean;
}
->(({ className, rootClassName, icon, ...props }, ref) => {
+>(({ className, rootClassName, icon, clearable = true, ...props }, ref) => {
+ const id = React.useId();
return (
<div className={cn("flex items-center border-b px-3", rootClassName)}>
{icon === null ? null : (
<SearchIcon className="mr-2 h-4 w-4 shrink-0 opacity-50" />
)}
<input
+ id={id}
ref={ref}
className={cn(
"placeholder:text-foreground-muted flex h-7 m-1 w-full rounded-md bg-transparent py-3 text-sm outline-none disabled:cursor-not-allowed disabled:opacity-50",
@@ -123,6 +126,27 @@ export const SearchInput = React.forwardRef<
)}
{...props}
/>
+ {clearable && props.value && (
+ <span
+ onPointerDown={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ const input = document.getElementById(id);
+ if (input && input instanceof HTMLInputElement) {
+ input.focus();
+ input.value = "";
+ props.onChange?.({
+ ...e,
+ target: input,
+ currentTarget: input,
+ type: "change",
+ } as React.ChangeEvent<HTMLInputElement>);
+ }
+ }}
+ >
+ <XIcon className="h-4 w-4 opacity-50 hover:opacity-90" />
+ </span>
+ )}
</div>
);
});
diff --git a/frontend/src/components/variables/variables-table.tsx b/frontend/src/components/variables/variables-table.tsx
index 854b0d64f3..9825ea220f 100644
--- a/frontend/src/components/variables/variables-table.tsx
+++ b/frontend/src/components/variables/variables-table.tsx
@@ -23,11 +23,13 @@ import {
SortingState,
getSortedRowModel,
ColumnSort,
+ getFilteredRowModel,
} from "@tanstack/react-table";
import { DataTableColumnHeader } from "../data-table/column-header";
import { sortBy } from "lodash-es";
import { getCellEditorView } from "@/core/cells/cells";
import { goToDefinition } from "@/core/codemirror/find-replace/search-highlight";
+import { SearchInput } from "../ui/input";
interface Props {
className?: string;
@@ -232,6 +234,7 @@ function sortData(
export const VariableTable: React.FC<Props> = memo(
({ className, cellIds, variables }) => {
const [sorting, setSorting] = React.useState<SortingState>([]);
+ const [globalFilter, setGlobalFilter] = React.useState("");
const sortedVariables = useMemo(() => {
const cellIdToIndex = new Map<CellId, number>();
@@ -243,39 +246,68 @@ export const VariableTable: React.FC<Props> = memo(
data: sortedVariables,
columns: COLUMNS,
getCoreRowModel: getCoreRowModel(),
+ // filtering
+ onGlobalFilterChange: setGlobalFilter,
+ getFilteredRowModel: getFilteredRowModel(),
+ enableFilters: true,
+ enableGlobalFilter: true,
+ getColumnCanGlobalFilter(column) {
+ // Opt-out only
+ return column.columnDef.enableGlobalFilter ?? true;
+ },
+ globalFilterFn: "auto",
// sorting
manualSorting: true,
onSortingChange: setSorting,
getSortedRowModel: getSortedRowModel(),
- state: { sorting },
+ state: {
+ sorting,
+ globalFilter,
+ },
});
return (
- <Table className={cn("w-full overflow-hidden text-sm flex-1", className)}>
- <TableHeader>
- <TableRow className="whitespace-nowrap text-xs">
- {table.getFlatHeaders().map((header) => (
- <TableHead key={header.id}>
- {flexRender(
- header.column.columnDef.header,
- header.getContext(),
- )}
- </TableHead>
- ))}
- </TableRow>
- </TableHeader>
- <TableBody>
- {table.getRowModel().rows.map((row) => (
- <TableRow key={row.id} className="hover:bg-accent">
- {row.getVisibleCells().map((cell) => (
- <TableCell key={cell.id}>
- {flexRender(cell.column.columnDef.cell, cell.getContext())}
- </TableCell>
+ <>
+ <SearchInput
+ className="w-full"
+ placeholder="Search"
+ value={globalFilter}
+ onChange={(e) => setGlobalFilter(e.target.value)}
+ />
+ <Table
+ className={cn(
+ "w-full text-sm flex-1 border-separate border-spacing-0",
+ className,
+ )}
+ >
+ <TableHeader>
+ <TableRow className="whitespace-nowrap text-xs">
+ {table.getFlatHeaders().map((header) => (
+ <TableHead
+ key={header.id}
+ className="sticky top-0 bg-background border-b"
+ >
+ {flexRender(
+ header.column.columnDef.header,
+ header.getContext(),
+ )}
+ </TableHead>
))}
</TableRow>
- ))}
- </TableBody>
- </Table>
+ </TableHeader>
+ <TableBody>
+ {table.getRowModel().rows.map((row) => (
+ <TableRow key={row.id} className="hover:bg-accent">
+ {row.getVisibleCells().map((cell) => (
+ <TableCell key={cell.id} className="border-b">
+ {flexRender(cell.column.columnDef.cell, cell.getContext())}
+ </TableCell>
+ ))}
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ </>
);
},
);