Skip to content

Commit c3f6faf

Browse files
Merge pull request #7 from refactorfirst/enhance-table-functionality
Enhance table functionality
2 parents f0974a0 + cc10f2e commit c3f6faf

22 files changed

Lines changed: 4856 additions & 113 deletions

‎AGENTS.md‎

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ in `out/` is served by any static host (GitHub Pages, GitLab Pages, Bitbucket).
1111
**Key Features:**
1212
- Search over curated repository listing (`repositories.txt`)
1313
- Reports rendered with Mustache.js (bundled template is authoritative)
14+
- Enhanced report tables: sticky headers, pagination (>20 rows), sortable
15+
columns, in-table search, CSV export, click/keyboard cell copy with toasts
1416
- Repository submission via pre-filled platform issues — no login, apps or tokens
1517
- Fully static deploy; deep links handled via generateStaticParams + `404.html`
1618

@@ -60,12 +62,17 @@ app/ # Next.js App Router (static export)
6062
components/ # client components: report-view, repo-list,
6163
# repo-submission-form, search-combobox,
6264
# hero-search, menu-search, menu-toggle,
63-
# workflow-sample, platform-config, sentry-provider
65+
# workflow-sample, platform-config, sentry-provider,
66+
# toast-notification (copy feedback live region)
6467
lib/ # shared logic (client + RSC): routes, fetcher,
6568
# renderer, search, utils, host, rate-limiter,
6669
# cache-manager, error-handler, repo-submission,
67-
# report-view, static-params, widget-loader; the
68-
# Node-side listing loader is lib/repositories.js
70+
# report-view, static-params, widget-loader,
71+
# table-operations (filter/sort/paginate/CSV/copy +
72+
# TABLE_CONFIG + REPORT_TABLES descriptors),
73+
# table-enhancer (binds toolbar/sort/pagination/
74+
# copy onto the rendered report DOM); the Node-side
75+
# listing loader is lib/repositories.js
6976
public/ # static files copied verbatim into out/:
7077
repositories.txt # synced from the repo root (sync-repositories.mjs)
7178
assets/ # mustache template, logo
@@ -117,12 +124,54 @@ coverage there when introducing new markup patterns.
117124
`sentry-dsn`, `platform-base-url`) plus `NEXT_PUBLIC_HOSTING_ENVIRONMENT`
118125
/ `NEXT_PUBLIC_BASE_PATH` at build time.
119126

