mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-09-22 11:13:26 +00:00
fix: storage alert disabling now properly persists and displays
- Use rawOverridesConfig() for saving instead of rebuilding overrides - Fix hasOverride flag to consider disabled state for storage/guests - Toggle now reads current state from resource object - Properly show "Custom" badge when alerts are disabled
This commit is contained in:
@@ -181,6 +181,9 @@ export function ThresholdsTable(props: ThresholdsTableProps) {
|
||||
override.thresholds[k] !== (props.guestDefaults as any)[k];
|
||||
});
|
||||
|
||||
// A guest has an override if it has custom thresholds OR is disabled
|
||||
const hasOverride = hasCustomThresholds || override?.disabled || false;
|
||||
|
||||
return {
|
||||
id: guestId,
|
||||
name: guest.name,
|
||||
@@ -190,7 +193,7 @@ export function ThresholdsTable(props: ThresholdsTableProps) {
|
||||
node: guest.node,
|
||||
instance: guest.instance,
|
||||
status: guest.status,
|
||||
hasOverride: hasCustomThresholds || false,
|
||||
hasOverride: hasOverride,
|
||||
disabled: override?.disabled || false,
|
||||
thresholds: override?.thresholds || {},
|
||||
defaults: props.guestDefaults
|
||||
@@ -290,6 +293,9 @@ export function ThresholdsTable(props: ThresholdsTableProps) {
|
||||
const hasCustomThresholds = override?.thresholds?.usage !== undefined &&
|
||||
override.thresholds.usage !== props.storageDefault();
|
||||
|
||||
// A storage device has an override if it has custom thresholds OR is disabled
|
||||
const hasOverride = hasCustomThresholds || override?.disabled || false;
|
||||
|
||||
return {
|
||||
id: storage.id,
|
||||
name: storage.name,
|
||||
@@ -298,7 +304,7 @@ export function ThresholdsTable(props: ThresholdsTableProps) {
|
||||
node: storage.node,
|
||||
instance: storage.instance,
|
||||
status: storage.status,
|
||||
hasOverride: hasCustomThresholds || false,
|
||||
hasOverride: hasOverride,
|
||||
disabled: override?.disabled || false,
|
||||
thresholds: override?.thresholds || {},
|
||||
defaults: { usage: props.storageDefault() }
|
||||
@@ -429,25 +435,16 @@ export function ThresholdsTable(props: ThresholdsTableProps) {
|
||||
// Get existing override if it exists
|
||||
const existingOverride = props.overrides().find(o => o.id === resourceId);
|
||||
|
||||
console.log('Toggle disabled for:', resourceId);
|
||||
console.log('Existing override:', existingOverride);
|
||||
console.log('Existing thresholds:', existingOverride?.thresholds);
|
||||
console.log('Threshold keys:', existingOverride ? Object.keys(existingOverride.thresholds || {}) : 'no override');
|
||||
|
||||
// Determine the current disabled state from the override (or false if no override)
|
||||
const currentDisabledState = existingOverride?.disabled || false;
|
||||
// Determine the current disabled state - check the resource's current state, not the override
|
||||
const currentDisabledState = resource.disabled;
|
||||
const newDisabledState = !currentDisabledState;
|
||||
|
||||
console.log('Current disabled state:', currentDisabledState);
|
||||
console.log('New disabled state:', newDisabledState);
|
||||
|
||||
// Clean the thresholds to exclude 'disabled' if it got in there
|
||||
const cleanThresholds: any = { ...(existingOverride?.thresholds || {}) };
|
||||
delete cleanThresholds.disabled;
|
||||
|
||||
// If enabling (disabled = false) and no custom thresholds exist, remove the override entirely
|
||||
if (!newDisabledState && (!existingOverride || Object.keys(cleanThresholds).length === 0)) {
|
||||
console.log('REMOVING OVERRIDE - enabling with no custom thresholds');
|
||||
// Remove the override completely
|
||||
props.setOverrides(props.overrides().filter(o => o.id !== resourceId));
|
||||
|
||||
@@ -456,7 +453,6 @@ export function ThresholdsTable(props: ThresholdsTableProps) {
|
||||
delete newRawConfig[resourceId];
|
||||
props.setRawOverridesConfig(newRawConfig);
|
||||
} else {
|
||||
console.log('UPDATING OVERRIDE - either disabling or has custom thresholds');
|
||||
|
||||
const override: Override = {
|
||||
id: resourceId,
|
||||
@@ -505,19 +501,15 @@ export function ThresholdsTable(props: ThresholdsTableProps) {
|
||||
};
|
||||
|
||||
const toggleNodeConnectivity = (nodeId: string) => {
|
||||
console.log('toggleNodeConnectivity called for:', nodeId);
|
||||
const node = nodesWithOverrides().find(r => r.id === nodeId);
|
||||
console.log('Found node:', node);
|
||||
if (!node || node.type !== 'node') return;
|
||||
|
||||
// Get existing override if it exists
|
||||
const existingOverride = props.overrides().find(o => o.id === nodeId);
|
||||
console.log('Existing override:', existingOverride);
|
||||
|
||||
// Determine the current state
|
||||
const currentDisableConnectivity = existingOverride?.disableConnectivity || false;
|
||||
const newDisableConnectivity = !currentDisableConnectivity;
|
||||
console.log('Current state:', currentDisableConnectivity, 'New state:', newDisableConnectivity);
|
||||
|
||||
// Clean the thresholds to exclude any unwanted fields
|
||||
const cleanThresholds: any = { ...(existingOverride?.thresholds || {}) };
|
||||
|
||||
@@ -468,23 +468,8 @@ export function Alerts() {
|
||||
suppressionWindow: 5,
|
||||
hysteresisMargin: 5.0,
|
||||
timeThreshold: timeThreshold() || 0,
|
||||
overrides: overrides().reduce((acc, o) => {
|
||||
// Convert thresholds to hysteresis format
|
||||
const hysteresisThresholds: any = {};
|
||||
Object.entries(o.thresholds).forEach(([metric, value]) => {
|
||||
hysteresisThresholds[metric] = createHysteresisThreshold(value as number);
|
||||
});
|
||||
// Include disabled field if present (for guests and storage)
|
||||
if (o.disabled) {
|
||||
hysteresisThresholds.disabled = true;
|
||||
}
|
||||
// Include disableConnectivity field if present (for nodes)
|
||||
if (o.disableConnectivity) {
|
||||
hysteresisThresholds.disableConnectivity = true;
|
||||
}
|
||||
acc[o.id] = hysteresisThresholds;
|
||||
return acc;
|
||||
}, {} as Record<string, any>),
|
||||
// Use rawOverridesConfig which is already properly formatted with disabled flags
|
||||
overrides: rawOverridesConfig(),
|
||||
schedule: scheduleRef.getScheduleConfig ? scheduleRef.getScheduleConfig() : {
|
||||
quietHours: {
|
||||
enabled: false,
|
||||
|
||||
Reference in New Issue
Block a user