Skip to content

Redesign the Reports tab: stat cards, hours by day and CSV export (ALI-2618) - #17

Merged
michaelaguiar merged 5 commits into
ali-2617-tui-clientsfrom
ali-2618-tui-reports
Dec 4, 2026
Merged

michaelaguiar merged 5 commits into
ali-2617-tui-clientsfrom
ali-2618-tui-reports

Conversation

@michaelaguiar

@michaelaguiar michaelaguiar commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Fixes ALI-2618

Stacked on #16: merge #16 first; GitHub then retargets this to main.

What changed

The Reports tab is redrawn from the canvas's Reports board (140×40) and computes everything with internal/report, the code behind notch report. It no longer uses db.ReportByProject, so it reads start dates in local time, like the CLI.

  • Range chips: t Today, w Week, m Month, y Year, a All, f Custom…, with the range's dates beside them. f opens a Custom range modal (the shared form modal from Modal forms with field errors, delete confirm and the keys sheet (ALI-2616) #15): From, To, Apply, Cancel, with errors under their fields. A blank date leaves that side open.
  • Stat cards: hours and entries, earned and the average rate, outstanding (invoiced, not paid) and unbilled, all from report.Report.
  • By day: bars in eighth blocks, each with its day and hours written under it. Today's bar is in success and its day name is bold. This week's bars run on to Sunday, as on the board. A range with more days than fit gets a bar per week, month or year.
  • By client and project: clients with their projects nested under them, showing hours, invoiced and paid counts, earned, and a total.
  • Narrow and short terminals: from 120 columns the bars sit beside the table. Below that they stack, with 3-row bars and cards without top and bottom borders. The bars drop before the table gets fewer than 3 rows.
  • e exports CSV with report.WriteCSV (the same rows as notch report --csv) to XDG_DOWNLOAD_DIR (from the environment or user-dirs.dirs), else ~/Downloads, else home. The file is named for the range, such as notch-2026-11-30-to-2026-12-03.csv. A taken name gets (2), (3)… (opened with O_EXCL), so an export never overwrites. The file is created 0600, and a folder it can't write to falls through to the next. The status line shows the path. An empty range says there's nothing to export.
  • Reloads: presets are worked out again on every reload, so a tab left open into a new day or month moves on. The tab also reloads when another process writes. The table cursor and the entries list follow their row by ID; if the row leaves the report, the list closes and the status line says so.
  • Amounts are never cut: they drop the cents, then go compact ($123k, $1.2M), with the same fitMoney/fitRate as the Clients tab in Fold Projects into a Clients master-detail tab (ALI-2617) #16. Since the merge with Fold Projects into a Clients master-detail tab (ALI-2617) #16 there's one copy, in internal/ui/views/money.go.
  • Enter opens the entries behind a client or project row, newest first. e there edits an entry, as before.
  • Keys: the Custom range modal, the entries list and the edit form all count as busy, so q types and only ctrl+c quits. The keys sheet's Reports group and the README cover the new keys, and the sheet still fits at 90×32.
  • New layout tokens: tui-card-gap, tui-bar-width, tui-bar-gap, tui-bar-rows, tui-bar-rows-compact, tui-report-col-hours, tui-report-col-count, tui-report-col-earned, tui-report-trail, tui-report-indent. No new colours. Every pair used is already in the contrast table, and design/build -check passes.

Differences from the board

  • The range chips show their key before each chip (t Today), as the Timers tab does, because y and a don't fit on the hotkey line.
  • The table's selected row has the ▌ cursor, so names start one cell further right than on the board. NAME takes the spare width instead of EARNED.
  • The running-timer note sits one row under the hours labels, not level with the table's bottom rule.

