Skip to content

Commit 4d9db38

Browse files
#23 data view config load/save patch for data refresh
1 parent e4159ea commit 4d9db38

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/data.preview.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,13 @@ export class DataPreview {
296296
this._logger.debug('loadConfig(): loading config:', configFilePath);
297297
const configString: string = fs.readFileSync(configFilePath, 'utf8'); // file encoding to read data as string
298298
const viewConfig: any = JSON.parse(configString);
299-
if (this._uri.fsPath.indexOf(viewConfig.fileName) >=0) { // matching data file config
299+
if (this._uri.fsPath.indexOf(viewConfig.dataFileName) >=0) { // matching data file config
300300
this._config = viewConfig.config;
301301
this._logger.debug('loadConfig(): loaded view config:', this._config);
302302
this.refresh(); // reload data & config for display
303303
}
304304
else {
305-
window.showErrorMessage(`Not a matching data view config for '${this._fileName}'!`);
305+
window.showErrorMessage(`Config doesn't match data file: '${this._fileName}'!`);
306306
}
307307
}
308308
}

templates/data.view.html

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@
5757
<option value=".csv">csv</option>
5858
</select>
5959
</div>
60-
<div>🈸 <a id="title" title="load data view config" href="#" onclick="loadConfig()"></a></div>
60+
<div>🈸 <a id="title" title="Load data view config" href="#" onclick="loadConfig()"></a></div>
6161
</div>
6262
<perspective-viewer id="data-viewer" view="grid"></perspective-viewer>
6363
<script type="text/javascript">
6464
// data preview vars
65-
let vscode, title, fileTypeSelector, dataUri, viewer, viewConfig = {}, viewData = [];
65+
let vscode, title, fileTypeSelector, dataUri, viewer, toggleConfig = true, viewConfig = {}, viewData = [];
6666

6767
// check web assembly support. uncomment this for dev debug:
6868
// console.log(`data.preview:supportsWebAssembly(): ${supportsWebAssembly()}`);
@@ -117,14 +117,19 @@
117117
try {
118118
// set preview state for restore on vscode reload
119119
dataUri = data.uri;
120-
viewConfig = data.config;
121-
vscode.setState({uri: dataUri, config: viewConfig});
122120
title.innerText = data.fileName;
121+
// check view config
122+
if (JSON.stringify(viewConfig) != JSON.stringify(data.config)) {
123+
viewConfig = data.config;
124+
vscode.setState({uri: dataUri, config: viewConfig});
125+
// update view config
126+
viewer.restore(viewConfig);
127+
// reset view data for new view load
128+
viewData = [];
129+
}
123130

124131
// load file data
125132
const tableData = getData(data.fileName, data.data, data.schema);
126-
// update view config
127-
viewer.restore(viewConfig);
128133
if (Array.isArray(viewData) && viewData.length === 0) {
129134
// initialize perspective viewer
130135
console.log(`data.view:refresh(): initializing view data for: ${data.fileName}`);
@@ -136,7 +141,11 @@
136141
else {
137142
viewer.load(tableData);
138143
}
139-
viewer.toggleConfig();
144+
if (toggleConfig) {
145+
// show viewer toggles on the 1st run
146+
viewer.toggleConfig();
147+
toggleConfig = false;
148+
}
140149
} else { // update viewer data without toggles reset
141150
console.log(`data.view:refresh(): updating view data for: ${data.fileName}`);
142151
viewer.clear();
@@ -209,7 +218,7 @@
209218
switch (dataFileType) {
210219
case '.config':
211220
const data = {
212-
fileName: dataUri.substr(dataUri.lastIndexOf('/') + 1),
221+
dataFileName: dataUri.substr(dataUri.lastIndexOf('/') + 1),
213222
config: viewConfig
214223
};
215224
postData(dataFileType, data);

0 commit comments

Comments
 (0)