Skip to content

Commit 19ba5bb

Browse files
author
Trong Nhan Mai
committed
chore: hide the check report table when first open the HTML report when there is no passing check
Signed-off-by: Trong Nhan Mai <[email protected]>
1 parent d040496 commit 19ba5bb

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

src/macaron/output_reporter/results.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,17 @@ def get_dict(self) -> dict:
116116
dict
117117
The dictionary representation of this record.
118118
"""
119+
has_passing_check = False
120+
if self.context:
121+
for res in self.context.check_results.values():
122+
if res["result_type"] == CheckResultType.PASSED:
123+
has_passing_check = True
124+
break
125+
119126
result = {
120127
"metadata": {
121128
"timestamps": datetime.now().isoformat(sep=" ", timespec="seconds"),
129+
"has_passing_check": has_passing_check,
122130
},
123131
"target": self.context.get_dict() if self.context else {},
124132
"dependencies": self.get_dep_summary(),

src/macaron/output_reporter/templates/base_template.html

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,26 +255,30 @@
255255
padding-left: 2em
256256
}
257257

258-
.caret {
258+
/*
259+
The reason why we need to create a separate .togler class is because all .caret calss are set binded
260+
to the listener for extending/collapsing the provenance fields.
261+
*/
262+
.caret, .toggler {
259263
cursor: pointer;
260264
user-select: none;
261265
}
262266

263267
/* Create the caret using a unicode symbol, and style it. */
264-
.caret::before {
268+
.caret::before, .toggler::before {
265269
content: "\25B8";
266270
color: black;
267271
display: inline-block;
268272
margin-right: 6px;
269273
}
270274

271275
/* Rotate the caret icon when clicked on. */
272-
.caret-down::before {
276+
.caret-down::before, .toggler-extend::before {
273277
transform: rotate(90deg);
274278
}
275279

276280
/* Hide the nested list. */
277-
.nested-ul {
281+
.nested-ul, .hidden {
278282
display: none;
279283
}
280284

@@ -672,6 +676,13 @@
672676
});
673677
}
674678

679+
// Add a listener to the caret for extending/collapsing the check status table.
680+
let check_status_toggler = document.getElementById("check_report_title");
681+
check_status_toggler.addEventListener("click", function() {
682+
this.classList.toggle("toggler-extend");
683+
document.getElementById("check_report_content").classList.toggle("hidden");
684+
});
685+
675686
// When loaded, expand all CI services.<n> elements
676687
setExpandState(document.querySelectorAll(".tree-view-nested-list > * > .caret"), true);
677688
setExpandState(document.querySelectorAll(".tree-view-nested-list > * > * > * > .caret"), true);

src/macaron/output_reporter/templates/macaron.html

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,29 @@
215215

216216
<div class='space_divider'></div>
217217

218-
<div class="table_caption">Reports for Macaron checks</div>
219-
{{ render_checks_report(target.checks.results) | indent(4) }}
218+
{#
219+
When there is no passing check for this software component, we hide the check report table when the viewer
220+
first open the HTML file. However, the viewer could click the `toggler` to expand the table if they want to see it. To achieve this, there are two component we need to handle:
221+
- The toggler, which is the symbol that indicate the Extended or Collapsed state of the check report table:
222+
The class ``toggler-extend`` will apply the CSS rule to rotate the toggler symbol indicating the "Extend" state.
223+
If ``toggler-extend`` is not set, the toggler will be in the Collapsed state.
224+
- The ``check_report_content`` div, which contains the check report table: The HTML class ``hidden`` will set ``display: none`` to this div and hide the check report table.
225+
#}
226+
{% if metadata.has_passing_check %}
227+
{#
228+
Set the default state to Extend if there is a passing check.
229+
#}
230+
<div class="table_caption toggler toggler-extend" id="check_report_title">Reports for Macaron checks</div>
231+
<div id="check_report_content">
232+
{% else %}
233+
{#
234+
Set the default state to Collapsed if there is no passing check.
235+
#}
236+
<div class="table_caption toggler" id="check_report_title">Reports for Macaron checks</div>
237+
<div id="check_report_content" class="hidden">
238+
{% endif %}
239+
{{ render_checks_report(target.checks.results) | indent(8) }}
240+
</div>
220241

221242
<div class='space_divider'></div>
222243

0 commit comments

Comments
 (0)