Skip to content

Commit

Permalink
FE: Reset page parameter in URL of topic messages page when changing …
Browse files Browse the repository at this point in the history
…mode (#550)
  • Loading branch information
hadisfr committed Sep 17, 2024
1 parent 50aa173 commit c1d4f92
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion frontend/src/lib/hooks/api/topicMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ export const useTopicMessages = ({
clusterName,
topicName,
}: UseTopicMessagesProps) => {
const [searchParams] = useSearchParams();
const [searchParams, setSearchParams] = useSearchParams();
const [messages, setMessages] = React.useState<TopicMessage[]>([]);
const [phase, setPhase] = React.useState<string>();
const [consumptionStats, setConsumptionStats] =
React.useState<TopicMessageConsuming>();
const [isFetching, setIsFetching] = React.useState(false);
const abortController = useRef(new AbortController());
const prevReqUrl = useRef<string>('');
const currentPage = useRef(1);

// get initial properties
Expand Down Expand Up @@ -104,6 +105,16 @@ export const useTopicMessages = ({
const { nextCursor, setNextCursor } = useMessageFiltersStore.getState();
const { prevCursor, setPrevCursor } = useMessageFiltersStore.getState();

const searchParamsWithoutPage = new URLSearchParams(searchParams);
searchParamsWithoutPage.delete(MessagesFilterKeys.page);
if (prevReqUrl.current !== searchParamsWithoutPage.toString()) {
searchParams.delete(MessagesFilterKeys.page);
setSearchParams(searchParams);
setPrevCursor(undefined);
setNextCursor(undefined);
}
prevReqUrl.current = searchParamsWithoutPage.toString();

const searchParamPage = getPageValue(searchParams);
if (currentPage.current < searchParamPage && nextCursor) {
requestParams.set(MessagesFilterKeys.cursor, nextCursor);
Expand Down

0 comments on commit c1d4f92

Please sign in to comment.