Skip to content

Improve memory display formatting#21

Draft
jbingham17 wants to merge 3 commits intomainfrom
improve-memory-display-formatting
Draft

Improve memory display formatting#21
jbingham17 wants to merge 3 commits intomainfrom
improve-memory-display-formatting

Conversation

@jbingham17
Copy link
Copy Markdown
Contributor

@jbingham17 jbingham17 commented Mar 5, 2026

Summary

  • Use full unit names (KB, MB, GB, TB) instead of abbreviations (K, M, G, T) with proper spacing in formatBytes
  • Show used/total memory with percentage in the graph header (e.g. "4.2 GB / 16.0 GB (26%)")
  • Add percentage display to the Used and Free stats in the memory details section

Test plan

  • Verify memory bar shows formatted values with full units (e.g. "4.2 GB" not "4.2G")
  • Verify memory graph header shows "used / total (percent%)" format
  • Verify Used stat shows percentage alongside bytes
  • Verify Free stat shows correct free percentage

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Memory display now uses standardized two-letter abbreviations (B, KB, MB, GB, TB) with spacing.
    • Memory panels show both byte values and percentages for used and free memory.
    • Added an Alert Bar showing system alerts (info/warn/critical), level icon, messages, flashing for non-info alerts, and timestamp.
  • UI / Style

    • Added a live status indicator (blinking dot and "LIVE" label) in the status bar with related styles.

Use full unit names (KB, MB, GB) with proper spacing and show
used/total with percentages in the memory graph header and stats.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 5, 2026

📝 Walkthrough

Walkthrough

Memory formatting was changed to use two-letter unit labels with a space (e.g., "12.3 MB"); MemoryGraph now shows used/total as bytes plus percentage and free bytes with computed free percentage. A blinking LIVE indicator and new AlertBar UI were added, plus related CSS.

Changes

Cohort / File(s) Summary
Memory UI
src/components/MemoryBar.tsx, src/components/MemoryGraph.tsx
Byte-size formatting updated: two-letter units and a space between number and unit. MemoryGraph header and stats now show formatted bytes alongside percentages; free percent is computed with a total<=0 guard.
New Alert UI & integration
src/components/AlertBar.tsx, src/App.tsx
Added AlertBar component that derives alerts from cpuUsage and memPercent, renders level-specific messages and icon, flashes when non-info alerts exist, and is mounted in App under EnvironmentPanel.
Status bar & live indicator
src/components/StatusBar.tsx, src/App.css
StatusBar now contains internal blinking LIVE indicator (1s toggle). App.css receives many new styles for alert bar, status indicator, and status bar controls (note: alert/status styles appear duplicated in file).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title describes memory display formatting improvements, but the changeset includes substantial additional features: AlertBar component with alert logic, StatusBar with live indicator, and CSS styling for alerts and status indicators. Revise the title to reflect all major changes, such as 'Add system health alerts and improve memory display formatting' or update the PR scope to match the stated title.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Min-Level ✅ Passed No security vulnerabilities detected. Code contains logic bugs (type mismatch, empty array handling) but no injection attacks, XSS vectors, unsafe code execution, or sensitive data exposure.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch improve-memory-display-formatting
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can use your project's `biome` configuration to improve the quality of JS/TS/CSS/JSON code reviews.

Add a configuration file to your project to customize how CodeRabbit runs biome.

jbingham17 and others added 2 commits March 5, 2026 11:24
Adds a green dot that flashes on/off every second with a "LIVE" label,
giving a visual heartbeat indicator in the bottom status bar.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
New AlertBar component sits above the status bar and displays system
health alerts. It flashes when CPU or memory usage exceeds thresholds
(70% warn, 90% critical) and shows "All systems nominal" when healthy.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jbingham17 jbingham17 marked this pull request as draft March 5, 2026 21:44
@jbingham17
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 17, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/App.css (1)

453-467: Add a reduced-motion fallback for alert flashing.

The flash effect should be disabled for users with reduced-motion preferences.

♿ Suggested CSS tweak
 .alert-bar.alert-flash-off {
   opacity: 0.4;
 }
+
+@media (prefers-reduced-motion: reduce) {
+  .alert-bar {
+    transition: none;
+  }
+  .alert-bar.alert-flash-off {
+    opacity: 1;
+  }
+}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/App.css` around lines 453 - 467, Add a reduced-motion fallback: detect
prefers-reduced-motion and disable the alert flashing by removing/overriding the
transition and any animation on .alert-bar (and ensure
.alert-bar.alert-flash-off still sets the final opacity) so users with
reduced-motion see the non-animated state; update the CSS to add a `@media`
(prefers-reduced-motion: reduce) rule that sets .alert-bar { transition: none;
animation: none; } and preserves .alert-bar.alert-flash-off { opacity: 0.4; } so
the flash is effectively disabled for those users.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/App.tsx`:
- Line 75: metrics.cpuUsage is an array of CpuUsage objects but AlertBar (and
its getAlerts) expects number[]; update the prop passed to AlertBar so you
convert metrics.cpuUsage into an array of numeric percentages (e.g., map
CpuUsage objects to their percent/value field) before passing it in, or change
the producer to expose a cpuPercent array; specifically modify the usage around
AlertBar to pass a number[] derived from metrics.cpuUsage (refer to AlertBar and
metrics.cpuUsage) so .reduce in getAlerts operates on numbers.

