feat(salesforce): add Salesforce SOQL data source
This commit is contained in:
125 files changed
+9999
-117
No files matched your search
@@ -948,11 +948,13 @@ describe("useDataGridEditor saveChanges reload", () => {
|
||||
currentPage?: Ref<number>;
|
||||
prepareFullReload?: () => void;
|
||||
customSaveHandler?: { save: ReturnType<typeof vi.fn> };
|
||||
confirmSaveRequest?: (request: import("@/composables/useDataGridEditor").DataGridSaveConfirmationRequest) => Promise<boolean>;
|
||||
manualTransactionSessionId?: string;
|
||||
ensureManualTransactionSession?: () => Promise<string>;
|
||||
refreshSavedRows?: ReturnType<typeof vi.fn>;
|
||||
onManualTransactionMutation?: ReturnType<typeof vi.fn>;
|
||||
connectionId?: string;
|
||||
databaseType?: import("@/types/database").DatabaseType;
|
||||
primaryKeys?: string[];
|
||||
onExecuteSql?: (sql: string) => Promise<void>;
|
||||
} = {},
|
||||
@@ -971,7 +973,7 @@ describe("useDataGridEditor saveChanges reload", () => {
|
||||
const editor = useDataGridEditor({
|
||||
result: computed(() => result.value),
|
||||
editable: computed(() => true),
|
||||
databaseType: computed(() => "mysql"),
|
||||
databaseType: computed(() => options.databaseType ?? "mysql"),
|
||||
connectionId: computed(() => ("connectionId" in options ? options.connectionId : "connection-1")),
|
||||
database: computed(() => "app"),
|
||||
tableMeta: computed(() => ({
|
||||
@@ -986,6 +988,7 @@ describe("useDataGridEditor saveChanges reload", () => {
|
||||
joinedWriteTargets: computed(() => options.joinedWriteTargets),
|
||||
onExecuteSql: computed(() => options.onExecuteSql),
|
||||
customSaveHandler: computed(() => options.customSaveHandler),
|
||||
confirmSaveRequest: computed(() => options.confirmSaveRequest),
|
||||
manualTransactionSessionId: computed(() => options.manualTransactionSessionId),
|
||||
ensureManualTransactionSession: computed(() => ensureManualTransactionSession.value),
|
||||
onManualTransactionMutation: options.onManualTransactionMutation,
|
||||
@@ -1390,6 +1393,62 @@ describe("useDataGridEditor saveChanges reload", () => {
|
||||
expect(prepareFullReload).not.toHaveBeenCalled();
|
||||
expect(emit).not.toHaveBeenCalledWith("reload", expect.anything());
|
||||
});
|
||||
|
||||
// Engines that cannot roll a partial batch back (Salesforce: one REST call per
|
||||
// record) hand the operation list to the host for review before it is written.
|
||||
it("summarizes inserts, updates and deletes for the host save confirmation and writes once accepted", async () => {
|
||||
mocks.prepareDataGridSave.mockResolvedValue({ statements: ["stmt-1", "stmt-2", "stmt-3"], rollbackStatements: [] });
|
||||
mocks.executeBatch.mockResolvedValue({ affected_rows: 1 });
|
||||
const confirmSaveRequest = vi.fn().mockResolvedValue(true);
|
||||
|
||||
const { editor } = createSaveTestEditor({ confirmSaveRequest, databaseType: "salesforce" });
|
||||
editor.dirtyRows.value.set(0, new Map([[1, "shipped"]]));
|
||||
editor.addRows(1);
|
||||
editor.deletedRows.value.add(1);
|
||||
|
||||
await editor.saveChanges();
|
||||
|
||||
expect(confirmSaveRequest).toHaveBeenCalledTimes(1);
|
||||
expect(confirmSaveRequest.mock.calls[0]?.[0]).toMatchObject({
|
||||
updates: 1,
|
||||
inserts: 1,
|
||||
deletes: 1,
|
||||
targetLabel: "orders_test",
|
||||
statements: ["stmt-1", "stmt-2", "stmt-3"],
|
||||
});
|
||||
expect(mocks.executeBatch).toHaveBeenCalledTimes(1);
|
||||
expect(editor.saveError.value).toBeFalsy();
|
||||
});
|
||||
|
||||
it("keeps every edit staged and reports no error when the host declines the save", async () => {
|
||||
mocks.prepareDataGridSave.mockResolvedValue({ statements: ["stmt-1"], rollbackStatements: [] });
|
||||
const confirmSaveRequest = vi.fn().mockResolvedValue(false);
|
||||
|
||||
const { editor } = createSaveTestEditor({ confirmSaveRequest, databaseType: "salesforce" });
|
||||
editor.dirtyRows.value.set(0, new Map([[1, "shipped"]]));
|
||||
|
||||
await editor.saveChanges();
|
||||
|
||||
expect(confirmSaveRequest).toHaveBeenCalledTimes(1);
|
||||
expect(mocks.executeBatch).not.toHaveBeenCalled();
|
||||
expect(editor.dirtyRows.value.get(0)?.get(1)).toBe("shipped");
|
||||
expect(editor.isSaving.value).toBe(false);
|
||||
expect(editor.saveError.value).toBeFalsy();
|
||||
});
|
||||
|
||||
it("never writes an auto-save past a required confirmation", async () => {
|
||||
mocks.prepareDataGridSave.mockResolvedValue({ statements: ["stmt-1"], rollbackStatements: [] });
|
||||
const confirmSaveRequest = vi.fn().mockResolvedValue(true);
|
||||
|
||||
const { editor } = createSaveTestEditor({ confirmSaveRequest, databaseType: "salesforce" });
|
||||
editor.dirtyRows.value.set(0, new Map([[1, "shipped"]]));
|
||||
|
||||
await editor.saveChanges({ autoSave: true });
|
||||
|
||||
expect(confirmSaveRequest).not.toHaveBeenCalled();
|
||||
expect(mocks.executeBatch).not.toHaveBeenCalled();
|
||||
expect(editor.dirtyRows.value.get(0)?.get(1)).toBe("shipped");
|
||||
});
|
||||
});
|
||||
|
||||
describe("useDataGridEditor cell edit focus", () => {
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { effectScope, type EffectScope } from "vue";
|
||||
import { useSalesforceSaveConfirmation } from "@/composables/useSalesforceSaveConfirmation";
|
||||
import type { DataGridSaveConfirmationRequest } from "@/composables/useDataGridEditor";
|
||||
|
||||
const saveRequest: DataGridSaveConfirmationRequest = {
|
||||
updates: 2,
|
||||
inserts: 1,
|
||||
deletes: 0,
|
||||
targetLabel: "Account",
|
||||
statements: ['DBX SALESFORCE DML\n{"op":"update","object":"Account","id":"001xx000003DGbY","fields":{"Name":"Acme"}}'],
|
||||
};
|
||||
|
||||
function createConfirmation(): { scope: EffectScope; confirmation: ReturnType<typeof useSalesforceSaveConfirmation> } {
|
||||
const scope = effectScope();
|
||||
const confirmation = scope.run(() => useSalesforceSaveConfirmation());
|
||||
if (!confirmation) throw new Error("useSalesforceSaveConfirmation must run inside an effect scope");
|
||||
return { scope, confirmation };
|
||||
}
|
||||
|
||||
describe("useSalesforceSaveConfirmation", () => {
|
||||
it("parks the save until the dialog confirms and exposes the batch summary", async () => {
|
||||
const { confirmation } = createConfirmation();
|
||||
const decision = confirmation.request(saveRequest);
|
||||
|
||||
expect(confirmation.open.value).toBe(true);
|
||||
expect(confirmation.pending.value).toEqual(saveRequest);
|
||||
expect(confirmation.updates.value).toBe(2);
|
||||
expect(confirmation.inserts.value).toBe(1);
|
||||
expect(confirmation.deletes.value).toBe(0);
|
||||
expect(confirmation.total.value).toBe(3);
|
||||
expect(confirmation.targetLabel.value).toBe("Account");
|
||||
expect(confirmation.statements.value).toEqual(saveRequest.statements);
|
||||
// The save stays parked: nothing is written to Salesforce until the operator decides.
|
||||
await Promise.resolve();
|
||||
expect(confirmation.open.value).toBe(true);
|
||||
|
||||
confirmation.confirm();
|
||||
|
||||
await expect(decision).resolves.toBe(true);
|
||||
expect(confirmation.open.value).toBe(false);
|
||||
expect(confirmation.pending.value).toBeNull();
|
||||
});
|
||||
|
||||
it("denies the save when the dialog is dismissed", async () => {
|
||||
const { confirmation } = createConfirmation();
|
||||
const decision = confirmation.request(saveRequest);
|
||||
|
||||
// `v-model:open` writes false on Cancel, Escape and backdrop clicks alike.
|
||||
confirmation.open.value = false;
|
||||
|
||||
await expect(decision).resolves.toBe(false);
|
||||
expect(confirmation.pending.value).toBeNull();
|
||||
});
|
||||
|
||||
it("denies a second concurrent save instead of leaving it waiting on a hidden dialog", async () => {
|
||||
const { confirmation } = createConfirmation();
|
||||
const first = confirmation.request(saveRequest);
|
||||
|
||||
await expect(confirmation.request({ ...saveRequest, updates: 5 })).resolves.toBe(false);
|
||||
|
||||
expect(confirmation.open.value).toBe(true);
|
||||
expect(confirmation.updates.value).toBe(2);
|
||||
confirmation.confirm();
|
||||
await expect(first).resolves.toBe(true);
|
||||
});
|
||||
|
||||
it("denies a parked save when the grid is torn down mid-review", async () => {
|
||||
const { scope, confirmation } = createConfirmation();
|
||||
const decision = confirmation.request(saveRequest);
|
||||
|
||||
scope.stop();
|
||||
|
||||
await expect(decision).resolves.toBe(false);
|
||||
});
|
||||
|
||||
it("reports an empty summary before any save is requested", () => {
|
||||
const { confirmation } = createConfirmation();
|
||||
|
||||
expect(confirmation.open.value).toBe(false);
|
||||
expect(confirmation.total.value).toBe(0);
|
||||
expect(confirmation.statements.value).toEqual([]);
|
||||
expect(confirmation.targetLabel.value).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -87,6 +87,22 @@ export interface CustomSaveHandler {
|
||||
targetLabel?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Summary handed to `confirmSaveRequest` so an engine whose writes cannot be
|
||||
* rolled back (Salesforce REST: one record per request, no transactions) can
|
||||
* show the operator exactly what is about to happen before anything is sent.
|
||||
*/
|
||||
export interface DataGridSaveConfirmationRequest {
|
||||
/** Rows with edited cells (one write per row). */
|
||||
updates: number;
|
||||
inserts: number;
|
||||
deletes: number;
|
||||
/** Save target name (table / sObject), when known. */
|
||||
targetLabel?: string;
|
||||
/** The statements about to be executed — for Salesforce these are `DBX SALESFORCE DML` pseudo-commands. */
|
||||
statements: string[];
|
||||
}
|
||||
|
||||
export interface UseDataGridEditorOptions {
|
||||
result: ComputedRef<{ columns: string[]; rows: CellValue[][] }>;
|
||||
editable: ComputedRef<boolean | undefined>;
|
||||
@@ -119,6 +135,12 @@ export interface UseDataGridEditorOptions {
|
||||
rowStatusFilter: Ref<RowStatusFilter>;
|
||||
dataGridQuickEntryEnabled?: ComputedRef<boolean>;
|
||||
confirmDangerousRowDeletion?: ComputedRef<boolean>;
|
||||
/**
|
||||
* Optional operator review before a save is executed. Return `false` to cancel:
|
||||
* the pending edits stay in the grid and nothing is sent. Engines whose writes
|
||||
* cannot be rolled back (Salesforce REST) use this; auto-save never bypasses it.
|
||||
*/
|
||||
confirmSaveRequest?: ComputedRef<((request: DataGridSaveConfirmationRequest) => Promise<boolean>) | undefined>;
|
||||
/** `生成 SQL 时包含数据库名` — qualify saved tables with their database. */
|
||||
includeDatabaseNameInSaveSql?: ComputedRef<boolean>;
|
||||
initialEditColumn?: ComputedRef<number>;
|
||||
@@ -1994,6 +2016,28 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Engines without transactional rollback (Salesforce: one REST call per record,
|
||||
// a failure leaves earlier records applied) let the host review the operation
|
||||
// list first. Auto-save never writes without that review, matching the
|
||||
// production-database interlock above.
|
||||
const confirmSaveRequest = options.confirmSaveRequest?.value;
|
||||
if (confirmSaveRequest) {
|
||||
if (saveOptions.autoSave) {
|
||||
await finishInterruptedSaveChanges(snapshot);
|
||||
return;
|
||||
}
|
||||
const saveConfirmed = await confirmSaveRequest({
|
||||
updates: snapshot.dirtyRows.size,
|
||||
inserts: snapshot.newRows.length,
|
||||
deletes: snapshot.deletedRows.size,
|
||||
targetLabel: tableMeta.value?.tableName,
|
||||
statements: stmts,
|
||||
});
|
||||
if (!saveConfirmed) {
|
||||
await finishInterruptedSaveChanges(snapshot);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!editable.value || stmtOptions?.tableMeta !== tableMeta.value) {
|
||||
await finishInterruptedSaveChanges(snapshot);
|
||||
return;
|
||||
|
||||
@@ -3,7 +3,7 @@ import { connectionObjectTreeNodeSchema, effectiveDatabaseTypeForConnection, met
|
||||
import { invalidateTableMetadataCache, loadTableMetadata } from "@/lib/metadata/tableMetadataCache";
|
||||
import { canApplyDataTabMetadata, canReuseActiveMongoTab, type DataTabReuseMode } from "@/lib/sidebar/dataTabOpenPolicy";
|
||||
import { isNoSnapshotErrorResult, isQueryExecutionErrorResult } from "@/lib/query/queryResultError";
|
||||
import { buildTableSelectSql } from "@/lib/table/tableSelectSql";
|
||||
import { buildTableSelectSql, requiresEagerTableMetadataForDataOpen } from "@/lib/table/tableSelectSql";
|
||||
import { resolveTableDefaultSort, applyTableDefaultSortResult } from "@/lib/table/tableDefaultSort";
|
||||
import { tableDataLargeValuePreviewOptions } from "@/lib/dataGrid/dataGridLargeValues";
|
||||
import { editableRowIdentifierColumns, physicalTablePrimaryKeys, shouldIncludeSyntheticRowId } from "@/lib/table/tableEditing";
|
||||
@@ -179,7 +179,7 @@ async function openTableTarget(target: NavigationTarget, options: { tableInfoTab
|
||||
return;
|
||||
}
|
||||
let eagerMetadata: Awaited<ReturnType<typeof loadTableMetadata>> | undefined;
|
||||
if (effectiveDbType === "mysql" || effectiveDbType === "postgres" || (settingsStore.editorSettings.tableOpenSortMode ?? "none") !== "none") {
|
||||
if (requiresEagerTableMetadataForDataOpen(effectiveDbType) || (settingsStore.editorSettings.tableOpenSortMode ?? "none") !== "none") {
|
||||
try {
|
||||
eagerMetadata = await loadTableMetadata({
|
||||
connectionId: target.connectionId,
|
||||
|
||||
@@ -25,7 +25,7 @@ const INITIAL_SQL_FILE_LIMIT = 20;
|
||||
const CONTENT_SEARCH_DEBOUNCE_MS = 200;
|
||||
const CONTENT_SEARCH_MAX_RESULTS = 500;
|
||||
|
||||
const REMOTE_SEARCH_UNSUPPORTED_TYPES = new Set<ConnectionConfig["db_type"]>(["redis", "mongodb", "elasticsearch", "easysearch", "meilisearch", "solr", "qdrant", "milvus", "weaviate", "chromadb", "neo4j", "influxdb", "victoriametrics", "etcd", "zookeeper", "mq", "nacos", "consul"]);
|
||||
const REMOTE_SEARCH_UNSUPPORTED_TYPES = new Set<ConnectionConfig["db_type"]>(["redis", "mongodb", "elasticsearch", "easysearch", "meilisearch", "solr", "qdrant", "milvus", "weaviate", "chromadb", "neo4j", "influxdb", "victoriametrics", "etcd", "zookeeper", "mq", "nacos", "consul", "salesforce"]);
|
||||
|
||||
export interface QuickOpenItem {
|
||||
id: string;
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
import { computed, onScopeDispose, ref, type ComputedRef, type Ref, type WritableComputedRef } from "vue";
|
||||
import type { DataGridSaveConfirmationRequest } from "@/composables/useDataGridEditor";
|
||||
|
||||
/**
|
||||
* Salesforce writes go out as one REST call per record and cannot be rolled back,
|
||||
* so every grid save is reviewed before it runs. This composable turns the
|
||||
* `confirmSaveRequest` hook from `useDataGridEditor` into a dialog decision:
|
||||
* `request()` parks the save on a promise the dialog settles.
|
||||
*
|
||||
* The pending request is transient — never persisted and never outliving the
|
||||
* component — so a dismissed grid denies the write instead of leaving it hanging.
|
||||
*/
|
||||
export function useSalesforceSaveConfirmation(): {
|
||||
pending: Ref<DataGridSaveConfirmationRequest | null>;
|
||||
open: WritableComputedRef<boolean>;
|
||||
updates: ComputedRef<number>;
|
||||
inserts: ComputedRef<number>;
|
||||
deletes: ComputedRef<number>;
|
||||
total: ComputedRef<number>;
|
||||
targetLabel: ComputedRef<string | undefined>;
|
||||
statements: ComputedRef<string[]>;
|
||||
request: (request: DataGridSaveConfirmationRequest) => Promise<boolean>;
|
||||
confirm: () => void;
|
||||
cancel: () => void;
|
||||
} {
|
||||
const pending = ref<DataGridSaveConfirmationRequest | null>(null);
|
||||
let resolvePending: ((confirmed: boolean) => void) | undefined;
|
||||
|
||||
const open = computed({
|
||||
get: () => !!pending.value,
|
||||
set: (next: boolean) => {
|
||||
if (!next) settle(false);
|
||||
},
|
||||
});
|
||||
|
||||
const updates = computed(() => pending.value?.updates ?? 0);
|
||||
const inserts = computed(() => pending.value?.inserts ?? 0);
|
||||
const deletes = computed(() => pending.value?.deletes ?? 0);
|
||||
const total = computed(() => updates.value + inserts.value + deletes.value);
|
||||
const targetLabel = computed(() => pending.value?.targetLabel);
|
||||
const statements = computed(() => pending.value?.statements ?? []);
|
||||
|
||||
function settle(confirmed: boolean) {
|
||||
const resolve = resolvePending;
|
||||
resolvePending = undefined;
|
||||
pending.value = null;
|
||||
resolve?.(confirmed);
|
||||
}
|
||||
|
||||
function request(saveRequest: DataGridSaveConfirmationRequest): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve) => {
|
||||
if (pending.value) {
|
||||
// A grid only saves once at a time, but never strand a second caller:
|
||||
// deny it so that save unwinds instead of waiting on a dialog it cannot see.
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
pending.value = saveRequest;
|
||||
resolvePending = resolve;
|
||||
});
|
||||
}
|
||||
|
||||
function confirm() {
|
||||
settle(true);
|
||||
}
|
||||
|
||||
function cancel() {
|
||||
settle(false);
|
||||
}
|
||||
|
||||
// The dialog is the only way to settle the promise; if it goes away first (tab
|
||||
// closed mid-review) the parked save must be denied, not leaked.
|
||||
onScopeDispose(() => settle(false));
|
||||
|
||||
return { pending, open, updates, inserts, deletes, total, targetLabel, statements, request, confirm, cancel };
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import { getCachedTableMetadata, loadTableMetadata, TABLE_METADATA_CACHE_TTL_MS,
|
||||
import { canApplyDataTabMetadata, dataTabMetadataNeedsRefresh, findExistingDataTabCandidate, isDataTabMetadataLifecycleStale, type DataTabOpenMode, type DataTabReuseMode } from "@/lib/sidebar/dataTabOpenPolicy";
|
||||
import type { SidebarDataOpenRequest } from "@/lib/sidebar/sidebarDataOpenCoordinator";
|
||||
import { hasTreeNodeDatabaseContext } from "@/lib/sidebar/treeNodeContext";
|
||||
import { buildTableSelectSql } from "@/lib/table/tableSelectSql";
|
||||
import { buildTableSelectSql, requiresEagerTableMetadataForDataOpen } from "@/lib/table/tableSelectSql";
|
||||
import { resolveTableDefaultSort, applyTableDefaultSortResult } from "@/lib/table/tableDefaultSort";
|
||||
import { physicalTablePrimaryKeys, shouldIncludeSyntheticRowId } from "@/lib/table/tableEditing";
|
||||
import { tableOpenPageLimit } from "@/lib/table/tableOpenPageLimit";
|
||||
@@ -354,7 +354,7 @@ export function useSidebarDataOpenRuntime() {
|
||||
}
|
||||
|
||||
const metadataRefresh = shouldRefreshTableMeta && !deferTableMetaRefresh ? refreshTableMetaInBackground(tabId) : undefined;
|
||||
if (!cachedTableMeta && (effectiveDbType === "mysql" || effectiveDbType === "postgres" || defaultSortMode !== "none")) {
|
||||
if (!cachedTableMeta && (requiresEagerTableMetadataForDataOpen(effectiveDbType) || defaultSortMode !== "none")) {
|
||||
// No query is in flight yet, so deferred drivers can safely load metadata serially.
|
||||
if (deferTableMetaRefresh) await refreshTableMetaInBackground(tabId);
|
||||
await metadataRefresh;
|
||||
|
||||
@@ -981,7 +981,7 @@ export function supportsSqlTemplateParameters(connection: Pick<ConnectionConfig,
|
||||
if (!connection) return false;
|
||||
if (connection.db_type === "meilisearch" || connection.db_type === "solr") return false;
|
||||
if (connection.db_type === "elasticsearch" || connection.db_type === "easysearch") return !isElasticsearchRestRequestText(sql);
|
||||
return connection.db_type !== "redis" && connection.db_type !== "mongodb" && connection.db_type !== "victoriametrics";
|
||||
return connection.db_type !== "redis" && connection.db_type !== "mongodb" && connection.db_type !== "victoriametrics" && connection.db_type !== "salesforce";
|
||||
}
|
||||
|
||||
export function requiresDatabaseSelection(tab: QueryTab, connection: ConnectionConfig | undefined, _sql = ""): boolean {
|
||||
|
||||
Reference in new issue
Block a user