Skip to content

Commit

Permalink
memoize alertsbutton and use string for global system alerts set
Browse files Browse the repository at this point in the history
  • Loading branch information
henrygd committed Oct 19, 2024
1 parent 8bf7a0e commit 7f01d1e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions beszel/site/src/components/alerts/alert-button.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react'
import { memo, useState } from 'react'
import { useStore } from '@nanostores/react'
import { $alerts, $systems } from '@/lib/stores'
import {
Expand All @@ -18,7 +18,7 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
import { Checkbox } from '../ui/checkbox'
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 [opened, setOpened] = useState(false)

Expand Down Expand Up @@ -47,7 +47,7 @@ export default function AlertsButton({ system }: { system: SystemRecord }) {
</DialogContent>
</Dialog>
)
}
})

function TheContent({
data: { system, alerts, systemAlerts },
Expand Down
6 changes: 3 additions & 3 deletions beszel/site/src/components/alerts/alerts-system.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function SystemAlertGlobal({
alerts: AlertRecord[]
systems: SystemRecord[]
}) {
const systemsWithExistingAlerts = useRef<{ set: Set<SystemRecord>; populatedSet: boolean }>({
const systemsWithExistingAlerts = useRef<{ set: Set<string>; populatedSet: boolean }>({
set: new Set(),
populatedSet: false,
})
Expand All @@ -106,7 +106,7 @@ export function SystemAlertGlobal({
}
for (let system of systems) {
// if overwrite is false and system is in set (alert existed), skip
if (!overwrite && set.has(system)) {
if (!overwrite && set.has(system.id)) {
continue
}
// find matching existing alert
Expand All @@ -115,7 +115,7 @@ export function SystemAlertGlobal({
)
// if first run, add system to set (alert already existed when global panel was opened)
if (existingAlert && !populatedSet && !overwrite) {
set.add(system)
set.add(system.id)
continue
}
const requestOptions: RecordOptions = {
Expand Down

0 comments on commit 7f01d1e

Please sign in to comment.