feat(grid): enhance field search and filter interaction

This commit is contained in:
zipg authored and GitHub committed 2026-08-07 13:43:55 +08:00
1 parent 13878a1a30
commit f9e93b356f
26 files changed
+491 -35

No files matched your search

@@ -0,0 +1,10 @@
import { describe, expect, it } from "vitest";
import { buildDocumentFilterCondition, documentFilterModeOptions } from "@/lib/app/documentStoreProvider";
describe("document store structured filters", () => {
it("offers and builds inclusive comparison filters", () => {
expect(documentFilterModeOptions.map((option) => option.value)).toEqual(expect.arrayContaining(["greater-than-or-equal", "less-than-or-equal"]));
expect(buildDocumentFilterCondition({ id: "gte", fieldName: "score", mode: "greater-than-or-equal", rawValue: "80", conjunction: "AND" })).toEqual({ score: { $gte: 80 } });
expect(buildDocumentFilterCondition({ id: "lte", fieldName: "score", mode: "less-than-or-equal", rawValue: "80", conjunction: "AND" })).toEqual({ score: { $lte: 80 } });
});
});
@@ -0,0 +1,20 @@
import { describe, expect, it } from "vitest";
import { buildDataGridColumnLookupItems, filterDataGridColumnLookupItems } from "@/lib/dataGrid/dataGridColumnLookup";
describe("data grid column lookup search", () => {
const items = buildDataGridColumnLookupItems({
columns: ["userProfile", "order_id", "created_at"],
});
it("matches camel-case initials", () => {
expect(filterDataGridColumnLookupItems(items, "up").map((item) => item.name)).toEqual(["userProfile"]);
});
it("matches text from any position", () => {
expect(filterDataGridColumnLookupItems(items, "id").map((item) => item.name)).toEqual(["order_id"]);
});
it("returns all columns for an empty query", () => {
expect(filterDataGridColumnLookupItems(items, " ")).toEqual(items);
});
});
@@ -2,6 +2,24 @@ import { describe, expect, it } from "vitest";
import { containsHan, matchesPinyinInitials, orderedSubsequenceSpan, pinyinAwareMatchScore, pinyinFirstLetters } from "@/lib/common/pinyin";
import { completionMatchRanges } from "@/lib/common/completionMatch";
import { buildSqlCompletionItems } from "@/lib/sql/sqlCompletion";
import { identifierMatchScore, matchesIdentifierSearch } from "@/lib/sql/identifierSearch";
describe("identifier search", () => {
it("matches camel-case initials and ranks them above loose fuzzy matches", () => {
expect(matchesIdentifierSearch("userProfile", "up")).toBe(true);
expect(identifierMatchScore("userProfile", "up")).toBeGreaterThan(identifierMatchScore("userPreference", "up"));
});
it("matches an identifier from any position", () => {
expect(matchesIdentifierSearch("order_id", "id")).toBe(true);
expect(matchesIdentifierSearch("created_at", "id")).toBe(false);
expect(matchesIdentifierSearch("customer_order_total", "cot")).toBe(true);
});
it("keeps unrelated identifiers out of the result", () => {
expect(matchesIdentifierSearch("userProfile", "xyz")).toBe(false);
});
});
describe("pinyinAwareMatchScore", () => {
it("ranks prefix above pinyin prefix above substring above pinyin subsequence", () => {
@@ -127,3 +145,35 @@ describe("sqlCompletion Chinese column matching", () => {
expect(items.some((item) => item.label === "总租金")).toBe(false);
});
});
describe("sqlCompletion identifier column matching", () => {
function completionItems(typedPrefix: string) {
const sql = `SELECT * FROM orders WHERE ${typedPrefix}`;
return buildSqlCompletionItems(sql, sql.length, {
databaseType: "mysql",
tables: [{ name: "orders", type: "table" }],
columnsByTable: new Map([
[
"orders",
[
{ name: "userProfile", table: "orders" },
{ name: "order_id", table: "orders" },
{ name: "created_at", table: "orders" },
],
],
]),
});
}
it("matches camel-case initials in WHERE column completion", () => {
const items = completionItems("up");
expect(items).toEqual(expect.arrayContaining([expect.objectContaining({ label: "userProfile", type: "column" })]));
expect(items.some((item) => item.label === "order_id")).toBe(false);
});
it("matches WHERE columns from any position", () => {
const items = completionItems("id");
expect(items).toEqual(expect.arrayContaining([expect.objectContaining({ label: "order_id", type: "column" })]));
expect(items.some((item) => item.label === "created_at")).toBe(false);
});
});