Skip to content

Commit

Permalink
fix: Preserve Page number in URL at AuditLogs page (#4913)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagoapolo authored Dec 11, 2024
1 parent 3434eb7 commit 6cd6cb8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
14 changes: 12 additions & 2 deletions frontend/web/components/AuditLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type AuditLogType = {
projectId: string
pageSize: number
onSearchChange?: (search: string) => void
onPageChange?: (page: number) => void
searchPanel?: ReactNode
onErrorChange?: (err: boolean) => void
match: {
Expand All @@ -33,11 +34,15 @@ type AuditLogType = {

const widths = [210, 310, 150]
const AuditLog: FC<AuditLogType> = (props) => {
const [page, setPage] = useState(1)
const [page, setPage] = useState(Utils.fromParam().page ?? 1)
const { search, searchInput, setSearchInput } = useSearchThrottle(
Utils.fromParam().search,
() => {
setPage(1)
if (searchInput !== search) {
return setPage(1)
}

setPage(Utils.fromParam().page)
},
)
const { data: subscriptionMeta } = useGetSubscriptionMetadataQuery({
Expand All @@ -58,6 +63,11 @@ const AuditLog: FC<AuditLogType> = (props) => {
//eslint-disable-next-line
}, [search])

useEffect(() => {
props.onPageChange?.(page)
//eslint-disable-next-line
}, [page])

const hasHadResults = useRef(false)

const {
Expand Down
11 changes: 11 additions & 0 deletions frontend/web/components/pages/AuditLogPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const AuditLogPage: FC<AuditLogType> = (props) => {
props.router.history.replace(
`${document.location.pathname}?${Utils.toParam({
env: environment,
page: currentParams.page,
search: currentParams.search,
})}`,
)
Expand All @@ -52,10 +53,20 @@ const AuditLogPage: FC<AuditLogType> = (props) => {
props.router.history.replace(
`${document.location.pathname}?${Utils.toParam({
env: environment,
page: Utils.fromParam().page,
search,
})}`,
)
}}
onPageChange={(page: number) => {
props.router.history.replace(
`${document.location.pathname}?${Utils.toParam({
env: environment,
page,
search: Utils.fromParam().search,
})}`,
)
}}
pageSize={10}
environmentId={environment}
projectId={projectId}
Expand Down

0 comments on commit 6cd6cb8

Please sign in to comment.