fix(objects): exclude type labels from browser search

This commit is contained in:
jearhe authored and GitHub committed 2026-08-18 10:51:13 +08:00
1 parent b6df771760
commit 665e5920c9
2 files changed
+39 -3

No files matched your search

@@ -231,9 +231,14 @@ export function filterObjectBrowserRows(rows: ObjectBrowserRow[], query: string)
if (!q) return rows; if (!q) return rows;
const regex = parseSlashDelimitedRegexQuery(query.trim()); const regex = parseSlashDelimitedRegexQuery(query.trim());
if (regex) { if (regex) {
return rows.filter((row) => [row.displayName, row.name, row.type, row.comment].filter(Boolean).some((value) => regex.test(String(value)))); // Object type labels ("TABLE", "VIEW", "PROCEDURE", ...) are deliberately
// not searchable: a query like "TAB" would otherwise match every TABLE row
// via its type label (issue #6488). The type filter buttons cover type
// scoping, and every other search path (sidebar tree, backend metadata)
// matches names and comments only.
return rows.filter((row) => [row.displayName, row.name, row.comment].filter(Boolean).some((value) => regex.test(String(value))));
} }
return rows.filter((row) => [row.displayName, row.name, row.type, row.comment].filter(Boolean).some((value) => String(value).toLowerCase().includes(q))); return rows.filter((row) => [row.displayName, row.name, row.comment].filter(Boolean).some((value) => String(value).toLowerCase().includes(q)));
} }
export function countObjectBrowserRowsByFilter(rows: ObjectBrowserRow[]): ObjectBrowserFilterCounts { export function countObjectBrowserRowsByFilter(rows: ObjectBrowserRow[]): ObjectBrowserFilterCounts {
+32 -1
View File
@@ -94,7 +94,7 @@ test("object browser rows normalize space separated materialized views", () => {
); );
}); });
test("object browser search matches names, types, and comments but not schema names", () => { test("object browser search matches names and comments but not schema names", () => {
const rows = buildObjectBrowserRows({ const rows = buildObjectBrowserRows({
objects: [ objects: [
{ name: "users", object_type: "TABLE", schema: "exam_hub", comment: "account records" }, { name: "users", object_type: "TABLE", schema: "exam_hub", comment: "account records" },
@@ -112,6 +112,37 @@ test("object browser search matches names, types, and comments but not schema na
); );
}); });
test("object browser search matches names, never object type labels", () => {
const rows = buildObjectBrowserRows({
objects: [
{ name: "tab_history", object_type: "TABLE", schema: "public" },
{ name: "user_accounts", object_type: "TABLE", schema: "public", comment: "user account records" },
{ name: "v_sales_summary", object_type: "VIEW", schema: "public" },
{ name: "refresh_sales", object_type: "PROCEDURE", schema: "public" },
],
database: "app",
fallbackSchema: "public",
needsSchema: true,
});
const names = (query: string) => filterObjectBrowserRows(rows, query).map((row) => row.name);
// "TAB" must not surface every TABLE row through its type label (issue #6488).
assert.deepEqual(names("TAB"), ["tab_history"]);
assert.deepEqual(names("tab"), ["tab_history"]);
assert.deepEqual(names("Tab"), ["tab_history"]);
assert.deepEqual(names("TABLE"), []);
assert.deepEqual(names("VIEW"), []);
// Name prefix and middle-substring matching keep working.
assert.deepEqual(names("sales"), ["v_sales_summary", "refresh_sales"]);
assert.deepEqual(names("history"), ["tab_history"]);
// Comment matching keeps working.
assert.deepEqual(names("accounts"), ["user_accounts"]);
// Non-existent keywords return nothing; empty queries keep everything.
assert.deepEqual(names("TAB1"), []);
assert.equal(names(" ").length, rows.length);
});
test("object browser search supports slash-delimited regular expression queries", () => { test("object browser search supports slash-delimited regular expression queries", () => {
const rows = buildObjectBrowserRows({ const rows = buildObjectBrowserRows({
objects: [ objects: [