1
- import React , { useEffect , useState } from "react" ;
1
+ import React , { useCallback , useEffect , useState } from "react" ;
2
2
import { useRouter } from "next/router" ;
3
3
import { observer } from "mobx-react-lite" ;
4
4
import { useForm } from "react-hook-form" ;
@@ -28,7 +28,8 @@ import {
28
28
renderShortMonthDate ,
29
29
} from "helpers/date-time.helper" ;
30
30
// types
31
- import { ICycle } from "types" ;
31
+ import { ICycle , IIssueFilterOptions } from "types" ;
32
+ import { EFilterType } from "store/issues/types" ;
32
33
// constants
33
34
import { EUserWorkspaceRoles } from "constants/workspace" ;
34
35
// fetch-keys
@@ -52,12 +53,20 @@ export const CycleDetailsSidebar: React.FC<Props> = observer((props) => {
52
53
const { workspaceSlug, projectId, peekCycle } = router . query ;
53
54
// store hooks
54
55
const {
56
+ < << << << HEAD
55
57
eventTracker : { setTrackElement } ,
56
58
} = useApplication ( ) ;
57
59
const {
58
60
membership : { currentProjectRole } ,
59
61
} = useUser ( ) ;
60
62
const { getCycleById, updateCycleDetails } = useCycle ( ) ;
63
+ = === ===
64
+ cycle: cycleDetailsStore ,
65
+ cycleIssuesFilter : { issueFilters, updateFilters } ,
66
+ trackEvent : { setTrackElement } ,
67
+ user : { currentProjectRole } ,
68
+ } = useMobxStore ( ) ;
69
+ > >>> >>> a86dafc11c3e52699f4050e9d9c97393e29f0434
61
70
62
71
const cycleDetails = getCycleById ( cycleId ) ;
63
72
@@ -246,6 +255,25 @@ export const CycleDetailsSidebar: React.FC<Props> = observer((props) => {
246
255
}
247
256
} ;
248
257
258
+ const handleFiltersUpdate = useCallback (
259
+ ( key : keyof IIssueFilterOptions , value : string | string [ ] ) => {
260
+ if ( ! workspaceSlug || ! projectId ) return ;
261
+ const newValues = issueFilters ?. filters ?. [ key ] ?? [ ] ;
262
+
263
+ if ( Array . isArray ( value ) ) {
264
+ value . forEach ( ( val ) => {
265
+ if ( ! newValues . includes ( val ) ) newValues . push ( val ) ;
266
+ } ) ;
267
+ } else {
268
+ if ( issueFilters ?. filters ?. [ key ] ?. includes ( value ) ) newValues . splice ( newValues . indexOf ( value ) , 1 ) ;
269
+ else newValues . push ( value ) ;
270
+ }
271
+
272
+ updateFilters ( workspaceSlug . toString ( ) , projectId . toString ( ) , EFilterType . FILTERS , { [ key ] : newValues } , cycleId ) ;
273
+ } ,
274
+ [ workspaceSlug , projectId , cycleId , issueFilters , updateFilters ]
275
+ ) ;
276
+
249
277
const cycleStatus =
250
278
cycleDetails ?. start_date && cycleDetails ?. end_date
251
279
? getDateRangeStatus ( cycleDetails ?. start_date , cycleDetails ?. end_date )
@@ -539,6 +567,9 @@ export const CycleDetailsSidebar: React.FC<Props> = observer((props) => {
539
567
} }
540
568
totalIssues = { cycleDetails . total_issues }
541
569
isPeekView = { Boolean ( peekCycle ) }
570
+ isCompleted = { isCompleted }
571
+ filters = { issueFilters ?. filters }
572
+ handleFiltersUpdate = { handleFiltersUpdate }
542
573
/>
543
574
</ div >
544
575
) }
0 commit comments