Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

feat(grid): improve data copy format controls

t8y238e1c66f262d
diff --git a/apps/desktop/src/components/document/DocumentBrowser.vue b/apps/desktop/src/components/document/DocumentBrowser.vue
index 4ba7a19352..008f8ed2e0 100644
--- a/apps/desktop/src/components/document/DocumentBrowser.vue
+++ b/apps/desktop/src/components/document/DocumentBrowser.vue
@@ -11,6 +11,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
import DangerConfirmDialog from "@/components/editor/DangerConfirmDialog.vue";
import ErrorBanner from "@/components/ui/ErrorBanner.vue";
import DataGrid from "@/components/grid/DataGrid.vue";
+import DataGridCopyFormatControl from "@/components/grid/DataGridCopyFormatControl.vue";
import QueryLoadingState from "@/components/common/QueryLoadingState.vue";
import * as api from "@/lib/backend/api";
import { useConnectionStore } from "@/stores/connectionStore";
@@ -116,6 +117,7 @@ const sortInput = ref("");
const filterInputRef = ref<HTMLTextAreaElement>();
const sortInputRef = ref<HTMLTextAreaElement>();
const dataGridRef = ref<InstanceType<typeof DataGrid>>();
+const viewOptionsOpen = ref(false);
const mongoUpdateTarget = computed(() => (props.databaseType === "mongodb" && mongoCopyDocumentsAvailable.value ? { collection: props.collection, idColumn: "_id" as const } : undefined));
const documentViewerRef = ref<HTMLElement>();
const documentSearchInputRef = ref<HTMLInputElement>();
@@ -126,6 +128,11 @@ const documentSearchHasNavigated = ref(false);
const documentViewerSearchActive = ref(false);
const columnVisibilitySearch = ref("");
const columnVisibilityOptions = computed(() => dataGridRef.value?.filteredColumnVisibilityOptions(columnVisibilitySearch.value) ?? []);
+
+function openDataGridExtractorConfiguration() {
+ viewOptionsOpen.value = false;
+ void nextTick(() => dataGridRef.value?.openExtractorConfiguration());
+}
const tableSearchSplitContainerRef = ref<HTMLDivElement>();
const tableFindPaneWidth = ref<number | null>(null);
const isResizingTableSearchSplit = ref(false);
@@ -1571,7 +1578,7 @@ defineExpose({ focusSearch });
</PopoverContent>
</Popover>
- <Popover v-if="viewMode === 'table' && gridResult.columns.length">
+ <Popover v-if="viewMode === 'table' && gridResult.columns.length" v-model:open="viewOptionsOpen">
<PopoverTrigger as-child>
<Button variant="ghost" size="icon" class="h-6 w-7 shrink-0 text-foreground hover:bg-accent" :class="{ 'bg-accent text-foreground': dataGridRef?.nullColumnsHidden }" :title="t('grid.viewOptions')" :aria-label="t('grid.viewOptions')">
<Wrench class="h-4 w-4" />
@@ -1588,6 +1595,13 @@ defineExpose({ focusSearch });
<span v-if="(dataGridRef?.allNullColumnCount ?? 0) > 0" class="text-muted-foreground tabular-nums"> ({{ dataGridRef?.allNullColumnCount }}) </span>
</span>
</label>
+ <DataGridCopyFormatControl
+ :current-label="dataGridRef?.defaultCopyExtractorLabel ?? '-'"
+ :current-value="dataGridRef?.defaultCopyExtractor ?? ''"
+ :items="dataGridRef?.copyExtractorMenuItems ?? []"
+ @select="dataGridRef?.setDefaultCopyExtractor($event)"
+ @configure="openDataGridExtractorConfiguration"
+ />
</PopoverContent>
</Popover>
</div>
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue
index 766486ec43..6d757022ab 100644
--- a/apps/desktop/src/components/grid/DataGrid.vue
+++ b/apps/desktop/src/components/grid/DataGrid.vue
@@ -39,6 +39,7 @@ import {
Eraser,
Columns3,
PencilRuler,
+ Settings2,
WandSparkles,
} from "@lucide/vue";
import { Button } from "@/components/ui/button";
@@ -206,7 +207,7 @@ import { useConnectionStore } from "@/stores/connectionStore";
import { useQueryStore } from "@/stores/queryStore";
import { useSettingsStore } from "@/stores/settingsStore";
import { simpleDataGridOrderByMatchesSort, simpleDataGridOrderByReferencesMissingColumn, type DataGridSortDirection, type DataGridSortMode } from "@/lib/dataGrid/dataGridSort";
-import { DATA_GRID_COMPACT_TOPBAR_WIDTH, type DataGridReloadIntent, type DataGridToolbarActionCapability, type DataGridToolbarAutoRefreshCapability, type DataGridToolbarCopyCapability, type DataGridToolbarSaveCapability } from "@/lib/dataGrid/dataGridToolbar";
+import { DATA_GRID_COMPACT_TOPBAR_WIDTH, type DataGridReloadIntent, type DataGridToolbarActionCapability, type DataGridToolbarAutoRefreshCapability, type DataGridToolbarSaveCapability } from "@/lib/dataGrid/dataGridToolbar";
import { getTableMetadataCapabilities } from "@/lib/table/tableMetadataCapabilities";
import { getTableStructureCapabilities } from "@/lib/table/tableStructureCapabilities";
import { filterObjectBrowserTableColumns } from "@/lib/table/objectBrowserTableInfo";
@@ -5269,6 +5270,10 @@ function copyExtractorLabel(extractor: DataGridCopyExtractorId): string {
}
const selectedCopyExtractor = computed(() => settingsStore.editorSettings.dataGridCopyExtractor);
+const defaultCopyExtractorLabel = computed(() => {
+ if (selectedCopyExtractor.value !== "sql-inserts") return copyExtractorLabel(selectedCopyExtractor.value);
+ return t(settingsStore.editorSettings.dataGridExtractorOptions.sql.excludePrimaryKeysFromInsert ? "grid.copyExtractorSqlInsertsWithoutPrimaryKeys" : "grid.copyExtractorSqlInsertsWithPrimaryKeys");
+});
const extractorConfigOpen = ref(false);
const extractorMenuItems = computed(() =>
DATA_GRID_COPY_EXTRACTOR_IDS.map((extractor) => ({
@@ -5278,23 +5283,23 @@ const extractorMenuItems = computed(() =>
separatorBefore: DATA_GRID_COPY_EXTRACTOR_DESCRIPTORS[extractor].separatorBefore,
})),
);
-const copyToolbarCapability = computed<DataGridToolbarCopyCapability>(() => ({
- label: copyExtractorLabel(selectedCopyExtractor.value),
- tooltip: `${t("grid.copy")} (${shortcutMod}+C)`,
- currentValue: selectedCopyExtractor.value,
- disabled: !canCopyWithExtractor(selectedCopyExtractor.value),
- items: [...extractorMenuItems.value, { value: "__configure__", label: t("grid.copyExtractorConfigure"), separatorBefore: true }],
- onCopy: async () => {
- await copyWithExtractor(selectedCopyExtractor.value);
- },
- onSelect: (value) => {
- if (value === "__configure__") {
- extractorConfigOpen.value = true;
- return;
- }
- settingsStore.updateEditorSettings({ dataGridCopyExtractor: value as DataGridCopyExtractorId });
- },
-}));
+function openExtractorConfiguration() {
+ extractorConfigOpen.value = true;
+}
+
+function setDefaultCopyExtractor(value: string) {
+ const item = extractorMenuItems.value.find((candidate) => candidate.value === value);
+ if (!item || item.disabled) return;
+ settingsStore.updateEditorSettings({ dataGridCopyExtractor: item.value });
+}
+
+function sqlInsertExtractorOptions(excludePrimaryKeysFromInsert: boolean) {
+ const options = settingsStore.editorSettings.dataGridExtractorOptions;
+ return {
+ ...options,
+ sql: { ...options.sql, excludePrimaryKeysFromInsert },
+ };
+}
function saveExtractorConfiguration(value: { extractor: DataGridCopyExtractorId; options: typeof settingsStore.editorSettings.dataGridExtractorOptions }) {
settingsStore.updateEditorSettings({ dataGridCopyExtractor: value.extractor, dataGridExtractorOptions: value.options });
@@ -7597,6 +7602,11 @@ defineExpose({
exportSql,
exportXlsx,
exportTxt,
+ defaultCopyExtractor: selectedCopyExtractor,
+ defaultCopyExtractorLabel,
+ copyExtractorMenuItems: extractorMenuItems,
+ setDefaultCopyExtractor,
+ openExtractorConfiguration,
});
// ---- CustomContextMenu ----
@@ -7637,22 +7647,34 @@ function buildExtractorContextItems(): ContextMenuItem[] {
items.push({ label: "", separator: true });
}
const selected = extractor === selectedCopyExtractor.value;
+ if (extractor === "sql-inserts") {
+ for (const excludePrimaryKeysFromInsert of [false, true]) {
+ const options = sqlInsertExtractorOptions(excludePrimaryKeysFromInsert);
+ items.push({
+ label: t(excludePrimaryKeysFromInsert ? "grid.copyExtractorSqlInsertsWithoutPrimaryKeys" : "grid.copyExtractorSqlInsertsWithPrimaryKeys"),
+ action: () => void copyWithExtractor(extractor, options),
+ disabled: !canCopyWithExtractor(extractor, options),
+ checked: selected && settingsStore.editorSettings.dataGridExtractorOptions.sql.excludePrimaryKeysFromInsert === excludePrimaryKeysFromInsert,
+ });
+ }
+ continue;
+ }
items.push({
- label: `${selected ? "✓ " : ""}${copyExtractorLabel(extractor)}`,
+ label: copyExtractorLabel(extractor),
action: () => {
// One-off copy as the chosen format; do NOT persist it as the default —
// the saved default stays controlled by the toolbar/settings dialog.
void copyWithExtractor(extractor);
},
disabled: !canCopyWithExtractor(extractor),
+ checked: selected,
});
}
items.push({ label: "", separator: true });
items.push({
label: t("grid.copyExtractorConfigure"),
- action: () => {
- extractorConfigOpen.value = true;
- },
+ icon: Settings2,
+ action: openExtractorConfiguration,
});
return items;
}
@@ -7899,7 +7921,6 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
:compact="compactDataGridToolbar"
:refresh="refreshToolbarCapability"
:auto-refresh="autoRefreshToolbarCapability"
- :copy-data="copyToolbarCapability"
:add-row="addRowToolbarCapability"
:preview="previewToolbarCapability"
:save="saveToolbarCapability"
diff --git a/apps/desktop/src/components/grid/DataGridCopyFormatControl.vue b/apps/desktop/src/components/grid/DataGridCopyFormatControl.vue
new file mode 100644
index 0000000000..1d61dd81e2
--- /dev/null
+++ b/apps/desktop/src/components/grid/DataGridCopyFormatControl.vue
@@ -0,0 +1,51 @@
+<script setup lang="ts">
+import { Check, ChevronDown, Copy, Settings2 } from "@lucide/vue";
+import { useI18n } from "vue-i18n";
+import { Button } from "@/components/ui/button";
+import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
+import type { DataGridToolbarMenuItem } from "@/lib/dataGrid/dataGridToolbar";
+
+defineProps<{
+ currentLabel: string;
+ currentValue: string;
+ items: readonly DataGridToolbarMenuItem[];
+}>();
+
+const emit = defineEmits<{
+ configure: [];
+ select: [value: string];
+}>();
+
+const { t } = useI18n();
+</script>
+
+<template>
+ <div class="flex items-center justify-between gap-3 px-3 py-1.5 text-xs">
+ <span class="flex min-w-0 items-center gap-2 font-medium">
+ <Copy class="h-3.5 w-3.5 shrink-0 text-muted-foreground" />
+ <span>{{ t("grid.copyExtractorDefaultFormat") }}</span>
+ </span>
+ <div class="flex min-w-0 items-center gap-1">
+ <DropdownMenu>
+ <DropdownMenuTrigger as-child>
+ <Button variant="outline" size="sm" class="h-6 max-w-52 min-w-0 gap-1 px-2 text-xs">
+ <span class="truncate">{{ currentLabel }}</span>
+ <ChevronDown class="h-3.5 w-3.5 shrink-0 text-muted-foreground" />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end" class="min-w-52">
+ <template v-for="item in items" :key="item.value">
+ <DropdownMenuSeparator v-if="item.separatorBefore" />
+ <DropdownMenuItem class="gap-2" :disabled="item.disabled" @select="emit('select', item.value)">
+ <span class="flex-1">{{ item.label }}</span>
+ <Check v-if="currentValue === item.value" class="h-3.5 w-3.5 shrink-0 text-primary" />
+ </DropdownMenuItem>
+ </template>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ <Button variant="ghost" size="icon" class="h-6 w-6 shrink-0" :title="t('grid.copyExtractorConfigure')" :aria-label="t('grid.copyExtractorConfigure')" @click="emit('configure')">
+ <Settings2 class="h-3.5 w-3.5" />
+ </Button>
+ </div>
+ </div>
+</template>
diff --git a/apps/desktop/src/components/grid/DataGridToolbar.vue b/apps/desktop/src/components/grid/DataGridToolbar.vue
index e476c9f715..90cb12561b 100644
--- a/apps/desktop/src/components/grid/DataGridToolbar.vue
+++ b/apps/desktop/src/components/grid/DataGridToolbar.vue
@@ -109,9 +109,8 @@ function actionLabelClass() {
<template v-for="item in copyData?.items ?? []" :key="item.value">
<DropdownMenuSeparator v-if="item.separatorBefore" />
<DropdownMenuItem class="gap-2" :disabled="item.disabled" @select="void selectDataGridToolbarCopyItem(copyData, item.value)">
- <Check v-if="copyData?.currentValue === item.value" class="h-3.5 w-3.5" />
- <span v-else class="h-3.5 w-3.5" />
- {{ item.label }}
+ <span class="flex-1">{{ item.label }}</span>
+ <Check v-if="copyData?.currentValue === item.value" class="h-3.5 w-3.5 shrink-0 text-primary" />
</DropdownMenuItem>
</template>
</DropdownMenuContent>
diff --git a/apps/desktop/src/components/layout/ContentArea.vue b/apps/desktop/src/components/layout/ContentArea.vue
index d2b188315f..a86627eede 100644
--- a/apps/desktop/src/components/layout/ContentArea.vue
+++ b/apps/desktop/src/components/layout/ContentArea.vue
@@ -19,6 +19,7 @@ import QueryLoadingState from "@/components/common/QueryLoadingState.vue";
import QueryErrorActions from "@/components/common/QueryErrorActions.vue";
import QueryResultToolbarActions from "@/components/layout/QueryResultToolbarActions.vue";
import QueryResultViewSwitcher from "@/components/layout/QueryResultViewSwitcher.vue";
+import DataGridCopyFormatControl from "@/components/grid/DataGridCopyFormatControl.vue";
import DataGridFontFamilyControl from "@/components/grid/DataGridFontFamilyControl.vue";
import type { ColumnInfo } from "@/components/editor/ColumnInfoPanel.vue";
let dataGridComponentPromise: Promise<typeof import("@/components/grid/DataGrid.vue")> | undefined;
@@ -112,6 +113,11 @@ type DataGridHandle = {
allNullColumnCount: number;
canToggleAllNullColumns: boolean;
toggleAllNullColumns: () => void;
+ defaultCopyExtractor: string;
+ defaultCopyExtractorLabel: string;
+ copyExtractorMenuItems: Array<{ value: string; label: string; disabled?: boolean; separatorBefore?: boolean }>;
+ setDefaultCopyExtractor: (value: string) => void;
+ openExtractorConfiguration: () => void;
showDdl: boolean;
toggleDdl: (tab?: TableInfoTab) => void;
multiRowTranspose: boolean;
@@ -211,6 +217,7 @@ const standaloneResultToolbarRef = ref<HTMLElement | null>(null);
const standaloneResultToolbarWidth = ref(0);
const resultTabsScrollerRef = ref<HTMLElement | null>(null);
const columnVisibilitySearch = ref("");
+const dataGridViewOptionsOpen = ref(false);
const columnVisibilityOptions = computed(() => dataGridRef.value?.filteredColumnVisibilityOptions(columnVisibilitySearch.value) ?? []);
const dataGridRenderMode = computed(() => settingsStore.editorSettings.dataGridRenderMode);
const dataGridSearchMode = computed(() => settingsStore.editorSettings.dataGridSearchMode);
@@ -220,6 +227,11 @@ const tableFontSize = computed(() => settingsStore.editorSettings.tableFontSize)
const redisKeyBrowserRef = ref<SearchableBrowserHandle>();
const documentBrowserRef = ref<SearchableBrowserHandle>();
+function openDataGridExtractorConfiguration() {
+ dataGridViewOptionsOpen.value = false;
+ void nextTick(() => dataGridRef.value?.openExtractorConfiguration());
+}
+
const etcdKeyBrowserRef = ref<SearchableBrowserHandle>();
const etcdDashboardRef = ref<{ refresh?: () => boolean }>();
const zookeeperKeyBrowserRef = ref<SearchableBrowserHandle>();
@@ -1080,7 +1092,7 @@ defineExpose({ focusSearch, refreshData, refreshQueryEditorCompletionCache, hand
</div>
</template>
<div class="ml-auto flex shrink-0 items-center gap-1">
- <Popover v-if="activeOutputView === 'result' && activeTab.result && hasTabularResult && !activeElasticsearchJsonResponse">
+ <Popover v-if="activeOutputView === 'result' && activeTab.result && hasTabularResult && !activeElasticsearchJsonResponse" v-model:open="dataGridViewOptionsOpen">
<PopoverTrigger as-child>
<Button variant="ghost" size="icon" class="h-6 w-7 shrink-0 text-foreground hover:bg-accent" :title="t('grid.viewOptions')" :aria-label="t('grid.viewOptions')">
<Wrench class="h-4 w-4" />
@@ -1270,6 +1282,13 @@ defineExpose({ focusSearch, refreshData, refreshQueryEditorCompletionCache, hand
</span>
<Switch size="sm" :model-value="!!dataGridRef?.nullColumnsHidden" :disabled="!dataGridRef?.canToggleAllNullColumns" :aria-label="t('grid.hideNullColumns')" @update:model-value="dataGridRef?.toggleAllNullColumns()" />
</div>
+ <DataGridCopyFormatControl
+ :current-label="dataGridRef?.defaultCopyExtractorLabel ?? '-'"
+ :current-value="dataGridRef?.defaultCopyExtractor ?? ''"
+ :items="dataGridRef?.copyExtractorMenuItems ?? []"
+ @select="dataGridRef?.setDefaultCopyExtractor($event)"
+ @configure="openDataGridExtractorConfiguration"
+ />
</PopoverContent>
</Popover>
<LightTooltip :text="t('editor.hideResultsPane')" side="bottom" :delay="0" :close-delay="0" nowrap>
@@ -1592,7 +1611,7 @@ defineExpose({ focusSearch, refreshData, refreshQueryEditorCompletionCache, hand
</div>
</DropdownMenuContent>
</DropdownMenu>
- <Popover v-if="activeTab.result?.columns.length">
+ <Popover v-if="activeTab.result?.columns.length" v-model:open="dataGridViewOptionsOpen">
<PopoverTrigger as-child>
<Button variant="ghost" size="icon" class="h-6 w-7 shrink-0 text-foreground hover:bg-accent" :title="t('grid.viewOptions')" :aria-label="t('grid.viewOptions')">
<Wrench class="h-4 w-4" />
@@ -1758,6 +1777,13 @@ defineExpose({ focusSearch, refreshData, refreshQueryEditorCompletionCache, hand
</span>
<Switch size="sm" :model-value="!!dataGridRef?.nullColumnsHidden" :disabled="!dataGridRef?.canToggleAllNullColumns" :aria-label="t('grid.hideNullColumns')" @update:model-value="dataGridRef?.toggleAllNullColumns()" />
</div>
+ <DataGridCopyFormatControl
+ :current-label="dataGridRef?.defaultCopyExtractorLabel ?? '-'"
+ :current-value="dataGridRef?.defaultCopyExtractor ?? ''"
+ :items="dataGridRef?.copyExtractorMenuItems ?? []"
+ @select="dataGridRef?.setDefaultCopyExtractor($event)"
+ @configure="openDataGridExtractorConfiguration"
+ />
</PopoverContent>
</Popover>
</div>
diff --git a/apps/desktop/src/components/ui/CustomContextMenu.vue b/apps/desktop/src/components/ui/CustomContextMenu.vue
index 4346b04a6c..99ffa27ac6 100644
--- a/apps/desktop/src/components/ui/CustomContextMenu.vue
+++ b/apps/desktop/src/components/ui/CustomContextMenu.vue
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { ref, watch, onBeforeUnmount, onMounted, nextTick, type Component } from "vue";
-import { ChevronRight } from "@lucide/vue";
+import { Check, ChevronRight } from "@lucide/vue";
import { shortcutDisplayKeys } from "@/lib/editor/shortcutDisplay";
import { registerGlobalContextMenu, type ContextMenuRegistration } from "@/components/ui/customContextMenuRegistry";
@@ -11,6 +11,7 @@ export interface ContextMenuItem {
separator?: boolean;
icon?: Component;
iconClass?: string;
+ checked?: boolean;
// Raw shortcut syntax such as `Mod+C` or `Shift+Alt+U`; display formatting stays in this component.
shortcut?: string;
variant?: "default" | "destructive";
@@ -283,6 +284,7 @@ onBeforeUnmount(() => {
<component :is="item.icon" v-if="item.icon" :class="['size-4', item.iconClass]" />
</span>
<span class="flex-1 whitespace-nowrap">{{ item.label }}</span>
+ <Check v-if="item.checked" class="ml-4 size-4 shrink-0 text-primary" />
<span v-if="item.shortcut" class="ml-8 inline-flex shrink-0 items-center gap-1 text-muted-foreground">
<kbd v-for="key in shortcutKeys(item.shortcut)" :key="key" class="min-w-4 rounded border border-border/70 bg-muted/60 px-1 py-0.5 text-center font-mono text-[10px] leading-none text-muted-foreground shadow-xs">{{ key }}</kbd>
</span>
@@ -313,6 +315,7 @@ onBeforeUnmount(() => {
<component :is="child.icon" v-if="child.icon" :class="['size-4', child.iconClass]" />
</span>
<span class="flex-1 whitespace-nowrap">{{ child.label }}</span>
+ <Check v-if="child.checked" class="ml-4 size-4 shrink-0 text-primary" />
<span v-if="child.shortcut" class="ml-8 inline-flex shrink-0 items-center gap-1 text-muted-foreground">
<kbd v-for="key in shortcutKeys(child.shortcut)" :key="key" class="min-w-4 rounded border border-border/70 bg-muted/60 px-1 py-0.5 text-center font-mono text-[10px] leading-none text-muted-foreground shadow-xs">{{ key }}</kbd>
</span>
diff --git a/apps/desktop/src/components/ui/__tests__/CustomContextMenu.spec.ts b/apps/desktop/src/components/ui/__tests__/CustomContextMenu.spec.ts
index 8d4f94d121..4d51efeb04 100644
--- a/apps/desktop/src/components/ui/__tests__/CustomContextMenu.spec.ts
+++ b/apps/desktop/src/components/ui/__tests__/CustomContextMenu.spec.ts
@@ -97,6 +97,36 @@ describe("CustomContextMenu lifecycle", () => {
app.unmount();
});
+ it("renders checked state after the menu label", async () => {
+ const root = defineComponent({
+ setup() {
+ return () =>
+ h(
+ CustomContextMenu,
+ { items: [{ label: "Current", checked: true }, { label: "Other" }] },
+ {
+ default: ({ onContextMenu }: { onContextMenu: (event: MouseEvent) => void }) => h("div", { id: "context-target", onContextmenu: onContextMenu }, "Target"),
+ },
+ );
+ },
+ });
+ const container = document.createElement("div");
+ mountedContainers.push(container);
+ document.body.append(container);
+ const app = createApp(root);
+ app.mount(container);
+
+ container.querySelector("#context-target")?.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true }));
+ await nextTick();
+
+ const current = Array.from(document.body.querySelectorAll("button")).find((button) => button.textContent?.includes("Current"));
+ const other = Array.from(document.body.querySelectorAll("button")).find((button) => button.textContent?.includes("Other"));
+ expect(current?.lastElementChild?.tagName.toLowerCase()).toBe("svg");
+ expect(other?.querySelector("svg")).toBeNull();
+
+ app.unmount();
+ });
+
it("resolves lazy menu items again for every open", async () => {
let copied = false;
const items = vi.fn(() =>
diff --git a/apps/desktop/src/composables/__tests__/useDataGridExport.spec.ts b/apps/desktop/src/composables/__tests__/useDataGridExport.spec.ts
index 8139866673..fd6f751d7a 100644
--- a/apps/desktop/src/composables/__tests__/useDataGridExport.spec.ts
+++ b/apps/desktop/src/composables/__tests__/useDataGridExport.spec.ts
@@ -433,6 +433,37 @@ describe("useDataGridExport prepared row statements", () => {
expect(state.canCopyWithExtractor("sql-inserts")).toBe(true);
});
+ it("supports a one-off INSERT primary-key override without changing saved options", async () => {
+ const autoIncrementTable: DataGridTableMeta = {
+ tableName: "users",
+ primaryKeys: ["id"],
+ columns: [{ name: "id", data_type: "int", is_nullable: false, is_primary_key: true, extra: "auto_increment" }],
+ };
+ const matrix: CellSelectionMatrix = { rowIndexes: [0], columnIndexes: [0], columns: ["id"], rows: [[7]] };
+ const savedOptions = {
+ ...DEFAULT_DATA_GRID_EXTRACTOR_OPTIONS,
+ sql: { ...DEFAULT_DATA_GRID_EXTRACTOR_OPTIONS.sql, excludePrimaryKeysFromInsert: true },
+ };
+ const includePrimaryKeys = {
+ ...savedOptions,
+ sql: { ...savedOptions.sql, excludePrimaryKeysFromInsert: false },
+ };
+ vi.mocked(extractDataGridSelection).mockResolvedValueOnce({
+ text: "INSERT INTO `users` (`id`) VALUES (7);",
+ mimeType: "text/sql",
+ fileExtension: "sql",
+ rowCount: 1,
+ columnCount: 1,
+ });
+ const state = createExportState(autoIncrementTable, ["id"], matrix, [7], undefined, undefined, [], savedOptions);
+
+ expect(state.canCopyWithExtractor("sql-inserts")).toBe(false);
+ expect(state.canCopyWithExtractor("sql-inserts", includePrimaryKeys)).toBe(true);
+ await expect(state.copyWithExtractor("sql-inserts", includePrimaryKeys)).resolves.toBe(true);
+ expect(extractDataGridSelection).toHaveBeenCalledWith(expect.objectContaining({ options: expect.objectContaining({ sql: expect.objectContaining({ excludePrimaryKeysFromInsert: false }) }) }));
+ expect(savedOptions.sql.excludePrimaryKeysFromInsert).toBe(true);
+ });
+
it("sends only selected values for non-SQL extraction and marks column selections", async () => {
const matrix: CellSelectionMatrix = { rowIndexes: [0], columnIndexes: [1], columns: ["name"], rows: [["Ada"]] };
vi.mocked(extractDataGridSelection).mockResolvedValueOnce({
diff --git a/apps/desktop/src/composables/useDataGridExtractor.ts b/apps/desktop/src/composables/useDataGridExtractor.ts
index 8181d7ccac..05bd2efe41 100644
--- a/apps/desktop/src/composables/useDataGridExtractor.ts
+++ b/apps/desktop/src/composables/useDataGridExtractor.ts
@@ -173,12 +173,12 @@ export function useDataGridExtractor(options: UseDataGridExtractorOptions) {
});
}
- function canCopyWithExtractor(extractor: DataGridCopyExtractorId): boolean {
+ function canCopyWithExtractor(extractor: DataGridCopyExtractorId, extractorOptions: DataGridExtractorOptions = options.extractorOptions?.value ?? DEFAULT_DATA_GRID_EXTRACTOR_OPTIONS): boolean {
if (hasUnsupportedDiscreteSelection.value) return false;
if (!options.hasRowSelection.value && !options.hasCellSelection.value && !options.contextCell.value) return false;
if (extractorUnavailableForDatabase(extractor, options.databaseType.value)) return false;
if (extractor === "sql-inserts") {
- const request = buildRequest(extractor);
+ const request = buildRequest(extractor, extractorOptions);
return request !== null && options.canCopySqlInsert(request);
}
if (extractor === "sql-updates") {
@@ -198,13 +198,13 @@ export function useDataGridExtractor(options: UseDataGridExtractorOptions) {
return { text, mimeType: "application/javascript", fileExtension: "js", rowCount: rowLimit ?? request.rows.length, columnCount: request.selectedColumnIndexes.length, warnings: undefined, omittedColumns: undefined };
}
- async function copyWithExtractor(extractor: DataGridCopyExtractorId): Promise<boolean> {
+ async function copyWithExtractor(extractor: DataGridCopyExtractorId, extractorOptions: DataGridExtractorOptions = options.extractorOptions?.value ?? DEFAULT_DATA_GRID_EXTRACTOR_OPTIONS): Promise<boolean> {
if (hasUnsupportedDiscreteSelection.value) {
toast(t("grid.copyExtractorUnsupportedSelection"), 5000);
return false;
}
- if (!canCopyWithExtractor(extractor)) return false;
- const request = buildRequest(extractor);
+ if (!canCopyWithExtractor(extractor, extractorOptions)) return false;
+ const request = buildRequest(extractor, extractorOptions);
if (!request) return false;
try {
const mongoResult = await resolveMongoExtractorResult(extractor, request);
diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts
index 8f9f6cb7f8..b901e39583 100644
--- a/apps/desktop/src/i18n/locales/en.ts
+++ b/apps/desktop/src/i18n/locales/en.ts
@@ -1033,11 +1033,14 @@ export default {
copyExtractorOneRow: "One-row",
copyExtractorSqlInList: "SQL IN List",
copyExtractorSqlInserts: "SQL Inserts",
+ copyExtractorSqlInsertsWithPrimaryKeys: "SQL Inserts (with Primary Keys)",
+ copyExtractorSqlInsertsWithoutPrimaryKeys: "SQL Inserts (without Primary Keys)",
copyExtractorSqlUpdates: "SQL Updates",
copyExtractorWhereClause: "Where Clause",
copyExtractorPipeSeparated: "Pipe-separated",
copyExtractorPretty: "Pretty Table",
copyExtractorConfigure: "Configure Data Extractors…",
+ copyExtractorDefaultFormat: "Default copy format",
copyExtractorFormat: "Extractor",
copyExtractorColumnSeparator: "Column separator",
copyExtractorRowSeparator: "Row separator",
diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.ts
index 7bd0dd38a7..23b87a85c5 100644
--- a/apps/desktop/src/i18n/locales/es.ts
+++ b/apps/desktop/src/i18n/locales/es.ts
@@ -1324,11 +1324,14 @@ export default withEnglishFallback({
copyExtractorOneRow: "CSV de una fila",
copyExtractorSqlInList: "Lista SQL IN",
copyExtractorSqlInserts: "Sentencias SQL INSERT",
+ copyExtractorSqlInsertsWithPrimaryKeys: "Sentencias SQL INSERT (con claves primarias)",
+ copyExtractorSqlInsertsWithoutPrimaryKeys: "Sentencias SQL INSERT (sin claves primarias)",
copyExtractorSqlUpdates: "Sentencias SQL UPDATE",
copyExtractorWhereClause: "Cláusula WHERE",
copyExtractorPipeSeparated: "Separado por barra vertical",
copyExtractorPretty: "Tabla formateada",
copyExtractorConfigure: "Configurar extractor de datos…",
+ copyExtractorDefaultFormat: "Formato de copia predeterminado",
copyExtractorFormat: "Extractor",
copyExtractorColumnSeparator: "Separador de columnas",
copyExtractorRowSeparator: "Separador de filas",
diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.ts
index 431d097b61..f5f8ce4047 100644
--- a/apps/desktop/src/i18n/locales/it.ts
+++ b/apps/desktop/src/i18n/locales/it.ts
@@ -1322,11 +1322,14 @@ export default withEnglishFallback({
copyExtractorOneRow: "CSV a riga singola",
copyExtractorSqlInList: "Lista SQL IN",
copyExtractorSqlInserts: "Istruzioni SQL INSERT",
+ copyExtractorSqlInsertsWithPrimaryKeys: "Istruzioni SQL INSERT (con chiavi primarie)",
+ copyExtractorSqlInsertsWithoutPrimaryKeys: "Istruzioni SQL INSERT (senza chiavi primarie)",
copyExtractorSqlUpdates: "Istruzioni SQL UPDATE",
copyExtractorWhereClause: "Clausola WHERE",
copyExtractorPipeSeparated: "Separato da pipe",
copyExtractorPretty: "Testo tabellare",
copyExtractorConfigure: "Configura estrattore dati…",
+ copyExtractorDefaultFormat: "Formato di copia predefinito",
copyExtractorFormat: "Estrattore",
copyExtractorColumnSeparator: "Separatore di colonna",
copyExtractorRowSeparator: "Separatore di riga",
diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.ts
index 6371c2975c..a11cba087e 100644
--- a/apps/desktop/src/i18n/locales/ja.ts
+++ b/apps/desktop/src/i18n/locales/ja.ts
@@ -1323,11 +1323,14 @@ export default withEnglishFallback({
copyExtractorOneRow: "単行CSV",
copyExtractorSqlInList: "SQL IN リスト",
copyExtractorSqlInserts: "SQL INSERT 文",
+ copyExtractorSqlInsertsWithPrimaryKeys: "SQL INSERT 文(主キーを含む)",
+ copyExtractorSqlInsertsWithoutPrimaryKeys: "SQL INSERT 文(主キーを除外)",
copyExtractorSqlUpdates: "SQL UPDATE 文",
copyExtractorWhereClause: "WHERE 条件",
copyExtractorPipeSeparated: "パイプ区切り",
copyExtractorPretty: "テーブルテキスト",
copyExtractorConfigure: "データ抽出の設定…",
+ copyExtractorDefaultFormat: "デフォルトのコピー形式",
copyExtractorFormat: "抽出器",
copyExtractorColumnSeparator: "列区切り文字",
copyExtractorRowSeparator: "行区切り文字",
diff --git a/apps/desktop/src/i18n/locales/ko.ts b/apps/desktop/src/i18n/locales/ko.ts
index 62e0dc2a0c..80a44fb78a 100644
--- a/apps/desktop/src/i18n/locales/ko.ts
+++ b/apps/desktop/src/i18n/locales/ko.ts
@@ -1022,11 +1022,14 @@ export default withEnglishFallback({
copyExtractorOneRow: "단일 행",
copyExtractorSqlInList: "SQL IN 목록",
copyExtractorSqlInserts: "SQL INSERT",
+ copyExtractorSqlInsertsWithPrimaryKeys: "SQL INSERT (기본 키 포함)",
+ copyExtractorSqlInsertsWithoutPrimaryKeys: "SQL INSERT (기본 키 제외)",
copyExtractorSqlUpdates: "SQL UPDATE",
copyExtractorWhereClause: "WHERE 절",
copyExtractorPipeSeparated: "파이프(|) 구분",
copyExtractorPretty: "보기 좋은 표",
copyExtractorConfigure: "데이터 추출기 설정…",
+ copyExtractorDefaultFormat: "기본 복사 형식",
copyExtractorFormat: "추출기",
copyExtractorColumnSeparator: "열 구분자",
copyExtractorRowSeparator: "행 구분자",
diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.ts
index 732ae94a38..f6822701be 100644
--- a/apps/desktop/src/i18n/locales/pt-BR.ts
+++ b/apps/desktop/src/i18n/locales/pt-BR.ts
@@ -1324,11 +1324,14 @@ export default withEnglishFallback({
copyExtractorOneRow: "CSV de linha única",
copyExtractorSqlInList: "Lista SQL IN",
copyExtractorSqlInserts: "Instruções SQL INSERT",
+ copyExtractorSqlInsertsWithPrimaryKeys: "Instruções SQL INSERT (com chaves primárias)",
+ copyExtractorSqlInsertsWithoutPrimaryKeys: "Instruções SQL INSERT (sem chaves primárias)",
copyExtractorSqlUpdates: "Instruções SQL UPDATE",
copyExtractorWhereClause: "Condição WHERE",
copyExtractorPipeSeparated: "Separado por pipe",
copyExtractorPretty: "Tabela formatada",
copyExtractorConfigure: "Configurar extrator de dados…",
+ copyExtractorDefaultFormat: "Formato de cópia padrão",
copyExtractorFormat: "Extrator",
copyExtractorColumnSeparator: "Separador de coluna",
copyExtractorRowSeparator: "Separador de linha",
diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts
index 839938101a..60d5a27058 100644
--- a/apps/desktop/src/i18n/locales/zh-CN.ts
+++ b/apps/desktop/src/i18n/locales/zh-CN.ts
@@ -1034,11 +1034,14 @@ export default withEnglishFallback({
copyExtractorOneRow: "单行 CSV",
copyExtractorSqlInList: "SQL IN 列表",
copyExtractorSqlInserts: "SQL INSERT 语句",
+ copyExtractorSqlInsertsWithPrimaryKeys: "SQL INSERT 语句(含主键)",
+ copyExtractorSqlInsertsWithoutPrimaryKeys: "SQL INSERT 语句(不含主键)",
copyExtractorSqlUpdates: "SQL UPDATE 语句",
copyExtractorWhereClause: "WHERE 条件",
copyExtractorPipeSeparated: "竖线分隔",
copyExtractorPretty: "表格文本",
copyExtractorConfigure: "配置数据提取器…",
+ copyExtractorDefaultFormat: "默认复制格式",
copyExtractorFormat: "提取器",
copyExtractorColumnSeparator: "列分隔符",
copyExtractorRowSeparator: "行分隔符",
diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.ts
index 7c44d1ec6c..0613f82484 100644
--- a/apps/desktop/src/i18n/locales/zh-TW.ts
+++ b/apps/desktop/src/i18n/locales/zh-TW.ts
@@ -1323,11 +1323,14 @@ export default withEnglishFallback({
copyExtractorOneRow: "單行 CSV",
copyExtractorSqlInList: "SQL IN 列表",
copyExtractorSqlInserts: "SQL INSERT 語句",
+ copyExtractorSqlInsertsWithPrimaryKeys: "SQL INSERT 語句(含主鍵)",
+ copyExtractorSqlInsertsWithoutPrimaryKeys: "SQL INSERT 語句(不含主鍵)",
copyExtractorSqlUpdates: "SQL UPDATE 語句",
copyExtractorWhereClause: "WHERE 條件",
copyExtractorPipeSeparated: "豎線分隔",
copyExtractorPretty: "表格文本",
copyExtractorConfigure: "配置資料提取器…",
+ copyExtractorDefaultFormat: "預設複製格式",
copyExtractorFormat: "提取器",
copyExtractorColumnSeparator: "列分隔符",
copyExtractorRowSeparator: "行分隔符",
diff --git a/apps/desktop/src/lib/dataGrid/dataGridContextMenu.ts b/apps/desktop/src/lib/dataGrid/dataGridContextMenu.ts
index 32b80ebbdf..4c0847e617 100644
--- a/apps/desktop/src/lib/dataGrid/dataGridContextMenu.ts
+++ b/apps/desktop/src/lib/dataGrid/dataGridContextMenu.ts
@@ -16,6 +16,7 @@ export type DataGridContextMenuItem = {
separator?: boolean;
icon?: Component;
iconClass?: string;
+ checked?: boolean;
shortcut?: string;
variant?: "default" | "destructive";
visible?: boolean;