Skip to content

One file-name helper and one set of byte units in the frontend (part of #1107) - #1161

Merged
ccoventry merged 3 commits into
devfrom
chore/shared-size-and-name-helpers-1107
Oct 30, 2026
Merged

ccoventry merged 3 commits into
devfrom
chore/shared-size-and-name-helpers-1107

Conversation

@ccoventry

Copy link
Copy Markdown
Owner

Release note: none

Part of #1107 (audit batch B2: frontend duplicates).

What changes

No visible change: every size and file name reads exactly as before. The copies go.

  • File name from a path: fileNameOf in path_display.js already existed, yet four modules defined their own fileName (batch_catch_up.js, combine_clips.js, render_history.js, split_pane.js, which analyzer_pane.js imported from) and nine more inlined split(/[\\/]/).pop(). All use fileNameOf now. The two sites that showed the whole path when the name came out empty (batch_catch_up.js, project_session.js) still do (fileNameOf(p) || p).
  • Byte sizes: new byte_size.js with BYTES_PER_KB/MB/GB/TB (standard section 4: no magic numbers) and the two formats that were copied:
    • gbOrMbText ("3.00 GB" / "20.9 MB"): was in batch_results.js and audit_duplicates.js.
    • renderSizeText(bytes, gbDecimals) (STRINGS.RENDER.fileSizeGb/Mb): was in render_pane.js, render_while_capturing.js and take_cleanup.js, which differ only in GB decimals (kept: 2, 1, 2).
    • setup_checklist.js, hd_progress.js, folder_pools.js, auditor_pane.js, capture_pane.js, scan_workers.js keep their own formats but use the constants.
  • shared_helpers_only.test.js: fails on a new split(/[\\/]/).pop() outside path_display.js or a 1024 * 1024 * 1024 / 1024 ** 3 outside byte_size.js, so the copies don't come back.

Decisions

  • Formats not unified. The audit suggested one formatter "with the variants as options". Unifying would change what some tabs show (decimals, TB handling), and this batch is behaviour-preserving, so only the identical copies were merged. Whether every tab should show sizes one way is a UI question for the user (noted on [Chore] Audit the codebase's health, legibility and organisation #1107).
  • Left alone: analyzer_damage.js's sizeText (MB/KB, and the web analyzer keeps a checked copy of analyzer code), and capture_pane.js's free-space warnings, which divide by 1e9 (decimal GB) where the rest of the app uses 1024-based GB. That one is a real inconsistency (the Capture tab's "not enough space" numbers are about 7% bigger than the same bytes elsewhere) but fixing it changes what users see, so it is listed on [Chore] Audit the codebase's health, legibility and organisation #1107 for a separate PR.
  • analyzer_pane.js's private formatDuration (same name as rescan_estimate.js's, different output) is left for the analyzer_pane split (B7), which moves that code anyway.

Test done

  • npm run test:unit: 122 files, 1,097 tests pass (adds byte_size.test.js, shared_helpers_only.test.js).
  • CI=1 npx playwright test (all specs, including app-boot.spec.js), own port: 449 passed.
  • No Rust changes.

🤖 Generated with Claude Code

Part of #1107.

- fileNameOf (path_display.js) replaces four local fileName helpers and
  nine inline copies of the same split. Sites that fell back to the whole
  path when it ends in a slash still do.
- byte_size.js holds BYTES_PER_KB/MB/GB/TB, gbOrMbText (batch results,
  Demo Auditor) and renderSizeText (Render tab, Render While Capturing,
  take clean-up), which each had a copy. Every size reads the same as
  before: the different decimals per tab stay as they were.
- shared_helpers_only.test.js fails on a new copy of either.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ccoventry

Copy link
Copy Markdown
Owner Author

Review: ready to merge.

I compared every call site with the old code:

  • fileNameOf (String(path || '').split(/[\\/]/).pop()) gives the same result for every string path these sites pass. The two that fell back to the whole path (batch_catch_up, project_session) keep their || path.
  • gbOrMbText is the same as the old wastedSizeText and batch_results.formatBytes. renderSizeText(bytes, 2|1) is the same as take_cleanup, render_while_capturing and render_pane. One tiny difference: render_pane.formatFileSize now runs Number() on its input, so a non-number shows "0 MB" instead of "NaN MB". Not reachable from real data.
  • The removed exports (split_pane.fileName, batch_results.formatBytes) had no other importers. setup_checklist.formatBytes is unchanged and still imported by movie_copy.js.
  • Nit, not worth a CI run: render_history.js keeps two blank lines where fileName was.

Merge notes:

ccoventry and others added 2 commits October 30, 2026 02:21
Import-line conflicts in batch_catch_up.js and capture_pane.js (#1171's
batch resume) keep both sides. batch_resume.js, new from #1171, takes its
file name from fileNameOf like everything else, so shared_helpers_only.test.js
passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ccoventry
ccoventry merged commit fa4324b into dev Oct 30, 2026
5 checks passed
@ccoventry
ccoventry deleted the chore/shared-size-and-name-helpers-1107 branch October 30, 2026 08:49
ccoventry added a commit that referenced this pull request Oct 30, 2026
analyzer_pane.js after #1161: fileNameOf from path_display.js beside the
analyzer_browser.js imports, and the split toast uses fileNameOf before
relistFolderOf.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ccoventry added a commit that referenced this pull request Oct 30, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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