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

Commit 455f75d

Browse files
committed
Fixed: inconsistent periods' selection state
If page size was greater than the total number of periods select-all-on-page checkbox and the number of selected periods in the message above the periods' table had incorrect state.
1 parent b9672c7 commit 455f75d

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/store/reducers/workPeriods.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,15 @@ const actionHandlers = {
439439
delete periodsSelected[periodId];
440440
}
441441
}
442-
if (Object.keys(periodsSelected).length === state.pagination.pageSize) {
442+
const selectedCount = Object.keys(periodsSelected).length;
443+
const pageSize = state.pagination.pageSize;
444+
const totalCount = state.pagination.totalCount;
445+
if (totalCount > pageSize) {
446+
if (selectedCount === pageSize) {
447+
isSelectedPeriodsVisible = true;
448+
}
449+
} else if (selectedCount === totalCount) {
450+
isSelectedPeriodsAll = true;
443451
isSelectedPeriodsVisible = true;
444452
}
445453
return {
@@ -533,7 +541,15 @@ const actionHandlers = {
533541
const isSelected = !periodsSelected[periodId];
534542
if (isSelected) {
535543
periodsSelected[periodId] = true;
536-
if (Object.keys(periodsSelected).length === state.pagination.pageSize) {
544+
const selectedCount = Object.keys(periodsSelected).length;
545+
const pageSize = state.pagination.pageSize;
546+
const totalCount = state.pagination.totalCount;
547+
if (totalCount > pageSize) {
548+
if (selectedCount === pageSize) {
549+
isSelectedPeriodsVisible = true;
550+
}
551+
} else if (selectedCount === totalCount) {
552+
isSelectedPeriodsAll = true;
537553
isSelectedPeriodsVisible = true;
538554
}
539555
} else {
@@ -564,18 +580,22 @@ const actionHandlers = {
564580
};
565581
},
566582
[ACTION_TYPE.WP_TOGGLE_PERIODS_VISIBLE]: (state, on) => {
567-
const isSelected = on === null ? !state.isSelectedPeriodsVisible : on;
583+
let isSelectedPeriodsAll = false;
584+
const isSelectedPeriodsVisible =
585+
on === null ? !state.isSelectedPeriodsVisible : on;
568586
const periodsSelected = {};
569-
if (isSelected) {
587+
if (isSelectedPeriodsVisible) {
570588
for (let period of state.periods) {
571589
periodsSelected[period.id] = true;
572590
}
591+
isSelectedPeriodsAll =
592+
state.periods.length === state.pagination.totalCount;
573593
}
574594
return {
575595
...state,
576596
periodsSelected,
577-
isSelectedPeriodsAll: false,
578-
isSelectedPeriodsVisible: isSelected,
597+
isSelectedPeriodsAll,
598+
isSelectedPeriodsVisible,
579599
};
580600
},
581601
[ACTION_TYPE.WP_TOGGLE_PROCESSING_PAYMENTS]: (state, on) => {

0 commit comments

Comments
 (0)