Skip to content

Fix and polish grading submissions table logic #2825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 27, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,28 @@ const GradingSubmissionTable: React.FC<GradingSubmissionTableProps> = ({
...tableFilters.columnFilters
]);

const [page, setPage] = useState(0);
const maxPage = useMemo(() => Math.ceil(totalRows / pageSize) - 1, [totalRows, pageSize]);
const resetPage = useCallback(() => setPage(0), [setPage]);

/** The value to be shown in the search bar */
const [searchQuery, setSearchQuery] = useState('');
/** The actual value sent to the backend */
const [searchValue, setSearchValue] = useState('');
const debouncedSetSearchValue = useMemo(() => debounce(setSearchValue, 300), []);
// Placing searchValue as a dependency for triggering a page reset will result in double-querying.
const debouncedUpdateSearchValue = useMemo(
() =>
debounce((newValue: string) => {
resetPage();
setSearchValue(newValue);
}, 300),
[resetPage]
);
const handleSearchQueryUpdate: React.ChangeEventHandler<HTMLInputElement> = e => {
setSearchQuery(e.target.value);
debouncedSetSearchValue(e.target.value);
debouncedUpdateSearchValue(e.target.value);
};

const [page, setPage] = useState(0);
const maxPage = useMemo(() => Math.ceil(totalRows / pageSize) - 1, [totalRows, pageSize]);
const resetPage = useCallback(() => setPage(0), [setPage]);

// Converts the columnFilters array into backend query parameters.
const backendFilterParams = useMemo(() => {
const filters: Array<{ [key: string]: any }> = [
Expand All @@ -158,7 +166,13 @@ const GradingSubmissionTable: React.FC<GradingSubmissionTableProps> = ({
const table = useReactTable({
data: submissions,
columns,
state: { columnFilters },
state: {
columnFilters,
pagination: {
pageIndex: 0,
pageSize: pageSize
}
},
onColumnFiltersChange: setColumnFilters,
getCoreRowModel: getCoreRowModel(),
getFilteredRowModel: getFilteredRowModel(),
Expand All @@ -168,6 +182,7 @@ const GradingSubmissionTable: React.FC<GradingSubmissionTableProps> = ({
const handleFilterRemove = ({ id, value }: ColumnFilter) => {
const newFilters = columnFilters.filter(filter => filter.id !== id && filter.value !== value);
setColumnFilters(newFilters);
resetPage();
};

useEffect(() => {
Expand All @@ -176,7 +191,7 @@ const GradingSubmissionTable: React.FC<GradingSubmissionTableProps> = ({

useEffect(() => {
resetPage();
}, [updateEntries, resetPage]);
}, [updateEntries, resetPage, searchValue]);

useEffect(() => {
updateEntries(page, backendFilterParams);
Expand Down