Tests

  • gofmt -l . is empty, and go vet ./..., go test -count=1 ./... and go run ./design/build -check pass.
  • New tests in internal/ui/views/reports_test.go cover:
    • range switching against report.Preset, and the custom modal's errors, q typing and blank sides;
    • the tab's report matching report.Build on the CLI's entry list, as JSON, for every preset;
    • the stat cards' values;
    • the bars' heights, labels and grouping;
    • the nested table at 140 and 90 columns, with every line exactly the content width;
    • a short terminal dropping the bars;
    • CSV export to a temp dir, matching report.WriteCSV and not overwriting;
    • the download-folder lookup;
    • Enter on client and project rows, then e to edit.
  • TestRenderReportsSample in internal/ui checks the full frame at 140×40 and 90×32, with and without the modal.
  • Each key test was shown failing with its code removed: presets ignored, the report built for the wrong range, no hours labels, no grouping, projects not indented, O_TRUNC instead of O_EXCL, and Enter doing nothing.

Try live

  • Open Reports at 140×40 and around 90×32, and switch ranges with t w m y a. Compare the cards and table with notch report -json --range week.
  • Press f, try a bad date, a To before From, and blank dates.
  • Press e, check the file in your downloads folder, then press e again to get (2).
  • Press Enter on a client row and on a project row, then edit an entry from there.
  • With a timer running, check the "Running timer not counted until it stops." note. Stop it from the CLI or the bar: the tab reloads on its own.

…I-2618)

The Reports tab now draws from internal/report, the code behind
`notch report`, so for the same range its numbers match
`notch report -json` (a test compares the two as JSON for every preset).
It no longer uses db.ReportByProject, so it reads start dates in local
time like the CLI.

The screen follows the canvas's Reports board:

- Range chips (t Today, w Week, m Month, y Year, a All, f Custom…) with
  the dates beside them. f opens a Custom range modal (From, To, Apply,
  Cancel) with field errors; a blank date leaves that side open.
- Four stat cards: hours and entries, earned and the average rate,
  outstanding (invoiced, not paid) and unbilled.
- BY DAY: block-character bars in eighth blocks, each with its day and
  hours written under it; today's bar is in success and its day bold.
  This week runs on to Sunday. Ranges with more days than fit show a bar
  per week, month or year.
- BY CLIENT AND PROJECT: clients with their projects nested under them,
  with hours, invoiced and paid counts and earned, and a total.

At 120 columns and up the bars sit beside the table; narrower terminals
stack them with shorter bars and compact cards, and drop the bars before
the table gets fewer than three rows.

e exports the range's entries with report.WriteCSV to the XDG download
folder (else ~/Downloads, else home), named for the range, adding
" (2)", " (3)"… rather than overwriting. The status line shows the path.
enter opens the entries behind a client or project row, where e edits an
entry as before.

New layout tokens: tui-card-gap, tui-bar-width, tui-bar-gap,
tui-bar-rows, tui-bar-rows-compact, tui-report-col-hours,
tui-report-col-count, tui-report-col-earned, tui-report-trail and
tui-report-indent. The keys sheet and README cover the new keys.
@michaelaguiar

Copy link
Copy Markdown
Member Author

Review round 1

A fresh reviewer ran code-review (high). The export itself checked out:

  • O_EXCL naming with " (2)" suffixes;
  • cleanup when a write fails;
  • ~ and $HOME expansion.

Sent for fixing. Each finding is checked against the code first, and any that isn't a bug is reported back.

  • P2: preset ranges are computed once, so a TUI left open past midnight or a month boundary shows and exports a stale range.
  • P2: the table cursor and entries list follow a row index, so after a reload they can show, and edit, another project's entries.
  • P2: Reports doesn't reload when the database changes elsewhere.
  • P3: the CSV is world-readable (it becomes 0600).
  • P3: an unwritable downloads folder isn't skipped, and user-dirs.dirs quoting isn't handled.
  • P3: "Entry not found" is never shown.
  • P3: some layout values are hand-coded instead of tokens.
  • P3: large amounts are cut with "…".

Round 2 also covers what round 1 didn't check: the Week preset's date and timezone edges, bar grouping, and narrow-terminal layout.

