feat(grid): export selections with data extractors

Closes #10360
This commit is contained in:
t8y2 committed 2026-09-26 16:45:22 +00:00
1 parent 5a272565bb
commit 749d72d874
5 files changed
+175 -22

No files matched your search

+11 -6
View File
@@ -7731,6 +7731,7 @@ const {
copyWithPreference,
previewWithPreference,
canCopyWithExtractor,
exportWithExtractor,
exportCsv,
exportCurrentPageCsv,
exportJson,
@@ -11771,7 +11772,7 @@ function filterSubmenu(): ContextMenuItem {
});
}
function buildExtractorContextItems(): ContextMenuItem[] {
function buildExtractorContextItems(destination: "copy" | "export" = "copy"): ContextMenuItem[] {
const items: ContextMenuItem[] = [];
let separatorPending = false;
for (const extractor of DATA_GRID_COPY_EXTRACTOR_IDS) {
@@ -11784,21 +11785,21 @@ function buildExtractorContextItems(): ContextMenuItem[] {
const extractorItems: ContextMenuItem[] = [];
if (extractor === "sql-inserts") {
for (const excludePrimaryKeysFromInsert of [false, true]) {
if (selected && settingsStore.editorSettings.dataGridExtractorOptions.sql.excludePrimaryKeysFromInsert === excludePrimaryKeysFromInsert) continue;
if (destination === "copy" && selected && settingsStore.editorSettings.dataGridExtractorOptions.sql.excludePrimaryKeysFromInsert === excludePrimaryKeysFromInsert) continue;
const options = sqlInsertExtractorOptions(excludePrimaryKeysFromInsert);
extractorItems.push({
label: t(excludePrimaryKeysFromInsert ? "grid.copyExtractorSqlInsertsWithoutPrimaryKeys" : "grid.copyExtractorSqlInsertsWithPrimaryKeys"),
action: () => void copyWithExtractor(extractor, options),
action: () => void (destination === "copy" ? copyWithExtractor(extractor, options) : exportWithExtractor(extractor, options)),
disabled: !canCopyWithExtractor(extractor, options),
});
}
} else if (!selected) {
} else if (destination === "export" || !selected) {
extractorItems.push({
label: copyExtractorLabel(extractor),
action: () => {
// One-off copy as the chosen format; do NOT persist it as the default —
// One-off use of the chosen format; do NOT persist it as the default —
// the saved default stays controlled by the toolbar/settings dialog.
void copyWithExtractor(extractor);
void (destination === "copy" ? copyWithExtractor(extractor) : exportWithExtractor(extractor));
},
disabled: !canCopyWithExtractor(extractor),
});
@@ -11902,6 +11903,10 @@ function exportSubmenu(): ContextMenuItem {
{ label: t("grid.exportSelectedRowsTxt"), action: exportSelectedRowsTxt },
);
}
const extractorItems = buildExtractorContextItems("export");
if (extractorItems.length > 0) {
items.push({ label: "", separator: true }, ...extractorItems);
}
return { label: t("grid.export"), icon: Upload, children: items };
}
@@ -353,6 +353,35 @@ describe("DataGrid context menu target lifecycle", () => {
expect(contextMenuLabels()).toContain("Filter");
});
it("offers extractor file exports for the selected cell", async () => {
const { host } = mountGrid(hydratedResult(1, "value"));
await settle();
openContextMenu(gridCell(host));
await settle();
contextMenuButton("Export").dispatchEvent(new MouseEvent("mouseenter", { bubbles: true }));
await settle();
expect(contextMenuButton("Cell Text").disabled).toBe(false);
expect(contextMenuButton("JSON Array").disabled).toBe(false);
expect(contextMenuButton("SQL Select").disabled).toBe(false);
});
it("keeps unsupported extractor exports disabled for a whole-column selection", async () => {
const { host } = mountGrid(hydratedResult(1, "value"));
await settle();
columnHeader(host, 1).click();
await settle();
openContextMenu(columnHeader(host, 1));
await settle();
contextMenuButton("Export").dispatchEvent(new MouseEvent("mouseenter", { bubbles: true }));
await settle();
expect(contextMenuButton("JSON Array").disabled).toBe(false);
expect(contextMenuButton("SQL Select").disabled).toBe(true);
});
async function openGridSearchAndType(host: HTMLElement, query: string) {
await settle();
const gridRoot = host.querySelector<HTMLElement>("[data-grid-root]");