Skip to content

Commit

Permalink
Preserve the selected view on scenario result updates (#1776)
Browse files Browse the repository at this point in the history
Previously, we always reverted back to the table view when the
scenario results changed. This PR changes this to preserve the
selected view.

I’ve also tested that this does not break backwards compatibility: If
you use the newer extension with an older SDK, you will get the
previous behavior of reverting to the table view and you can still
switch by clicking on the button.

Fixes #1675
  • Loading branch information
cocreature committed Jun 20, 2019
1 parent e04f15c commit 647c4d5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
Expand Up @@ -920,13 +920,38 @@ renderScenarioResult world res = TL.toStrict $ Blaze.renderHtml $ do

javascript :: T.Text
javascript = T.unlines
[ "function show_archived_changed() {"
[ "const vscode = acquireVsCodeApi();"
, "function show_archived_changed() {"
, " document.body.classList.toggle('hide_archived', !document.getElementById('show_archived').checked);"
, "}"
, "function toggle_view() {"
, " document.body.classList.toggle('hide_transaction');"
, " document.body.classList.toggle('hide_table');"
, " vscode.postMessage({"
, " 'command': 'selected_view',"
, " 'value': document.body.classList.contains('hide_transaction') ? 'table' : 'transaction'"
, " });"
, "}"
, "window.addEventListener('message', event => {"
, " const message = event.data;"
, " switch (message.command) {"
, " case 'select_view':"
, " switch (message.value) {"
, " case 'transaction':"
, " document.body.classList.remove('hide_transaction');"
, " document.body.classList.add('hide_table');"
, " break;"
, " case 'table':"
, " document.body.classList.add('hide_transaction');"
, " document.body.classList.remove('hide_table');"
, " break;"
, " default:"
, " console.log('Unexpected value for select_view: ' + message.value);"
, " break;"
, " }"
, " break;"
, " }"
, "});"
]

stylesheet :: T.Text
Expand Down
17 changes: 17 additions & 0 deletions daml-foundations/daml-tools/daml-extension/src/extension.ts
Expand Up @@ -266,8 +266,12 @@ namespace DamlWorkspaceValidationsNotification {
}

class VirtualResourceManager {
// Mapping from URIs to the web view panel
private _panels: Map<string, vscode.WebviewPanel> = new Map<string, vscode.WebviewPanel>();
// Mapping from URIs to the HTML content of the webview
private _panelContents: Map<string, string> = new Map<string, string>();
// Mapping from URIs to selected view
private _panelStates: Map<string, string> = new Map<string, string>();
private _client: LanguageClient;
private _disposables: vscode.Disposable[] = [];

Expand Down Expand Up @@ -316,6 +320,15 @@ class VirtualResourceManager {
null,
this._disposables
);
panel.webview.onDidReceiveMessage(
message => {
switch (message.command) {
case 'selected_view':
this._panelStates.set(uri, message.value);
break;
}
}
);
this._panels.set(uri, panel);
panel.webview.html = this._panelContents.get(uri) || '';
}
Expand All @@ -325,6 +338,10 @@ class VirtualResourceManager {
const panel = this._panels.get(uri);
if (panel) {
panel.webview.html = contents;
const panelState = this._panelStates.get(uri);
if (panelState) {
panel.webview.postMessage({command: 'select_view', value: panelState});
};
}
}

Expand Down
6 changes: 6 additions & 0 deletions unreleased.rst
Expand Up @@ -9,3 +9,9 @@ This page contains release notes for the SDK.
HEAD — ongoing
--------------

DAML Studio
~~~~~~~~~~~

- The selected view for scenario results (table or transaction) is now
preserved when the scenario results are updated.
See `#1675 <https://github.com/digital-asset/daml/issues/1675>`__.

0 comments on commit 647c4d5

Please sign in to comment.