fix(telefoni): preserve SSR call rows when client refresh fails
This commit is contained in:
parent
ef8e68fc16
commit
94f6735ed5
@ -850,6 +850,27 @@ function hasExistingCallRows(tbody) {
|
|||||||
return Boolean(tbody && tbody.querySelector('tr[data-call-id]'));
|
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() {
|
function hasActiveCallFilters() {
|
||||||
const userId = document.getElementById('filterUser')?.value;
|
const userId = document.getElementById('filterUser')?.value;
|
||||||
const from = document.getElementById('filterFrom')?.value;
|
const from = document.getElementById('filterFrom')?.value;
|
||||||
@ -862,6 +883,7 @@ async function loadCalls(options = {}) {
|
|||||||
const preserveOnEmpty = Boolean(options.preserveOnEmpty);
|
const preserveOnEmpty = Boolean(options.preserveOnEmpty);
|
||||||
const skipLoadingState = Boolean(options.skipLoadingState);
|
const skipLoadingState = Boolean(options.skipLoadingState);
|
||||||
const tbody = document.getElementById('telefoniRows');
|
const tbody = document.getElementById('telefoniRows');
|
||||||
|
cacheInitialSsrRows(tbody);
|
||||||
const hadRowsBeforeLoad = hasExistingCallRows(tbody);
|
const hadRowsBeforeLoad = hasExistingCallRows(tbody);
|
||||||
const noActiveFilters = !hasActiveCallFilters();
|
const noActiveFilters = !hasActiveCallFilters();
|
||||||
|
|
||||||
@ -888,6 +910,10 @@ async function loadCalls(options = {}) {
|
|||||||
console.warn('Telefoni: bevarer SSR-rækker efter tom/fejlende auto-refresh');
|
console.warn('Telefoni: bevarer SSR-rækker efter tom/fejlende auto-refresh');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (preserveOnEmpty && noActiveFilters && restoreInitialSsrRows(tbody)) {
|
||||||
|
console.warn('Telefoni: gendannede SSR-rækker efter API-fejl under auto-refresh');
|
||||||
|
return;
|
||||||
|
}
|
||||||
tbody.innerHTML = `<tr><td colspan="7" class="text-danger small">Fejl: ${escapeHtml(t)}</td></tr>`;
|
tbody.innerHTML = `<tr><td colspan="7" class="text-danger small">Fejl: ${escapeHtml(t)}</td></tr>`;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -899,6 +925,10 @@ async function loadCalls(options = {}) {
|
|||||||
console.warn('Telefoni: API returnerede 0 rækker, bevarer eksisterende SSR-visning');
|
console.warn('Telefoni: API returnerede 0 rækker, bevarer eksisterende SSR-visning');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (preserveOnEmpty && noActiveFilters && restoreInitialSsrRows(tbody)) {
|
||||||
|
console.warn('Telefoni: gendannede SSR-rækker efter tom API-respons');
|
||||||
|
return;
|
||||||
|
}
|
||||||
tbody.innerHTML = '<tr><td colspan="7" class="text-muted small">Ingen opkald fundet</td></tr>';
|
tbody.innerHTML = '<tr><td colspan="7" class="text-muted small">Ingen opkald fundet</td></tr>';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -972,6 +1002,10 @@ async function loadCalls(options = {}) {
|
|||||||
console.warn('Telefoni: bevarer SSR-rækker efter exception i auto-refresh');
|
console.warn('Telefoni: bevarer SSR-rækker efter exception i auto-refresh');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (preserveOnEmpty && noActiveFilters && restoreInitialSsrRows(tbody)) {
|
||||||
|
console.warn('Telefoni: gendannede SSR-rækker efter exception i auto-refresh');
|
||||||
|
return;
|
||||||
|
}
|
||||||
tbody.innerHTML = '<tr><td colspan="7" class="text-danger small">Kunne ikke hente opkald</td></tr>';
|
tbody.innerHTML = '<tr><td colspan="7" class="text-danger small">Kunne ikke hente opkald</td></tr>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1030,6 +1064,7 @@ async function unlinkCase(callId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', async () => {
|
document.addEventListener('DOMContentLoaded', async () => {
|
||||||
|
cacheInitialSsrRows(document.getElementById('telefoniRows'));
|
||||||
initLinkContactModalEvents();
|
initLinkContactModalEvents();
|
||||||
initLinkSagModalEvents();
|
initLinkSagModalEvents();
|
||||||
const userFilter = document.getElementById('filterUser');
|
const userFilter = document.getElementById('filterUser');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user