@@ -2,8 +2,8 @@ import * as vscode from 'vscode';
22import * as path from 'path' ;
33
44import { 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' ;
77
88enum MRType {
99 Open = `open` ,
@@ -23,7 +23,7 @@ interface IFileNode extends IMRPathItem {
2323 children ?: IFileNode [ ]
2424}
2525
26- type ITreeNode = string | number | IMRDiffStat | IFileNode ;
26+ type ITreeNode = string | number | IMRDiffStat | IFileNode | IMRData ;
2727
2828export class MRTreeDataProvider implements vscode . TreeDataProvider < ListItem < ITreeNode > > {
2929 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
4747
4848 getChildren ( element ?: ListItem < ITreeNode > ) : Thenable < ListItem < ITreeNode > [ ] > {
4949 if ( ! this . _service . loggedIn ) {
50- vscode . window . showErrorMessage ( `[Auth] expired.` ) ;
50+ vscode . window . showErrorMessage ( `[MR Tree] auth expired.` ) ;
5151 return Promise . resolve ( [ ] ) ;
5252 }
5353
@@ -86,21 +86,12 @@ export class MRTreeDataProvider implements vscode.TreeDataProvider<ListItem<ITre
8686 throw new Error ( `team not exist` ) ;
8787 }
8888
89- return list . map ( ( i : MRData ) => {
89+ return list . map ( ( i : IMRData ) => {
9090 return new MRItem (
9191 i . title ,
92- i . iid ,
92+ i ,
9393 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
10495 ) ;
10596 } ) ;
10697 } )
@@ -109,7 +100,7 @@ export class MRTreeDataProvider implements vscode.TreeDataProvider<ListItem<ITre
109100 } ) ;
110101 }
111102 case ItemType . MRItem : {
112- return this . _service . getMRDiff ( element . value as number )
103+ return this . _service . getMRDiff ( ( element . value as IMRData ) . iid )
113104 . then ( ( { data : { diffStat} } ) => {
114105 return element . getChildren ( diffStat ) ;
115106 } ) ;
@@ -144,19 +135,43 @@ export class CategoryItem extends ListItem<string> {
144135 contextValue = ItemType . CategoryItem ;
145136}
146137
147- export class MRItem extends ListItem < string | number > {
138+ export class MRItem extends ListItem < IMRData > {
148139 contextValue = ItemType . MRItem ;
149140
150141 iconPath = {
151142 light : path . join ( __filename , '../../../src/assets/star.light.svg' ) ,
152143 dark : path . join ( __filename , '../../../src/assets/star.dark.svg' ) ,
153144 } ;
154145
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+
155155 async getChildren ( diffStat : IMRDiffStat ) : Promise < ListItem < string | number | IFileNode > [ ] > {
156156 const files = this . _transformTree ( diffStat . paths ) ;
157+ const repoInfo = this . context . workspaceState . get ( `repoInfo` , { } ) ;
158+ const session = this . context . workspaceState . get ( `session` , { } as SessionData ) ;
157159
158160 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+ } ) ,
160175 ...files . map ( f => new FileNode ( f . name , f , ( f . children || [ ] ) ?. length > 0 ? vscode . TreeItemCollapsibleState . Expanded : vscode . TreeItemCollapsibleState . None ) ) ,
161176 ] ;
162177 }
0 commit comments