Skip to content

Commit

Permalink
[WC-2300]: DG2: fix not exporting dynamicText (#895)
Browse files Browse the repository at this point in the history
  • Loading branch information
rahmanunver authored Jan 22, 2024
2 parents ee57610 + df1e693 commit b173e9c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
4 changes: 4 additions & 0 deletions packages/pluggableWidgets/datagrid-web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/pluggableWidgets/datagrid-web/package.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
5 changes: 4 additions & 1 deletion packages/pluggableWidgets/datagrid-web/src/Datagrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
40 changes: 32 additions & 8 deletions packages/pluggableWidgets/datagrid-web/src/features/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,24 +219,45 @@ function exportColumns(columns: ColumnsType[]): Message {
return { type: "columns", payload: exportColumns };
}

function exportData(data: ObjectItem[], columns: ColumnsType[]): Message {
type ExportDataResult =
| {
status: "pending";
}
| {
status: "ready";
message: Message;
};

function exportData(data: ObjectItem[], columns: ColumnsType[]): ExportDataResult {
let hasLoadingItem = false;
const items = data.map(item => {
return columns.map(column => {
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)";
}

return value;
});
});

return { type: "data", payload: items };
if (hasLoadingItem) {
return {
status: "pending"
};
}

return { status: "ready", message: { type: "data", payload: items } };
}

type CallbackFunction = (msg: Message) => Promise<void> | void;
Expand Down Expand Up @@ -397,7 +418,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
Expand Down Expand Up @@ -511,8 +532,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;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/pluggableWidgets/datagrid-web/src/package.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<package xmlns="http://www.mendix.com/package/1.0/">
<clientModule name="Datagrid" version="2.12.0" xmlns="http://www.mendix.com/clientModule/1.0/">
<clientModule name="Datagrid" version="2.12.1" xmlns="http://www.mendix.com/clientModule/1.0/">
<widgetFiles>
<widgetFile path="Datagrid.xml" />
</widgetFiles>
Expand Down

0 comments on commit b173e9c

Please sign in to comment.