From 94f6735ed5c443965fba17dc7abe04a812640edb Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 18 May 2026 07:00:52 +0200 Subject: [PATCH] fix(telefoni): preserve SSR call rows when client refresh fails --- app/modules/telefoni/templates/log.html | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/app/modules/telefoni/templates/log.html b/app/modules/telefoni/templates/log.html index 24edc0b..1560638 100644 --- a/app/modules/telefoni/templates/log.html +++ b/app/modules/telefoni/templates/log.html @@ -850,6 +850,27 @@ function hasExistingCallRows(tbody) { return Boolean(tbody && tbody.querySelector('tr[data-call-id]')); } +function cacheInitialSsrRows(tbody) { + if (!tbody) return; + if (tbody.dataset.initialRowsCached === '1') return; + tbody.dataset.initialRowsHtml = tbody.innerHTML; + tbody.dataset.initialRowsCached = '1'; +} + +function restoreInitialSsrRows(tbody) { + if (!tbody) return false; + const initialHtml = String(tbody.dataset.initialRowsHtml || '').trim(); + if (!initialHtml) return false; + if (!initialHtml.includes('data-call-id')) return false; + + tbody.innerHTML = initialHtml; + tbody.classList.remove('d-none'); + tbody.style.display = ''; + tbody.style.visibility = ''; + tbody.style.opacity = ''; + return true; +} + function hasActiveCallFilters() { const userId = document.getElementById('filterUser')?.value; const from = document.getElementById('filterFrom')?.value; @@ -862,6 +883,7 @@ async function loadCalls(options = {}) { const preserveOnEmpty = Boolean(options.preserveOnEmpty); const skipLoadingState = Boolean(options.skipLoadingState); const tbody = document.getElementById('telefoniRows'); + cacheInitialSsrRows(tbody); const hadRowsBeforeLoad = hasExistingCallRows(tbody); const noActiveFilters = !hasActiveCallFilters(); @@ -888,6 +910,10 @@ async function loadCalls(options = {}) { console.warn('Telefoni: bevarer SSR-rækker efter tom/fejlende auto-refresh'); return; } + if (preserveOnEmpty && noActiveFilters && restoreInitialSsrRows(tbody)) { + console.warn('Telefoni: gendannede SSR-rækker efter API-fejl under auto-refresh'); + return; + } tbody.innerHTML = `Fejl: ${escapeHtml(t)}`; return; } @@ -899,6 +925,10 @@ async function loadCalls(options = {}) { console.warn('Telefoni: API returnerede 0 rækker, bevarer eksisterende SSR-visning'); return; } + if (preserveOnEmpty && noActiveFilters && restoreInitialSsrRows(tbody)) { + console.warn('Telefoni: gendannede SSR-rækker efter tom API-respons'); + return; + } tbody.innerHTML = 'Ingen opkald fundet'; return; } @@ -972,6 +1002,10 @@ async function loadCalls(options = {}) { console.warn('Telefoni: bevarer SSR-rækker efter exception i auto-refresh'); return; } + if (preserveOnEmpty && noActiveFilters && restoreInitialSsrRows(tbody)) { + console.warn('Telefoni: gendannede SSR-rækker efter exception i auto-refresh'); + return; + } tbody.innerHTML = 'Kunne ikke hente opkald'; } } @@ -1030,6 +1064,7 @@ async function unlinkCase(callId) { } document.addEventListener('DOMContentLoaded', async () => { + cacheInitialSsrRows(document.getElementById('telefoniRows')); initLinkContactModalEvents(); initLinkSagModalEvents(); const userFilter = document.getElementById('filterUser');