Skip to content

Conversation

@Boy132
Copy link
Member

@Boy132 Boy132 commented Sep 23, 2025

Closes #1716

@Boy132 Boy132 self-assigned this Sep 23, 2025
@coderabbitai
Copy link

coderabbitai bot commented Sep 23, 2025

📝 Walkthrough

Walkthrough

Select option sources were made lazy by switching to closures for allocations and egg imports. Refresh hint actions were added: allocation IP selects clear the node IP cache, and the egg import select runs an Artisan command to rebuild the egg index. A "refresh" translation key was added.

Changes

Cohort / File(s) Summary of Changes
Allocation IP selects: lazy options + refresh hint
app/Filament/Admin/Resources/Nodes/RelationManagers/AllocationsRelationManager.php, app/Filament/Admin/Resources/Servers/Pages/CreateServer.php, app/Filament/Admin/Resources/Servers/RelationManagers/AllocationsRelationManager.php
Changed Select::make('allocation_ip')->options(...) to use a closure ->options(fn () => ...) for lazy evaluation; added hintAction refresh button that calls cache()->forget("nodes.{node_id}.ips").
Egg import select: lazy options + consolidated refresh action
app/Filament/Components/Actions/ImportEggAction.php
Switched Select::make('github')->options(cache('eggs.index')) to ->options(fn () => cache('eggs.index')); replaced separate hint icon/inline action with hintAction(Action::make('refresh')->iconButton()->icon('tabler-refresh')->tooltip(...)->action(...)) which calls the UpdateEggIndexCommand.
Localization
lang/en/admin/node.php
Added translation key: refresh => "Refresh".

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant F as Filament Form (Allocation IP Select)
  participant C as Cache
  participant N as Node Model

  U->>F: Click "Refresh" hint action
  Note right of F #eeeeff: Hint action clears node IP cache
  F->>C: forget("nodes.{node_id}.ips")
  F->>N: fetch ipAddresses()
  N-->>F: [ips]
  F->>F: rebuild options via closure
  F-->>U: Updated IP options
Loading
sequenceDiagram
  autonumber
  actor U as User
  participant F as ImportEggAction
  participant A as Artisan
  participant CMD as UpdateEggIndexCommand
  participant C as Cache

  U->>F: Click "Refresh" hint action
  Note right of F #eeffee: Action calls Artisan command to rebuild index
  F->>A: call(UpdateEggIndexCommand)
  A->>CMD: execute
  CMD->>C: update cache('eggs.index')
  U->>F: Open select / reload options
  F->>C: get cache('eggs.index') via closure
  C-->>F: [egg repos]
  F-->>U: Updated GitHub options
Loading

