Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/odd-hats-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

fix: move pagination reset out of useMemo into useEffect in RoomsTable
29 changes: 14 additions & 15 deletions apps/meteor/client/views/admin/rooms/RoomsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { useEndpoint } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import type { ReactElement, MutableRefObject } from 'react';
import { useRef, useState, useEffect, useMemo } from 'react';
import { useState, useEffect, useMemo } from 'react';
import { useTranslation } from 'react-i18next';

import RoomRow from './RoomRow';
Expand All @@ -33,22 +33,17 @@ const RoomsTable = ({ reload }: { reload: MutableRefObject<() => void> }): React

const [roomFilters, setRoomFilters] = useState<RoomFilters>({ searchText: '', types: [] });

const prevRoomFilterText = useRef<string>(roomFilters.searchText);

const { sortBy, sortDirection, setSort } = useSort<'name' | 't' | 'usersCount' | 'msgs' | 'default' | 'featured' | 'ts'>('name');
const { current, itemsPerPage, setItemsPerPage, setCurrent, ...paginationProps } = usePagination();
const searchText = useDebouncedValue(roomFilters.searchText, 500);

const query = useDebouncedValue(
useMemo(() => {
if (searchText !== prevRoomFilterText.current) {
setCurrent(0);
}
return {
useMemo(
() => ({
filter: searchText || '',
sort: `{ "${sortBy}": ${sortDirection === 'asc' ? 1 : -1} }`,
count: itemsPerPage,
offset: searchText === prevRoomFilterText.current ? current : 0,
offset: current,
types: (roomFilters.types.length ? [...roomFilters.types.map((roomType) => roomType.id)] : DEFAULT_TYPES) as unknown as (
| 'c'
| 'd'
Expand All @@ -57,11 +52,11 @@ const RoomsTable = ({ reload }: { reload: MutableRefObject<() => void> }): React
| 'discussions'
| 'teams'
)[],
};
}, [searchText, sortBy, sortDirection, itemsPerPage, current, roomFilters.types, setCurrent]),
}),
[searchText, sortBy, sortDirection, itemsPerPage, current, roomFilters.types],
),
500,
);

const getAdminRooms = useEndpoint('GET', '/v1/rooms.adminRooms');

const { data, refetch, isSuccess, isLoading, isError } = useQuery({
Expand All @@ -74,8 +69,8 @@ const RoomsTable = ({ reload }: { reload: MutableRefObject<() => void> }): React
}, [reload, refetch]);

useEffect(() => {
prevRoomFilterText.current = searchText;
}, [searchText]);
setCurrent(0);
}, [searchText, setCurrent]);

const headers = (
<>
Expand Down Expand Up @@ -144,7 +139,11 @@ const RoomsTable = ({ reload }: { reload: MutableRefObject<() => void> }): React
<>
<GenericTable>
<GenericTableHeader>{headers}</GenericTableHeader>
<GenericTableBody>{data.rooms?.map((room) => <RoomRow key={room._id} room={room} />)}</GenericTableBody>
<GenericTableBody>
{data.rooms?.map((room) => (
<RoomRow key={room._id} room={room} />
))}
</GenericTableBody>
</GenericTable>
<Pagination
divider
Expand Down