Skip to content

Commit 6efcd2d

Browse files
authored
Merge pull request #587 from fahad-aot/rework/fwf4607-reordertaskfiltermodal-updates
fwf-4607:rework in re-order taskfilter modal
2 parents da2f4f0 + 46e0082 commit 6efcd2d

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

forms-flow-review/src/components/ReorderTaskFilterModal.tsx

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import {
1010
SharedWithOthersIcon,
1111
} from "@formsflow/components";
1212
import { useTranslation } from "react-i18next";
13-
import { saveFilterPreference } from "../api/services/filterServices";
14-
import { useSelector } from "react-redux";
13+
import { fetchBPMTaskCount,fetchFilterList, saveFilterPreference } from "../api/services/filterServices";
14+
import { useSelector,useDispatch } from "react-redux";
1515
import { RootState } from "../reducers/index.js";
16+
import { setBPMFilterList } from "../actions/taskActions";
17+
1618

1719
interface ReorderTaskFilterModalProps {
1820
showModal?: boolean;
@@ -28,6 +30,8 @@ export const ReorderTaskFilterModal: React.FC<ReorderTaskFilterModalProps> =
2830
(state: RootState) => state.task.userDetails
2931
);
3032
const { t } = useTranslation();
33+
const dispatch = useDispatch();
34+
3135
const [sortedFilterList, setSortedFilterList] = useState<any[]>([
3236
filtersList,
3337
]);
@@ -69,17 +73,28 @@ export const ReorderTaskFilterModal: React.FC<ReorderTaskFilterModalProps> =
6973
const handleDiscardChanges = () => {
7074
onClose();
7175
};
72-
const handleSaveChanges = () => {
73-
// here need to call the saveFilterPreference api to save the updated filterList before
74-
// payload only contains the id and sortOrder ,hide: the isChecked
75-
const updatedFiltersPreference = sortedFilterList.map((item) => ({
76-
filterId: item.id,
77-
hide: item.isChecked,
78-
sortOrder: item.sortOrder,
79-
}));
80-
saveFilterPreference(updatedFiltersPreference);
81-
setShowReorderFilterModal(false);
76+
const handleSaveChanges = async () => {
77+
// saveFilterPreference payload only contains the id and sortOrder ,hide
78+
const updatedFiltersPreference = sortedFilterList.map(
79+
({ id, isChecked, sortOrder }) => ({
80+
filterId: id,
81+
hide: isChecked,
82+
sortOrder,
83+
})
84+
);
85+
86+
try {
87+
await saveFilterPreference(updatedFiltersPreference);
88+
89+
const { data: { filters } } = await fetchFilterList();
90+
dispatch(fetchBPMTaskCount(filters));
91+
dispatch(setBPMFilterList(filters));
92+
setShowReorderFilterModal(false);
93+
} catch (error) {
94+
console.error("Failed to save filter preferences:", error);
95+
}
8296
};
97+
8398
const isSaveBtnDisabled = useMemo(() => {
8499
const original = JSON.stringify(
85100
updateFilterList.map(({ id, isChecked, sortOrder }) => ({
@@ -145,3 +160,5 @@ export const ReorderTaskFilterModal: React.FC<ReorderTaskFilterModalProps> =
145160
);
146161
}
147162
);
163+
164+

forms-flow-review/src/components/TaskList/TaskFilterDropdown.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,13 @@ const changeFilterSelection = (filter) => {
103103
dataTestId: "filter-item-reorder",
104104
ariaLabel: t("Re-order And Hide Filters"),
105105
};
106-
const mappedItems = filtersAndCount.map((filter) => {
106+
const mappedItems = filtersAndCount
107+
.filter((filter) => {
108+
const details = filterList.find((item) => item.id === filter.id);
109+
110+
return details && !details.hide; // only include visible filters
111+
})
112+
.map((filter) => {
107113
const filterDetails = filterList.find((item) => item.id === filter.id);
108114
let icon = null;
109115
if(filterDetails){
@@ -149,7 +155,7 @@ const changeFilterSelection = (filter) => {
149155
}
150156

151157
return filterDropdownItemsArray;
152-
}, [filtersAndCount, defaultFilter, ]);
158+
}, [filtersAndCount, defaultFilter,filterList,userDetails ]);
153159

154160
const title = selectedFilter
155161
? `${isUnsavedFilter ? t("Unsaved Filter") : t(selectedFilter.name)} (${

0 commit comments

Comments
 (0)