Pre-merge checks

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning The PR also modifies ImportEggAction (changing options to a lazy closure and replacing the hint UI with an Action) and adds a translation entry, which address the egg-index refresh and are not part of linked issue #1716, so these changes are outside the scope of the provided issue. Either split the egg-index-related changes (ImportEggAction and the language entry) into a separate PR or update this PR to include the additional linked issue(s) and rationale; ensure tests or a brief manual test note are added to cover the egg-index refresh behavior.
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly and accurately describes the primary changes: it fixes the egg-index select refresh and adds refresh actions to allocation IP selects, matching the modified files and behavior in the changeset.
Linked Issues Check ✅ Passed The PR implements the linked issue [#1716] by adding refresh hint actions to the allocation IP Select fields (CreateServer and AllocationsRelationManager) that clear the cached node IPs (cache key nodes.{id}.ips), enabling on-demand refresh of the IP list as requested.
Description Check ✅ Passed The description "Closes #1716" is related to the changes because it links the relevant issue requesting an IP-select refresh action, but it is minimal and does not summarize the code changes.

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.

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: 0

🧹 Nitpick comments (3)
app/Filament/Admin/Resources/Nodes/RelationManagers/AllocationsRelationManager.php (1)

95-103: Verify the translation key path.

The tooltip references trans('admin/admin/node.refresh') with a double "admin/" path, which appears incorrect. Based on the translation file lang/en/admin/node.php, it should likely be trans('admin/node.refresh').

-                                    ->tooltip(trans('admin/admin/node.refresh'))
+                                    ->tooltip(trans('admin/node.refresh'))
app/Filament/Admin/Resources/Servers/RelationManagers/AllocationsRelationManager.php (1)

85-93: Fix the translation key path.

Same issue as in the nodes relation manager - the tooltip uses an incorrect double "admin/" path.

-                                    ->tooltip(trans('admin/admin/node.refresh'))
+                                    ->tooltip(trans('admin/node.refresh'))
app/Filament/Admin/Resources/Servers/Pages/CreateServer.php (1)

227-235: Fix the translation key path.

Same translation key issue as found in the other components.

-                                                    ->tooltip(trans('admin/admin/node.refresh'))
+                                                    ->tooltip(trans('admin/node.refresh'))
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bb40a52 and eee13c7.

📒 Files selected for processing (5)
  • app/Filament/Admin/Resources/Nodes/RelationManagers/AllocationsRelationManager.php (1 hunks)
  • app/Filament/Admin/Resources/Servers/Pages/CreateServer.php (1 hunks)
  • app/Filament/Admin/Resources/Servers/RelationManagers/AllocationsRelationManager.php (1 hunks)
  • app/Filament/Components/Actions/ImportEggAction.php (1 hunks)
  • lang/en/admin/node.php (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
app/Filament/Admin/Resources/Nodes/RelationManagers/AllocationsRelationManager.php (1)
app/Models/Node.php (1)
  • ipAddresses (379-401)
app/Filament/Admin/Resources/Servers/Pages/CreateServer.php (1)
app/Models/Node.php (2)
  • Node (59-402)
  • ipAddresses (379-401)
app/Filament/Components/Actions/ImportEggAction.php (1)
app/Console/Commands/Egg/UpdateEggIndexCommand.php (1)
  • UpdateEggIndexCommand (8-46)
app/Filament/Admin/Resources/Servers/RelationManagers/AllocationsRelationManager.php (1)
app/Models/Node.php (1)
  • ipAddresses (379-401)
🔇 Additional comments (10)
lang/en/admin/node.php (1)

40-40: LGTM!

The translation entry is correctly added and aligns with the refresh functionality being introduced across the codebase. The 'refresh' translation key provides proper localization support for the refresh buttons that clear cached data using Laravel's cache()->forget() method.

app/Filament/Admin/Resources/Nodes/RelationManagers/AllocationsRelationManager.php (2)

88-88: Good change to lazy evaluation!

Converting the options from eager evaluation to a closure improves performance by deferring the expensive ipAddresses() call until the field is actually rendered.


100-102: Effective cache invalidation implementation!

The refresh action properly clears the specific cache key that corresponds to the node's IP addresses, ensuring users get fresh data when needed. This aligns with Laravel's recommended practice of using Cache::forget() to remove specific cache items.

app/Filament/Admin/Resources/Servers/RelationManagers/AllocationsRelationManager.php (2)

80-80: LGTM! Consistent lazy evaluation implementation.

The conversion to closure-based options is consistent with the pattern implemented across other components in this PR and improves performance.


90-92: Proper cache key targeting!

The cache invalidation correctly targets the specific node's IP cache using the server's node relationship, maintaining data integrity.

app/Filament/Components/Actions/ImportEggAction.php (3)

128-128: Consistent lazy evaluation pattern!

The migration to closure-based options follows the same performance optimization pattern implemented in the allocation IP selects.


133-141: Verify the Artisan command execution approach.

The refresh action directly calls the Artisan command, which will execute synchronously and might block the UI for users. Consider if this could cause performance issues for the user experience, especially if the command takes time to fetch and process the egg index data.

The UpdateEggIndexCommand fetches data from a remote GitHub URL, which could potentially be slow or fail. Consider:

  1. Adding error handling for the refresh action
  2. Potentially showing a loading state or notification to the user
  3. Evaluating if this should run asynchronously

Based on the relevant code snippet, the command makes an HTTP request to GitHub and processes JSON data, which could take several seconds.


137-137: Translation key present — no action required. Found trans('admin/egg.import.refresh') in lang/*/admin/egg.php (e.g. lang/en/admin/egg.php:22).

app/Filament/Admin/Resources/Servers/Pages/CreateServer.php (2)

221-221: Consistent implementation pattern!

The lazy evaluation approach matches the implementation in the relation managers, maintaining consistency across the codebase.


232-234: Proper cache key construction!

The cache invalidation correctly uses the current form state to build the cache key, ensuring the right node's IP cache is cleared.

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: 0

🧹 Nitpick comments (1)
app/Filament/Admin/Resources/Servers/Pages/CreateServer.php (1)

221-221: Prefer explicit Get parameter and return array for options.

Avoid capturing $get; pass it explicitly. Also return an array to align with Filament expectations and your other options closures.

-                                            ->options(fn () => collect(Node::find($get('node_id'))?->ipAddresses())->mapWithKeys(fn (string $ip) => [$ip => $ip]))
+                                            ->options(fn (Get $get) => collect(Node::find($get('node_id'))?->ipAddresses())
+                                                ->mapWithKeys(fn (string $ip) => [$ip => $ip])
+                                                ->toArray()
+                                            )
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eee13c7 and 90b72fb.

📒 Files selected for processing (3)
  • app/Filament/Admin/Resources/Nodes/RelationManagers/AllocationsRelationManager.php (1 hunks)
  • app/Filament/Admin/Resources/Servers/Pages/CreateServer.php (1 hunks)
  • app/Filament/Admin/Resources/Servers/RelationManagers/AllocationsRelationManager.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • app/Filament/Admin/Resources/Nodes/RelationManagers/AllocationsRelationManager.php
  • app/Filament/Admin/Resources/Servers/RelationManagers/AllocationsRelationManager.php
🧰 Additional context used
🧬 Code graph analysis (1)
app/Filament/Admin/Resources/Servers/Pages/CreateServer.php (1)
app/Models/Node.php (2)
  • Node (59-402)
  • ipAddresses (379-401)
🔇 Additional comments (1)
app/Filament/Admin/Resources/Servers/Pages/CreateServer.php (1)

227-235: Accept Get $get in the action; add a success notification; translation found in en

  • Accept Get $get in the action closure instead of capturing $get to avoid stale state.
  • Optional: send a success Notification after cache()->forget(...) so users see the list was refreshed.
  • Found translation: lang/en/admin/node.php:40 -> 'refresh' => 'Refresh' — add to other locales if needed.
-                                            ->hintAction(
-                                                Action::make('refresh')
-                                                    ->iconButton()
-                                                    ->icon('tabler-refresh')
-                                                    ->tooltip(trans('admin/node.refresh'))
-                                                    ->action(function () use ($get) {
-                                                        cache()->forget("nodes.{$get('node_id')}.ips");
-                                                    })
-                                            )
+                                            ->hintAction(
+                                                Action::make('refresh')
+                                                    ->iconButton()
+                                                    ->icon('tabler-refresh')
+                                                    ->tooltip(trans('admin/node.refresh'))
+                                                    ->action(function (Get $get) {
+                                                        cache()->forget("nodes.{$get('node_id')}.ips");
+                                                        // Optional: notify success
+                                                        // Notification::make()->title('IP list refreshed')->success()->send();
+                                                    })
+                                            )

@Boy132 Boy132 merged commit 4792542 into main Sep 23, 2025
25 checks passed
@Boy132 Boy132 deleted the boy132/refresh-hint-actions branch September 23, 2025 12:56
@github-actions github-actions bot locked and limited conversation to collaborators Sep 23, 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.

Add refresh hint action to IP selection for new allocations

3 participants