Skip to content

Commit

Permalink
Merge pull request #4172 from bruntib/static_html_dynamic
Browse files Browse the repository at this point in the history
[feat] Display dynamic columns in static HTML
  • Loading branch information
bruntib authored Apr 16, 2024
2 parents 3d46cda + 96549b3 commit 8f08fa8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class HTMLReport(TypedDict):
notes: HTMLBugPathEvents
reviewStatus: Optional[str]
severity: Optional[str]
testcase: Optional[str]
timestamp: Optional[str]


HTMLReports = List[HTMLReport]
Expand Down Expand Up @@ -251,7 +253,11 @@ def to_macro_expansions(
'notes': to_bug_path_events(report.notes),
'reviewStatus': report.review_status.formatted_status()
if report.review_status else '',
'severity': self.get_severity(report.checker_name)
'severity': self.get_severity(report.checker_name),
'testcase': report.annotations.get('testcase')
if report.annotations else None,
'timestamp': report.annotations.get('timestamp')
if report.annotations else None
})

return html_reports, files
Expand Down Expand Up @@ -312,7 +318,9 @@ def create_index_html(self, output_dir: str):
'message': data['report']['message'],
'review-status': data['report']['reviewStatus'],
'severity': data['report']['severity'],
'bug-path-length': len(data['report']['events'])
'bug-path-length': len(data['report']['events']),
'testcase': data['report']['testcase'],
'timestamp': data['report']['timestamp']
}, html_report_links)

self._tag_contents['table_reports'] = json.dumps(list(table_reports))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
<th id="message">Message</th>
<th id="bug-path-length">Bug path length</th>
<th id="review-status">Review status</th>
<th id="testcase" class="dynamic">Testcase</th>
<th id="timestamp" class="dynamic">Timestamp</th>
</tr>
</thead>
<tbody id="report-list">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ var BugList = {
},

_cmp3 : function (a, b) {
return a < b ? -1 : a > b ? 1 : 0;
if (a === null)
return -1;
else if (b === null)
return 1;
else
return a < b ? -1 : a > b ? 1 : 0;
},

initTableSort : function () {
Expand Down Expand Up @@ -73,17 +78,24 @@ var BugList = {
function compare(a, b) {
var result;

if (columnId == 'file-path')
result = that._cmp3(
[a['file-path'], a['line']],
[b['file-path'], b['line']]);

if (columnId == 'severity')
result = that._cmp3(
severities.indexOf(a['severity']),
severities.indexOf(b['severity']));

result = that._cmp3(a[columnId], b[columnId]);
switch (columnId)
{
case 'file-path':
result = that._cmp3(
[a['file-path'], a['line']],
[b['file-path'], b['line']]);
break;

case 'severity':
result = that._cmp3(
severities.indexOf(a['severity']),
severities.indexOf(b['severity']));
break;

default:
result = that._cmp3(a[columnId], b[columnId]);
break;
}

return asc ? result : -result;
}
Expand Down Expand Up @@ -138,6 +150,18 @@ var BugList = {
review_col.appendChild(document.createTextNode(data['review-status']));
row.appendChild(review_col);

let testcase_col = document.createElement('td');
testcase_col.setAttribute('class', 'dynamic');
testcase_col.appendChild(
document.createTextNode(data['testcase'] || ''));
row.appendChild(testcase_col);

let timestamp_col = document.createElement('td');
timestamp_col.setAttribute('class', 'dynamic');
timestamp_col.appendChild(
document.createTextNode(data['timestamp'] || ''));
row.appendChild(timestamp_col);

return row;
},

Expand All @@ -148,9 +172,21 @@ var BugList = {
var report_list = document.getElementById('report-list');
report_list.innerHTML = '';

for (var i = startIdx; i < endIdx; ++i)
var dynamic_cols_needed = false;

for (var i = startIdx; i < endIdx; ++i) {
report_list.appendChild(this.buildRow(reports[i], i + 1));

if (reports[i]['testcase'] || reports[i]['timestamp'])
dynamic_cols_needed = true;
}

for (var tag of document.getElementsByClassName('dynamic'))
if (dynamic_cols_needed)
tag.style.removeProperty('display');
else
tag.style.display = 'none';

this.initBugPathLength();
},

Expand Down

0 comments on commit 8f08fa8

Please sign in to comment.