Skip to content

Commit

Permalink
Add plan name column to action dashboard export
Browse files Browse the repository at this point in the history
The new column is only added when there are multiple plans in the
dashboard, which can happen for umbrella plans.
  • Loading branch information
bbliem committed Nov 25, 2024
1 parent 2132e6a commit 482a614
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
22 changes: 19 additions & 3 deletions components/dashboard/ActionStatusExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -126,7 +138,7 @@ async function exportActions(
.filter((p) => p.role === null)
.map(getOrgName);

worksheet.addRow([
const row = [
act.identifier,
actionName,
status?.name,
Expand All @@ -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];
Expand Down
1 change: 1 addition & 0 deletions locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 482a614

Please sign in to comment.