Skip to content

Commit 1ad25dd

Browse files
fix: [M3-10266] - Add automatic redirect for empty paginated Access Keys pages (linode#12598)
* fix: [M3-10266] - OBJ Pagination Redirects * Added changeset: Add automatic redirect for empty paginated Access Keys pages * Add todo comment --------- Co-authored-by: Jaalah Ramos <[email protected]>
1 parent 4d61cd6 commit 1ad25dd

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Fixed
3+
---
4+
5+
Add automatic redirect for empty paginated Access Keys pages ([#12598](https://github.com/linode/manager/pull/12598))

packages/manager/src/features/ObjectStorage/AccessKeyLanding/AccessKeyLanding.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from '@linode/api-v4/lib/object-storage';
66
import { useAccountSettings } from '@linode/queries';
77
import { useErrors, useOpenClose } from '@linode/utilities';
8+
import { useNavigate } from '@tanstack/react-router';
89
import * as React from 'react';
910

1011
import { DocumentTitleSegment } from 'src/components/DocumentTitle';
@@ -53,6 +54,7 @@ export const AccessKeyLanding = (props: Props) => {
5354
openAccessDrawer,
5455
} = props;
5556

57+
const navigate = useNavigate();
5658
const pagination = usePaginationV2({
5759
currentRoute: '/object-storage/access-keys',
5860
initialPage: 1,
@@ -88,6 +90,25 @@ export const AccessKeyLanding = (props: Props) => {
8890

8991
const { isObjMultiClusterEnabled } = useIsObjMultiClusterEnabled();
9092

93+
// Redirect to base access keys route if current page has no data
94+
// TODO: Remove this implementation and replace `usePagination` with `usePaginate` hook. See [M3-10442]
95+
React.useEffect(() => {
96+
const currentPage = Number(pagination.page);
97+
98+
// Only redirect if we have data, no results, and we're not on page 1
99+
if (
100+
!isLoading &&
101+
data &&
102+
(data.results === 0 || data.data.length === 0) &&
103+
currentPage > 1
104+
) {
105+
navigate({
106+
to: '/object-storage/access-keys',
107+
search: { page: undefined, pageSize: undefined },
108+
});
109+
}
110+
}, [data, isLoading, pagination.page, navigate]);
111+
91112
const handleCreateKey = (
92113
values: CreateObjectStorageKeyPayload,
93114
{

0 commit comments

Comments
 (0)