From 7ff7fd5bab50c379be500123d52157b1c21a43b0 Mon Sep 17 00:00:00 2001 From: Lauren Davidson <32903719+1aurend@users.noreply.github.com> Date: Mon, 5 Feb 2024 09:15:33 -0800 Subject: [PATCH] [B] Ensure page reset on dashboard list filter change --- .../list/EntitiesList/List/Search/index.js | 3 ++ .../backend/containers/dashboards/Admin.js | 49 +++---------------- 2 files changed, 11 insertions(+), 41 deletions(-) diff --git a/client/src/backend/components/list/EntitiesList/List/Search/index.js b/client/src/backend/components/list/EntitiesList/List/Search/index.js index b4e1048c07..6687a5de38 100644 --- a/client/src/backend/components/list/EntitiesList/List/Search/index.js +++ b/client/src/backend/components/list/EntitiesList/List/Search/index.js @@ -18,6 +18,7 @@ class ListEntitiesListSearch extends PureComponent { setParam: PropTypes.func.isRequired, onReset: PropTypes.func.isRequired, searchStyle: PropTypes.oneOf(["horizontal", "vertical"]), + onFilterChange: PropTypes.func, t: PropTypes.func }; @@ -115,12 +116,14 @@ class ListEntitiesListSearch extends PureComponent { const value = event.target.value; const { setParam } = this.props; setParam(param, value); + if (this.props.onFilterChange) this.props.onFilterChange(); } submitKeywordForm = event => { event.preventDefault(); const { setParam } = this.props; setParam(this.keywordParam, this.state.keyword); + if (this.props.onFilterChange) this.props.onFilterChange(); }; ensureParamObject(param) { diff --git a/client/src/backend/containers/dashboards/Admin.js b/client/src/backend/containers/dashboards/Admin.js index 17a9a37e92..76b0963444 100644 --- a/client/src/backend/containers/dashboards/Admin.js +++ b/client/src/backend/containers/dashboards/Admin.js @@ -1,4 +1,4 @@ -import React, { useCallback, useMemo } from "react"; +import React, { useMemo } from "react"; import EntitiesList, { Button, Search, @@ -21,38 +21,13 @@ import { useTranslation } from "react-i18next"; export function DashboardsAdminContainer({ entitiesListSearchProps, - entitiesListSearchParams, - saveSearchState, - savedSearchPaginationState + entitiesListSearchParams }) { - const { - number: projectPageNumber, - size: projectPageSize - } = savedSearchPaginationState("projects") || { number: 1, size: 5 }; - const { - number: journalPageNumber, - size: journalPageSize - } = savedSearchPaginationState("journals") || { number: 1, size: 5 }; - - const [projectsPagination, setProjectsPageNumber] = usePaginationState( - projectPageNumber, - projectPageSize - ); - const [journalsPagination, setJournalsPageNumber] = usePaginationState( - journalPageNumber, - journalPageSize - ); + const [projectsPagination, setProjectsPageNumber] = usePaginationState(1, 5); + const [journalsPagination, setJournalsPageNumber] = usePaginationState(1, 5); const authentication = useAuthentication(); - const saveProjectsSearch = useCallback(() => { - saveSearchState("projects", projectsPagination); - }, [saveSearchState, projectsPagination]); - - const saveJournalsSearch = useCallback(() => { - saveSearchState("journals", journalsPagination); - }, [saveSearchState, journalsPagination]); - const projectFiltersWithDefaults = useMemo( () => ({ withUpdateAbility: true, @@ -70,21 +45,11 @@ export function DashboardsAdminContainer({ ); const { data: projects, meta: projectsMeta } = useFetch({ - request: [ - projectsAPI.index, - projectFiltersWithDefaults, - projectsPagination - ], - afterFetch: saveProjectsSearch + request: [projectsAPI.index, projectFiltersWithDefaults, projectsPagination] }); const { data: journals, meta: journalsMeta } = useFetch({ - request: [ - journalsAPI.index, - journalFiltersWithDefaults, - journalsPagination - ], - afterFetch: saveJournalsSearch + request: [journalsAPI.index, journalFiltersWithDefaults, journalsPagination] }); const authorization = new Authorization(); @@ -137,6 +102,7 @@ export function DashboardsAdminContainer({ search={ setProjectsPageNumber(1)} {...entitiesListSearchProps("projects")} /> } @@ -184,6 +150,7 @@ export function DashboardsAdminContainer({ search={ setJournalsPageNumber(1)} {...entitiesListSearchProps("journals")} /> }