From 43da2757538f2ea78674017ebdbebdc1bc7611a9 Mon Sep 17 00:00:00 2001 From: "courtmanr@gmail.com" Date: Thu, 8 May 2025 11:23:03 +0100 Subject: [PATCH] Fix(state.js): Ensure all default threshold properties are preserved during initialization --- src/public/js/state.js | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/public/js/state.js b/src/public/js/state.js index f5125a392..267b5dda7 100644 --- a/src/public/js/state.js +++ b/src/public/js/state.js @@ -38,16 +38,27 @@ PulseApp.state = (() => { activeLoggingThresholds: null }; - for (const type in internalState.thresholdState) { - if (savedThresholdState.hasOwnProperty(type)) { - if (internalState.thresholdState[type].hasOwnProperty('operator')) { - internalState.thresholdState[type].operator = savedThresholdState[type]?.operator || '>='; - internalState.thresholdState[type].input = savedThresholdState[type]?.input || ''; - } else { - internalState.thresholdState[type].value = savedThresholdState[type]?.value || 0; - } + // Initialize thresholdState by merging saved state with defaults + Object.keys(internalState.thresholdState).forEach(type => { + const savedTypeState = savedThresholdState[type] || {}; + if (internalState.thresholdState[type].hasOwnProperty('operator')) { // Assuming this structure means it's the advanced threshold type + internalState.thresholdState[type] = { + operator: savedTypeState.operator || '>=', + input: savedTypeState.input || '', + // Preserve any other default properties if they exist + ...internalState.thresholdState[type], + ...savedTypeState // This ensures saved values overwrite defaults but keeps other default props + }; + } else { // Simple value threshold + internalState.thresholdState[type] = { + value: savedTypeState.value || 0, + // Preserve any other default properties + ...internalState.thresholdState[type], + ...savedTypeState + }; } - } + }); + function saveFilterState() { const stateToSave = { @@ -125,4 +136,4 @@ PulseApp.state = (() => { delete internalState.dashboardHistory[guestId]; } }; -})(); \ No newline at end of file +})();