From b136084e8c557143bdacd7888a8de9efbc3812ee Mon Sep 17 00:00:00 2001
From: RachelElysia <71795832+RachelElysia@users.noreply.github.com>
Date: Wed, 6 Aug 2025 15:33:27 -0400
Subject: [PATCH] Fleet UI: Fix clientside url source of truth bug (#31664)
---
.../Software/SelfService/SelfService.tsx | 50 ++++++-------------
.../Software/SelfService/debug.test3250248476 | 0
2 files changed, 16 insertions(+), 34 deletions(-)
create mode 100644 frontend/pages/hosts/details/cards/Software/SelfService/debug.test3250248476
diff --git a/frontend/pages/hosts/details/cards/Software/SelfService/SelfService.tsx b/frontend/pages/hosts/details/cards/Software/SelfService/SelfService.tsx
index bd5658bef5..4480b534f0 100644
--- a/frontend/pages/hosts/details/cards/Software/SelfService/SelfService.tsx
+++ b/frontend/pages/hosts/details/cards/Software/SelfService/SelfService.tsx
@@ -211,12 +211,12 @@ const SoftwareSelfService = ({
{
scope: "device_software",
id: deviceToken,
- page: queryParams.page,
+ page: 0, // Pagination is clientside
query: "", // Search is now client-side to reduce API calls
...DEFAULT_SELF_SERVICE_QUERY_PARAMS,
},
];
- }, [deviceToken, queryParams.page]);
+ }, [deviceToken]);
// Fetch self-service software (regular API call)
const {
@@ -549,25 +549,18 @@ const SoftwareSelfService = ({
onInstallOrUninstall();
};
- const onNextPage = useCallback(() => {
- router.push(
- getPathWithQueryParams(pathname, {
- query: queryParams.query,
- category_id: queryParams.category_id,
- page: queryParams.page + 1,
- })
- );
- }, [pathname, queryParams, router]);
-
- const onPrevPage = useCallback(() => {
- router.push(
- getPathWithQueryParams(pathname, {
- query: queryParams.query,
- category_id: queryParams.category_id,
- page: queryParams.page - 1,
- })
- );
- }, [pathname, queryParams, router]);
+ const onClientSidePaginationChange = useCallback(
+ (page: number) => {
+ router.push(
+ getPathWithQueryParams(pathname, {
+ query: queryParams.query,
+ category_id: queryParams.category_id,
+ page,
+ })
+ );
+ },
+ [pathname, queryParams.query, queryParams.category_id, router]
+ );
// TODO: handle empty state better, this is just a placeholder for now
// TODO: what should happen if query params are invalid (e.g., page is negative or exceeds the
@@ -703,13 +696,14 @@ const SoftwareSelfService = ({
defaultSortDirection={
DEFAULT_SELF_SERVICE_QUERY_PARAMS.order_direction
}
- pageIndex={0}
+ pageIndex={queryParams.page ?? 0} // Client-side pagination with URL source of truth
disableNextPage={selfServiceData?.meta.has_next_results === false}
pageSize={DEFAULT_CLIENT_SIDE_PAGINATION}
searchQuery={queryParams.query} // Search is now client-side to reduce API calls
searchQueryColumn="name"
isClientSideFilter
isClientSidePagination
+ onClientSidePaginationChange={onClientSidePaginationChange}
emptyComponent={() => {
return isEmptySearch ? (
-
-
>
);
};
diff --git a/frontend/pages/hosts/details/cards/Software/SelfService/debug.test3250248476 b/frontend/pages/hosts/details/cards/Software/SelfService/debug.test3250248476
new file mode 100644
index 0000000000..e69de29bb2