Skip to content

Commit

Permalink
#24 save data table name in webview state for display on vscode reload
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomFractals committed Jun 12, 2019
1 parent 03b9df0 commit b81f164
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/data.preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export class DataPreviewSerializer implements WebviewPanelSerializer {
this.viewType,
this.extensionPath,
Uri.parse(state.uri),
state.config, // view config
state.table, // data table
state.config, // data view config
webviewPanel.viewColumn,
this.htmlTemplate,
webviewPanel
Expand Down Expand Up @@ -86,6 +87,7 @@ export class DataPreview {
* @param viewType Preview webview type, i.e. data.preview.
* @param extensionPath Extension path for loading webview scripts, etc.
* @param uri Source data file uri to preview.
* @param table Data table name.
* @param viewConfig Data view config.
* @param viewColumn vscode IDE view column to display data preview in.
* @param htmlTemplate Webview html template reference.
Expand All @@ -95,6 +97,7 @@ export class DataPreview {
viewType: string,
extensionPath: string,
uri: Uri,
table: string,
viewConfig: any,
viewColumn: ViewColumn,
htmlTemplate: Template,
Expand All @@ -103,6 +106,7 @@ export class DataPreview {
// save ext path, document uri, view config, and create preview uri
this._extensionPath = extensionPath;
this._uri = uri;
this._dataTable = (table !== undefined) ? table: '';
this._config = viewConfig;
this._fileName = path.basename(uri.fsPath);
this._fileExtension = this._fileName.substr(this._fileName.lastIndexOf('.'));
Expand Down Expand Up @@ -691,6 +695,13 @@ export class DataPreview {
return this._schema;
}

/**
* Gets data table name for data files with multiple data sets on vscode reload.
*/
get table(): string {
return this._dataTable;
}

/**
* Gets UI theme to use for Data Preview display from workspace config.
* see package.json 'configuration' section for more info.
Expand Down
4 changes: 3 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ function createDataPreviewCommand(
}
}
const preview: DataPreview = new DataPreview(viewType,
extensionPath, resource, {}, // viewConfig
extensionPath, resource,
'', // default data table
{}, // data view config
viewColumn, viewTemplate);
previewManager.add(preview);
return preview.webview;
Expand Down
2 changes: 1 addition & 1 deletion templates/data.view.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
// check view config
if (JSON.stringify(viewConfig) != JSON.stringify(data.config)) {
viewConfig = data.config;
vscode.setState({uri: dataUri, config: viewConfig});
vscode.setState({uri: dataUri, table: dataTable, config: viewConfig});
// update view config
viewer.restore(viewConfig);
// reset view data for reaload
Expand Down

0 comments on commit b81f164

Please sign in to comment.