fix(postgres): quote data grid condition completions
This commit is contained in:
1 parent
ff4eac3782
commit
4e926cf22a
6 files changed
+77
-4
No files matched your search
@@ -70,6 +70,39 @@ describe("useDataGridConditionEditor", () => {
|
||||
expect(editor.suggestions.value).toEqual([{ value: "customer_id = 1", kind: "history" }]);
|
||||
});
|
||||
|
||||
it.each(["where", "orderBy"] as const)("displays raw PostgreSQL column names but inserts their quoted %s text", async (kind) => {
|
||||
const value = ref("");
|
||||
const editor = useDataGridConditionEditor({
|
||||
kind,
|
||||
value,
|
||||
columns: [{ name: "OrderId", insertText: '"OrderId"', comment: "Mixed-case identifier" }],
|
||||
historyScope: {},
|
||||
});
|
||||
|
||||
value.value = kind === "where" ? "status = Order" : "created_at DESC, Order";
|
||||
await nextTick();
|
||||
await vi.waitFor(() => expect(editor.suggestions.value).toEqual([{ value: "OrderId", insertText: '"OrderId"', kind: "column", comment: "Mixed-case identifier" }]));
|
||||
|
||||
expect(editor.accept()).toBe(true);
|
||||
expect(value.value).toBe(kind === "where" ? 'status = "OrderId"' : 'created_at DESC, "OrderId"');
|
||||
});
|
||||
|
||||
it("restores quoted history verbatim instead of quoting it again", () => {
|
||||
const scope = { connectionId: "connection", database: "db", tableName: "orders" };
|
||||
rememberDataGridConditionHistory("orderBy", scope, '"OrderId" DESC');
|
||||
const value = ref("");
|
||||
const editor = useDataGridConditionEditor({
|
||||
kind: "orderBy",
|
||||
value,
|
||||
columns: [{ name: "OrderId", insertText: '"OrderId"' }],
|
||||
historyScope: scope,
|
||||
});
|
||||
|
||||
editor.openHistory();
|
||||
expect(editor.accept(0)).toBe(true);
|
||||
expect(value.value).toBe('"OrderId" DESC');
|
||||
});
|
||||
|
||||
it.each(["where", "orderBy"] as const)("normalizes %s comments from different metadata providers", async (kind) => {
|
||||
const value = ref("");
|
||||
const editor = useDataGridConditionEditor({
|
||||
|
||||
@@ -5,6 +5,7 @@ export type DataGridConditionSuggestionKind = "column" | "history";
|
||||
|
||||
export interface DataGridConditionColumnSuggestion {
|
||||
name: string;
|
||||
insertText?: string;
|
||||
comment?: string | null;
|
||||
}
|
||||
|
||||
@@ -12,6 +13,7 @@ export type DataGridConditionColumnOption = string | DataGridConditionColumnSugg
|
||||
|
||||
export interface DataGridConditionSuggestion {
|
||||
value: string;
|
||||
insertText?: string;
|
||||
kind: DataGridConditionSuggestionKind;
|
||||
comment?: string;
|
||||
}
|
||||
@@ -97,7 +99,8 @@ export function useDataGridConditionEditor(options: UseDataGridConditionEditorOp
|
||||
if (!normalizedValue.startsWith(normalizedToken) || normalizedValue === normalizedToken || seen.has(value)) continue;
|
||||
seen.add(value);
|
||||
const comment = normalizedColumnComment(column);
|
||||
suggestions.push({ value, kind: "column", ...(comment ? { comment } : {}) });
|
||||
const insertText = typeof column === "string" ? value : column.insertText;
|
||||
suggestions.push({ value, kind: "column", ...(insertText !== undefined && insertText !== value ? { insertText } : {}), ...(comment ? { comment } : {}) });
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
@@ -177,7 +180,8 @@ export function useDataGridConditionEditor(options: UseDataGridConditionEditorOp
|
||||
const suggestion = suggestions.value[index];
|
||||
if (!suggestion) return false;
|
||||
suppressNextValueSuggestion = true;
|
||||
options.value.value = suggestion.kind === "history" ? suggestion.value : replaceActiveToken(options.kind, options.value.value, suggestion.value);
|
||||
// History is already executable SQL; only fresh column suggestions apply dialect quoting.
|
||||
options.value.value = suggestion.kind === "history" ? suggestion.value : replaceActiveToken(options.kind, options.value.value, suggestion.insertText ?? suggestion.value);
|
||||
dismiss();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user