- Presets follow the clock: each reload works out today, this week,
  this month or this year again, so a tab left open past midnight or
  into a new month shows (and exports) the current range. Custom ranges
  stay put.
- The table cursor and the entries list follow their row by client and
  project ID, and the entries cursor its entry by ID, across reloads.
  When the list's row leaves the report, the list closes and the status
  line says so; an open edit form closes to the report.
- A database change from another process (dbWatch, and the fallback
  tick) reloads the Reports tab as well as Timers.
- CSV exports are created 0600, and a download folder that can't be
  written to falls through to the next (~/Downloads, then home).
  user-dirs.dirs values in single quotes, unquoted, after export, or
  followed by a comment now parse.
- An entry gone before its edit form opens says so on the status line;
  the old message was never shown.
- Amounts are never cut: cards, the table and the entries list drop the
  cents, then go compact ($123k, $1.2M), with the same fitMoney and
  fitRate as the Clients tab in ALI-2617 (in money.go, to merge into one
  copy). Hours too wide show as whole hours.
- Layout counts come from what's drawn (card lines, the table's fixed
  lines, entry columns from their widest values and the cell padding),
  and two new tokens: tui-card-pad and tui-report-min-rows.
Stacks the Reports redesign (ALI-2618) on the Clients tab (ALI-2617).

- Tabs are 1 Timers, 2 Clients, 3 Reports; the Reports tests that
  pressed 4 press 3.
- dbWatch and the fallback tick reload Timers, Clients and Reports.
- tokens.json and design/build carry both PRs' tokens; tui-min-width's
  note keeps both measurements. The generated files are regenerated.
- The keys sheet has the Clients and Reports groups.
- One copy of fitMoney, fitRate, wholeMoney and compactMoney, in
  money.go; clients.go's copy is gone.
- The README's feature list, keys and file list, and the landing page's
  Reports card, cover both tabs.
…-2618)

The Clients tab (ALI-2617) has its own moneyOrDash(x, rate, w), so the
Reports one, which shows an amount in full or a dash, is amountOrDash.
@michaelaguiar
michaelaguiar changed the base branch from main to ali-2617-tui-clients December 4, 2026 17:41
Tab 4 no longer exists after the Clients fold, so pressing 4 did nothing
and that iteration tested nothing.
@michaelaguiar

Copy link
Copy Markdown
Member Author

Review round 2 (final, narrow)

5ec09c1 fixed round 1's findings:

  • P2: preset ranges. They move with the clock on every reload.
  • P2: the selected row. Rows are kept by client and project ID across reloads. A row that disappears closes its entries list, with a status.
  • P2: reloads. Reports reloads when the database changes elsewhere.
  • P3s:
    • exports are written with mode 0600;
    • unwritable download folders are skipped;
    • user-dirs.dirs quoting and comments are handled;
    • a missing entry's error is now shown;
    • row counts are derived from what's drawn;
    • amounts are never cut with "…".

All seven were confirmed as real bugs before fixing.

Stacked on #16. 12e223f merges #16's branch in, and aff033d fixes a helper-name clash from that merge. The result:

  • three tabs;
  • every tab reloads when the database changes;
  • one copy of the money helpers (money.go);
  • both tabs' keys in the keys sheet, which still fits at 90×32;
  • both PRs' tokens, regenerated.

The review. A fresh reviewer checked these commits. Its code-review skill run started in the background but didn't report back within 17 minutes, so the reviewer reviewed by hand. It checked vet, the tests and design/build -check, and that nothing landed in ~/Downloads. It found:

  • the display, cards and export all use the same range;
  • custom ranges stay fixed;
  • the unconditional database-change reload can't loop, because the watcher fires only when SQLite's data_version changes, and reloads only read;
  • open forms keep their state across reloads.

Nothing was found at P1 or P2.

P3 fixed in 9a4864a: TestTabSwitch_ClosesDetails still pressed the removed tab 4.

During round 1's fail-without-fix checks, one test briefly exported into the real ~/Downloads. The file held only test data and was deleted. Every export test now isolates HOME and the XDG folders.

