avoiding triple reload in last job list

This commit is contained in:
2026-08-03 21:34:06 +00:00
parent 9b080bc860
commit bfc6128353
10 changed files with 77 additions and 11 deletions
+43 -6
View File
@@ -142,6 +142,8 @@
const isAssetTable = table.id === 'asset-table';
const usesServerFilters = table.dataset.serverFilters === '1';
let serverFilterTimer = null;
let serverFilterController = null;
let serverFilterRequestId = 0;
// Normal tables get stable synthetic keys. The asset table already has
// real data-field keys on its movable columns; selection and action
@@ -316,7 +318,7 @@
if (!usesServerFilters) return;
if (serverFilterTimer) window.clearTimeout(serverFilterTimer);
const navigate = () => {
const navigate = async () => {
const target = new URL(
table.dataset.serverFilterUrl || window.location.pathname,
window.location.origin
@@ -331,13 +333,48 @@
if (value) target.searchParams.set(`job_filter_${definition.serverName}`, value);
});
const requestId = ++serverFilterRequestId;
serverFilterController?.abort();
serverFilterController = new AbortController();
table.classList.add('server-filter-loading');
table.setAttribute('aria-busy', 'true');
try {
window.sessionStorage.setItem(
'assetmanager:software-jobs:last-server-filter',
document.activeElement?.name || ''
const response = await fetch(target.toString(), {
cache: 'no-store',
headers: {'X-Requested-With': 'AssetManagerTableFilter'},
signal: serverFilterController.signal,
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const html = await response.text();
if (requestId !== serverFilterRequestId) return;
const documentCopy = new DOMParser().parseFromString(html, 'text/html');
const replacement = documentCopy.querySelector(
`table[data-storage-key="${CSS.escape(table.dataset.storageKey || '')}"]`
);
} catch (_) {}
window.location.assign(target.toString());
const replacementBody = replacement?.tBodies?.[0];
if (!replacement || !replacementBody) throw new Error('Filtered table not found');
tbody.replaceChildren(...[...replacementBody.rows].map(row => row.cloneNode(true)));
table.dataset.serverFilterTotal = replacement.dataset.serverFilterTotal || String(tbody.rows.length);
window.history.replaceState({}, '', target.toString());
window.AssetManagerTime?.scan(tbody);
applyFilters();
window.dispatchEvent(new CustomEvent('asset-table-content-reloaded', {
detail: {table}
}));
} catch (error) {
if (error?.name !== 'AbortError') {
// Fall back to a normal navigation only when the partial reload fails.
window.location.assign(target.toString());
}
} finally {
if (requestId === serverFilterRequestId) {
table.classList.remove('server-filter-loading');
table.removeAttribute('aria-busy');
}
}
};
if (immediate) navigate();