@@ -38,40 +38,39 @@ const sortIssuesListByUsername = (cardsWithIssue: ICardWithIssue[]) => {
38
38
return result ;
39
39
} ;
40
40
41
- const getIssuesForLabel = (
42
- label : string ,
43
- labels : string [ ] ,
44
- cardsWithIssue : ICardWithIssue [ ] ,
45
- ) : ICardWithIssue [ ] => {
46
- const result = cardsWithIssue . filter ( ( { issue } ) => {
41
+ const findLabel = ( labelName : string , found = true ) => {
42
+ return ( { issue } : ICardWithIssue ) => {
47
43
if ( ! issue ) {
48
44
return false ;
49
45
}
50
46
51
- const firstLabelFromTheList = issue . labels . find ( ( issueLabel ) => {
52
- return labels . includes ( issueLabel . name ) ;
53
- } ) ;
54
-
55
47
const foundLabel = issue . labels . find ( ( issueLabel ) => {
56
- return issueLabel . name === label ;
48
+ return issueLabel . name === labelName ;
57
49
} ) ;
58
50
59
- /**
60
- * The `labels` array has the descending priority for the defined labels,
61
- * hence if the found label is not the first in the list, dont use it
62
- */
63
- if ( firstLabelFromTheList !== foundLabel ) {
64
- return false ;
65
- }
51
+ return ! ! foundLabel === found ;
52
+ }
53
+ }
66
54
67
- return ! ! foundLabel ;
68
- } ) ;
55
+ const getIssuesForLabel = (
56
+ label : string ,
57
+ cardsWithIssue : ICardWithIssue [ ] ,
58
+ ) : [ ICardWithIssue [ ] , ICardWithIssue [ ] ] => {
59
+ const originalCards = [ ...cardsWithIssue ] ;
69
60
70
- return result ;
61
+ const result = originalCards . filter (
62
+ findLabel ( label ) ,
63
+ ) ;
64
+
65
+ const rest = originalCards . filter (
66
+ findLabel ( label , false ) ,
67
+ ) ;
68
+
69
+ return [ result , rest ] ;
71
70
} ;
72
71
73
72
const groupIssuesByLabels = (
74
- issues : ICardWithIssue [ ] ,
73
+ cardsWithIssues : ICardWithIssue [ ] ,
75
74
projectWithConfig : IProjectWithConfig ,
76
75
) : TLabeledIssues => {
77
76
const result : TLabeledIssues = { } ;
@@ -83,19 +82,29 @@ const groupIssuesByLabels = (
83
82
84
83
const includedIssues = new Set < ICardWithIssue > ( ) ;
85
84
for ( let label of labels ) {
86
- const issuesForLabel = sortIssuesListByUsername (
87
- getIssuesForLabel ( label , labels , issues ) ,
88
- ) ;
85
+ const [ cardsForLabel , restCards ] = getIssuesForLabel ( label , cardsWithIssues ) ;
86
+ /**
87
+ * !! We return the `restCards` above - the list of cards that does not hold
88
+ * the label, and reassign the "rest" list to the original one, so we don't
89
+ * match the same card against other labels. This enforces descending priority
90
+ * of the `trackLabels` labels list defined in the project config.
91
+ * e.g. with the ["port-forwarding", "workbench", "performance", "serverless"]
92
+ * list in the config, the issues with both "port-forwarding" and "performance"
93
+ * labels, will show up only in the` Port-forwarding` section since it has the
94
+ * highe precedence over the "performance" label.
95
+ */
96
+ cardsWithIssues = restCards ;
89
97
90
- result [ label ] = issuesForLabel ;
98
+ const sortedIssuesForLabel = sortIssuesListByUsername ( cardsForLabel ) ;
99
+ result [ label ] = sortedIssuesForLabel ;
91
100
92
- for ( let issueForLabel of issuesForLabel ) {
101
+ for ( let issueForLabel of sortedIssuesForLabel ) {
93
102
includedIssues . add ( issueForLabel ) ;
94
103
}
95
104
}
96
105
97
106
// get all issues that have no label
98
- const notIncludedIssues = issues . filter ( ( issue ) => {
107
+ const notIncludedIssues = cardsWithIssues . filter ( ( issue ) => {
99
108
return ! includedIssues . has ( issue ) ;
100
109
} ) ;
101
110
0 commit comments