fix(grid): project mongodb full export to visible columns

This commit is contained in:
二丫讲梵 authored and GitHub committed 2026-09-19 10:54:51 +08:00
1 parent 73178fe677
commit 4a068a4eeb
3 files changed
+115 -16

No files matched your search

@@ -75,6 +75,8 @@ function createMongoExportState(options: {
contextColumn?: number;
syntheticContext?: boolean;
fullExportResult?: UseDataGridExportOptions["fullExportResult"];
hasCompleteLocalResult?: UseDataGridExportOptions["hasCompleteLocalResult"];
completeLocalResult?: UseDataGridExportOptions["completeLocalResult"];
externalCellValue?: UseDataGridExportOptions["externalCellValue"];
}) {
const items = options.items ?? [options.item];
@@ -106,6 +108,8 @@ function createMongoExportState(options: {
selectedRowIds: ref(selectedRowIds),
hasRowSelection: computed(() => selectedRowIds.size > 0),
fullExportResult: options.fullExportResult,
hasCompleteLocalResult: options.hasCompleteLocalResult,
completeLocalResult: options.completeLocalResult,
externalCellValue: options.externalCellValue,
};
return useDataGridExport(state);
@@ -1590,6 +1594,58 @@ describe("useDataGridExport prepared row statements", () => {
expect(exportQueryResultCsv).toHaveBeenLastCalledWith(expect.any(String), ["_id", "value"], [["1", reservedString]], expect.anything());
});
it("exports only visible Mongo columns from the full result set", async () => {
setActivePinia(createPinia());
const state = createMongoExportState({
columns: ["name"],
item: { ...row(["Visible"]), sourceIndex: 0 },
mongoDocuments: [{ _id: "1", name: "Visible", secret: "hidden" }],
fullExportResult: async () => ({
columns: ["_id", "name", "secret"],
column_types: ["", "varchar", "varchar"],
rows: [
["1", "Visible", "hidden"],
["2", "Other", "hidden-too"],
],
affected_rows: 2,
execution_time_ms: 1,
}),
});
await state.exportCsv();
expect(exportQueryResultCsv).toHaveBeenLastCalledWith(expect.any(String), ["name"], [["Visible"], ["Other"]], expect.anything());
});
it("applies visible Mongo columns when the complete result is already local", async () => {
setActivePinia(createPinia());
const completeLocalResult = {
columns: ["_id", "name", "secret"],
column_types: ["", "varchar", "varchar"],
rows: [
["1", "Visible", "hidden"],
["2", "Other", "hidden-too"],
],
mongo_copy_documents: [
{ _id: "1", name: "Visible", secret: "hidden" },
{ _id: "2", name: "Other", secret: "hidden-too" },
],
affected_rows: 2,
execution_time_ms: 1,
};
const state = createMongoExportState({
columns: ["name"],
item: { ...row(["Visible"]), sourceIndex: 0 },
mongoDocuments: [completeLocalResult.mongo_copy_documents[0]],
hasCompleteLocalResult: computed(() => true),
completeLocalResult: computed(() => completeLocalResult),
});
await state.exportCsv();
expect(exportQueryResultCsv).toHaveBeenLastCalledWith(expect.any(String), ["name"], [["Visible"], ["Other"]], expect.anything());
});
it("exports missing Mongo fields as null while retaining explicit empty strings", async () => {
const columns = ["_id", "missing", "nullable", "empty"];
const document = { _id: "1", nullable: null, empty: "" };