127+
## Report Tables (Enhanced)
128+
129+
- Every data table in the report (class/package relationships, disharmony
130+
findings, cycle summary, cycle breakdown) is enhanced: sticky `thead th`,
131+
toolbar (match live region + copy hint left; search + CSV export right —
132+
the `.rf-table-block` wrapper shrink-wraps the table and the toolbar uses
133+
`contain: inline-size` so controls align with the table's right edge),
134+
sortable th buttons with `aria-sort`, pagination below 20+ row tables, and
135+
click/Enter/Space cell copy with toast feedback. The filter's clear control
136+
is an × button (accessible name "Clear the … table filter").
137+
- Horizontal scrollbar: tables wider than the viewport get `overflow-x: auto`
138+
via the `rf-scroll-x-enabled` class, toggled by `lib/table-enhancer.js`
139+
after measuring `wrapper.scrollWidth > clientWidth` (re-measured on each
140+
re-render and on window resize). It MUST stay conditional — any overflow
141+
ancestor becomes the sticky constraint container and breaks the
142+
viewport-sticky `thead th`. Scrolling tables keep their header pinned
143+
anyway: `refreshStickyHeaders` in lib/table-enhancer.js compensates by
144+
translating every `thead th` down by the viewport scroll offset (clamped to
145+
the table's bottom edge) on window scroll/resize; narrow tables keep pure
146+
CSS stickiness and stale transforms are cleared when overflow goes away.
147+
- Pipeline: `prepareReportData(data, tableStates, TABLE_CONFIG)` in
148+
lib/renderer.js applies **filter → sort → paginate** per table and injects
149+
`tableUi` blocks the mustache template renders; `enhanceTables` in
150+
lib/table-enhancer.js binds the controls and reports state changes back to
151+
components/report-view.jsx, which re-renders (widgets only gate the first
152+
render; the search input's focus/caret is restored after each re-render).
153+
The expensive `enhanceReport` pipeline (Chart.js charts, WASM DOT layout)
154+
runs only when the payload changes — table-state re-renders stash the live
155+
chart canvases / graph containers before the innerHTML swap and graft them
156+
back into the fresh DOM (`statefulElementIds`/`stashStatefulDom`/
157+
`graftStatefulDom` in lib/report-view.js), re-binding only the cheap popup
158+
handlers.
159+
- Search `<input>`s are injected by table-enhancer — `<input>` is FORBID in
160+
the renderer's sanitization allow-list, so it must never appear in the
161+
mustache template.
162+
- CSV export honors the current filter + sort but ignores pagination;
163+
filenames are `refactorfirst-<table>-<ISO timestamp>.csv`.
164+
120165
## Current Test Count
121166

122-
~313 unit/integration + 112 E2E (three browsers + basePath leg).
167+
~485 unit/integration + 175 E2E (171 across three browsers + 4 basePath leg).
123168

124169
WCAG 2.2 AA / HTML5 guards live in tests/unit/html5-attributes.test.js,
125170
tests/unit/report-template-wcag.test.js, tests/unit/css-a11y.test.js and
126171
tests/unit/page-titles.test.js — the report mustache keeps a single h1,
127172
scoped table headers, captions, labelled canvases and a named nav; obsolete
128-
presentational attributes are FORBID_ATTR-stripped in lib/renderer.js.
173+
presentational attributes are FORBID_ATTR-stripped in lib/renderer.js. The
174+
report-template-wcag guard also asserts sticky-header CSS, per-table
175+
toolbars/aria-labelled export buttons and pagination navs, valid `aria-sort`
176+
on every enhanced th, sortable keyboard-operable header buttons and live
177+
match-count regions.

‎README.md‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ is a **Next.js static export** (`bun run build` produces `out/`, which any stati
1010
branch fallback — the same report the
1111
[RefactorFirst report viewer](https://github.com/RefactorFirst/RefactorFirst) produces:
1212
class/package maps (vizdom WASM SVGs with pan/zoom, plus Sigma 2D and 3D force-graph popups), relationship-removal
13-
priority tables, Chart.js disharmony bubble charts and class cycle summaries
13+
priority tables, Chart.js disharmony bubble charts and class cycle summaries — with
14+
[enhanced tables](#enhanced-report-tables) (sticky headers, pagination, sorting, search, CSV export, copy)
1415
- **Repository submission** via a pre-filled issue on the hosting platform (no login, apps or tokens on this site): your
1516
platform account is captured as the issue author and validated server-side by the platform's CI
1617
- Reports and submissions work for repositories hosted on the same platform as the deployment (GitHub, GitLab or
@@ -29,6 +30,7 @@ is a **Next.js static export** (`bun run build` produces `out/`, which any stati
2930
- [Deploying to Bitbucket](#deploying-to-bitbucket)
3031
- [Deploying to GitLab](#deploying-to-gitlab)
3132
- [How repository submission works](#how-repository-submission-works)
33+
- [Enhanced report tables](#enhanced-report-tables)
3234
- [Making Changes (Developer Guide)](#making-changes-developer-guide)
3335
- [Testing](#testing)
3436

@@ -289,6 +291,37 @@ GitLab Pages deploys from the `pages` job and serves
289291
290292
---
291293

294+
## Enhanced report tables
295+
296+
Large report tables (class/package relationships, disharmony findings, cycle summaries and cycle breakdowns) are
297+
interactive — all WCAG 2.2 AA and keyboard-operable, with no extra dependencies:
298+
299+
- **Sticky headers** — column headers stay pinned to the top of the viewport while you scroll a table.
300+
- **Pagination** — tables with more than 20 matching rows paginate at 20 rows per page ("Page X of Y" + Previous/Next
301+
buttons; disabled on the first/last page). Small tables render in full without controls.
302+
- **Sorting** — click a column header (or focus it and press Enter/Space) to sort the whole table ascending; click
303+
again for descending. `aria-sort` reflects the current direction, sorting happens before pagination, and the sort is
304+
kept while navigating pages.
305+
- **Search/filter** — the filter box sits at the right edge of the table (next to Export) and narrows rows
306+
case-insensitively across all columns (debounced), with the match count announced via a live region and an **×**
307+
button to reset.
308+
- **CSV export** — "Export CSV" downloads the entire table (current filter and sort applied, pagination ignored) with
309+
proper escaping; the filename includes the table name and a timestamp.
310+
- **Horizontal scrolling** — when a table is wider than the screen its wrapper gains a horizontal scrollbar
311+
(`rf-scroll-x-enabled`, toggled by measurement in `lib/table-enhancer.js`); the scrollbar is deliberately conditional
312+
because an unconditional `overflow-x` would break the viewport-sticky table header. Scrolling tables keep their
313+
header pinned anyway: `lib/table-enhancer.js` translates the header cells down by the viewport scroll offset
314+
(clamped to the table's bottom edge) on every window scroll/resize.
315+
- **Copy cells** — click any cell (or focus it and press Enter/Space) to copy its text; an auto-dismissing toast
316+
confirms the copy. Falls back gracefully when the Clipboard API is unavailable.
317+
318+
Implementation: pure table operations live in `lib/table-operations.js` (filter → sort → paginate pipeline, CSV
319+
generation, clipboard helper, `TABLE_CONFIG` defaults: threshold/page size 20, 300&nbsp;ms search debounce, 3&nbsp;s
320+
toast duration), the rendered DOM is wired by `lib/table-enhancer.js`, and table state re-renders through
321+
`prepareReportData` in `lib/renderer.js`.
322+
323+
---
324+
292325
## How repository submission works
293326

294327
No OAuth app, client ID, token or secret is involved on the client side — forks need **zero auth setup**. The flow on

‎app/globals.css‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,3 +461,50 @@ pre {
461461
grid-template-columns: 1fr;
462462
}
463463
}
464+
465+
/* Toast notifications (copy feedback on report tables). Rendered by
466+
components/toast-notification.jsx as a persistent aria-live region. */
467+
.rf-toast-region {
468+
position: fixed;
469+
left: 50%;
470+
bottom: 1.25rem;
471+
transform: translateX(-50%);
472+
z-index: 2000;
473+
display: flex;
474+
flex-direction: column;
475+
gap: 0.5rem;
476+
align-items: center;
477+
pointer-events: none;
478+
max-width: min(90vw, 40rem);
479+
}
480+
481+
.rf-toast {
482+
display: flex;
483+
align-items: center;
484+
gap: 0.75rem;
485+
padding: 0.6rem 0.9rem;
486+
border-radius: var(--radius);
487+
background: #1f2933;
488+
color: #fff;
489+
box-shadow: var(--shadow);
490+
pointer-events: auto;
491+
}
492+
493+
.rf-toast-message {
494+
overflow-wrap: anywhere;
495+
}
496+
497+
.rf-toast-dismiss {
498+
background: none;
499+
border: none;
500+
color: #fff;
501+
font-size: 1.1rem;
502+
line-height: 1;
503+
cursor: pointer;
504+
padding: 0.15rem 0.45rem;
505+
}
506+
507+
.rf-toast-dismiss:focus-visible {
508+
outline: 2px solid var(--brand-color);
509+
outline-offset: 2px;
510+
}

0 commit comments

Comments
 (0)