Skip to content

Commit

Permalink
Use getAtRisk which filters duplicate statements.
Browse files Browse the repository at this point in the history
  • Loading branch information
aljones15 committed Sep 18, 2024
1 parent 0f6fdd6 commit c8e9699
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions lib/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const extensions = {
templateData: {
addAtRisk({templateData}) {
if(templateData.matrices.length) {
const atRiskRows = templateData.matrices.flatMap(addAtRisk);
const atRiskRows = getAtRisk({matrices: templateData.matrices});
if(atRiskRows.length) {
const atRiskMatrix = {
title: 'At Risk',
Expand All @@ -27,10 +27,20 @@ export const extensions = {
}
};

function addAtRisk({rows = []} = {}) {
return rows.filter(({cells}) => atRisk(cells)).map(
row => {
row.cells = [{state: 'failed'}];
return row;
});
function getAtRisk({matrices}) {
const riskRows = [];
for(const {rows} of matrices) {
for(const row of rows) {
// only include at risk rows
if(atRisk(row?.cells)) {
// do not include duplicate statements
if(!riskRows.find(r => r.id === row.id)) {
const riskRow = structuredClone(row);
riskRow.cells = [{state: 'failed'}];
riskRows.push(riskRow);
}
}
}
}
return riskRows;
}

0 comments on commit c8e9699

Please sign in to comment.