Skip to content

Commit

Permalink
Fix findingTemplates, status tables
Browse files Browse the repository at this point in the history
  • Loading branch information
emiliorizzo committed Nov 10, 2023
1 parent 3160467 commit f1241ec
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
22 changes: 15 additions & 7 deletions src/templates/findingTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,31 @@ export const sortDataByRisk = (data: any[]) => {
)
}

const getTableFields = (fields: string[] | undefined) => {
return fields
? fields.reduce((v: any, a) => {
v[a] = FINDING_LIST_TITLES[a]
return v
}, {})
: {}
}

const renderFindingTable = (
doc: MdDoc,
fields?: string[] | undefined,
sort?: string[] | undefined,
filterStatus?: string,
sortCb?: Function
) => {
const tableFields = fields
? fields.reduce((v: any, a) => {
v[a] = FINDING_LIST_TITLES[a]
return v
}, {})
: {}
const tableFields = getTableFields(fields)
let data = filterDataByStatus(getFindings(doc), filterStatus)
if (sort) {
if (sort && !sortCb) {
data = sortData(data, sort, sortCb)
}
if (sortCb) {
data = sortCb(data)
}

return table(data, tableFields, undefined, undefined, linkFindingTitle)
}

Expand Down
32 changes: 16 additions & 16 deletions src/test/full-example.html
Original file line number Diff line number Diff line change
Expand Up @@ -233,37 +233,37 @@ <h2 id="action-required-findings" tabindex="-1">Action required findings</h2>
<div class="finding-table-status-problem">
<table ><tr ><th class="field-id" data-value="Id" >Id</th>
<th class="field-title" data-value="Title" >Title</th>
<th class="field-risk" data-value="Risk" >Risk</th></tr><tr ><td class="field-id" data-value="ISSUE-001" >ISSUE-001</td>
<td class="field-title" ><a href="#finding-ISSUE-001" >Untitled Finding</a></td>
<td class="field-risk" data-value="high" >high</td></tr><tr ><td class="field-id" data-value="ISSUE-006" >ISSUE-006</td>
<th class="field-risk" data-value="Risk" >Risk</th></tr><tr ><td class="field-id" data-value="ISSUE-006" >ISSUE-006</td>
<td class="field-title" ><a href="#finding-ISSUE-006" >Untitled Finding</a></td>
<td class="field-risk" data-value="medium" >medium</td></tr></table></div>
<td class="field-risk" data-value="medium" >medium</td></tr><tr ><td class="field-id" data-value="ISSUE-001" >ISSUE-001</td>
<td class="field-title" ><a href="#finding-ISSUE-001" >Untitled Finding</a></td>
<td class="field-risk" data-value="high" >high</td></tr></table></div>
<h2 id="attention-required-findings" tabindex="-1">Attention required findings</h2>
<div class="finding-table-status-warning">
<table ><tr ><th class="field-id" data-value="Id" >Id</th>
<th class="field-title" data-value="Title" >Title</th>
<th class="field-risk" data-value="Risk" >Risk</th></tr><tr ><td class="field-id" data-value="ISSUE-003" >ISSUE-003</td>
<td class="field-title" ><a href="#finding-ISSUE-003" >Untitled Finding</a></td>
<td class="field-risk" data-value="high" >high</td></tr><tr ><td class="field-id" data-value="ISSUE-004" >ISSUE-004</td>
<td class="field-title" ><a href="#finding-ISSUE-004" >Untitled Finding</a></td>
<td class="field-risk" data-value="high" >high</td></tr><tr ><td class="field-id" data-value="ISSUE-005" >ISSUE-005</td>
<td class="field-title" ><a href="#finding-ISSUE-005" >Untitled Finding</a></td>
<td class="field-risk" data-value="high" >high</td></tr><tr ><td class="field-id" data-value="ISSUE-008" >ISSUE-008</td>
<th class="field-risk" data-value="Risk" >Risk</th></tr><tr ><td class="field-id" data-value="ISSUE-008" >ISSUE-008</td>
<td class="field-title" ><a href="#finding-ISSUE-008" >Untitled Finding</a></td>
<td class="field-risk" data-value="low" >low</td></tr><tr ><td class="field-id" data-value="ISSUE-009" >ISSUE-009</td>
<td class="field-title" ><a href="#finding-ISSUE-009" >Untitled Finding</a></td>
<td class="field-risk" data-value="low" >low</td></tr><tr ><td class="field-id" data-value="ISSUE-010" >ISSUE-010</td>
<td class="field-title" ><a href="#finding-ISSUE-010" >Untitled Finding</a></td>
<td class="field-risk" data-value="low" >low</td></tr></table></div>
<td class="field-risk" data-value="low" >low</td></tr><tr ><td class="field-id" data-value="ISSUE-003" >ISSUE-003</td>
<td class="field-title" ><a href="#finding-ISSUE-003" >Untitled Finding</a></td>
<td class="field-risk" data-value="high" >high</td></tr><tr ><td class="field-id" data-value="ISSUE-004" >ISSUE-004</td>
<td class="field-title" ><a href="#finding-ISSUE-004" >Untitled Finding</a></td>
<td class="field-risk" data-value="high" >high</td></tr><tr ><td class="field-id" data-value="ISSUE-005" >ISSUE-005</td>
<td class="field-title" ><a href="#finding-ISSUE-005" >Untitled Finding</a></td>
<td class="field-risk" data-value="high" >high</td></tr></table></div>
<h2 id="no-action-required-findings" tabindex="-1">No action required findings</h2>
<div class="finding-table-status-ok">
<table ><tr ><th class="field-id" data-value="Id" >Id</th>
<th class="field-title" data-value="Title" >Title</th>
<th class="field-risk" data-value="Risk" >Risk</th></tr><tr ><td class="field-id" data-value="ISSUE-002" >ISSUE-002</td>
<td class="field-title" ><a href="#finding-ISSUE-002" >Untitled Finding</a></td>
<td class="field-risk" data-value="high" >high</td></tr><tr ><td class="field-id" data-value="ISSUE-007" >ISSUE-007</td>
<th class="field-risk" data-value="Risk" >Risk</th></tr><tr ><td class="field-id" data-value="ISSUE-007" >ISSUE-007</td>
<td class="field-title" ><a href="#finding-ISSUE-007" >Untitled Finding</a></td>
<td class="field-risk" data-value="medium" >medium</td></tr></table></div>
<td class="field-risk" data-value="medium" >medium</td></tr><tr ><td class="field-id" data-value="ISSUE-002" >ISSUE-002</td>
<td class="field-title" ><a href="#finding-ISSUE-002" >Untitled Finding</a></td>
<td class="field-risk" data-value="high" >high</td></tr></table></div>
<h2 id="executive-summary" tabindex="-1">Executive Summary</h2>
<div class="finding-resume">
<table ><tr ><th class="field-high" >high risk</th>
Expand Down

0 comments on commit f1241ec

Please sign in to comment.