Skip to content

add a clear-sort button to the data viewer status bar - #17960

Merged
kevinushey merged 4 commits into
mainfrom
feature/data-viewer-clear-sort-button
Jun 12, 2026
Merged

kevinushey merged 4 commits into
mainfrom
feature/data-viewer-clear-sort-button

Conversation

@kevinushey

@kevinushey kevinushey commented Jun 12, 2026 •

Copy link
Copy Markdown
Collaborator

When a column sort is active, the "Sorted by: ()" status at the right of the data viewer's info bar now includes a small X button that clears the sort, restoring the frame's natural row order.

Implementation notes:

  • The sort status element is split into a text span plus a persistent <button>, so the button's click listener (wired once at DOMContentLoaded, like the sidebar toggle) survives info-bar updates; a setSortStatus() helper updates the text and toggles button visibility everywhere the status used to be written directly.
  • clearSort() mirrors handleSortClick's unsort path: it resets the sort state, clears the active cell, resets header arrows and aria-sort, re-fetches from the top, and saves state so the cleared sort persists.
  • The button reuses the same inline-SVG X icon styling as the column filter's clear affordance.

Includes an e2e test covering: sort applied -> status text and button visible -> click -> natural order restored, status cleared, button hidden, header indicator and aria-sort reset.

No NEWS.md entry since the sort status bar is part of the unreleased data viewer rework.

Fixes #17959.


Also tags along an unrelated e2e-stability fix (45d2a49): ScrollUtil.setScrollPositionOnLoad polled the rmd preview frame's document without a try/catch, so a transiently cross-origin frame raised an uncaught SecurityError from the 50ms timer -- killing the scroll restore and (since #17956) failing whichever e2e test was running, as seen with create new rmarkdown and knit to HTML in run #240. A throw is now treated like the other not-ready cases and polling continues, matching the guarded versions of the same access in RmdOutputFramePane.

When a column sort is active, the "Sorted by: <column>" status at the
right of the info bar now includes a small X button that clears the
sort, restoring the frame's natural row order. The status element is
split into a text span plus a persistent button so the button's click
listener survives info-bar updates.
@kevinushey kevinushey added this to the Blue Plumbago milestone Jun 12, 2026
@kevinushey kevinushey self-assigned this Jun 12, 2026
@gtritchie

Copy link
Copy Markdown
Member

Code review findings

Actionable items from an automated multi-agent review. Strengths, dismissed findings, and ratings
are omitted.

Important

  1. src/cpp/session/resources/grid/DataViewer.js:1095 — the comment "Reset the header arrows, and
    aria-sort on whichever header was sorted" is misleading: the loop below resets aria-sort on
    every sortable header, not just the sorted one. It also doesn't explain why the loop is needed.
    Fix: reword to note that applySortIndicators() only resets arrow classes, so aria-sort must
    be cleared on every sortable header separately.

  2. e2e/rstudio/tests/panes/data-viewer/pagination-sorting.test.ts:131 — the PR claims clearing
    "saves state so the cleared sort persists," and clearSort() writes sort: null via
    saveState() (DataViewer.js:1110/4499), but no test verifies the sort stays cleared after a
    reload. A sort that visibly clears then reappears on reload would pass the current test. Fix: add
    a reload assertion using the existing template at data_viewer.test.ts:273.

Suggestions

  1. e2e/rstudio/tests/panes/data-viewer/pagination-sorting.test.ts:131 — the 3-row frame makes
    scrollToTop() + re-fetch-from-row-0 (DataViewer.js:1106-1109) a no-op, leaving the logic that
    distinguishes clearSort from a trivial state reset uncovered. A tall frame scrolled down then
    cleared would exercise it.

  2. e2e/rstudio/tests/panes/data-viewer/pagination-sorting.test.ts:131 — only a descending sort is
    cleared; the ascending case (one click) is untested. Low risk since clearSort is
    direction-agnostic.

  3. e2e/rstudio/tests/panes/data-viewer/pagination-sorting.test.ts:160 — sortStatus.not. toContainText('Sorted by') reads the whole container; the new #rsGridData_info_sort_text span
    would be marginally more precise. Current assertion is correct as-is.

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Feedback posted, nit-picky stuff.

@github-actions

github-actions Bot commented Jun 12, 2026 •

Copy link
Copy Markdown

🍎 macOS Desktop E2E · ARM64

✅ All tests passed!

████████████████████ 100% pass rate

✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
376 0 16 0
📥 Download Playwright report

⬇️ playwright-report.zip — extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


2 shards · macos-26 ARM64 · commit 45d2a49e069015213c02bae1c708f93623114dcf · Run #246

@kevinushey

Copy link
Copy Markdown
Collaborator Author

Addressed in 916ed63:

  1. Fixed -- reworded the comment: applySortIndicators() only updates the arrow classes, so aria-sort is cleared separately on every sortable header (mirroring handleSortClick).
  2. Fixed -- the clear-sort test now calls refreshData() after clearing and asserts the rebuilt grid comes back unsorted (natural row order, no status text, hidden button, aria-sort="none"). A restore-path regression that re-applied the stale sort (the filter analogue was add data viewer filter coverage; fix factor restore and stale filter re-apply #17950) would now fail the test.

Dismissing the suggestions:

  1. The re-fetch is already exercised even with 3 rows -- the natural-order assertion only passes if unsorted data came back. What's uncovered is just the scroll reset from a scrolled position, which is marginal.
  2. Agree with the review's own caveat: clearSort() is direction-agnostic past the early-return guard, so an ascending variant adds no coverage.
  3. The review itself concludes the current assertion is correct as-is.

ScrollUtil.setScrollPositionOnLoad polled the preview frame's document
from a 50ms Scheduler timer with no try/catch. When the frame is
transiently cross-origin (mid-navigation or an interim error page),
reading contentWindow.document throws a SecurityError, which killed the
polling loop (so the scroll position was never restored) and surfaced
as an uncaught client exception that fails e2e tests since #17956.

Treat a throw like the other not-ready cases and keep polling, matching
the guarded versions of this same access in RmdOutputFramePane.
@kevinushey
kevinushey merged commit 999f032 into main Jun 12, 2026
1 of 2 checks passed
@kevinushey
kevinushey deleted the feature/data-viewer-clear-sort-button branch June 12, 2026 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

data viewer: add a button to clear the active column sort

2 participants