The review stops here. Merge #16 first; GitHub then retargets this PR to main.

@michaelaguiar
michaelaguiar marked this pull request as ready for review December 4, 2026 17:53
@michaelaguiar
michaelaguiar merged commit ae66de2 into ali-2617-tui-clients Dec 4, 2026
1 check passed
michaelaguiar added a commit that referenced this pull request Dec 4, 2026
…I-2618) (#17) (#18)

* Redesign the Reports tab: stat cards, hours by day and CSV export (ALI-2618)

The Reports tab now draws from internal/report, the code behind
`notch report`, so for the same range its numbers match
`notch report -json` (a test compares the two as JSON for every preset).
It no longer uses db.ReportByProject, so it reads start dates in local
time like the CLI.

The screen follows the canvas's Reports board:

- Range chips (t Today, w Week, m Month, y Year, a All, f Custom…) with
  the dates beside them. f opens a Custom range modal (From, To, Apply,
  Cancel) with field errors; a blank date leaves that side open.
- Four stat cards: hours and entries, earned and the average rate,
  outstanding (invoiced, not paid) and unbilled.
- BY DAY: block-character bars in eighth blocks, each with its day and
  hours written under it; today's bar is in success and its day bold.
  This week runs on to Sunday. Ranges with more days than fit show a bar
  per week, month or year.
- BY CLIENT AND PROJECT: clients with their projects nested under them,
  with hours, invoiced and paid counts and earned, and a total.

At 120 columns and up the bars sit beside the table; narrower terminals
stack them with shorter bars and compact cards, and drop the bars before
the table gets fewer than three rows.

e exports the range's entries with report.WriteCSV to the XDG download
folder (else ~/Downloads, else home), named for the range, adding
" (2)", " (3)"… rather than overwriting. The status line shows the path.
enter opens the entries behind a client or project row, where e edits an
entry as before.

New layout tokens: tui-card-gap, tui-bar-width, tui-bar-gap,
tui-bar-rows, tui-bar-rows-compact, tui-report-col-hours,
tui-report-col-count, tui-report-col-earned, tui-report-trail and
tui-report-indent. The keys sheet and README cover the new keys.

* Reports review fixes (ALI-2618)

- Presets follow the clock: each reload works out today, this week,
  this month or this year again, so a tab left open past midnight or
  into a new month shows (and exports) the current range. Custom ranges
  stay put.
- The table cursor and the entries list follow their row by client and
  project ID, and the entries cursor its entry by ID, across reloads.
  When the list's row leaves the report, the list closes and the status
  line says so; an open edit form closes to the report.
- A database change from another process (dbWatch, and the fallback
  tick) reloads the Reports tab as well as Timers.
- CSV exports are created 0600, and a download folder that can't be
  written to falls through to the next (~/Downloads, then home).
  user-dirs.dirs values in single quotes, unquoted, after export, or
  followed by a comment now parse.
- An entry gone before its edit form opens says so on the status line;
  the old message was never shown.
- Amounts are never cut: cards, the table and the entries list drop the
  cents, then go compact ($123k, $1.2M), with the same fitMoney and
  fitRate as the Clients tab in ALI-2617 (in money.go, to merge into one
  copy). Hours too wide show as whole hours.
- Layout counts come from what's drawn (card lines, the table's fixed
  lines, entry columns from their widest values and the cell padding),
  and two new tokens: tui-card-pad and tui-report-min-rows.

* Rename the Reports entries header's amountOrDash after the merge (ALI-2618)

The Clients tab (ALI-2617) has its own moneyOrDash(x, rate, w), so the
Reports one, which shows an amount in full or a dash, is amountOrDash.

* Drop the removed fourth tab from the tab-switch test

Tab 4 no longer exists after the Clients fold, so pressing 4 did nothing
and that iteration tested nothing.
@michaelaguiar
michaelaguiar deleted the ali-2618-tui-reports branch December 4, 2026 18:05
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.

1 participant