refactor: streamline log update handling in Proxmox Firewall component by simplifying initialization and event listener for improved performance and clarity
This commit is contained in:
@@ -323,22 +323,18 @@
|
|||||||
|
|
||||||
@if(count($firewallLogs) > 0)
|
@if(count($firewallLogs) > 0)
|
||||||
<div
|
<div
|
||||||
|
wire:key="firewall-logs-table"
|
||||||
x-data="{
|
x-data="{
|
||||||
logs: [],
|
logs: @js($firewallLogs),
|
||||||
searchTerm: '',
|
searchTerm: '',
|
||||||
sortField: 'timestamp_iso',
|
sortField: 'timestamp_iso',
|
||||||
sortDirection: 'desc',
|
sortDirection: 'desc',
|
||||||
initialize(initialLogs) {
|
initialize(initialLogs) {
|
||||||
this.logs = (initialLogs || []).map((log, index) => ({
|
// This is called on x-init
|
||||||
index,
|
|
||||||
...log,
|
|
||||||
}));
|
|
||||||
},
|
},
|
||||||
updateLogs(newLogs) {
|
updateLogs(newLogs) {
|
||||||
this.logs = (newLogs || []).map((log, index) => ({
|
if (!newLogs || newLogs.length === 0) return;
|
||||||
index,
|
this.logs = newLogs;
|
||||||
...log,
|
|
||||||
}));
|
|
||||||
},
|
},
|
||||||
sort(field) {
|
sort(field) {
|
||||||
if (this.sortField === field) {
|
if (this.sortField === field) {
|
||||||
@@ -384,12 +380,7 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
}"
|
}"
|
||||||
x-init="
|
@logs-updated.window="updateLogs($event.detail.logs || $event.detail[0]?.logs || $event.detail[0] || [])"
|
||||||
initialize(@js($firewallLogs));
|
|
||||||
$wire.on('logs-updated', (event) => {
|
|
||||||
updateLogs(event.logs || event[0]?.logs || event[0] || []);
|
|
||||||
});
|
|
||||||
"
|
|
||||||
class="space-y-4"
|
class="space-y-4"
|
||||||
>
|
>
|
||||||
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-3">
|
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-3">
|
||||||
|
|||||||
Reference in New Issue
Block a user