Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit d01eced

Browse files
committed
Fixed: issues with sorting loaded from URL.
1 parent cf03d81 commit d01eced

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/routes/WorkPeriods/components/Periods/index.jsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import {
1010
getWorkPeriodsSorting,
1111
} from "store/selectors/workPeriods";
1212
import { updateStateFromQuery } from "store/actions/workPeriods";
13-
import { loadWorkPeriodsPage } from "store/thunks/workPeriods";
13+
import {
14+
loadWorkPeriodsPage,
15+
updateQueryFromState,
16+
} from "store/thunks/workPeriods";
1417

1518
/**
1619
* Displays working periods' list or a "Loading..." message or an error message.
@@ -30,6 +33,7 @@ const Periods = () => {
3033
}, [dispatch, pagination.pageNumber, pagination.pageSize, sorting]);
3134

3235
useEffect(() => {
36+
dispatch(updateQueryFromState(true));
3337
return globalHistory.listen(({ action, location }) => {
3438
if (action === "POP") {
3539
dispatch(updateStateFromQuery(location.search));

src/store/reducers/workPeriods.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -759,14 +759,17 @@ function updateStateFromQuery(queryStr, state) {
759759
updateFilters = true;
760760
}
761761
// checking sorting criteria
762-
const criteria = params.criteria?.toUpperCase();
763-
if (criteria in SORT_BY && criteria !== sorting.criteria) {
762+
let criteria = params.criteria?.toUpperCase();
763+
criteria = criteria in SORT_BY ? criteria : SORT_BY_DEFAULT;
764+
if (criteria !== sorting.criteria) {
764765
sorting.criteria = criteria;
765766
updateSorting = true;
766767
}
767768
// checking sorting order
768-
const order = params.order;
769-
if (order && order.toUpperCase() in SORT_ORDER && order !== sorting.order) {
769+
let order = params.order;
770+
order =
771+
order && order.toUpperCase() in SORT_ORDER ? order : SORT_ORDER_DEFAULT;
772+
if (order !== sorting.order) {
770773
sorting.order = order;
771774
updateSorting = true;
772775
}

0 commit comments

Comments
 (0)