@@ -2,8 +2,8 @@ import * as vscode from 'vscode';
2
2
import * as path from 'path' ;
3
3
4
4
import { CodingServer } from '../codingServer' ;
5
- import { RepoInfo } from '../typings/commonTypes' ;
6
- import { IMRDiffStat , MRData , IMRPathItem } from '../typings/respResult' ;
5
+ import { RepoInfo , SessionData } from '../typings/commonTypes' ;
6
+ import { IMRDiffStat , IMRData , IMRPathItem } from '../typings/respResult' ;
7
7
8
8
enum MRType {
9
9
Open = `open` ,
@@ -23,7 +23,7 @@ interface IFileNode extends IMRPathItem {
23
23
children ?: IFileNode [ ]
24
24
}
25
25
26
- type ITreeNode = string | number | IMRDiffStat | IFileNode ;
26
+ type ITreeNode = string | number | IMRDiffStat | IFileNode | IMRData ;
27
27
28
28
export class MRTreeDataProvider implements vscode . TreeDataProvider < ListItem < ITreeNode > > {
29
29
private _onDidChangeTreeData : vscode . EventEmitter < ListItem < ITreeNode > | undefined | void > = new vscode . EventEmitter < ListItem < ITreeNode > | undefined | void > ( ) ;
@@ -47,7 +47,7 @@ export class MRTreeDataProvider implements vscode.TreeDataProvider<ListItem<ITre
47
47
48
48
getChildren ( element ?: ListItem < ITreeNode > ) : Thenable < ListItem < ITreeNode > [ ] > {
49
49
if ( ! this . _service . loggedIn ) {
50
- vscode . window . showErrorMessage ( `[Auth] expired.` ) ;
50
+ vscode . window . showErrorMessage ( `[MR Tree] auth expired.` ) ;
51
51
return Promise . resolve ( [ ] ) ;
52
52
}
53
53
@@ -86,21 +86,12 @@ export class MRTreeDataProvider implements vscode.TreeDataProvider<ListItem<ITre
86
86
throw new Error ( `team not exist` ) ;
87
87
}
88
88
89
- return list . map ( ( i : MRData ) => {
89
+ return list . map ( ( i : IMRData ) => {
90
90
return new MRItem (
91
91
i . title ,
92
- i . iid ,
92
+ i ,
93
93
vscode . TreeItemCollapsibleState . Collapsed ,
94
- {
95
- command : 'codingPlugin.showDetail' ,
96
- title : `${ i . iid } ${ i . title } ` ,
97
- arguments : [ {
98
- ...repoInfo ,
99
- iid : i . iid ,
100
- type : `mr` ,
101
- accessToken : this . _service . session ?. accessToken ,
102
- } ] ,
103
- } ,
94
+ this . _context
104
95
) ;
105
96
} ) ;
106
97
} )
@@ -109,7 +100,7 @@ export class MRTreeDataProvider implements vscode.TreeDataProvider<ListItem<ITre
109
100
} ) ;
110
101
}
111
102
case ItemType . MRItem : {
112
- return this . _service . getMRDiff ( element . value as number )
103
+ return this . _service . getMRDiff ( ( element . value as IMRData ) . iid )
113
104
. then ( ( { data : { diffStat} } ) => {
114
105
return element . getChildren ( diffStat ) ;
115
106
} ) ;
@@ -144,19 +135,43 @@ export class CategoryItem extends ListItem<string> {
144
135
contextValue = ItemType . CategoryItem ;
145
136
}
146
137
147
- export class MRItem extends ListItem < string | number > {
138
+ export class MRItem extends ListItem < IMRData > {
148
139
contextValue = ItemType . MRItem ;
149
140
150
141
iconPath = {
151
142
light : path . join ( __filename , '../../../src/assets/star.light.svg' ) ,
152
143
dark : path . join ( __filename , '../../../src/assets/star.dark.svg' ) ,
153
144
} ;
154
145
146
+ constructor (
147
+ public readonly label : string ,
148
+ public readonly value : IMRData ,
149
+ public readonly collapsibleState : vscode . TreeItemCollapsibleState ,
150
+ public readonly context : vscode . ExtensionContext ,
151
+ ) {
152
+ super ( label , value , collapsibleState ) ;
153
+ }
154
+
155
155
async getChildren ( diffStat : IMRDiffStat ) : Promise < ListItem < string | number | IFileNode > [ ] > {
156
156
const files = this . _transformTree ( diffStat . paths ) ;
157
+ const repoInfo = this . context . workspaceState . get ( `repoInfo` , { } ) ;
158
+ const session = this . context . workspaceState . get ( `session` , { } as SessionData ) ;
157
159
158
160
return [
159
- new ListItem ( `Description` , `mr-desc` , vscode . TreeItemCollapsibleState . None ) ,
161
+ new ListItem (
162
+ `Description` ,
163
+ `mr-desc` ,
164
+ vscode . TreeItemCollapsibleState . None ,
165
+ {
166
+ command : 'codingPlugin.showDetail' ,
167
+ title : `${ this . value . iid } ${ this . value . title } ` ,
168
+ arguments : [ {
169
+ ...repoInfo ,
170
+ iid : this . value . iid ,
171
+ type : `mr` ,
172
+ accessToken : session ?. accessToken ,
173
+ } ] ,
174
+ } ) ,
160
175
...files . map ( f => new FileNode ( f . name , f , ( f . children || [ ] ) ?. length > 0 ? vscode . TreeItemCollapsibleState . Expanded : vscode . TreeItemCollapsibleState . None ) ) ,
161
176
] ;
162
177
}
0 commit comments