Skip to content
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

[B] Reset pagination on filter change on dashboard lists #3714

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
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 @@ -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 Expand Up @@ -230,8 +233,6 @@ class ListEntitiesListSearch extends PureComponent {
)}
>
{this.filterParams.map((param, i) => {
const SelectLabel =
i > 0 ? Styled.EmptySelectLabel : Styled.SelectLabel;
return (
<div
key={i}
Expand All @@ -240,11 +241,17 @@ class ListEntitiesListSearch extends PureComponent {
)}
>
<div>
<SelectLabel>
{i === 0
? t("filters.labels.filter_results")
: "\u00A0"}
</SelectLabel>
{i === 0 ? (
<Styled.SelectLabel>
{t("filters.labels.filter_results")}
</Styled.SelectLabel>
) : (
this.searchStyle === "horizontal" && (
<Styled.EmptySelectLabel>
{"\u00A0"}
</Styled.EmptySelectLabel>
)
)}
<div className="rel">
<label
htmlFor={`${id}-filter-${i}`}
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
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export default `
&--vertical {
display: block;
margin: 0;
padding-block-start: 30px;
}
}

Expand All @@ -92,6 +93,10 @@ export default `
}
padding-top: 30px;
}

& + & {
margin-block-start: 30px;
}
}

${respond(`flex: 0 0 33.333%;`, 60)}
Expand Down
Loading