Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Split thresholds availability mutation owner
rcourtmanf02fc8455b32
diff --git a/docs/release-control/v6/internal/subsystems/alerts.md b/docs/release-control/v6/internal/subsystems/alerts.mdindex 1f948a00eb..d50378fc27 100644--- a/docs/release-control/v6/internal/subsystems/alerts.md+++ b/docs/release-control/v6/internal/subsystems/alerts.md@@ -145,10 +145,15 @@ backup and snapshot default sanitization plus factory-drift policy now live in`frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsRecoveryDefaultsState.ts`,while `frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsTableState.ts`owns threshold-table route sync, section collapse state, search/edit shell-state, and bulk-edit dialog control. Override persistence, bulk threshold-application, powered-off/connectivity state transitions, and alert-removal side+state, and bulk-edit dialog control. Pure override upsert and hysteresis-entry+helpers now live in+`frontend-modern/src/features/alerts/thresholds/thresholdsOverrideMutationModel.ts`.+Threshold edit persistence, bulk threshold application, and backup/snapshot+override toggles now route through+`frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsOverrideMutations.ts`,+while powered-off/connectivity state transitions plus alert-removal sideeffects now route through-`frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsOverrideMutations.ts`.+`frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsAvailabilityMutations.ts`.The thresholds tab adapter contract now lives in`frontend-modern/src/features/alerts/thresholds/thresholdsTabModel.ts`, so`frontend-modern/src/features/alerts/tabs/ThresholdsTab.tsx` stays a shelldiff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.mdindex ed0e76f051..6587663b04 100644--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md@@ -240,9 +240,13 @@ must stay the table-shell owner for route sync and local UI state, whilestays the composition shell for threshold resource-family projectors,`frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsRecoveryDefaultsState.ts`owns backup/snapshot default sanitization and factory-drift policy, and+`frontend-modern/src/features/alerts/thresholds/thresholdsOverrideMutationModel.ts`+owns pure override upsert/hysteresis/state-strip helpers,`frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsOverrideMutations.ts`-owns override save/bulk/toggle persistence and alert-removal side effects. The-table-shell hook should not re-accumulate raw override mutation logic,+owns threshold-save and backup/snapshot override persistence, and+`frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsAvailabilityMutations.ts`+owns availability-state policy and alert-removal side effects. The table-shell+hook should not re-accumulate raw override mutation logic,recovery-threshold defaults policy, or resource-family projection enginesinline.diff --git a/frontend-modern/src/features/alerts/thresholds/hooks/__tests__/useThresholdsAvailabilityMutations.test.tsx b/frontend-modern/src/features/alerts/thresholds/hooks/__tests__/useThresholdsAvailabilityMutations.test.tsxnew file mode 100644index 0000000000..0d1f6e3767--- /dev/null+++ b/frontend-modern/src/features/alerts/thresholds/hooks/__tests__/useThresholdsAvailabilityMutations.test.tsx@@ -0,0 +1,87 @@+import { renderHook } from '@solidjs/testing-library';+import { createSignal } from 'solid-js';+import { describe, expect, it, vi } from 'vitest';++import type { ThresholdsTableProps } from '@/features/alerts/thresholds/types';+import type { Resource as TableResource } from '@/features/alerts/thresholds/tableTypes';++import { useThresholdsAvailabilityMutations } from '../useThresholdsAvailabilityMutations';++const buildTableProps = (overridesSignal: ReturnType<typeof createSignal<any[]>>) => {+ const [overrides, setOverrides] = overridesSignal;+ const [rawOverridesConfig, setRawOverridesConfig] = createSignal<Record<string, any>>({});+ const setHasUnsavedChanges = vi.fn();+ const removeAlerts = vi.fn();++ const props = {+ overrides,+ setOverrides,+ rawOverridesConfig,+ setRawOverridesConfig,+ guestDisableConnectivity: () => false,+ guestPoweredOffSeverity: () => 'warning' as const,+ dockerDisableConnectivity: () => false,+ dockerPoweredOffSeverity: () => 'warning' as const,+ setHasUnsavedChanges,+ removeAlerts,+ } as unknown as ThresholdsTableProps;++ return {+ props,+ rawOverridesConfig,+ setHasUnsavedChanges,+ removeAlerts,+ };+};++describe('useThresholdsAvailabilityMutations', () => {+ it('owns powered-off severity and disable-connectivity persistence for guest resources', () => {+ const overrideSignal = createSignal<any[]>([]);+ const { props, rawOverridesConfig, setHasUnsavedChanges, removeAlerts } =+ buildTableProps(overrideSignal);+ const guestResource: TableResource = {+ id: 'vm-100',+ name: 'db-01',+ type: 'guest',+ resourceType: 'VM',+ vmid: 100,+ node: 'pve-1',+ instance: 'qemu/100',+ thresholds: {},+ };++ const { result } = renderHook(() =>+ useThresholdsAvailabilityMutations({+ props,+ resources: {+ nodesWithOverrides: () => [],+ agentsWithOverrides: () => [],+ agentDisksWithOverrides: () => [],+ dockerHostsWithOverrides: () => [],+ guestsFlat: () => [guestResource],+ dockerContainersFlat: () => [],+ pbsServersWithOverrides: () => [],+ storageWithOverrides: () => [],+ },+ removeOverride: vi.fn(),+ }),+ );++ result.setOfflineState('vm-100', 'critical');++ expect(overrideSignal[0]()).toEqual([+ expect.objectContaining({+ id: 'vm-100',+ disableConnectivity: false,+ poweredOffSeverity: 'critical',+ }),+ ]);+ expect(rawOverridesConfig()).toEqual({+ 'vm-100': {+ poweredOffSeverity: 'critical',+ },+ });+ expect(setHasUnsavedChanges).toHaveBeenCalledWith(true);+ expect(removeAlerts).not.toHaveBeenCalled();+ });+});diff --git a/frontend-modern/src/features/alerts/thresholds/hooks/__tests__/useThresholdsOverrideMutations.test.tsx b/frontend-modern/src/features/alerts/thresholds/hooks/__tests__/useThresholdsOverrideMutations.test.tsxindex 2b5d7a1ce5..b605b7b693 100644--- a/frontend-modern/src/features/alerts/thresholds/hooks/__tests__/useThresholdsOverrideMutations.test.tsx+++ b/frontend-modern/src/features/alerts/thresholds/hooks/__tests__/useThresholdsOverrideMutations.test.tsx@@ -113,63 +113,4 @@ describe('useThresholdsOverrideMutations', () => {expect(setHasUnsavedChanges).toHaveBeenCalledWith(true);expect(cancelEdit).toHaveBeenCalledTimes(1);});-- it('owns powered-off severity and disable-connectivity persistence for guest resources', () => {- const overrideSignal = createSignal<any[]>([]);- const { props, rawOverridesConfig, setHasUnsavedChanges, removeAlerts } =- buildTableProps(overrideSignal);- const [editingThresholds] = createSignal<Record<string, number | undefined>>({});- const [editingNote] = createSignal('');- const [bulkEditIds] = createSignal<string[]>([]);- const guestResource: TableResource = {- id: 'vm-100',- name: 'db-01',- type: 'guest',- resourceType: 'VM',- vmid: 100,- node: 'pve-1',- instance: 'qemu/100',- thresholds: {},- };-- const { result } = renderHook(() =>- useThresholdsOverrideMutations({- props,- resources: {- nodesWithOverrides: () => [],- agentsWithOverrides: () => [],- agentDisksWithOverrides: () => [],- dockerHostsWithOverrides: () => [],- guestsFlat: () => [guestResource],- dockerContainersFlat: () => [],- pbsServersWithOverrides: () => [],- pmgServersWithOverrides: () => [],- storageWithOverrides: () => [],- },- editingThresholds,- editingNote,- bulkEditIds,- cancelEdit: vi.fn(),- updateBackupDefaults: vi.fn(),- updateSnapshotDefaults: vi.fn(),- }),- );-- result.setOfflineState('vm-100', 'critical');-- expect(overrideSignal[0]()).toEqual([- expect.objectContaining({- id: 'vm-100',- disableConnectivity: false,- poweredOffSeverity: 'critical',- }),- ]);- expect(rawOverridesConfig()).toEqual({- 'vm-100': {- poweredOffSeverity: 'critical',- },- });- expect(setHasUnsavedChanges).toHaveBeenCalledWith(true);- expect(removeAlerts).not.toHaveBeenCalled();- });});diff --git a/frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsAvailabilityMutations.ts b/frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsAvailabilityMutations.tsnew file mode 100644index 0000000000..c6d8f6bef9--- /dev/null+++ b/frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsAvailabilityMutations.ts@@ -0,0 +1,312 @@+import { matchesAlertIdentifier } from '@/features/alerts/identity';++import type {+ OfflineState,+ Override,+ OverrideType,+ ThresholdsTableProps,+} from '@/features/alerts/thresholds/types';+import type { Resource as TableResource } from '@/features/alerts/thresholds/tableTypes';+import {+ stripStateKeys,+ upsertOverride,+ withThresholdEntries,+} from '@/features/alerts/thresholds/thresholdsOverrideMutationModel';++interface ThresholdsAvailabilityMutationResources {+ nodesWithOverrides: () => TableResource[];+ agentsWithOverrides: () => TableResource[];+ agentDisksWithOverrides: () => TableResource[];+ dockerHostsWithOverrides: () => TableResource[];+ guestsFlat: () => TableResource[];+ dockerContainersFlat: () => TableResource[];+ pbsServersWithOverrides: () => TableResource[];+ storageWithOverrides: () => TableResource[];+}++interface ThresholdsAvailabilityMutationProps {+ props: ThresholdsTableProps;+ resources: ThresholdsAvailabilityMutationResources;+ removeOverride: (resourceId: string) => void;+}++export function useThresholdsAvailabilityMutations({+ props,+ resources,+ removeOverride,+}: ThresholdsAvailabilityMutationProps) {+ const guestLikeResources = () => [+ ...resources.guestsFlat(),+ ...resources.dockerContainersFlat(),+ ];++ const clearDockerHostConnectivityAlerts = (resourceId: string) => {+ if (!props.removeAlerts) return;++ const offlineId = `docker-host-offline-${resourceId}`;+ const resourceKey = `docker:${resourceId}`;+ props.removeAlerts(+ (alert) => matchesAlertIdentifier(alert, offlineId) || alert.resourceId === resourceKey,+ );+ };++ const toggleDisabled = (resourceId: string, forceState?: boolean) => {+ const resource = [+ ...guestLikeResources(),+ ...resources.storageWithOverrides(),+ ...resources.pbsServersWithOverrides(),+ ...resources.agentsWithOverrides(),+ ...resources.agentDisksWithOverrides(),+ ].find((entry) => entry.id === resourceId);++ if (+ !resource ||+ (resource.type !== 'guest' &&+ resource.type !== 'storage' &&+ resource.type !== 'pbs' &&+ resource.type !== 'dockerContainer' &&+ resource.type !== 'agent' &&+ resource.type !== 'agentDisk')+ ) {+ return;+ }++ const existingOverride = props.overrides().find((override) => override.id === resourceId);+ const currentDisabledState = resource.disabled;+ const newDisabledState = forceState !== undefined ? forceState : !currentDisabledState;+ const cleanThresholds = stripStateKeys({ ...(existingOverride?.thresholds || {}) });++ if (!newDisabledState && (!existingOverride || Object.keys(cleanThresholds).length === 0)) {+ removeOverride(resourceId);+ return;+ }++ const override: Override = {+ id: resourceId,+ name: resource.name,+ type: resource.type as OverrideType,+ resourceType: resource.resourceType,+ vmid: 'vmid' in resource ? resource.vmid : undefined,+ node: 'node' in resource ? resource.node : undefined,+ instance: 'instance' in resource ? resource.instance : undefined,+ disabled: newDisabledState,+ disableConnectivity: existingOverride?.disableConnectivity,+ poweredOffSeverity: existingOverride?.poweredOffSeverity,+ backup: existingOverride?.backup,+ snapshot: existingOverride?.snapshot,+ thresholds: cleanThresholds,+ };++ props.setOverrides(upsertOverride(props.overrides(), override));++ const hysteresisThresholds = withThresholdEntries({}, override.thresholds);+ if (newDisabledState) hysteresisThresholds.disabled = true;+ if (override.backup) hysteresisThresholds.backup = override.backup;+ if (override.snapshot) hysteresisThresholds.snapshot = override.snapshot;+ if (override.disableConnectivity) hysteresisThresholds.disableConnectivity = true;+ if (override.poweredOffSeverity) {+ hysteresisThresholds.poweredOffSeverity = override.poweredOffSeverity;+ }++ const nextRawConfig = { ...props.rawOverridesConfig() };+ if (Object.keys(hysteresisThresholds).length === 0) {+ delete nextRawConfig[resourceId];+ } else {+ nextRawConfig[resourceId] = hysteresisThresholds;+ }+ props.setRawOverridesConfig(nextRawConfig);++ if (newDisabledState && props.removeAlerts) {+ if (resource.type === 'guest') {+ props.removeAlerts(+ (alert) => alert.resourceId === resourceId && alert.type === 'powered-off',+ );+ } else if (resource.type === 'pbs') {+ const offlineId = `pbs-offline-${resourceId}`;+ props.removeAlerts(+ (alert) =>+ alert.resourceId === resourceId &&+ (matchesAlertIdentifier(alert, offlineId) || alert.type === 'offline'),+ );+ } else if (resource.type === 'dockerContainer') {+ props.removeAlerts(+ (alert) =>+ alert.resourceId === resourceId &&+ (alert.type === 'docker-container-state' || alert.type === 'docker-container-health'),+ );+ }+ }++ props.setHasUnsavedChanges(true);+ };++ const toggleNodeConnectivity = (resourceId: string, forceState?: boolean) => {+ const resource = [+ ...resources.nodesWithOverrides(),+ ...resources.pbsServersWithOverrides(),+ ...resources.guestsFlat(),+ ...resources.agentsWithOverrides(),+ ...resources.dockerHostsWithOverrides(),+ ].find((entry) => entry.id === resourceId);++ if (+ !resource ||+ (resource.type !== 'agent' &&+ resource.type !== 'pbs' &&+ resource.type !== 'guest' &&+ resource.type !== 'dockerHost')+ ) {+ return;+ }++ const existingOverride = props.overrides().find((override) => override.id === resourceId);+ const currentDisableConnectivity = resource.disableConnectivity;+ const newDisableConnectivity =+ forceState !== undefined ? forceState : !currentDisableConnectivity;+ const cleanThresholds = stripStateKeys({ ...(existingOverride?.thresholds || {}) });++ if (!newDisableConnectivity && Object.keys(cleanThresholds).length === 0) {+ removeOverride(resourceId);+ if (resource.type === 'dockerHost') {+ clearDockerHostConnectivityAlerts(resourceId);+ }+ return;+ }++ const override: Override = {+ id: resourceId,+ name: resource.name,+ type: resource.type as OverrideType,+ resourceType: resource.resourceType,+ disableConnectivity: newDisableConnectivity,+ disabled: existingOverride?.disabled,+ poweredOffSeverity: existingOverride?.poweredOffSeverity,+ backup: existingOverride?.backup,+ snapshot: existingOverride?.snapshot,+ thresholds: cleanThresholds,+ };++ props.setOverrides(upsertOverride(props.overrides(), override));++ const hysteresisThresholds = withThresholdEntries({}, cleanThresholds);+ if (newDisableConnectivity) {+ hysteresisThresholds.disableConnectivity = true;+ }+ if (override.backup) hysteresisThresholds.backup = override.backup;+ if (override.snapshot) hysteresisThresholds.snapshot = override.snapshot;+ if (override.disabled) hysteresisThresholds.disabled = true;+ if (override.poweredOffSeverity) {+ hysteresisThresholds.poweredOffSeverity = override.poweredOffSeverity;+ }++ const nextRawConfig = { ...props.rawOverridesConfig() };+ if (Object.keys(hysteresisThresholds).length === 0) {+ delete nextRawConfig[resourceId];+ } else {+ nextRawConfig[resourceId] = hysteresisThresholds;+ }+ props.setRawOverridesConfig(nextRawConfig);+ props.setHasUnsavedChanges(true);++ if (resource.type === 'dockerHost') {+ clearDockerHostConnectivityAlerts(resourceId);+ }+ };++ const setOfflineState = (resourceId: string, state: OfflineState) => {+ const resource = guestLikeResources().find((entry) => entry.id === resourceId);+ if (!resource) return;++ const isDockerContainer = resource.type === 'dockerContainer';+ const defaultDisabled = isDockerContainer+ ? props.dockerDisableConnectivity()+ : props.guestDisableConnectivity();+ const defaultSeverity = isDockerContainer+ ? props.dockerPoweredOffSeverity()+ : props.guestPoweredOffSeverity();++ const existingOverride = props.overrides().find((override) => override.id === resourceId);+ const cleanThresholds = stripStateKeys({ ...(existingOverride?.thresholds || {}) });++ const newDisableConnectivity = state === 'off';+ const newSeverity: 'warning' | 'critical' | undefined =+ state === 'off' ? undefined : state === 'critical' ? 'critical' : 'warning';++ const overrideDisabled = existingOverride?.disabled || false;+ const hasThresholds = Object.keys(cleanThresholds).length > 0;+ const differsFromDefaults =+ newDisableConnectivity !== defaultDisabled ||+ (!newDisableConnectivity && newSeverity !== defaultSeverity);++ if (+ !differsFromDefaults &&+ !hasThresholds &&+ !overrideDisabled &&+ !existingOverride?.disableConnectivity+ ) {+ if (existingOverride) {+ removeOverride(resourceId);+ }+ return;+ }++ const override: Override = {+ id: resourceId,+ name: resource.name,+ type: resource.type as OverrideType,+ resourceType: resource.resourceType,+ vmid: 'vmid' in resource ? resource.vmid : undefined,+ node: 'node' in resource ? resource.node : undefined,+ instance: 'instance' in resource ? resource.instance : undefined,+ disabled: overrideDisabled,+ disableConnectivity: newDisableConnectivity,+ poweredOffSeverity: newDisableConnectivity ? undefined : newSeverity,+ backup: existingOverride?.backup,+ snapshot: existingOverride?.snapshot,+ thresholds: cleanThresholds,+ };++ props.setOverrides(upsertOverride(props.overrides(), override));++ const hysteresisThresholds = withThresholdEntries({}, cleanThresholds);+ if (overrideDisabled) hysteresisThresholds.disabled = true;+ if (newDisableConnectivity) {+ hysteresisThresholds.disableConnectivity = true;+ } else {+ if (defaultDisabled) hysteresisThresholds.disableConnectivity = false;+ if (newSeverity) hysteresisThresholds.poweredOffSeverity = newSeverity;+ }+ if (override.backup) hysteresisThresholds.backup = override.backup;+ if (override.snapshot) hysteresisThresholds.snapshot = override.snapshot;++ const nextRawConfig = { ...props.rawOverridesConfig() };+ if (Object.keys(hysteresisThresholds).length > 0) {+ nextRawConfig[resourceId] = hysteresisThresholds;+ } else {+ delete nextRawConfig[resourceId];+ }++ props.setRawOverridesConfig(nextRawConfig);+ props.setHasUnsavedChanges(true);++ if (props.removeAlerts && newDisableConnectivity) {+ if (resource.type === 'guest') {+ props.removeAlerts(+ (alert) => alert.resourceId === resourceId && alert.type === 'powered-off',+ );+ } else if (resource.type === 'dockerContainer') {+ props.removeAlerts(+ (alert) =>+ alert.resourceId === resourceId &&+ (alert.type === 'docker-container-state' || alert.type === 'docker-container-health'),+ );+ }+ }+ };++ return {+ setOfflineState,+ toggleDisabled,+ toggleNodeConnectivity,+ } as const;+}diff --git a/frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsOverrideMutations.ts b/frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsOverrideMutations.tsindex 7262fe3888..cd9cd2030e 100644--- a/frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsOverrideMutations.ts+++ b/frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsOverrideMutations.ts@@ -5,7 +5,6 @@ import type {BackupAlertConfig,SnapshotAlertConfig,} from '@/types/alerts';-import { matchesAlertIdentifier } from '@/features/alerts/identity';import {DEFAULT_SNAPSHOT_WARNING,DEFAULT_SNAPSHOT_CRITICAL,@@ -17,10 +16,14 @@ import {import type {Override,OverrideType,- OfflineState,ThresholdsTableProps,} from '@/features/alerts/thresholds/types';import type { Resource as TableResource } from '@/features/alerts/thresholds/tableTypes';+import {+ removeOverrideState,+ upsertOverride,+ withThresholdEntries,+} from '@/features/alerts/thresholds/thresholdsOverrideMutationModel';interface ThresholdsOverrideMutationResources {nodesWithOverrides: Accessor<TableResource[]>;@@ -49,43 +52,6 @@ interface ThresholdsOverrideMutationProps {) => void;}-const upsertOverride = (overrides: Override[], override: Override): Override[] => {- const existingIndex = overrides.findIndex((entry) => entry.id === override.id);- if (existingIndex >= 0) {- const nextOverrides = [...overrides];- nextOverrides[existingIndex] = override;- return nextOverrides;- }-- return [...overrides, override];-};--const withThresholdEntries = (- rawConfig: RawOverrideConfig,- thresholds: Record<string, number | undefined>,-): RawOverrideConfig => {- const next = { ...rawConfig };-- Object.entries(thresholds).forEach(([metric, value]) => {- if (value !== undefined && value !== null) {- next[metric] = {- clear: Math.max(0, value - 5),- trigger: value,- };- }- });-- return next;-};--const stripStateKeys = (thresholds: Record<string, number>): Record<string, number> => {- const next = { ...thresholds };- delete (next as Record<string, unknown>).disabled;- delete (next as Record<string, unknown>).disableConnectivity;- delete (next as Record<string, unknown>).poweredOffSeverity;- return next;-};-export function useThresholdsOverrideMutations({props,resources,@@ -114,10 +80,13 @@ export function useThresholdsOverrideMutations({const allThresholdResources = () => [...proxmoxResources(), ...guestLikeResources()];const removeOverride = (resourceId: string) => {- props.setOverrides(props.overrides().filter((override) => override.id !== resourceId));- const newRawConfig = { ...props.rawOverridesConfig() };- delete newRawConfig[resourceId];- props.setRawOverridesConfig(newRawConfig);+ const { nextOverrides, nextRawConfig } = removeOverrideState(+ props.overrides(),+ props.rawOverridesConfig(),+ resourceId,+ );+ props.setOverrides(nextOverrides);+ props.setRawOverridesConfig(nextRawConfig);props.setHasUnsavedChanges(true);};@@ -435,268 +404,11 @@ export function useThresholdsOverrideMutations({props.setHasUnsavedChanges(true);};- const toggleDisabled = (resourceId: string, forceState?: boolean) => {- const resource = [- ...guestLikeResources(),- ...resources.storageWithOverrides(),- ...resources.pbsServersWithOverrides(),- ...resources.agentsWithOverrides(),- ...resources.agentDisksWithOverrides(),- ].find((entry) => entry.id === resourceId);-- if (- !resource ||- (resource.type !== 'guest' &&- resource.type !== 'storage' &&- resource.type !== 'pbs' &&- resource.type !== 'dockerContainer' &&- resource.type !== 'agent' &&- resource.type !== 'agentDisk')- ) {- return;- }-- const existingOverride = props.overrides().find((override) => override.id === resourceId);- const currentDisabledState = resource.disabled;- const newDisabledState = forceState !== undefined ? forceState : !currentDisabledState;- const cleanThresholds = stripStateKeys({ ...(existingOverride?.thresholds || {}) });-- if (!newDisabledState && (!existingOverride || Object.keys(cleanThresholds).length === 0)) {- removeOverride(resourceId);- } else {- const override: Override = {- id: resourceId,- name: resource.name,- type: resource.type as OverrideType,- resourceType: resource.resourceType,- vmid: 'vmid' in resource ? resource.vmid : undefined,- node: 'node' in resource ? resource.node : undefined,- instance: 'instance' in resource ? resource.instance : undefined,- disabled: newDisabledState,- disableConnectivity: existingOverride?.disableConnectivity,- poweredOffSeverity: existingOverride?.poweredOffSeverity,- backup: existingOverride?.backup,- snapshot: existingOverride?.snapshot,- thresholds: cleanThresholds,- };-- props.setOverrides(upsertOverride(props.overrides(), override));-- let hysteresisThresholds: RawOverrideConfig = withThresholdEntries({}, override.thresholds);- if (newDisabledState) hysteresisThresholds.disabled = true;- if (override.backup) hysteresisThresholds.backup = override.backup;- if (override.snapshot) hysteresisThresholds.snapshot = override.snapshot;- if (override.disableConnectivity) hysteresisThresholds.disableConnectivity = true;- if (override.poweredOffSeverity) {- hysteresisThresholds.poweredOffSeverity = override.poweredOffSeverity;- }-- const nextRawConfig = { ...props.rawOverridesConfig() };- if (Object.keys(hysteresisThresholds).length === 0) {- delete nextRawConfig[resourceId];- } else {- nextRawConfig[resourceId] = hysteresisThresholds;- }- props.setRawOverridesConfig(nextRawConfig);- }-- if (newDisabledState && props.removeAlerts) {- if (resource.type === 'guest') {- props.removeAlerts(- (alert) => alert.resourceId === resourceId && alert.type === 'powered-off',- );- } else if (resource.type === 'pbs') {- const offlineId = `pbs-offline-${resourceId}`;- props.removeAlerts(- (alert) =>- alert.resourceId === resourceId &&- (matchesAlertIdentifier(alert, offlineId) || alert.type === 'offline'),- );- } else if (resource.type === 'dockerContainer') {- props.removeAlerts(- (alert) =>- alert.resourceId === resourceId &&- (alert.type === 'docker-container-state' || alert.type === 'docker-container-health'),- );- }- }-- props.setHasUnsavedChanges(true);- };-- const toggleNodeConnectivity = (resourceId: string, forceState?: boolean) => {- const resource = [- ...resources.nodesWithOverrides(),- ...resources.pbsServersWithOverrides(),- ...resources.guestsFlat(),- ...resources.agentsWithOverrides(),- ...resources.dockerHostsWithOverrides(),- ].find((entry) => entry.id === resourceId);-- if (- !resource ||- (resource.type !== 'agent' &&- resource.type !== 'pbs' &&- resource.type !== 'guest' &&- resource.type !== 'dockerHost')- ) {- return;- }-- const existingOverride = props.overrides().find((override) => override.id === resourceId);- const currentDisableConnectivity = resource.disableConnectivity;- const newDisableConnectivity =- forceState !== undefined ? forceState : !currentDisableConnectivity;- const cleanThresholds = stripStateKeys({ ...(existingOverride?.thresholds || {}) });-- if (!newDisableConnectivity && Object.keys(cleanThresholds).length === 0) {- removeOverride(resourceId);- } else {- const override: Override = {- id: resourceId,- name: resource.name,- type: resource.type as OverrideType,- resourceType: resource.resourceType,- disableConnectivity: newDisableConnectivity,- disabled: existingOverride?.disabled,- poweredOffSeverity: existingOverride?.poweredOffSeverity,- backup: existingOverride?.backup,- snapshot: existingOverride?.snapshot,- thresholds: cleanThresholds,- };-- props.setOverrides(upsertOverride(props.overrides(), override));-- let hysteresisThresholds: RawOverrideConfig = withThresholdEntries({}, cleanThresholds);- if (newDisableConnectivity) {- hysteresisThresholds.disableConnectivity = true;- }- if (override.backup) hysteresisThresholds.backup = override.backup;- if (override.snapshot) hysteresisThresholds.snapshot = override.snapshot;- if (override.disabled) hysteresisThresholds.disabled = true;- if (override.poweredOffSeverity) {- hysteresisThresholds.poweredOffSeverity = override.poweredOffSeverity;- }-- const nextRawConfig = { ...props.rawOverridesConfig() };- if (Object.keys(hysteresisThresholds).length === 0) {- delete nextRawConfig[resourceId];- } else {- nextRawConfig[resourceId] = hysteresisThresholds;- }- props.setRawOverridesConfig(nextRawConfig);- }-- props.setHasUnsavedChanges(true);-- if (props.removeAlerts && resource.type === 'dockerHost') {- const offlineId = `docker-host-offline-${resourceId}`;- const resourceKey = `docker:${resourceId}`;- props.removeAlerts(- (alert) => matchesAlertIdentifier(alert, offlineId) || alert.resourceId === resourceKey,- );- }- };-- const setOfflineState = (resourceId: string, state: OfflineState) => {- const resource = guestLikeResources().find((entry) => entry.id === resourceId);- if (!resource) return;-- const isDockerContainer = resource.type === 'dockerContainer';- const defaultDisabled = isDockerContainer- ? props.dockerDisableConnectivity()- : props.guestDisableConnectivity();- const defaultSeverity = isDockerContainer- ? props.dockerPoweredOffSeverity()- : props.guestPoweredOffSeverity();-- const existingOverride = props.overrides().find((override) => override.id === resourceId);- const cleanThresholds = stripStateKeys({ ...(existingOverride?.thresholds || {}) });-- const newDisableConnectivity = state === 'off';- const newSeverity: 'warning' | 'critical' | undefined =- state === 'off' ? undefined : state === 'critical' ? 'critical' : 'warning';-- const overrideDisabled = existingOverride?.disabled || false;- const hasThresholds = Object.keys(cleanThresholds).length > 0;- const differsFromDefaults =- newDisableConnectivity !== defaultDisabled ||- (!newDisableConnectivity && newSeverity !== defaultSeverity);-- if (- !differsFromDefaults &&- !hasThresholds &&- !overrideDisabled &&- !existingOverride?.disableConnectivity- ) {- if (existingOverride) {- removeOverride(resourceId);- }- return;- }-- const override: Override = {- id: resourceId,- name: resource.name,- type: resource.type as OverrideType,- resourceType: resource.resourceType,- vmid: 'vmid' in resource ? resource.vmid : undefined,- node: 'node' in resource ? resource.node : undefined,- instance: 'instance' in resource ? resource.instance : undefined,- disabled: overrideDisabled,- disableConnectivity: newDisableConnectivity,- poweredOffSeverity: newDisableConnectivity ? undefined : newSeverity,- backup: existingOverride?.backup,- snapshot: existingOverride?.snapshot,- thresholds: cleanThresholds,- };-- props.setOverrides(upsertOverride(props.overrides(), override));-- let hysteresisThresholds: RawOverrideConfig = withThresholdEntries({}, cleanThresholds);- if (overrideDisabled) hysteresisThresholds.disabled = true;- if (newDisableConnectivity) {- hysteresisThresholds.disableConnectivity = true;- } else {- if (defaultDisabled) hysteresisThresholds.disableConnectivity = false;- if (newSeverity) hysteresisThresholds.poweredOffSeverity = newSeverity;- }- if (override.backup) hysteresisThresholds.backup = override.backup;- if (override.snapshot) hysteresisThresholds.snapshot = override.snapshot;-- const nextRawConfig = { ...props.rawOverridesConfig() };- if (Object.keys(hysteresisThresholds).length > 0) {- nextRawConfig[resourceId] = hysteresisThresholds;- } else {- delete nextRawConfig[resourceId];- }-- props.setRawOverridesConfig(nextRawConfig);- props.setHasUnsavedChanges(true);-- if (props.removeAlerts && newDisableConnectivity) {- if (resource.type === 'guest') {- props.removeAlerts(- (alert) => alert.resourceId === resourceId && alert.type === 'powered-off',- );- } else if (resource.type === 'dockerContainer') {- props.removeAlerts(- (alert) =>- alert.resourceId === resourceId &&- (alert.type === 'docker-container-state' || alert.type === 'docker-container-health'),- );- }- }- };-return {handleSaveBulkEdit,removeOverride,saveEdit,- setOfflineState,toggleBackup,- toggleDisabled,- toggleNodeConnectivity,toggleSnapshot,} as const;}diff --git a/frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsTableState.ts b/frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsTableState.tsindex ec3b069551..035b1ef317 100644--- a/frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsTableState.ts+++ b/frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsTableState.ts@@ -39,6 +39,7 @@ import type {ThresholdsActiveTab,} from '@/features/alerts/thresholds/tableTypes';import { useCollapsedSections } from '@/components/Alerts/Thresholds/hooks/useCollapsedSections';+import { useThresholdsAvailabilityMutations } from './useThresholdsAvailabilityMutations';import { useThresholdsData } from './useThresholdsData';import { useThresholdsRecoveryDefaultsState } from './useThresholdsRecoveryDefaultsState';import { useThresholdsOverrideMutations } from './useThresholdsOverrideMutations';@@ -392,10 +393,7 @@ export function useThresholdsTableState(props: ThresholdsTableProps) {handleSaveBulkEdit: persistBulkEdit,removeOverride,saveEdit,- setOfflineState,toggleBackup,- toggleDisabled,- toggleNodeConnectivity,toggleSnapshot,} = useThresholdsOverrideMutations({props,@@ -418,6 +416,22 @@ export function useThresholdsTableState(props: ThresholdsTableProps) {updateSnapshotDefaults,});+ const { setOfflineState, toggleDisabled, toggleNodeConnectivity } =+ useThresholdsAvailabilityMutations({+ props,+ resources: {+ nodesWithOverrides,+ agentsWithOverrides,+ agentDisksWithOverrides,+ dockerHostsWithOverrides,+ guestsFlat,+ dockerContainersFlat,+ pbsServersWithOverrides,+ storageWithOverrides,+ },+ removeOverride,+ });+const handleBulkEdit = (ids: string[], columns: string[]) => {setBulkEditIds(ids);setBulkEditColumns(columns);diff --git a/frontend-modern/src/features/alerts/thresholds/thresholdsOverrideMutationModel.ts b/frontend-modern/src/features/alerts/thresholds/thresholdsOverrideMutationModel.tsnew file mode 100644index 0000000000..aa865a156a--- /dev/null+++ b/frontend-modern/src/features/alerts/thresholds/thresholdsOverrideMutationModel.ts@@ -0,0 +1,56 @@+import type { RawOverrideConfig } from '@/types/alerts';++import type { Override } from './types';++export const upsertOverride = (overrides: Override[], override: Override): Override[] => {+ const existingIndex = overrides.findIndex((entry) => entry.id === override.id);+ if (existingIndex >= 0) {+ const nextOverrides = [...overrides];+ nextOverrides[existingIndex] = override;+ return nextOverrides;+ }++ return [...overrides, override];+};++export const withThresholdEntries = (+ rawConfig: RawOverrideConfig,+ thresholds: Record<string, number | undefined>,+): RawOverrideConfig => {+ const next = { ...rawConfig };++ Object.entries(thresholds).forEach(([metric, value]) => {+ if (value !== undefined && value !== null) {+ next[metric] = {+ clear: Math.max(0, value - 5),+ trigger: value,+ };+ }+ });++ return next;+};++export const stripStateKeys = (+ thresholds: Record<string, number>,+): Record<string, number> => {+ const next = { ...thresholds };+ delete (next as Record<string, unknown>).disabled;+ delete (next as Record<string, unknown>).disableConnectivity;+ delete (next as Record<string, unknown>).poweredOffSeverity;+ return next;+};++export const removeOverrideState = (+ overrides: Override[],+ rawOverridesConfig: Record<string, RawOverrideConfig>,+ resourceId: string,+) => {+ const nextRawConfig = { ...rawOverridesConfig };+ delete nextRawConfig[resourceId];++ return {+ nextOverrides: overrides.filter((override) => override.id !== resourceId),+ nextRawConfig,+ };+};diff --git a/frontend-modern/src/pages/__tests__/Alerts.helpers.test.ts b/frontend-modern/src/pages/__tests__/Alerts.helpers.test.tsindex e2a96b090b..3a389ccb64 100644--- a/frontend-modern/src/pages/__tests__/Alerts.helpers.test.ts+++ b/frontend-modern/src/pages/__tests__/Alerts.helpers.test.ts@@ -57,7 +57,9 @@ import thresholdsGuestDataHookSource from '@/features/alerts/thresholds/hooks/usimport thresholdsInfrastructureDataHookSource from '@/features/alerts/thresholds/hooks/useThresholdsInfrastructureData.ts?raw';import thresholdsRecoveryDefaultsStateHookSource from '@/features/alerts/thresholds/hooks/useThresholdsRecoveryDefaultsState.ts?raw';import thresholdsTableStateHookSource from '@/features/alerts/thresholds/hooks/useThresholdsTableState.ts?raw';+import thresholdsAvailabilityMutationsHookSource from '@/features/alerts/thresholds/hooks/useThresholdsAvailabilityMutations.ts?raw';import thresholdsOverrideMutationsHookSource from '@/features/alerts/thresholds/hooks/useThresholdsOverrideMutations.ts?raw';+import thresholdsOverrideMutationModelSource from '@/features/alerts/thresholds/thresholdsOverrideMutationModel.ts?raw';import thresholdsResourceModelSource from '@/features/alerts/thresholds/thresholdsResourceModel.ts?raw';import thresholdsTableSectionPropsSource from '@/features/alerts/thresholds/thresholdsTableSectionProps.ts?raw';@@ -531,6 +533,7 @@ describe('tab path helpers', () => {expect(thresholdsTableStateHookSource).toContain('useThresholdsData(props, editingId, searchTerm)');expect(thresholdsTableStateHookSource).toContain('useThresholdsRecoveryDefaultsState(props)');expect(thresholdsTableStateHookSource).toContain('useThresholdsOverrideMutations');+ expect(thresholdsTableStateHookSource).toContain('useThresholdsAvailabilityMutations');expect(thresholdsTableStateHookSource).not.toContain('const saveEdit = (resourceId: string) => {');expect(thresholdsTableStateHookSource).not.toContain('const toggleNodeConnectivity = (resourceId: string, forceState?: boolean) => {',@@ -545,7 +548,29 @@ describe('tab path helpers', () => {expect(thresholdsOverrideMutationsHookSource).toContain('export function useThresholdsOverrideMutations',);- expect(thresholdsOverrideMutationsHookSource).toContain('matchesAlertIdentifier');+ expect(thresholdsOverrideMutationsHookSource).toContain('const saveEdit = (resourceId: string) => {');+ expect(thresholdsOverrideMutationsHookSource).toContain(+ 'const handleSaveBulkEdit = (thresholds: Record<string, number | undefined>) => {',+ );+ expect(thresholdsOverrideMutationsHookSource).not.toContain('matchesAlertIdentifier');+ expect(thresholdsOverrideMutationsHookSource).not.toContain(+ 'const toggleNodeConnectivity = (resourceId: string, forceState?: boolean) => {',+ );+ expect(thresholdsAvailabilityMutationsHookSource).toContain(+ 'export function useThresholdsAvailabilityMutations',+ );+ expect(thresholdsAvailabilityMutationsHookSource).toContain('matchesAlertIdentifier');+ expect(thresholdsAvailabilityMutationsHookSource).toContain(+ 'const toggleNodeConnectivity = (resourceId: string, forceState?: boolean) => {',+ );+ expect(thresholdsAvailabilityMutationsHookSource).toContain(+ 'const setOfflineState = (resourceId: string, state: OfflineState) => {',+ );+ expect(thresholdsOverrideMutationModelSource).toContain('export const upsertOverride =');+ expect(thresholdsOverrideMutationModelSource).toContain(+ 'export const withThresholdEntries =',+ );+ expect(thresholdsOverrideMutationModelSource).toContain('export const stripStateKeys =');});});diff --git a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.tsindex bbecc72b38..ad10ed1599 100644--- a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts+++ b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts@@ -379,7 +379,9 @@ import thresholdsGuestDataHookSource from '@/features/alerts/thresholds/hooks/usimport thresholdsInfrastructureDataHookSource from '@/features/alerts/thresholds/hooks/useThresholdsInfrastructureData.ts?raw';import thresholdsRecoveryDefaultsStateHookSource from '@/features/alerts/thresholds/hooks/useThresholdsRecoveryDefaultsState.ts?raw';import thresholdsTableStateHookSource from '@/features/alerts/thresholds/hooks/useThresholdsTableState.ts?raw';+import thresholdsAvailabilityMutationsHookSource from '@/features/alerts/thresholds/hooks/useThresholdsAvailabilityMutations.ts?raw';import thresholdsOverrideMutationsHookSource from '@/features/alerts/thresholds/hooks/useThresholdsOverrideMutations.ts?raw';+import thresholdsOverrideMutationModelSource from '@/features/alerts/thresholds/thresholdsOverrideMutationModel.ts?raw';import thresholdsResourceModelSource from '@/features/alerts/thresholds/thresholdsResourceModel.ts?raw';import thresholdsTableSectionPropsSource from '@/features/alerts/thresholds/thresholdsTableSectionProps.ts?raw';import alertIncidentPresentationSource from '@/utils/alertIncidentPresentation.ts?raw';@@ -3095,6 +3097,7 @@ describe('frontend resource type boundaries', () => {expect(thresholdsTableStateHookSource).toContain('useThresholdsData(props, editingId, searchTerm)');expect(thresholdsTableStateHookSource).toContain('useThresholdsRecoveryDefaultsState(props)');expect(thresholdsTableStateHookSource).toContain('useThresholdsOverrideMutations');+ expect(thresholdsTableStateHookSource).toContain('useThresholdsAvailabilityMutations');expect(thresholdsTableStateHookSource).not.toContain('const saveEdit = (resourceId: string) => {');expect(thresholdsTableStateHookSource).not.toContain('const toggleNodeConnectivity = (resourceId: string, forceState?: boolean) => {',@@ -3109,7 +3112,29 @@ describe('frontend resource type boundaries', () => {expect(thresholdsOverrideMutationsHookSource).toContain('export function useThresholdsOverrideMutations',);- expect(thresholdsOverrideMutationsHookSource).toContain('matchesAlertIdentifier');+ expect(thresholdsOverrideMutationsHookSource).toContain('const saveEdit = (resourceId: string) => {');+ expect(thresholdsOverrideMutationsHookSource).toContain(+ 'const handleSaveBulkEdit = (thresholds: Record<string, number | undefined>) => {',+ );+ expect(thresholdsOverrideMutationsHookSource).not.toContain('matchesAlertIdentifier');+ expect(thresholdsOverrideMutationsHookSource).not.toContain(+ 'const toggleNodeConnectivity = (resourceId: string, forceState?: boolean) => {',+ );+ expect(thresholdsAvailabilityMutationsHookSource).toContain(+ 'export function useThresholdsAvailabilityMutations',+ );+ expect(thresholdsAvailabilityMutationsHookSource).toContain('matchesAlertIdentifier');+ expect(thresholdsAvailabilityMutationsHookSource).toContain(+ 'const toggleNodeConnectivity = (resourceId: string, forceState?: boolean) => {',+ );+ expect(thresholdsAvailabilityMutationsHookSource).toContain(+ 'const setOfflineState = (resourceId: string, state: OfflineState) => {',+ );+ expect(thresholdsOverrideMutationModelSource).toContain('export const upsertOverride =');+ expect(thresholdsOverrideMutationModelSource).toContain(+ 'export const withThresholdEntries =',+ );+ expect(thresholdsOverrideMutationModelSource).toContain('export const stripStateKeys =');expect(alertsPageSource).not.toContain('getAlertConfigUnsavedChangesLabel');expect(alertsConfigurationSurfaceSource).toContain('getAlertConfigUnsavedChangesLabel');expect(alertsConfigurationSurfaceSource).toContain('getAlertConfigSaveChangesLabel');