Skip to content

Commit 888c27f

Browse files
committed
No longer replace results with error and instead undo cell change
Signed-off-by: worksofliam <[email protected]>
1 parent 77aa0f4 commit 888c27f

File tree

2 files changed

+50
-11
lines changed

2 files changed

+50
-11
lines changed

src/views/results/html.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,32 @@ export function generateScroller(basicSelect: string, isCL: boolean, withCancel?
9595
}
9696
}, { threshold: [0] }).observe(document.getElementById(messageSpanId));
9797
98+
let updateRequests = {};
99+
100+
function requestCellUpdate(cellNode, originalValue, statement, bindings) {
101+
const randomId = Math.floor(Math.random() * 1000000);
102+
updateRequests[randomId] = {cellNode, originalValue};
103+
104+
vscode.postMessage({
105+
command: 'update',
106+
id: randomId,
107+
update: statement,
108+
bindings: bindings
109+
});
110+
}
111+
112+
function handleCellResponse(id, success) {
113+
const previousRequest = updateRequests[id];
114+
115+
if (previousRequest) {
116+
if (!success) {
117+
previousRequest.cellNode.innerText = previousRequest.originalValue;
118+
}
119+
120+
delete updateRequests[id];
121+
}
122+
}
123+
98124
document.getElementById('resultset').onclick = function(e){
99125
console.log('click')
100126
if (updateTable === undefined) return;
@@ -219,11 +245,7 @@ export function generateScroller(basicSelect: string, isCL: boolean, withCancel?
219245
220246
editableNode = undefined;
221247
222-
vscode.postMessage({
223-
command: 'update',
224-
update: updateStatement,
225-
bindings: bindings
226-
});
248+
requestCellUpdate(target, chosenValue, updateStatement, bindings);
227249
}
228250
229251
editableNode.addEventListener('blur', (e) => {
@@ -246,6 +268,11 @@ export function generateScroller(basicSelect: string, isCL: boolean, withCancel?
246268
}
247269
248270
switch (data.command) {
271+
case 'cellResponse':
272+
if (data.id) {
273+
handleCellResponse(data.id, data.success === true);
274+
}
275+
break;
249276
case 'rows':
250277
hideSpinner();
251278

src/views/results/resultSetPanelProvider.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CancellationToken, WebviewPanel, WebviewView, WebviewViewProvider, WebviewViewResolveContext, commands } from "vscode";
1+
import { window, CancellationToken, WebviewPanel, WebviewView, WebviewViewProvider, WebviewViewResolveContext, commands } from "vscode";
22

33
import { setCancelButtonVisibility } from ".";
44
import { JobManager } from "../../config";
@@ -44,21 +44,33 @@ export class ResultSetPanelProvider implements WebviewViewProvider {
4444
};
4545

4646
webviewView.webview.html = html.getLoadingHTML();
47+
48+
const postCellResponse = (id: number, success: boolean) => {
49+
this._view.webview.postMessage({
50+
command: `cellResponse`,
51+
id,
52+
success
53+
});
54+
}
55+
4756
this._view.webview.onDidReceiveMessage(async (message) => {
4857
switch (message.command) {
4958
case `cancel`:
5059
this.endQuery();
5160
break;
5261

5362
case `update`:
54-
if (message.update && message.bindings) {
63+
if (message.id && message.update && message.bindings) {
5564
try {
5665
const result = await JobManager.runSQL(message.update, {parameters: message.bindings});
66+
postCellResponse(message.id, true);
5767
} catch (e) {
58-
this.setError(e.message);
59-
if (this.currentQuery) {
60-
this.currentQuery.close();
61-
}
68+
// this.setError(e.message);
69+
// if (this.currentQuery) {
70+
// this.currentQuery.close();
71+
// }
72+
postCellResponse(message.id, false);
73+
window.showWarningMessage(e.message);
6274
}
6375
}
6476
break;

0 commit comments

Comments
 (0)