@@ -31,61 +31,70 @@ export const ReorderTaskFilterModal: React.FC<ReorderTaskFilterModalProps> =
3131 const { t } = useTranslation ( ) ;
3232 const dispatch = useDispatch ( ) ;
3333 const selectedFilter = useSelector ( ( state : any ) => state . task . selectedFilter ) ;
34- const [ sortedFilterList , setSortedFilterList ] = useState < any [ ] > ( [
35- filtersList ,
36- ] ) ;
34+
35+ const [ myFilterList , setMyFilterList ] = useState < any [ ] > ( [ ] ) ;
36+ const [ sharedFilterList , setSharedFilterList ] = useState < any [ ] > ( [ ] ) ;
3737
3838 const darkColor = StyleServices . getCSSVariable ( "--secondary-dark" ) ;
3939 // need to update the filterList with only key of Id,name,isChcked ,sortOrder,Icon in order to pass to drag and drop
4040 const updateFilterList = useMemo ( ( ) => {
4141 return filtersList . map ( ( item ) => {
42- // const createdByMe = userDetails.preferred_username === item.createdBy;
43- // const isSharedToPublic = !item.roles?.length && !item.users?.length;
44- // const isSharedToRoles = item.roles.length
45- // const isShareToMe = item.roles?.some((role) =>
46- // userDetails.groups?.includes(role)
47- // );
48- // let icon = null;
49- // // icon for filters except private and All tasks
50- // if (createdByMe&& (isSharedToPublic || isSharedToRoles)) {
51- // icon = <SharedWithOthersIcon />;
52- // } else if (isSharedToPublic || isShareToMe) {
53- // icon = <SharedWithMeIcon />;
54- // }
42+ const createdByMe = userDetails ?. preferred_username === item ?. createdBy ;
43+ const isSharedToPublic = ! item ?. roles ?. length && ! item ?. users ?. length ;
44+ const isSharedToRoles = item ?. roles ?. length ;
45+ const isSharedToMe = item ?. roles ?. some ( ( role ) =>
46+ userDetails ?. groups ?. includes ( role )
47+ ) ;
48+
49+ let category = "my" ;
50+ if ( createdByMe && ( isSharedToPublic || isSharedToRoles ) ) {
51+ category = "my" ;
52+ } else if ( isSharedToPublic || isSharedToMe ) {
53+ category = "shared" ;
54+ }
55+
5556 return {
5657 id : item . id ,
5758 name : item . name ,
5859 isChecked : ! item . hide ,
5960 sortOrder : item . sortOrder ,
60- // icon: icon ,
61+ category ,
6162 } ;
6263 } ) ;
63- } , [ filtersList ] ) ;
64+ } , [ filtersList , userDetails ] ) ;
6465
6566 // set the updated filterList to sortedfilterLis state ,to compare the updated filterList with the original filterList initially
6667 useEffect ( ( ) => {
67- setSortedFilterList ( updateFilterList ) ;
68+ const myFilters = updateFilterList . filter ( f => f . category === "my" ) ;
69+ const sharedFilters = updateFilterList . filter ( f => f . category === "shared" ) ;
70+ setMyFilterList ( myFilters ) ;
71+ setSharedFilterList ( sharedFilters ) ;
6872 } , [ updateFilterList ] ) ;
6973
70- //callback function to update the filterList after drag and drop
71- const onUpdateFilterOrder = ( dragedFilterList ) => {
72- setSortedFilterList ( dragedFilterList ) ;
74+ const onUpdateMyFilters = ( updatedList ) => {
75+ setMyFilterList ( updatedList ) ;
76+ } ;
77+
78+ const onUpdateSharedFilters = ( updatedList ) => {
79+ setSharedFilterList ( updatedList ) ;
7380 } ;
7481
7582 const handleDiscardChanges = ( ) => {
7683 onClose ( ) ;
7784 } ;
7885 const handleSaveChanges = async ( ) => {
79- // saveFilterPreference payload only contains the id and sortOrder ,hide
80- const updatedFiltersPreference = sortedFilterList . map (
81- ( { id, isChecked, sortOrder } ) => ( {
86+ // Combine lists for saving
87+ const combinedList = [ ...myFilterList , ...sharedFilterList ] ;
88+
89+ const updatedFiltersPreference = combinedList . map (
90+ ( { id, isChecked } , index ) => ( {
8291 filterId : id ,
8392 hide : ! isChecked ,
84- sortOrder,
93+ sortOrder : index , // Update sort order based on new position
8594 } )
8695 ) ;
87- // check if the selected filter is hidden or not
88- const selectedFilterHide = sortedFilterList . some (
96+
97+ const selectedFilterHide = combinedList . some (
8998 ( { id, isChecked } ) => id === selectedFilter . id && ! isChecked
9099 ) ;
91100
@@ -110,22 +119,23 @@ export const ReorderTaskFilterModal: React.FC<ReorderTaskFilterModalProps> =
110119 } ;
111120
112121 const isSaveBtnDisabled = useMemo ( ( ) => {
113- const original = JSON . stringify (
114- updateFilterList . map ( ( { id, isChecked, sortOrder } ) => ( {
115- id,
116- isChecked,
117- sortOrder,
118- } ) )
119- ) ;
120- const current = JSON . stringify (
121- sortedFilterList . map ( ( { id, isChecked, sortOrder } ) => ( {
122- id,
123- isChecked,
124- sortOrder,
125- } ) )
126- ) ;
127- return original === current ;
128- } , [ sortedFilterList , updateFilterList ] ) ;
122+ const myFiltersChecked = myFilterList . some ( f => f . isChecked ) ;
123+ const sharedFiltersChecked = sharedFilterList . some ( f => f . isChecked ) ;
124+
125+ if ( ! myFiltersChecked && ! sharedFiltersChecked ) {
126+ return true ;
127+ }
128+
129+ const originalMy = updateFilterList . filter ( f => f . category === "my" ) ;
130+ const originalShared = updateFilterList . filter ( f => f . category === "shared" ) ;
131+
132+ const formatForCompare = ( list ) => list . map ( ( { id, isChecked } ) => ( { id, isChecked } ) ) ;
133+
134+ const myChanged = JSON . stringify ( formatForCompare ( originalMy ) ) !== JSON . stringify ( formatForCompare ( myFilterList ) ) ;
135+ const sharedChanged = JSON . stringify ( formatForCompare ( originalShared ) ) !== JSON . stringify ( formatForCompare ( sharedFilterList ) ) ;
136+
137+ return ! myChanged && ! sharedChanged ;
138+ } , [ myFilterList , sharedFilterList , updateFilterList ] ) ;
129139
130140 return (
131141 < Modal
@@ -148,12 +158,24 @@ export const ReorderTaskFilterModal: React.FC<ReorderTaskFilterModalProps> =
148158 </ div >
149159 </ Modal . Header >
150160 < Modal . Body >
151-
152- < DragandDropSort
153- items = { updateFilterList }
154- onUpdate = { onUpdateFilterOrder }
155- preventLastCheck = { true }
156- />
161+ < div className = "filter-section mb-3" >
162+ < DragandDropSort
163+ items = { myFilterList }
164+ onUpdate = { onUpdateMyFilters }
165+ preventLastCheck = { true }
166+ heading = { t ( "Personal Filters" ) }
167+ subHeading = { t ( "Only you can see these" ) }
168+ />
169+ </ div >
170+ < div className = "filter-section" >
171+ < DragandDropSort
172+ items = { sharedFilterList }
173+ onUpdate = { onUpdateSharedFilters }
174+ preventLastCheck = { false }
175+ heading = { t ( "Shared Filters" ) }
176+ subHeading = { t ( "Both you and others can see these" ) }
177+ />
178+ </ div >
157179 </ Modal . Body >
158180 < Modal . Footer >
159181 < V8CustomButton
0 commit comments