💄(frontend) fix flickering on datagrid sorting member

The datagrid was flickering when sorting the member list.
This was due to the fact that the list was getting
empty and then filled again with the sorted list
causing the flickering.
This commit is contained in:
Anthony LC
2024-06-28 10:12:31 +02:00
committed by Anthony LC
parent 5c87bd74cd
commit 8dcd6d5bb8

View File

@@ -15,6 +15,7 @@ import { Role, Team } from '@/features/teams/team-management';
import { useTeamAccesses } from '../api'; import { useTeamAccesses } from '../api';
import { PAGE_SIZE } from '../conf'; import { PAGE_SIZE } from '../conf';
import { Access } from '../types';
import { MemberAction } from './MemberAction'; import { MemberAction } from './MemberAction';
@@ -23,7 +24,6 @@ interface MemberGridProps {
currentRole: Role; currentRole: Role;
} }
// FIXME : ask Cunningham to export this type
type SortModelItem = { type SortModelItem = {
field: string; field: string;
sort: 'asc' | 'desc' | null; sort: 'asc' | 'desc' | null;
@@ -58,6 +58,7 @@ export const MemberGrid = ({ team, currentRole }: MemberGridProps) => {
pageSize: PAGE_SIZE, pageSize: PAGE_SIZE,
}); });
const [sortModel, setSortModel] = useState<SortModel>([]); const [sortModel, setSortModel] = useState<SortModel>([]);
const [accesses, setAccesses] = useState<Access[]>([]);
const { page, pageSize, setPagesCount } = pagination; const { page, pageSize, setPagesCount } = pagination;
const ordering = sortModel.length ? formatSortModel(sortModel[0]) : undefined; const ordering = sortModel.length ? formatSortModel(sortModel[0]) : undefined;
@@ -68,6 +69,11 @@ export const MemberGrid = ({ team, currentRole }: MemberGridProps) => {
ordering, ordering,
}); });
useEffect(() => {
if (isLoading) {
return;
}
const localizedRoles = { const localizedRoles = {
[Role.ADMIN]: t('Administration'), [Role.ADMIN]: t('Administration'),
[Role.MEMBER]: t('Member'), [Role.MEMBER]: t('Member'),
@@ -89,6 +95,9 @@ export const MemberGrid = ({ team, currentRole }: MemberGridProps) => {
}, },
})) || []; })) || [];
setAccesses(accesses);
}, [data?.results, t, isLoading]);
useEffect(() => { useEffect(() => {
setPagesCount(data?.count ? Math.ceil(data.count / pageSize) : 0); setPagesCount(data?.count ? Math.ceil(data.count / pageSize) : 0);
}, [data?.count, pageSize, setPagesCount]); }, [data?.count, pageSize, setPagesCount]);