Skip to content

Commit 7a5f68f

Browse files
committed
HUE-9352 [editor] Wait with showing the execute button until the session is loaded in editor v2
1 parent e925014 commit 7a5f68f

File tree

2 files changed

+56
-15
lines changed

2 files changed

+56
-15
lines changed

desktop/core/src/desktop/js/apps/notebook2/components/ko.executableActions.js

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import DisposableComponent from 'ko/components/DisposableComponent';
2121
import huePubSub from 'utils/huePubSub';
2222
import I18n from 'utils/i18n';
2323
import { EXECUTABLE_UPDATED_EVENT, EXECUTION_STATUS } from 'apps/notebook2/execution/executable';
24+
import sessionManager from 'apps/notebook2/execution/sessionManager';
2425

2526
export const NAME = 'executable-actions';
2627

@@ -30,24 +31,32 @@ export const EXECUTE_ACTIVE_EXECUTABLE_EVENT = 'executable.active.executable';
3031
const TEMPLATE = `
3132
<div class="snippet-execute-actions" data-test="${ NAME }">
3233
<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 -->
3339
<!-- 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>
3743
<!-- /ko -->
3844
<!-- ko if: showStop -->
3945
<!-- 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 -->
4754
</button>
4855
<!-- /ko -->
4956
<!-- 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>
5160
<!-- /ko -->
5261
<!-- /ko -->
5362
</div>
@@ -68,6 +77,8 @@ class ExecutableActions extends DisposableComponent {
6877
this.partOfRunningExecution = ko.observable(false);
6978
this.beforeExecute = params.beforeExecute;
7079

80+
this.lastSession = ko.observable();
81+
7182
this.limit = ko.observable();
7283

7384
this.subscribe(this.limit, newVal => {
@@ -83,12 +94,16 @@ class ExecutableActions extends DisposableComponent {
8394
this.partOfRunningExecution()
8495
);
8596

97+
this.showLoading = ko.pureComputed(() => !this.lastSession());
98+
8699
this.showExecute = ko.pureComputed(
87100
() =>
101+
!this.showLoading() &&
88102
this.status() !== EXECUTION_STATUS.running &&
89103
this.status() !== EXECUTION_STATUS.streaming &&
90104
!this.waiting()
91105
);
106+
92107
this.showStop = ko.pureComputed(
93108
() =>
94109
this.status() === EXECUTION_STATUS.running ||
@@ -100,8 +115,10 @@ class ExecutableActions extends DisposableComponent {
100115
const executable = this.activeExecutable();
101116

102117
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)))
105122
);
106123
});
107124

@@ -125,9 +142,17 @@ class ExecutableActions extends DisposableComponent {
125142
}
126143

127144
updateFromExecutable(executable) {
145+
const waitForSession =
146+
!this.lastSession() || this.lastSession().type !== executable.executor.connector().type;
128147
this.status(executable.status);
129148
this.partOfRunningExecution(executable.isPartOfRunningExecution());
130149
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+
}
131156
}
132157

133158
async stop() {

desktop/core/src/desktop/js/apps/notebook2/components/ko.executableActions.test.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ import { koSetup } from 'jest/koTestUtils';
33
import { NAME } from './ko.executableActions';
44
import { EXECUTABLE_UPDATED_EVENT, EXECUTION_STATUS } from 'apps/notebook2/execution/executable';
55
import { sleep } from 'utils/hueUtils';
6+
import sessionManager from 'apps/notebook2/execution/sessionManager';
67

78
describe('ko.executableActions.js', () => {
89
const setup = koSetup();
910

1011
it('should render component', async () => {
12+
const spy = spyOn(sessionManager, 'getSession').and.returnValue(
13+
Promise.resolve({ type: 'foo' })
14+
);
1115
const mockExecutable = {
1216
cancel: () => {},
1317
cancelBatchChain: () => {},
@@ -17,7 +21,10 @@ describe('ko.executableActions.js', () => {
1721
reset: () => {},
1822
nextExecutable: {},
1923
executor: {
20-
defaultLimit: () => {}
24+
defaultLimit: () => {},
25+
connector: () => ({
26+
id: 'foo'
27+
})
2128
},
2229
status: EXECUTION_STATUS.ready
2330
};
@@ -27,10 +34,14 @@ describe('ko.executableActions.js', () => {
2734
activeExecutable: activeExecutable
2835
});
2936

37+
expect(spy).toHaveBeenCalled();
3038
expect(element.querySelector('[data-test="' + NAME + '"]')).toBeTruthy();
3139
});
3240

3341
it('should handle execute and stop clicks', async () => {
42+
const spy = spyOn(sessionManager, 'getSession').and.returnValue(
43+
Promise.resolve({ type: 'foo' })
44+
);
3445
let executeCalled = false;
3546
let cancelCalled = false;
3647
const mockExecutable = {
@@ -48,7 +59,10 @@ describe('ko.executableActions.js', () => {
4859
reset: () => {},
4960
nextExecutable: {},
5061
executor: {
51-
defaultLimit: () => {}
62+
defaultLimit: () => {},
63+
connector: () => ({
64+
id: 'foo'
65+
})
5266
},
5367
status: EXECUTION_STATUS.ready
5468
};
@@ -58,6 +72,8 @@ describe('ko.executableActions.js', () => {
5872
activeExecutable: activeExecutable
5973
});
6074

75+
expect(spy).toHaveBeenCalled();
76+
6177
// Click play
6278
expect(executeCalled).toBeFalsy();
6379
expect(wrapper.querySelector('[data-test="execute"]')).toBeTruthy();

0 commit comments

Comments
 (0)