From 482a61486f0641932c6467f22c5992cc0e3a216a Mon Sep 17 00:00:00 2001 From: Bernhard Bliem Date: Mon, 18 Nov 2024 11:23:52 +0100 Subject: [PATCH] Add plan name column to action dashboard export The new column is only added when there are multiple plans in the dashboard, which can happen for umbrella plans. --- components/dashboard/ActionStatusExport.js | 22 +++++++++++++++++++--- locales/en/common.json | 1 + 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/components/dashboard/ActionStatusExport.js b/components/dashboard/ActionStatusExport.js index e094a388c..f9a816a30 100644 --- a/components/dashboard/ActionStatusExport.js +++ b/components/dashboard/ActionStatusExport.js @@ -22,7 +22,9 @@ async function exportActions( const worksheet = workbook.addWorksheet( t('actions', getActionTermContext(plan)) ); - worksheet.columns = [ + const planIds = new Set(actions.map((action) => action.plan.id)); + const multiplePlans = planIds.size > 1; + const columns = [ { header: t('action-identifier'), key: 'id', width: 10 }, { header: t('action-name-title', getActionTermContext(plan)), @@ -72,6 +74,16 @@ async function exportActions( width: 20, }, ]; + if (multiplePlans) { + columns.unshift({ + header: t('plan'), + key: 'plan', + width: 20, + }); + } + // When assigning to worksheet.columns, some magic happens and manipulating worksheet.columns afterwards does not + // yield the desired results. So we prepare the columns array separately before assigning it to worksheet.columns. + worksheet.columns = columns; actions.forEach((act) => { const status = cleanActionStatus(act, actionStatuses); // Remove any soft hyphens in action name (due to `hyphenated: true` when querying the name) as Excel renders @@ -126,7 +138,7 @@ async function exportActions( .filter((p) => p.role === null) .map(getOrgName); - worksheet.addRow([ + const row = [ act.identifier, actionName, status?.name, @@ -139,7 +151,11 @@ async function exportActions( primaryResponsibleOrgs.join(';'), collaboratorResponsibleOrgs.join(';'), otherResponsibleOrgs.join(';'), - ]); + ]; + if (multiplePlans) { + row.unshift(act.plan.name); + } + worksheet.addRow(row); }); const today = new Date().toISOString().split('T')[0]; diff --git a/locales/en/common.json b/locales/en/common.json index 3a9982a34..136d4cf34 100644 --- a/locales/en/common.json +++ b/locales/en/common.json @@ -98,6 +98,7 @@ "page": "Page", "page-not-found": "Page not found", "percent-point-abbreviation": "p.p.", + "plan": "Plan", "previous": "Previous", "published-on": "Published on", "read-more": "Read more",