mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2025-07-01 11:13:50 +02:00
fix continuous scroll next page logic error
This commit is contained in:
parent
f471214ef7
commit
ad108b285f
@ -850,7 +850,7 @@ func (ccms *CCMetricStore) LoadNodeListData(
|
||||
if len(nodes) > page.ItemsPerPage {
|
||||
start := (page.Page - 1) * page.ItemsPerPage
|
||||
end := start + page.ItemsPerPage
|
||||
if end > len(nodes) {
|
||||
if end >= len(nodes) {
|
||||
end = len(nodes)
|
||||
hasNextPage = false
|
||||
} else {
|
||||
|
@ -539,7 +539,7 @@ func (pdb *PrometheusDataRepository) LoadNodeListData(
|
||||
if len(nodes) > page.ItemsPerPage {
|
||||
start := (page.Page - 1) * page.ItemsPerPage
|
||||
end := start + page.ItemsPerPage
|
||||
if end > len(nodes) {
|
||||
if end >= len(nodes) {
|
||||
end = len(nodes)
|
||||
hasNextPage = false
|
||||
} else {
|
||||
|
@ -86,11 +86,10 @@
|
||||
let page = $state(1);
|
||||
let itemsPerPage = $state(usePaging ? (ccconfig?.plot_list_nodesPerPage || 10) : 10);
|
||||
let headerPaddingTop = $state(0);
|
||||
let matchedNodes = $state(0);
|
||||
|
||||
/* Derived */
|
||||
const paging = $derived({ itemsPerPage, page });
|
||||
const matchedNodes = $derived($nodesQuery?.data?.nodeMetricsList?.totalNodes || 0);
|
||||
|
||||
const nodesQuery = $derived(queryStore({
|
||||
client: client,
|
||||
query: nodeListQuery,
|
||||
@ -119,7 +118,7 @@
|
||||
} = document.documentElement;
|
||||
|
||||
// Add 100 px offset to trigger load earlier
|
||||
if (scrollTop + clientHeight >= scrollHeight - 100 && $nodesQuery?.data != null && $nodesQuery.data?.nodeMetricsList.hasNextPage) {
|
||||
if (scrollTop + clientHeight >= scrollHeight - 100 && $nodesQuery?.data?.nodeMetricsList?.hasNextPage) {
|
||||
page += 1
|
||||
};
|
||||
});
|
||||
@ -127,7 +126,7 @@
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
handleNodes($nodesQuery?.data?.nodeMetricsList?.items);
|
||||
handleNodes($nodesQuery?.data?.nodeMetricsList);
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
@ -145,14 +144,15 @@
|
||||
/* Functions */
|
||||
function handleNodes(data) {
|
||||
if (data) {
|
||||
matchedNodes = data.totalNodes;
|
||||
if (usePaging || nodes.length == 0) {
|
||||
nodes = [...data].sort((a, b) => a.host.localeCompare(b.host));
|
||||
nodes = [...data.items].sort((a, b) => a.host.localeCompare(b.host));
|
||||
} else {
|
||||
// Workaround to ignore secondary store triggers (reason tbd)
|
||||
const oldNodes = $state.snapshot(nodes)
|
||||
const newNodes = [...data].map((d) => d.host)
|
||||
const newNodes = [...data.items].map((d) => d.host)
|
||||
if (!oldNodes.some((n) => newNodes.includes(n.host))) {
|
||||
nodes = nodes.concat([...data].sort((a, b) => a.host.localeCompare(b.host)))
|
||||
nodes = nodes.concat([...data.items].sort((a, b) => a.host.localeCompare(b.host)))
|
||||
};
|
||||
};
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user