Skip to content

Make HTML column sorting consistent across index pages (fix #1766) #1768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
92f84bd
Add ids to column headers that you can sort by.
devdanzin Apr 26, 2024
ca3d293
Use table header ids to remember sort columns, special casing the fun…
devdanzin Apr 26, 2024
bffc527
Rename 'function_or_class' and related names to 'region' and related.
devdanzin Apr 27, 2024
775df06
Use 'file' as placeholder for the th id, so we sort on file in the ab…
devdanzin Apr 27, 2024
ad0165d
Fix bug of incorrectly recording direction changes.
devdanzin Apr 27, 2024
e10ecc2
Merge branch 'nedbat:master' into keep_sorted_columns
devdanzin Apr 27, 2024
537b556
Merge remote-tracking branch 'refs/remotes/origin/keep_sorted_columns…
devdanzin Apr 27, 2024
c3303b0
Use 'let' instead of 'var' in the new code.
devdanzin Apr 27, 2024
56958af
Update gold HTML tests.
devdanzin Apr 28, 2024
796239e
Merge branch 'nedbat:master' into keep_sorted_columns
devdanzin Apr 28, 2024
7f0e846
Merge remote-tracking branch 'refs/remotes/origin/keep_sorted_columns…
devdanzin Apr 28, 2024
98d57b0
Support scrubbing temporary paths in test_html.py on Windows.
devdanzin Apr 28, 2024
0df3a27
Fix long line in test_html.
devdanzin Apr 28, 2024
d70d1cf
Add gold files for test_html partial (needs running tests on Python <…
devdanzin Apr 29, 2024
ef5d7fb
Merge branch 'nedbat:master' into keep_sorted_columns
devdanzin Apr 30, 2024
e0bd91d
Merge branch 'nedbat:master' into support_gold_in_windows
devdanzin Apr 30, 2024
b6813d2
Use scrub for Windows path when running test suite in all OSes.
devdanzin Apr 30, 2024
6853e12
Merge branch 'support_gold_in_windows' into keep_sorted_columns
devdanzin Apr 30, 2024
792287d
Merge branch 'nedbat:master' into keep_sorted_columns
devdanzin Apr 30, 2024
173ff76
Merge remote-tracking branch 'refs/remotes/origin/keep_sorted_columns…
devdanzin Apr 30, 2024
188e1e1
Move scrubbing of Windows paths into test_other.
devdanzin Apr 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 48 additions & 4 deletions coverage/htmlfiles/coverage_html.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,31 @@ function sortColumn(th) {
.forEach(tr => tr.parentElement.appendChild(tr));

// Save the sort order for next time.
localStorage.setItem(coverage.INDEX_SORT_STORAGE, JSON.stringify({column, direction}));
if (th.id !== "function_or_class") {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to use function_or_class as the id. I've been careful throughout the function/class implementation to generalize to "region", and in the reports I simply call it "column2" (though now that I type this, "region" would have been better).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've replaced it with "region" and it reads well. Let me know if you'd rather have "column2" instead.

var th_id = "";
const stored_list = localStorage.getItem(coverage.INDEX_SORT_STORAGE);
if (stored_list) {
({th_id, direction} = JSON.parse(stored_list))
}
localStorage.setItem(coverage.INDEX_SORT_STORAGE, JSON.stringify({
"th_id": th.id,
"direction": direction
}));
if (th.id !== th_id || document.getElementById("function_or_class")) {
// Sort column has changed, unset sorting by function or class.
localStorage.setItem(coverage.SORTED_BY_FUNCTION_OR_CLASS, JSON.stringify({
"by_function_or_class": false,
"direction_fc": direction
}));
}
}
else {
// Sort column has changed to by function or class, remember that.
localStorage.setItem(coverage.SORTED_BY_FUNCTION_OR_CLASS, JSON.stringify({
"by_function_or_class": true,
"direction_fc": direction
}));
}
}

// Find all the elements with data-shortcut attribute, and use them to assign a shortcut key.
Expand Down Expand Up @@ -223,18 +247,38 @@ coverage.wire_up_sorting = function () {
);

// Look for a localStorage item containing previous sort settings:
var column = 0, direction = "ascending";
var th_id = "file", direction = "ascending";
const stored_list = localStorage.getItem(coverage.INDEX_SORT_STORAGE);
if (stored_list) {
({column, direction} = JSON.parse(stored_list));
({th_id, direction} = JSON.parse(stored_list));
}
var by_function_or_class = false, direction_fc = "ascending";
const sorted_by_function_or_class = localStorage.getItem(coverage.SORTED_BY_FUNCTION_OR_CLASS);
if (sorted_by_function_or_class) {
({
by_function_or_class,
direction_fc
} = JSON.parse(sorted_by_function_or_class));
}

const th = document.querySelector("[data-sortable]").tHead.rows[0].cells[column]; // nosemgrep: eslint.detect-object-injection
const fcid = "function_or_class";
if (by_function_or_class && document.getElementById(fcid)) {
direction = direction_fc;
}
// If we are in a page that has a column with id of "function_or_class", sort on
// it if the last sort was by function or class.
if (document.getElementById(fcid)) {
var th = document.getElementById(by_function_or_class ? fcid : th_id);
}
else {
var th = document.getElementById(th_id);
}
th.setAttribute("aria-sort", direction === "ascending" ? "descending" : "ascending");
th.click()
};

coverage.INDEX_SORT_STORAGE = "COVERAGE_INDEX_SORT_2";
coverage.SORTED_BY_FUNCTION_OR_CLASS = "COVERAGE_SORT_FUNCTION";

// Loaded on index.html
coverage.index_ready = function () {
Expand Down
16 changes: 8 additions & 8 deletions coverage/htmlfiles/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,18 @@ <h2>
<thead>
{# The title="" attr doesn't work in Safari. #}
<tr class="tablehead" title="Click to sort">
<th class="name left" aria-sort="none" data-shortcut="f">File<span class="arrows"></span></th>
<th id="file" class="name left" aria-sort="none" data-shortcut="f">File<span class="arrows"></span></th>
{% if column2 %}
<th class="name left" aria-sort="none" data-default-sort-order="ascending" data-shortcut="n">{{ column2 }}<span class="arrows"></span></th>
<th id="function_or_class" class="name left" aria-sort="none" data-default-sort-order="ascending" data-shortcut="n">{{ column2 }}<span class="arrows"></span></th>
{% endif %}
<th aria-sort="none" data-default-sort-order="descending" data-shortcut="s">statements<span class="arrows"></span></th>
<th aria-sort="none" data-default-sort-order="descending" data-shortcut="m">missing<span class="arrows"></span></th>
<th aria-sort="none" data-default-sort-order="descending" data-shortcut="x">excluded<span class="arrows"></span></th>
<th id="statements" aria-sort="none" data-default-sort-order="descending" data-shortcut="s">statements<span class="arrows"></span></th>
<th id="missing" aria-sort="none" data-default-sort-order="descending" data-shortcut="m">missing<span class="arrows"></span></th>
<th id="excluded" aria-sort="none" data-default-sort-order="descending" data-shortcut="x">excluded<span class="arrows"></span></th>
{% if has_arcs %}
<th aria-sort="none" data-default-sort-order="descending" data-shortcut="b">branches<span class="arrows"></span></th>
<th aria-sort="none" data-default-sort-order="descending" data-shortcut="p">partial<span class="arrows"></span></th>
<th id="branches" aria-sort="none" data-default-sort-order="descending" data-shortcut="b">branches<span class="arrows"></span></th>
<th id="partial" aria-sort="none" data-default-sort-order="descending" data-shortcut="p">partial<span class="arrows"></span></th>
{% endif %}
<th class="right" aria-sort="none" data-shortcut="c">coverage<span class="arrows"></span></th>
<th id="coverage" class="right" aria-sort="none" data-shortcut="c">coverage<span class="arrows"></span></th>
</tr>
</thead>
<tbody>
Expand Down
Loading