fix(app): exclude schema from object search

This commit is contained in:
t8y2 2026-05-19 14:01:59 +08:00
parent c1ba7235b9
commit ec0e2498ca
3 changed files with 30 additions and 12 deletions

View File

@ -47,7 +47,7 @@ import QueryEditor from "@/components/editor/QueryEditor.vue";
import type { SqlFormatDialect } from "@/lib/sqlFormatter";
import { isCancelSearchShortcut } from "@/lib/keyboardShortcuts";
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { buildObjectBrowserRows, type ObjectBrowserRow } from "@/lib/objectBrowserRows";
import { buildObjectBrowserRows, filterObjectBrowserRows, type ObjectBrowserRow } from "@/lib/objectBrowserRows";
type ObjectFilter = "all" | "tables" | "views" | "procedures" | "functions";
@ -129,16 +129,10 @@ const objectFilters = computed<ObjectFilter[]>(() =>
const showObjectFilter = computed(() => objectFilters.value.length > 2);
const hasComments = computed(() => rows.value.some((row) => row.comment?.trim()));
const gridTemplateColumns = computed(() =>
hasComments.value ? "minmax(0,1fr) 120px 160px minmax(160px,0.7fr)" : "minmax(0,1fr) 120px 160px",
hasComments.value ? "minmax(0,1fr) 120px minmax(160px,0.7fr)" : "minmax(0,1fr) 120px",
);
const searchedRows = computed(() => {
const q = search.value.trim().toLowerCase();
if (!q) return rows.value;
return rows.value.filter((row) =>
[row.name, row.schema, row.type, row.comment]
.filter(Boolean)
.some((value) => String(value).toLowerCase().includes(q)),
);
return filterObjectBrowserRows(rows.value, search.value);
});
const filteredRows = computed(() => {
if (objectFilter.value === "tables") return searchedRows.value.filter((row) => row.type === "TABLE");
@ -614,7 +608,6 @@ watch(
>
<div class="truncate">{{ t("objects.name") }}</div>
<div class="truncate">{{ t("objects.type") }}</div>
<div class="truncate">{{ t("objects.schemaColumn") }}</div>
<div v-if="hasComments" class="truncate">{{ t("objects.comment") }}</div>
</div>
<RecycleScroller
@ -639,7 +632,6 @@ watch(
<span class="truncate text-[13px] font-medium text-foreground">{{ item.name }}</span>
</div>
<div class="truncate text-xs text-muted-foreground">{{ typeLabel(item.type) }}</div>
<div class="truncate text-xs text-muted-foreground">{{ item.schema || props.database }}</div>
<div v-if="hasComments" class="truncate text-xs text-muted-foreground" :title="item.comment || ''">
{{ item.comment || "" }}
</div>

View File

@ -44,3 +44,11 @@ export function buildObjectBrowserRows(options: {
];
});
}
export function filterObjectBrowserRows(rows: ObjectBrowserRow[], query: string): ObjectBrowserRow[] {
const q = query.trim().toLowerCase();
if (!q) return rows;
return rows.filter((row) =>
[row.name, row.type, row.comment].filter(Boolean).some((value) => String(value).toLowerCase().includes(q)),
);
}

View File

@ -1,6 +1,6 @@
import { strict as assert } from "node:assert";
import test from "node:test";
import { buildObjectBrowserRows } from "../../apps/desktop/src/lib/objectBrowserRows.ts";
import { buildObjectBrowserRows, filterObjectBrowserRows } from "../../apps/desktop/src/lib/objectBrowserRows.ts";
test("builds unique row ids for overloaded routines with the same visible name", () => {
const rows = buildObjectBrowserRows({
@ -19,3 +19,21 @@ test("builds unique row ids for overloaded routines with the same visible name",
["dbms_pipe:list_pipes:FUNCTION:0", "dbms_pipe:list_pipes:FUNCTION:1", "dbms_pipe:create_pipe:FUNCTION:0"],
);
});
test("object browser search matches names, types, and comments but not schema names", () => {
const rows = buildObjectBrowserRows({
objects: [
{ name: "users", object_type: "TABLE", schema: "exam_hub", comment: "account records" },
{ name: "orders", object_type: "TABLE", schema: "sales", comment: "exam invoices" },
{ name: "refresh_exam_stats", object_type: "PROCEDURE", schema: "public" },
],
database: "app",
fallbackSchema: "public",
needsSchema: true,
});
assert.deepEqual(
filterObjectBrowserRows(rows, "exam").map((row) => row.name),
["orders", "refresh_exam_stats"],
);
});