Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix: stop variables search from matching internal cell IDs
  • Loading branch information
burrows99 committed Nov 15, 2026
commit 7d9e42253d8234721b090a3820c546347aa42cc5
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,78 @@ describe("VariableTable cell links", () => {
);
});
});

describe("VariableTable search", () => {
const importCell = cellId("Hbol");
const summaryCell = cellId("Xref");

const renderTable = () => {
store.set(
notebookAtom,
MockNotebook.notebookState({
cellData: {
[importCell]: { name: "_" },
[summaryCell]: { name: "report" },
},
}),
);
const variables: Variables = {
[variableName("reference")]: {
dataType: "str",
declaredBy: [importCell],
name: variableName("reference"),
usedBy: [],
value: "ORDER-1042",
},
[variableName("Total")]: {
dataType: "float",
declaredBy: [importCell],
name: variableName("Total"),
usedBy: [summaryCell],
value: "50.7",
},
[variableName("summary")]: {
dataType: "Html",
declaredBy: [summaryCell],
name: variableName("summary"),
usedBy: [],
value: null,
},
};
render(
<Provider store={store}>
<TooltipProvider>
<VariableTable
cellIds={[importCell, summaryCell]}
variables={variables}
/>
</TooltipProvider>
</Provider>,
);
};

const search = (query: string) => {
fireEvent.change(screen.getByPlaceholderText("Search"), {
target: { value: query },
});
return ["reference", "Total", "summary"].filter(
(name) => screen.queryByText(name) !== null,
);
};

test("does not match the IDs of the declaring or using cells", () => {
renderTable();
expect(search("ref")).toEqual(["reference"]);
expect(search("Hbol")).toEqual([]);
});

test("matches name, type, value and cell names, ignoring case", () => {
renderTable();
expect(search("TOTAL")).toEqual(["Total"]);
expect(search("float")).toEqual(["Total"]);
expect(search("order-10")).toEqual(["reference"]);
expect(search("report")).toEqual(["Total", "summary"]);
expect(search("cell-0")).toEqual(["reference", "Total"]);
expect(search("")).toEqual(["reference", "Total", "summary"]);
});
});
28 changes: 18 additions & 10 deletions frontend/src/components/variables/variables-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,7 @@ const COLUMNS = [
}),
columnDefOf({
id: ColumnIds.defs,
// Include declaredByNames and usedByNames for filtering
accessorFn: (v) =>
[
v.declaredBy,
v.usedBy,
v.name,
v.declaredByNames,
v.usedByNames,
] as const,
accessorFn: (v) => [v.declaredBy, v.usedBy, v.name] as const,
enableSorting: true,
sortingFn: "basic",
header: ({ column }) => (
Expand Down Expand Up @@ -192,6 +184,21 @@ const COLUMNS = [
}),
];

/**
* Search the text the table shows. Cell IDs are internal, so they are left
* out; cells are searched by name instead.
*/
function matchesSearch(variable: ResolvedVariable, search: string): boolean {
const query = search.toLowerCase();
return [
variable.name,
variable.dataType,
variable.value,
...variable.declaredByNames,
...variable.usedByNames,
].some((text) => text?.toLowerCase().includes(query));
}

/**
* Sort the variables by the specified column sort
* Defaults to the order they are defined in the notebook
Expand Down Expand Up @@ -277,7 +284,8 @@ export const VariableTable: React.FC<Props> = memo(
// Opt-out only
return column.columnDef.enableGlobalFilter ?? true;
},
globalFilterFn: "auto",
globalFilterFn: (row, _columnId, search: string) =>
matchesSearch(row.original, search),
// sorting
manualSorting: true,
locale: locale,
Expand Down
Loading