From 9d0235fa7364fd1b6a413092b400340661789c11 Mon Sep 17 00:00:00 2001 From: Rahman Date: Wed, 17 Jan 2024 15:20:18 +0100 Subject: [PATCH 1/3] fix(datagrid-web): fix not exporting dynamicText in xlsx --- .../datagrid-web/src/Datagrid.tsx | 5 +- .../datagrid-web/src/features/export.ts | 52 ++++++++++++++----- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/packages/pluggableWidgets/datagrid-web/src/Datagrid.tsx b/packages/pluggableWidgets/datagrid-web/src/Datagrid.tsx index 815f1de60b..6ab0ae5ed2 100644 --- a/packages/pluggableWidgets/datagrid-web/src/Datagrid.tsx +++ b/packages/pluggableWidgets/datagrid-web/src/Datagrid.tsx @@ -43,7 +43,10 @@ function Container(props: Props): ReactElement { const [state, actions] = useGridState(props.initParams, props.mappedColumns, props.onStateChange); const [{ items, exporting, processedRows }, { abort }] = useDG2ExportApi({ - columns: state.visibleColumns.map(column => props.columns[column.columnNumber]), + columns: useMemo( + () => state.visibleColumns.map(column => props.columns[column.columnNumber]), + [state.visibleColumns, props.columns] + ), hasMoreItems: props.datasource.hasMoreItems || false, items: props.datasource.items, name: props.name, diff --git a/packages/pluggableWidgets/datagrid-web/src/features/export.ts b/packages/pluggableWidgets/datagrid-web/src/features/export.ts index 9c95ae67a0..290459f2d0 100644 --- a/packages/pluggableWidgets/datagrid-web/src/features/export.ts +++ b/packages/pluggableWidgets/datagrid-web/src/features/export.ts @@ -219,24 +219,49 @@ function exportColumns(columns: ColumnsType[]): Message { return { type: "columns", payload: exportColumns }; } -function exportData(data: ObjectItem[], columns: ColumnsType[]): Message { - const items = data.map(item => { - return columns.map(column => { - let value = ""; +type ExportDataResult = + | { + status: "pending"; + } + | { + status: "ready"; + message: Message; + }; + +function exportData(data: ObjectItem[], columns: ColumnsType[]): ExportDataResult { + const rows = []; + let hasLoadingItem = false; + for (const item of data) { + const row = []; + for (const column of columns) { + let value = ""; if (column.showContentAs === "attribute") { value = column.attribute?.get(item)?.displayValue ?? ""; } else if (column.showContentAs === "dynamicText") { - value = column.dynamicText?.get(item)?.value ?? ""; + const dynamicText = column.dynamicText?.get(item); + if (dynamicText?.status === "loading") { + hasLoadingItem = true; + } else if (dynamicText?.status === "unavailable") { + value = "n/a"; + } else { + value = dynamicText?.value ?? ""; + } } else { value = "n/a (custom content)"; } + row.push(value); + } + rows.push(row); + } - return value; - }); - }); + if (hasLoadingItem) { + return { + status: "pending" + }; + } - return { type: "data", payload: items }; + return { status: "ready", message: { type: "data", payload: rows } }; } type CallbackFunction = (msg: Message) => Promise | void; @@ -397,7 +422,7 @@ function exportStateReducer(state: State, action: Action): State { } if (action.type === "ColumnsUpdate") { - if (state.phase === "readyToStart" || state.phase === "exportColumns") { + if (state.phase === "readyToStart" || state.phase === "exportColumns" || state.phase === "exportData") { return { ...state, columns: action.payload.columns @@ -511,8 +536,11 @@ function createExportFlow(): [ExportFlowFn, ExportFlowCleanup] { if (state.phase === "exportData") { const { currentItems, callback, columns } = state; if (currentItems.length > 0) { - await controller.exec(() => callback(exportData(currentItems, columns))); - controller.exec(() => dispatch({ type: "PageExported" })); + const result = exportData(currentItems, columns); + if (result.status === "ready") { + await controller.exec(() => callback(result.message)); + controller.exec(() => dispatch({ type: "PageExported" })); + } } return; } From 17400ab0906a8ad52adbc5b9dcf5d04ded261012 Mon Sep 17 00:00:00 2001 From: Rahman Date: Wed, 17 Jan 2024 16:10:10 +0100 Subject: [PATCH 2/3] fix(datagrid-web): bump version and update changelog --- packages/pluggableWidgets/datagrid-web/CHANGELOG.md | 4 ++++ packages/pluggableWidgets/datagrid-web/package.json | 2 +- packages/pluggableWidgets/datagrid-web/src/package.xml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/pluggableWidgets/datagrid-web/CHANGELOG.md b/packages/pluggableWidgets/datagrid-web/CHANGELOG.md index d9b4f0d345..7b176a9d94 100644 --- a/packages/pluggableWidgets/datagrid-web/CHANGELOG.md +++ b/packages/pluggableWidgets/datagrid-web/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +### Fixed + +- We fixed an issue where Dynamic text values cells would be blank in exported .xlsx + ## [2.12.0] - 2024-01-16 ### Added diff --git a/packages/pluggableWidgets/datagrid-web/package.json b/packages/pluggableWidgets/datagrid-web/package.json index 7e8c4a6111..041e2f56b0 100644 --- a/packages/pluggableWidgets/datagrid-web/package.json +++ b/packages/pluggableWidgets/datagrid-web/package.json @@ -1,7 +1,7 @@ { "name": "@mendix/datagrid-web", "widgetName": "Datagrid", - "version": "2.12.0", + "version": "2.12.1", "description": "", "copyright": "© Mendix Technology BV 2023. All rights reserved.", "private": true, diff --git a/packages/pluggableWidgets/datagrid-web/src/package.xml b/packages/pluggableWidgets/datagrid-web/src/package.xml index 11b5e1610d..4517de8918 100644 --- a/packages/pluggableWidgets/datagrid-web/src/package.xml +++ b/packages/pluggableWidgets/datagrid-web/src/package.xml @@ -1,6 +1,6 @@ - + From df1e693ff1057627f200e1d3cc0e0bf3b4fa78d6 Mon Sep 17 00:00:00 2001 From: Rahman Date: Fri, 19 Jan 2024 14:30:07 +0100 Subject: [PATCH 3/3] fix(datagrid-web): revert back to .map() usage --- .../datagrid-web/src/features/export.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/pluggableWidgets/datagrid-web/src/features/export.ts b/packages/pluggableWidgets/datagrid-web/src/features/export.ts index 290459f2d0..d3b5090147 100644 --- a/packages/pluggableWidgets/datagrid-web/src/features/export.ts +++ b/packages/pluggableWidgets/datagrid-web/src/features/export.ts @@ -229,12 +229,9 @@ type ExportDataResult = }; function exportData(data: ObjectItem[], columns: ColumnsType[]): ExportDataResult { - const rows = []; let hasLoadingItem = false; - - for (const item of data) { - const row = []; - for (const column of columns) { + const items = data.map(item => { + return columns.map(column => { let value = ""; if (column.showContentAs === "attribute") { value = column.attribute?.get(item)?.displayValue ?? ""; @@ -250,10 +247,9 @@ function exportData(data: ObjectItem[], columns: ColumnsType[]): ExportDataResul } else { value = "n/a (custom content)"; } - row.push(value); - } - rows.push(row); - } + return value; + }); + }); if (hasLoadingItem) { return { @@ -261,7 +257,7 @@ function exportData(data: ObjectItem[], columns: ColumnsType[]): ExportDataResul }; } - return { status: "ready", message: { type: "data", payload: rows } }; + return { status: "ready", message: { type: "data", payload: items } }; } type CallbackFunction = (msg: Message) => Promise | void;