Skip to content

Conversation

@Boy132
Copy link
Member

@Boy132 Boy132 commented Aug 18, 2025

image

#SavePirateLanguage

@Boy132 Boy132 self-assigned this Aug 18, 2025
@coderabbitai
Copy link

coderabbitai bot commented Aug 18, 2025

📝 Walkthrough

Walkthrough

Introduces a global format_number(...) helper (with user-language fallback) and replaces direct uses of Illuminate\Support\Number::format across widgets, pages, models, and helpers. Some chart widgets now emit numeric values via round(...) instead of formatted strings. No public API signatures changed.

Changes

Cohort / File(s) Summary
Helper introduction and centralization
app/helpers.php
Added `format_number(int
Admin node charts formatting refactor
app/Filament/Admin/Resources/NodeResource/Widgets/NodeCpuChart.php, app/Filament/Admin/Resources/NodeResource/Widgets/NodeMemoryChart.php
Removed Illuminate\Support\Number import and replaced Number::format calls with format_number(...) in heading formatting; adjusted precision/maxPrecision usage.
Server widgets emit numeric chart data
app/Filament/Server/Widgets/ServerCpuChart.php, app/Filament/Server/Widgets/ServerMemoryChart.php
Removed Number import; replaced Number::format(..., maxPrecision: 2) with round(..., 2) so chart data fields are numeric floats instead of formatted strings.
Server UI/pages/models formatting via helper
app/Filament/Server/Pages/Settings.php, app/Filament/Server/Widgets/ServerOverview.php, app/Livewire/ServerEntry.php, app/Models/Server.php
Removed Number imports and replaced Number::format(...) with format_number(...) for CPU/percentage and heading displays; preserved existing suffixes and fallback display logic.

Sequence Diagram(s)

sequenceDiagram
  participant Caller as Widget/Page/Model/Helper
  participant F as format_number()
  participant N as Number::format()

  Caller->>F: format_number(value, precision?, maxPrecision?)
  F->>N: Number::format(value, precision?, maxPrecision?, auth()->user()->language ?? 'en')
  alt Number::format throws
    F->>N: Number::format(value, precision?, maxPrecision?, 'en')
  end
  N-->>F: formatted string
  F-->>Caller: formatted string
Loading
sequenceDiagram
  participant Widget as ServerCpu/ServerMemoryChart
  participant R as round()

  Widget->>R: round(value, 2)
  R-->>Widget: numeric float (2 decimals)
  Widget-->>Chart: dataset with numeric values
Loading

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 86532ca and f5f27b0.

📒 Files selected for processing (1)
  • app/helpers.php (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/helpers.php

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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

🔭 Outside diff range comments (1)
app/Filament/Admin/Resources/NodeResource/Widgets/NodeMemoryChart.php (1)

82-95: Fix latest value retrieval; array_slice on end(...) breaks ['memory'] access

Line 84 calls array_slice(end($this->memoryHistory), -60), which reindexes keys numerically. Accessing $latestMemoryUsed['memory'] will be undefined. Also, handle empty history safely, and avoid duplicating the binary/decimal branches.

Apply:

-        $latestMemoryUsed = array_slice(end($this->memoryHistory), -60);
-
-        $used = config('panel.use_binary_prefix')
-            ? format_number($latestMemoryUsed['memory'], maxPrecision: 2) .' GiB'
-            : format_number($latestMemoryUsed['memory'], maxPrecision: 2) . ' GB';
-
-        $total = config('panel.use_binary_prefix')
-            ? format_number($this->totalMemory / 1024 / 1024 / 1024, maxPrecision: 2) .' GiB'
-            : format_number($this->totalMemory / 1000 / 1000 / 1000, maxPrecision: 2) . ' GB';
+        $latestMemoryUsed = end($this->memoryHistory) ?: ['memory' => 0.0, 'timestamp' => now(auth()->user()->timezone ?? 'UTC')->format('H:i:s')];
+        $useBinary = config('panel.use_binary_prefix');
+        $usedValue = (float) $latestMemoryUsed['memory'];
+        $totalValue = $useBinary
+            ? $this->totalMemory / 1024 / 1024 / 1024
+            : $this->totalMemory / 1000 / 1000 / 1000;
+
+        $unitLabel = $useBinary ? ' GiB' : ' GB';
+        $used = format_number($usedValue, maxPrecision: 2) . $unitLabel;
+        $total = format_number($totalValue, maxPrecision: 2) . $unitLabel;

Additionally, the docblock at Line 18 states memory: string, but memory is now numeric. Consider updating it to memory: float.

🧹 Nitpick comments (5)
app/Filament/Server/Widgets/ServerOverview.php (1)

56-56: Consistent formatting; consider no decimals for limits

  • Line 56: Using format_number with maxPrecision: 2 for live CPU is appropriate.
  • Line 58: For the configured CPU limit (an integer in most setups), consider precision: 0 to avoid rendering a trailing “.00 %”.

Proposed change for Line 58 only:

-        return $cpu . ($this->server->cpu > 0 ? ' / ' . format_number($this->server->cpu) . ' %' : ' / ∞');
+        return $cpu . ($this->server->cpu > 0 ? ' / ' . format_number($this->server->cpu, precision: 0) . ' %' : ' / ∞');

Also applies to: 58-58

app/Filament/Admin/Resources/NodeResource/Widgets/NodeCpuChart.php (1)

84-86: Update docblock to reflect numeric cpu; optional: avoid decimals for max

  • Given getData() uses round(..., 2) for 'cpu', $this->cpuHistory now holds numeric floats, but the docblock at Line 18 still declares cpu: string. Update it to cpu: float for accuracy.
  • For $max (threads * 100), consider precision: 0 since this should be a whole number.

Outside this hunk, update the docblock:

/**
 * @var array<int, array{cpu: float, timestamp: string}>
 */

And adjust Line 85 if you want whole numbers:

-        $max = format_number($this->threads * 100);
+        $max = format_number($this->threads * 100, precision: 0);
app/Filament/Server/Widgets/ServerMemoryChart.php (1)

33-35: Micro-optimization: avoid repeated config lookups inside the map

config('panel.use_binary_prefix') is evaluated for every element. Cache it in a local $useBinary (and optionally a $unit = $useBinary ? 1024 : 1000) outside the map for readability and tiny perf wins.

app/Models/Server.php (2)

486-487: Guard against non-string return from format_number when concatenating '%'

format_number is declared as false|string. If it ever returns false, concatenation produces just '%' which is misleading. Prefer ensuring a string, or make format_number always return string (see helpers.php comment).

For a local guard here:

-            return format_number($resourceAmount, precision: 2) . '%';
+            $formatted = (string) format_number($resourceAmount, precision: 2);
+            return $formatted . '%';

480-484: Use logical AND (&&) instead of bitwise &

The condition uses bitwise AND, which happens to work via type juggling but is misleading and error-prone.

-        if ($resourceAmount === 0 & $resourceType->isLimit()) {
+        if ($resourceAmount === 0 && $resourceType->isLimit()) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3b9c815 and 86532ca.

📒 Files selected for processing (9)
  • app/Filament/Admin/Resources/NodeResource/Widgets/NodeCpuChart.php (1 hunks)
  • app/Filament/Admin/Resources/NodeResource/Widgets/NodeMemoryChart.php (1 hunks)
  • app/Filament/Server/Pages/Settings.php (1 hunks)
  • app/Filament/Server/Widgets/ServerCpuChart.php (1 hunks)
  • app/Filament/Server/Widgets/ServerMemoryChart.php (1 hunks)
  • app/Filament/Server/Widgets/ServerOverview.php (1 hunks)
  • app/Livewire/ServerEntry.php (1 hunks)
  • app/Models/Server.php (1 hunks)
  • app/helpers.php (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (5)
app/Models/Server.php (1)
app/helpers.php (1)
  • format_number (103-111)
app/Filament/Admin/Resources/NodeResource/Widgets/NodeMemoryChart.php (1)
app/helpers.php (1)
  • format_number (103-111)
app/Filament/Server/Widgets/ServerOverview.php (1)
app/helpers.php (1)
  • format_number (103-111)
app/Filament/Server/Pages/Settings.php (2)
app/Models/Server.php (1)
  • Server (126-498)
app/helpers.php (1)
  • format_number (103-111)
app/Filament/Admin/Resources/NodeResource/Widgets/NodeCpuChart.php (1)
app/helpers.php (1)
  • format_number (103-111)
🔇 Additional comments (4)
app/Filament/Server/Widgets/ServerCpuChart.php (1)

33-35: Good move: feed Chart.js numeric datapoints

Switching to round($value, 2) ensures the dataset is numeric, avoiding locale-induced commas in strings that can break chart rendering. This is the right direction for chart data.

app/Livewire/ServerEntry.php (1)

41-41: LGTM: consistent with centralized formatting

Using format_number here keeps the placeholder consistent with the rest of the UI and avoids locale-specific pitfalls.

app/Filament/Server/Widgets/ServerMemoryChart.php (1)

33-34: Good change: emit numeric values to the chart

Switching from localized strings to round(..., 2) yields proper numeric data for Chart.js and avoids locale parsing issues. Keep it.

app/helpers.php (1)

48-49: LGTM: centralize formatting in convert_bytes_to_readable

Delegating to format_number is the right direction to keep locale handling consistent.

@Boy132 Boy132 merged commit 0104a08 into main Aug 31, 2025
25 checks passed
@Boy132 Boy132 deleted the boy132/custom-number-format branch August 31, 2025 11:48
@github-actions github-actions bot locked and limited conversation to collaborators Aug 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants