diff --git a/lib/extensions.js b/lib/extensions.js index e37d8bf..83c9d1b 100644 --- a/lib/extensions.js +++ b/lib/extensions.js @@ -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', @@ -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; }