@@ -12,6 +12,7 @@ import { homedir } from "os";
12
12
import { exists } from "../utils/utils" ;
13
13
import UntitledSqlDocumentService from '../controllers/untitledSqlDocumentService' ;
14
14
import * as path from 'path' ;
15
+ import { ApiStatus } from "../sharedInterfaces/webview" ;
15
16
16
17
export class ExecutionPlanWebViewController extends ReactWebViewPanelController <
17
18
ep . ExecutionPlanWebViewState ,
@@ -30,7 +31,15 @@ export class ExecutionPlanWebViewController extends ReactWebViewPanelController<
30
31
context ,
31
32
`${ xmlPlanFileName } ` , // Sets the webview title
32
33
WebviewRoute . executionPlanDocument ,
33
- { } ,
34
+ {
35
+ sqlPlanContent : executionPlanContents ,
36
+ theme : vscode . window . activeColorTheme . kind === vscode . ColorThemeKind . Dark ? "dark" : "light" ,
37
+ localizedConstants : LocalizedConstants ,
38
+ loadState : ApiStatus . Loading ,
39
+ executionPlan : undefined ,
40
+ executionPlanGraphs : [ ] ,
41
+ totalCost : 0 ,
42
+ } ,
34
43
vscode . ViewColumn . Active ,
35
44
{
36
45
dark : vscode . Uri . joinPath (
@@ -45,25 +54,19 @@ export class ExecutionPlanWebViewController extends ReactWebViewPanelController<
45
54
) ,
46
55
}
47
56
) ;
48
- this . state . isLoading = true ;
49
57
this . initialize ( ) ;
50
58
}
51
59
52
60
private async initialize ( ) {
53
- this . state . sqlPlanContent = this . executionPlanContents ;
54
- this . state . theme = vscode . window . activeColorTheme . kind === vscode . ColorThemeKind . Dark ? "dark" : "light" ;
55
- this . state . localizedConstants = LocalizedConstants ;
56
-
61
+ this . state . loadState = ApiStatus . Loading ;
62
+ this . updateState ( ) ;
57
63
await this . createExecutionPlanGraphs ( ) ;
58
- this . state . totalCost = this . calculateTotalCost ( ) ;
59
64
this . registerRpcHandlers ( ) ;
60
- this . state . isLoading = false ;
61
65
}
62
66
63
67
private registerRpcHandlers ( ) {
64
68
this . registerReducer ( "getExecutionPlan" , async ( state , payload ) => {
65
69
await this . createExecutionPlanGraphs ( ) ;
66
-
67
70
return {
68
71
...state ,
69
72
executionPlan : this . state . executionPlan ,
@@ -141,10 +144,18 @@ export class ExecutionPlanWebViewController extends ReactWebViewPanelController<
141
144
graphFileContent : this . executionPlanContents ,
142
145
graphFileType : ".sqlplan" ,
143
146
} ;
144
- this . state . executionPlan =
145
- await this . executionPlanService . getExecutionPlan ( planFile ) ;
146
- this . state . executionPlanGraphs = this . state . executionPlan . graphs ;
147
+ try {
148
+ this . state . executionPlan =
149
+ await this . executionPlanService . getExecutionPlan ( planFile ) ;
150
+ this . state . executionPlanGraphs = this . state . executionPlan . graphs ;
151
+ this . state . loadState = ApiStatus . Loaded ;
152
+ this . state . totalCost = this . calculateTotalCost ( ) ;
153
+ } catch ( e ) {
154
+ this . state . loadState = ApiStatus . Error ;
155
+ this . state . errorMessage = e . toString ( ) ;
156
+ }
147
157
}
158
+ this . updateState ( ) ;
148
159
}
149
160
150
161
private calculateTotalCost ( ) : number {
@@ -154,4 +165,8 @@ export class ExecutionPlanWebViewController extends ReactWebViewPanelController<
154
165
}
155
166
return sum ;
156
167
}
168
+
169
+ private updateState ( ) {
170
+ this . state = this . state ;
171
+ }
157
172
}
0 commit comments