fix: fix job list render for continuous mode on filter or sort changes

This commit is contained in:
Christoph Kluge 2024-12-02 12:49:43 +01:00
parent 93377f53fc
commit 76d0fc979b

View File

@ -30,6 +30,10 @@
initialized = getContext("initialized"), initialized = getContext("initialized"),
globalMetrics = getContext("globalMetrics"); globalMetrics = getContext("globalMetrics");
const equalsCheck = (a, b) => {
return JSON.stringify(a) === JSON.stringify(b);
}
export let sorting = { field: "startTime", type: "col", order: "DESC" }; export let sorting = { field: "startTime", type: "col", order: "DESC" };
export let matchedJobs = 0; export let matchedJobs = 0;
export let metrics = ccconfig.plot_list_selectedMetrics; export let metrics = ccconfig.plot_list_selectedMetrics;
@ -40,6 +44,8 @@
let page = 1; let page = 1;
let paging = { itemsPerPage, page }; let paging = { itemsPerPage, page };
let filter = []; let filter = [];
let lastFilter = [];
let lastSorting = null;
let triggerMetricRefresh = false; let triggerMetricRefresh = false;
function getUnit(m) { function getUnit(m) {
@ -105,12 +111,33 @@
variables: { paging, sorting, filter }, variables: { paging, sorting, filter },
}); });
let jobs = [] $: if (!usePaging && sorting) {
// console.log('Reset Paging ...')
paging = { itemsPerPage: 10, page: 1 }
};
let jobs = [];
$: if ($initialized && $jobsStore.data) { $: if ($initialized && $jobsStore.data) {
if (usePaging) { if (usePaging) {
jobs = [...$jobsStore.data.jobs.items] jobs = [...$jobsStore.data.jobs.items]
} else { // Prevents jump to table head: Extends existing list instead of rendering new list } else { // Prevents jump to table head in continiuous mode, only if no change in sort or filter
jobs = jobs.concat([...$jobsStore.data.jobs.items]) if (equalsCheck(filter, lastFilter) && equalsCheck(sorting, lastSorting)) {
// console.log('Both Equal: Continuous Addition ... Set None')
jobs = jobs.concat([...$jobsStore.data.jobs.items])
} else if (equalsCheck(filter, lastFilter)) {
// console.log('Filter Equal: Continuous Reset ... Set lastSorting')
lastSorting = { ...sorting }
jobs = [...$jobsStore.data.jobs.items]
} else if (equalsCheck(sorting, lastSorting)) {
// console.log('Sorting Equal: Continuous Reset ... Set lastFilter')
lastFilter = [ ...filter ]
jobs = [...$jobsStore.data.jobs.items]
} else {
// console.log('None Equal: Continuous Reset ... Set lastBoth')
lastSorting = { ...sorting }
lastFilter = [ ...filter ]
jobs = [...$jobsStore.data.jobs.items]
}
} }
} }