mirror of
https://github.com/fankes/beszel.git
synced 2025-10-20 10:19:27 +08:00
memoize alertsbutton and use string for global system alerts set
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useState } from 'react'
|
import { memo, useState } from 'react'
|
||||||
import { useStore } from '@nanostores/react'
|
import { useStore } from '@nanostores/react'
|
||||||
import { $alerts, $systems } from '@/lib/stores'
|
import { $alerts, $systems } from '@/lib/stores'
|
||||||
import {
|
import {
|
||||||
@@ -18,7 +18,7 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
|||||||
import { Checkbox } from '../ui/checkbox'
|
import { Checkbox } from '../ui/checkbox'
|
||||||
import { SystemAlert, SystemAlertGlobal } from './alerts-system'
|
import { SystemAlert, SystemAlertGlobal } from './alerts-system'
|
||||||
|
|
||||||
export default function AlertsButton({ system }: { system: SystemRecord }) {
|
export default memo(function AlertsButton({ system }: { system: SystemRecord }) {
|
||||||
const alerts = useStore($alerts)
|
const alerts = useStore($alerts)
|
||||||
const [opened, setOpened] = useState(false)
|
const [opened, setOpened] = useState(false)
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ export default function AlertsButton({ system }: { system: SystemRecord }) {
|
|||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
)
|
)
|
||||||
}
|
})
|
||||||
|
|
||||||
function TheContent({
|
function TheContent({
|
||||||
data: { system, alerts, systemAlerts },
|
data: { system, alerts, systemAlerts },
|
||||||
|
@@ -79,7 +79,7 @@ export function SystemAlertGlobal({
|
|||||||
alerts: AlertRecord[]
|
alerts: AlertRecord[]
|
||||||
systems: SystemRecord[]
|
systems: SystemRecord[]
|
||||||
}) {
|
}) {
|
||||||
const systemsWithExistingAlerts = useRef<{ set: Set<SystemRecord>; populatedSet: boolean }>({
|
const systemsWithExistingAlerts = useRef<{ set: Set<string>; populatedSet: boolean }>({
|
||||||
set: new Set(),
|
set: new Set(),
|
||||||
populatedSet: false,
|
populatedSet: false,
|
||||||
})
|
})
|
||||||
@@ -106,7 +106,7 @@ export function SystemAlertGlobal({
|
|||||||
}
|
}
|
||||||
for (let system of systems) {
|
for (let system of systems) {
|
||||||
// if overwrite is false and system is in set (alert existed), skip
|
// if overwrite is false and system is in set (alert existed), skip
|
||||||
if (!overwrite && set.has(system)) {
|
if (!overwrite && set.has(system.id)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// find matching existing alert
|
// find matching existing alert
|
||||||
@@ -115,7 +115,7 @@ export function SystemAlertGlobal({
|
|||||||
)
|
)
|
||||||
// if first run, add system to set (alert already existed when global panel was opened)
|
// if first run, add system to set (alert already existed when global panel was opened)
|
||||||
if (existingAlert && !populatedSet && !overwrite) {
|
if (existingAlert && !populatedSet && !overwrite) {
|
||||||
set.add(system)
|
set.add(system.id)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
const requestOptions: RecordOptions = {
|
const requestOptions: RecordOptions = {
|
||||||
|
Reference in New Issue
Block a user