feat(grid): improve WHERE condition completion
This commit is contained in:
10 files changed
+576
-56
No files matched your search
+9
-1
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { dataGridConditionColumnOptions } from "@/lib/dataGrid/dataGridConditionCompletion";
|
||||
import { dataGridConditionColumnOptions, dataGridConditionIdentifierQuote } from "@/lib/dataGrid/dataGridConditionCompletion";
|
||||
|
||||
describe("dataGridConditionColumnOptions", () => {
|
||||
it("reuses PostgreSQL completion quoting while preserving display metadata", () => {
|
||||
@@ -17,4 +17,12 @@ describe("dataGridConditionColumnOptions", () => {
|
||||
{ name: "order", insertText: "order" },
|
||||
]);
|
||||
});
|
||||
|
||||
it("uses the active dialect identifier quote while preserving runtime overrides", () => {
|
||||
expect(dataGridConditionIdentifierQuote("postgres")).toBe('"');
|
||||
expect(dataGridConditionIdentifierQuote("oracle")).toBe('"');
|
||||
expect(dataGridConditionIdentifierQuote("sqlite")).toBe('"');
|
||||
expect(dataGridConditionIdentifierQuote("mysql")).toBe("`");
|
||||
expect(dataGridConditionIdentifierQuote("kingbase", "`")).toBe("`");
|
||||
});
|
||||
});
|
||||
+2
-1
@@ -34,10 +34,11 @@ describe("getDataGridConditionSuggestionPosition", () => {
|
||||
expect(position.width).toBeLessThanOrEqual(520);
|
||||
});
|
||||
|
||||
test("keeps normal width when suggestions have no comments or are history entries", () => {
|
||||
test("keeps normal width when suggestions have no comments or are keyword/history entries", () => {
|
||||
expect(
|
||||
getDataGridConditionSuggestionPreferredWidth([
|
||||
{ value: "customer_id", kind: "column", comment: "" },
|
||||
{ value: "AND", kind: "keyword" },
|
||||
{ value: "status = 'active'", kind: "history" },
|
||||
]),
|
||||
).toBeUndefined();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { DataGridConditionColumnOption } from "@/composables/useDataGridConditionEditor";
|
||||
import { codeMirrorSqlDialect } from "@/lib/database/jdbcDialect";
|
||||
import { quoteSqlIdentifier } from "@/lib/sql/sqlCompletion";
|
||||
import { sqlSemanticDialectFor } from "@/lib/sql/semantic/dialect";
|
||||
import type { DatabaseType } from "@/types/database";
|
||||
|
||||
export function dataGridConditionColumnOptions(columns: readonly DataGridConditionColumnOption[], databaseType?: DatabaseType): DataGridConditionColumnOption[] {
|
||||
@@ -12,3 +13,8 @@ export function dataGridConditionColumnOptions(columns: readonly DataGridConditi
|
||||
return { name, insertText, ...(comment !== undefined ? { comment } : {}) };
|
||||
});
|
||||
}
|
||||
|
||||
export function dataGridConditionIdentifierQuote(databaseType?: DatabaseType, runtimeQuote?: string): string | undefined {
|
||||
if (runtimeQuote !== undefined) return runtimeQuote || undefined;
|
||||
return sqlSemanticDialectFor({ databaseType }).identifierQuotes[0]?.open;
|
||||
}
|
||||
@@ -21,7 +21,7 @@ export interface DataGridConditionSuggestionPosition {
|
||||
|
||||
export interface DataGridConditionSuggestionContent {
|
||||
value: string;
|
||||
kind: "column" | "history";
|
||||
kind: "column" | "keyword" | "history";
|
||||
comment?: string | null;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user