From 2d65069d346709ae5f06977bae405adf3f987f67 Mon Sep 17 00:00:00 2001 From: Remi Blom-Ohlsen Date: Tue, 16 Apr 2024 10:35:17 +0200 Subject: [PATCH] Fix issue with exporting currency and number values in views #1395 --- CHANGELOG.md | 1 + .../ToolbarItems/useExcelExport.ts | 14 +++++++++++++- .../ToolbarItems/useExcelExport.ts | 14 +++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68b0e561e..7234755fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ Sjekk ut [release notes](./releasenotes/1.9.0.md) for høydepunkter og mer detal - Rettet et problem hvor avviklede termer ble vist i nedtrekksmenyer for taksonomi felter [#1499](https://github.com/Puzzlepart/prosjektportalen365/issues/1499) - Rettet et problem hvor antall linjer angitt for et 'multi-linje' felt ikke ble reflektert i det nye redigeringspanelet [#1500](https://github.com/Puzzlepart/prosjektportalen365/issues/1500) - Rettet et problem hvor valuta ikke ble riktig sortert på porteføljeoversikt og andre aggregerte oversikter [#1369](https://github.com/Puzzlepart/prosjektportalen365/issues/1369) +- Rettet et problem hvor eksportering av visninger som inneholdt felttypene 'valuta' og 'nummer' ble vist med masse desimaler [#1395](https://github.com/Puzzlepart/prosjektportalen365/issues/1395) ### Forbedringer diff --git a/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/ToolbarItems/useExcelExport.ts b/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/ToolbarItems/useExcelExport.ts index 6d65314b9..dab7284d9 100644 --- a/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/ToolbarItems/useExcelExport.ts +++ b/SharePointFramework/PortfolioWebParts/src/components/PortfolioAggregation/ToolbarItems/useExcelExport.ts @@ -37,7 +37,19 @@ export function useExcelExport(context: IPortfolioAggregationContext) { }) }) }) - ExcelExportService.export(items, columns) + + const filteredItems = items.map((item) => { + const filteredItem = { ...item } + Object.keys(filteredItem).forEach((key) => { + const column = columns.find((c) => c.fieldName === key) + if (column && (column.dataType === 'currency' || column.dataType === 'number')) { + filteredItem[key] = Math.floor(filteredItem[key]) + } + }) + return filteredItem + }) + + ExcelExportService.export(filteredItems, columns) } catch (error) {} }, [context.state]) diff --git a/SharePointFramework/PortfolioWebParts/src/components/PortfolioOverview/ToolbarItems/useExcelExport.ts b/SharePointFramework/PortfolioWebParts/src/components/PortfolioOverview/ToolbarItems/useExcelExport.ts index d325f2362..069ecb9c3 100644 --- a/SharePointFramework/PortfolioWebParts/src/components/PortfolioOverview/ToolbarItems/useExcelExport.ts +++ b/SharePointFramework/PortfolioWebParts/src/components/PortfolioOverview/ToolbarItems/useExcelExport.ts @@ -37,11 +37,23 @@ export function useExcelExport(context: IPortfolioOverviewContext) { }) }) }) + + const filteredItems = items.map((item) => { + const filteredItem = { ...item } + Object.keys(filteredItem).forEach((key) => { + const column = columns.find((c) => c.fieldName === key) + if (column && (column.dataType === 'currency' || column.dataType === 'number')) { + filteredItem[key] = Math.floor(filteredItem[key]) + } + }) + return filteredItem + }) + let fileNamePart: string if (includeViewNameInExcelExportFilename) { fileNamePart = currentView?.title.replace(/[^a-z0-9]/gi, '-') } - ExcelExportService.export(items, columns, fileNamePart) + ExcelExportService.export(filteredItems, columns, fileNamePart) context.dispatch(EXCEL_EXPORT_SUCCESS()) } catch (error) { context.dispatch(EXCEL_EXPORT_ERROR(error))