refactor: modify log loading behavior in Proxmox Firewall component to prevent event dispatch on initial load, enhancing performance and user experience
This commit is contained in:
@@ -58,7 +58,7 @@ class Firewall extends Component
|
||||
$this->loadFirewallOptions();
|
||||
$this->loadFirewallRules();
|
||||
$this->loadNetworkAdapters();
|
||||
$this->loadFirewallLogs();
|
||||
$this->loadFirewallLogs(false); // Don't dispatch event on initial load
|
||||
}
|
||||
|
||||
protected function loadAvailableIps(): void
|
||||
@@ -797,7 +797,7 @@ class Firewall extends Component
|
||||
}
|
||||
}
|
||||
|
||||
public function loadFirewallLogs(): void
|
||||
public function loadFirewallLogs(bool $dispatchEvent = true): void
|
||||
{
|
||||
$this->logError = '';
|
||||
try {
|
||||
@@ -937,6 +937,11 @@ class Firewall extends Component
|
||||
} elseif (empty($this->firewallLogs)) {
|
||||
$this->logError = 'No firewall logs available. Ensure firewall logging is enabled in Proxmox (Datacenter > Firewall > Options).';
|
||||
}
|
||||
|
||||
// Dispatch event only when manually refreshed (not on mount)
|
||||
if ($dispatchEvent) {
|
||||
$this->dispatch('logs-refreshed');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$errorMessage = $e->getMessage();
|
||||
if (method_exists($e, 'response') && $e->response()) {
|
||||
|
||||
@@ -323,12 +323,23 @@
|
||||
|
||||
@if(count($firewallLogs) > 0)
|
||||
<div
|
||||
wire:ignore.self
|
||||
x-data="{
|
||||
logs: @js($firewallLogs),
|
||||
logs: [],
|
||||
searchTerm: '',
|
||||
sortField: 'timestamp_iso',
|
||||
sortDirection: 'desc',
|
||||
init() {
|
||||
// Use window storage to persist logs across Livewire updates
|
||||
if (!window.firewallLogsCache) {
|
||||
window.firewallLogsCache = @js($firewallLogs);
|
||||
}
|
||||
this.logs = window.firewallLogsCache;
|
||||
},
|
||||
refreshLogs() {
|
||||
// Update cache when refresh button is clicked
|
||||
window.firewallLogsCache = @js($firewallLogs);
|
||||
this.logs = window.firewallLogsCache;
|
||||
},
|
||||
sort(field) {
|
||||
if (this.sortField === field) {
|
||||
this.sortDirection = this.sortDirection === 'asc' ? 'desc' : 'asc';
|
||||
@@ -373,7 +384,7 @@
|
||||
});
|
||||
},
|
||||
}"
|
||||
@logs-updated.window="logs = $event.detail.logs || $event.detail[0]?.logs || $event.detail[0] || []"
|
||||
@logs-refreshed.window="refreshLogs()"
|
||||
class="space-y-4"
|
||||
>
|
||||
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-3">
|
||||
|
||||
Reference in New Issue
Block a user