In `@src/components/AlertBar.tsx`:
- Around line 8-11: The avgCpu calculation in getAlerts uses
cpuUsage.reduce(...) / cpuUsage.length which yields NaN for an empty cpuUsage
array; update getAlerts to handle empty samples before averaging by checking
cpuUsage.length === 0 and either early-return appropriate alerts (or set avgCpu
= 0) so downstream CPU alert logic uses a safe numeric value; locate the
getAlerts function and adjust the avgCpu computation/flow to guard against empty
cpuUsage arrays (reference: getAlerts, avgCpu, cpuUsage).

---

Nitpick comments:
In `@src/App.css`:
- Around line 453-467: Add a reduced-motion fallback: detect
prefers-reduced-motion and disable the alert flashing by removing/overriding the
transition and any animation on .alert-bar (and ensure
.alert-bar.alert-flash-off still sets the final opacity) so users with
reduced-motion see the non-animated state; update the CSS to add a `@media`
(prefers-reduced-motion: reduce) rule that sets .alert-bar { transition: none;
animation: none; } and preserves .alert-bar.alert-flash-off { opacity: 0.4; } so
the flash is effectively disabled for those users.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c2a3c2b3-9962-4a1f-8a5b-18debf3012c5

📥 Commits

Reviewing files that changed from the base of the PR and between 526cb45 and 109c0ff.

📒 Files selected for processing (3)
  • src/App.css
  • src/App.tsx
  • src/components/AlertBar.tsx
📜 Review details
🔇 Additional comments (1)
src/components/AlertBar.tsx (1)

36-42: Effect cleanup is implemented correctly.

The interval is cleared on dependency changes/unmount, which prevents timer leaks.

Comment thread src/App.tsx

<EnvironmentPanel filter={filter} />

<AlertBar cpuUsage={metrics.cpuUsage} memPercent={metrics.memPercent} />
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the cpuUsage type contract across call site and component props.
rg -n -C3 'interface AlertBarProps|cpuUsage:' src/components/AlertBar.tsx
rg -n -C3 'interface SystemMetrics|cpuUsage:' src/types.ts
rg -n -C3 '<AlertBar|cpuUsage=\{metrics\.cpuUsage' src/App.tsx

Repository: coderabbit-demo/btop

Length of output: 1174


Pass numeric CPU percentages into AlertBar.

At line 75, metrics.cpuUsage is CpuUsage[] but AlertBar expects number[]. The component's getAlerts function will fail when it tries to compute the average with .reduce((a, b) => a + b, 0).

Fix
-      <AlertBar cpuUsage={metrics.cpuUsage} memPercent={metrics.memPercent} />
+      <AlertBar cpuUsage={metrics.cpuUsage.map((core) => core.usage)} memPercent={metrics.memPercent} />
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<AlertBar cpuUsage={metrics.cpuUsage} memPercent={metrics.memPercent} />
<AlertBar cpuUsage={metrics.cpuUsage.map((core) => core.usage)} memPercent={metrics.memPercent} />
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/App.tsx` at line 75, metrics.cpuUsage is an array of CpuUsage objects but
AlertBar (and its getAlerts) expects number[]; update the prop passed to
AlertBar so you convert metrics.cpuUsage into an array of numeric percentages
(e.g., map CpuUsage objects to their percent/value field) before passing it in,
or change the producer to expose a cpuPercent array; specifically modify the
usage around AlertBar to pass a number[] derived from metrics.cpuUsage (refer to
AlertBar and metrics.cpuUsage) so .reduce in getAlerts operates on numbers.

Comment on lines +8 to +11
function getAlerts(cpuUsage: number[], memPercent: number): { message: string; level: 'info' | 'warn' | 'critical' }[] {
const alerts: { message: string; level: 'info' | 'warn' | 'critical' }[] = [];
const avgCpu = cpuUsage.reduce((a, b) => a + b, 0) / cpuUsage.length;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Handle empty CPU samples before averaging.

At Line 10, dividing by cpuUsage.length can produce NaN when the array is empty, which suppresses CPU alerting logic.

💡 Proposed fix
-  const avgCpu = cpuUsage.reduce((a, b) => a + b, 0) / cpuUsage.length;
+  const avgCpu =
+    cpuUsage.length > 0
+      ? cpuUsage.reduce((a, b) => a + b, 0) / cpuUsage.length
+      : 0;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/AlertBar.tsx` around lines 8 - 11, The avgCpu calculation in
getAlerts uses cpuUsage.reduce(...) / cpuUsage.length which yields NaN for an
empty cpuUsage array; update getAlerts to handle empty samples before averaging
by checking cpuUsage.length === 0 and either early-return appropriate alerts (or
set avgCpu = 0) so downstream CPU alert logic uses a safe numeric value; locate
the getAlerts function and adjust the avgCpu computation/flow to guard against
empty cpuUsage arrays (reference: getAlerts, avgCpu, cpuUsage).

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