Skip to content
Snippets Groups Projects
Commit 7ec8047e authored by Rémi PAILHAREY's avatar Rémi PAILHAREY :fork_knife_plate:
Browse files

fix: returns to first page when search changes

parent 276f0e01
Branches
No related tags found
Loading
Pipeline #53348 passed
......@@ -153,25 +153,28 @@ const Consents: React.FC = () => {
}
}, [gridApi, selectedNodes])
const handleSearchChange = useCallback(
async (newSearch: string) => {
setSearch(newSearch)
if (user) {
const consentPagination = await consentService.searchConsents(
newSearch,
rowsPerPage,
page,
getAxiosXSRFHeader(user.xsrftoken)
)
if (consentPagination) {
setConsents(consentPagination.rows)
checkSelectedNodes()
setTotalRows(consentPagination.totalRows)
}
const searchConsents = async () => {
if (user) {
const consentPagination = await consentService.searchConsents(
search,
rowsPerPage,
page,
getAxiosXSRFHeader(user.xsrftoken)
)
if (consentPagination) {
setConsents(consentPagination.rows)
checkSelectedNodes()
setTotalRows(consentPagination.totalRows)
console.log(search)
console.log(consentPagination)
}
},
[user, consentService, rowsPerPage, page, checkSelectedNodes]
)
}
}
const handleSearchChange = (newSearch: string) => {
setSearch(newSearch)
setPage(0)
}
const resetSelection = useCallback(() => {
if (gridApi) {
......@@ -252,12 +255,12 @@ const Consents: React.FC = () => {
}
}, [gridApi])
/** Trigger search when page loads or when admin changes pagination */
/** Trigger search when page loads or when admin changes input or pagination */
useEffect(() => {
handleSearchChange(search)
searchConsents()
// /!\ Do not change dependencies or effect will not trigger when pagination changes
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [rowsPerPage, page])
}, [rowsPerPage, page, search])
return (
<>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment