@@ -21,6 +21,7 @@ import DisposableComponent from 'ko/components/DisposableComponent';
21
21
import huePubSub from 'utils/huePubSub' ;
22
22
import I18n from 'utils/i18n' ;
23
23
import { EXECUTABLE_UPDATED_EVENT , EXECUTION_STATUS } from 'apps/notebook2/execution/executable' ;
24
+ import sessionManager from 'apps/notebook2/execution/sessionManager' ;
24
25
25
26
export const NAME = 'executable-actions' ;
26
27
@@ -30,24 +31,32 @@ export const EXECUTE_ACTIVE_EXECUTABLE_EVENT = 'executable.active.executable';
30
31
const TEMPLATE = `
31
32
<div class="snippet-execute-actions" data-test="${ NAME } ">
32
33
<div class="btn-group">
34
+ <!-- ko if: showLoading -->
35
+ <button class="btn btn-primary btn-mini btn-execute disable-feedback" disabled title="${ I18n ( 'Creating session' ) } ">
36
+ <i class="fa fa-fw fa-spinner fa-spin"></i> ${ I18n ( 'Loading' ) }
37
+ </button>
38
+ <!-- /ko -->
33
39
<!-- ko if: showExecute -->
34
- <button class="btn btn-primary btn-mini btn-execute disable-feedback" data-test="execute" data-bind="click: execute, disable: disabled"><i class="fa fa-play fa-fw"></i> ${ I18n (
35
- 'Execute'
36
- ) } </button>
40
+ <button class="btn btn-primary btn-mini btn-execute disable-feedback" data-test="execute" data-bind="click: execute, disable: disabled">
41
+ <i class="fa fa-fw fa-play"></i> ${ I18n ( 'Execute' ) }
42
+ </button>
37
43
<!-- /ko -->
38
44
<!-- ko if: showStop -->
39
45
<!-- ko ifnot: stopping -->
40
- <button class="btn btn-danger btn-mini btn-execute disable-feedback" data-test="stop" data-bind="click: stop"><i class="fa fa-stop fa-fw"></i>
41
- <!-- ko ifnot: waiting -->
42
- ${ I18n ( 'Stop' ) }
43
- <!-- /ko -->
44
- <!-- ko if: waiting -->
45
- ${ I18n ( 'Stop batch' ) }
46
- <!-- /ko -->
46
+ <button class="btn btn-danger btn-mini btn-execute disable-feedback" data-test="stop" data-bind="click: stop">
47
+ <i class="fa fa-stop fa-fw"></i>
48
+ <!-- ko ifnot: waiting -->
49
+ ${ I18n ( 'Stop' ) }
50
+ <!-- /ko -->
51
+ <!-- ko if: waiting -->
52
+ ${ I18n ( 'Stop batch' ) }
53
+ <!-- /ko -->
47
54
</button>
48
55
<!-- /ko -->
49
56
<!-- ko if: stopping -->
50
- <button class="btn btn-primary btn-mini btn-execute disable-feedback disabled"><i class="fa fa-spinner fa-spin fa-fw"></i>${ I18n ( 'Stopping' ) } </button>
57
+ <button class="btn btn-primary btn-mini btn-execute disable-feedback disabled">
58
+ <i class="fa fa-fw fa-spinner fa-spin"></i> ${ I18n ( 'Stopping' ) }
59
+ </button>
51
60
<!-- /ko -->
52
61
<!-- /ko -->
53
62
</div>
@@ -68,6 +77,8 @@ class ExecutableActions extends DisposableComponent {
68
77
this . partOfRunningExecution = ko . observable ( false ) ;
69
78
this . beforeExecute = params . beforeExecute ;
70
79
80
+ this . lastSession = ko . observable ( ) ;
81
+
71
82
this . limit = ko . observable ( ) ;
72
83
73
84
this . subscribe ( this . limit , newVal => {
@@ -83,12 +94,16 @@ class ExecutableActions extends DisposableComponent {
83
94
this . partOfRunningExecution ( )
84
95
) ;
85
96
97
+ this . showLoading = ko . pureComputed ( ( ) => ! this . lastSession ( ) ) ;
98
+
86
99
this . showExecute = ko . pureComputed (
87
100
( ) =>
101
+ ! this . showLoading ( ) &&
88
102
this . status ( ) !== EXECUTION_STATUS . running &&
89
103
this . status ( ) !== EXECUTION_STATUS . streaming &&
90
104
! this . waiting ( )
91
105
) ;
106
+
92
107
this . showStop = ko . pureComputed (
93
108
( ) =>
94
109
this . status ( ) === EXECUTION_STATUS . running ||
@@ -100,8 +115,10 @@ class ExecutableActions extends DisposableComponent {
100
115
const executable = this . activeExecutable ( ) ;
101
116
102
117
return (
103
- ! executable ||
104
- ( executable . parsedStatement && WHITE_SPACE_REGEX . test ( executable . parsedStatement . statement ) )
118
+ ! this . lastSession ( ) ||
119
+ ( ! executable ||
120
+ ( executable . parsedStatement &&
121
+ WHITE_SPACE_REGEX . test ( executable . parsedStatement . statement ) ) )
105
122
) ;
106
123
} ) ;
107
124
@@ -125,9 +142,17 @@ class ExecutableActions extends DisposableComponent {
125
142
}
126
143
127
144
updateFromExecutable ( executable ) {
145
+ const waitForSession =
146
+ ! this . lastSession ( ) || this . lastSession ( ) . type !== executable . executor . connector ( ) . type ;
128
147
this . status ( executable . status ) ;
129
148
this . partOfRunningExecution ( executable . isPartOfRunningExecution ( ) ) ;
130
149
this . limit ( executable . executor . defaultLimit ( ) ) ;
150
+ if ( waitForSession ) {
151
+ this . lastSession ( undefined ) ;
152
+ sessionManager
153
+ . getSession ( { type : executable . executor . connector ( ) . id } )
154
+ . then ( this . lastSession ) ;
155
+ }
131
156
}
132
157
133
158
async stop ( ) {
0 commit comments