Skip to content

Commit

Permalink
[B] Ensure page reset on dashboard list filter change
Browse files Browse the repository at this point in the history
  • Loading branch information
1aurend committed Feb 5, 2024
1 parent 78f5c1e commit 7ff7fd5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -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) {
Expand Down
49 changes: 8 additions & 41 deletions client/src/backend/containers/dashboards/Admin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useMemo } from "react";
import React, { useMemo } from "react";
import EntitiesList, {
Button,
Search,
Expand All @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -137,6 +102,7 @@ export function DashboardsAdminContainer({
search={
<Search
searchStyle="vertical"
onFilterChange={() => setProjectsPageNumber(1)}
{...entitiesListSearchProps("projects")}
/>
}
Expand Down Expand Up @@ -184,6 +150,7 @@ export function DashboardsAdminContainer({
search={
<Search
searchStyle="vertical"
onFilterChange={() => setJournalsPageNumber(1)}
{...entitiesListSearchProps("journals")}
/>
}
Expand Down

0 comments on commit 7ff7fd5

Please sign in to comment.