1
1
import { uniq , update } from "lodash" ;
2
2
import isEmpty from "lodash/isEmpty" ;
3
3
import omit from "lodash/omit" ;
4
- import orderBy from "lodash/orderBy" ;
5
4
import set from "lodash/set" ;
6
5
import { action , computed , makeObservable , observable , runInAction } from "mobx" ;
7
6
import { computedFn } from "mobx-utils" ;
@@ -42,11 +41,11 @@ export interface IProjectInboxStore {
42
41
inboxIssueIds : string [ ] ;
43
42
// computed
44
43
getAppliedFiltersCount : number ;
44
+ filteredInboxIssueIds : string [ ] ;
45
45
// computed functions
46
46
getIssueInboxByIssueId : ( issueId : string ) => IInboxIssueStore ;
47
47
getIsIssueAvailable : ( inboxIssueId : string ) => boolean ;
48
48
// helper actions
49
- inboxIssueSorting : ( issues : IInboxIssueStore [ ] ) => IInboxIssueStore [ ] ;
50
49
inboxIssueQueryParams : (
51
50
inboxFilters : Partial < TInboxIssueFilter > ,
52
51
inboxSorting : Partial < TInboxIssueSorting > ,
@@ -103,6 +102,7 @@ export class ProjectInboxStore implements IProjectInboxStore {
103
102
inboxIssueIds : observable ,
104
103
// computed
105
104
getAppliedFiltersCount : computed ,
105
+ filteredInboxIssueIds : computed ,
106
106
// actions
107
107
handleInboxIssueFilters : action ,
108
108
handleInboxIssueSorting : action ,
@@ -127,35 +127,23 @@ export class ProjectInboxStore implements IProjectInboxStore {
127
127
return count ;
128
128
}
129
129
130
+ get filteredInboxIssueIds ( ) {
131
+ let appliedFilters =
132
+ this . currentTab === EInboxIssueCurrentTab . OPEN
133
+ ? [ EInboxIssueStatus . PENDING , EInboxIssueStatus . SNOOZED ]
134
+ : [ EInboxIssueStatus . ACCEPTED , EInboxIssueStatus . DECLINED , EInboxIssueStatus . DUPLICATE ] ;
135
+ appliedFilters = appliedFilters . filter ( ( filter ) => this . inboxFilters ?. status ?. includes ( filter ) ) ;
136
+
137
+ return this . inboxIssueIds . filter ( ( id ) => appliedFilters . includes ( this . inboxIssues [ id ] . status ) ) ;
138
+ }
139
+
130
140
getIssueInboxByIssueId = computedFn ( ( issueId : string ) => this . inboxIssues ?. [ issueId ] ) ;
131
141
132
142
getIsIssueAvailable = computedFn ( ( inboxIssueId : string ) => {
133
143
if ( ! this . inboxIssueIds ) return true ;
134
144
return this . inboxIssueIds . includes ( inboxIssueId ) ;
135
145
} ) ;
136
146
137
- // helpers
138
- inboxIssueSorting = ( issues : IInboxIssueStore [ ] ) => {
139
- let inboxIssues : IInboxIssueStore [ ] = issues ;
140
- inboxIssues = orderBy ( inboxIssues , "issue.sequence_id" , "desc" ) ;
141
- if ( this . inboxSorting ?. order_by && this . inboxSorting ?. sort_by ) {
142
- switch ( this . inboxSorting . order_by ) {
143
- case "issue__created_at" :
144
- if ( this . inboxSorting . sort_by === "desc" ) inboxIssues = orderBy ( inboxIssues , "issue.created_at" , "desc" ) ;
145
- else inboxIssues = orderBy ( inboxIssues , "issue.created_at" , "asc" ) ;
146
- case "issue__updated_at" :
147
- if ( this . inboxSorting . sort_by === "desc" ) inboxIssues = orderBy ( inboxIssues , "issue.updated_at" , "desc" ) ;
148
- else inboxIssues = orderBy ( inboxIssues , "issue.updated_at" , "asc" ) ;
149
- case "issue__sequence_id" :
150
- if ( this . inboxSorting . sort_by === "desc" ) inboxIssues = orderBy ( inboxIssues , "issue.sequence_id" , "desc" ) ;
151
- else inboxIssues = orderBy ( inboxIssues , "issue.sequence_id" , "asc" ) ;
152
- default :
153
- inboxIssues = inboxIssues ;
154
- }
155
- }
156
- return inboxIssues ;
157
- } ;
158
-
159
147
inboxIssueQueryParams = (
160
148
inboxFilters : Partial < TInboxIssueFilter > ,
161
149
inboxSorting : Partial < TInboxIssueSorting > ,
0 commit comments