Skip to content

Commit 84f91a8

Browse files
add saveData() hook and post to tableView.ts (#25)
1 parent 1051441 commit 84f91a8

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/views/tableView.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,12 @@ export class TableView {
155155
const text = message.text;
156156
switch (command) {
157157
case 'refresh':
158-
// relad data view and config
158+
// reload data view and config
159159
this.refresh();
160+
break;
161+
case 'saveData':
162+
this.saveData(message.data, message.dataFileName, message.dataFileType);
163+
break;
160164
}
161165
}, undefined, this._disposables);
162166
}
@@ -187,6 +191,14 @@ export class TableView {
187191
});
188192
}
189193

194+
/**
195+
* Saves table data in a new data file.
196+
*/
197+
public async saveData(data: any, dataFileName: string, dataFileType: string): Promise<void> {
198+
console.log('tabView:saveData(): saving data:', dataFileName);
199+
this.logTextData(data);
200+
}
201+
190202
/**
191203
* Logs truncated text data for debug.
192204
*

web/scripts/tableView.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const vscode = acquireVsCodeApi();
66
// data document vars
77
let documentUrl = '';
88
let fileName = '';
9+
let saveDataFileName = '';
910

1011
// table view vars
1112
let tableContainer, table, progressRing, saveFileTypeSelector;
@@ -187,9 +188,15 @@ function loadData(tableData, documentUrl) {
187188
downloadReady: function (fileContents, blob) {
188189
// fileContents - unencoded contents of the file to save
189190
// blob - blob object for data file download/save
190-
console.log(fileContents);
191+
// console.log(fileContents);
191192

192-
// TODO: save data via vscode workspace.fs api
193+
// request data file save
194+
vscode.postMessage({
195+
command: 'saveData',
196+
data: fileContents,
197+
dataFileType: saveFileTypeSelector.value,
198+
dataFileName: saveDataFileName
199+
});
193200

194201
// Note: this must return a blob to proceed with the download in a browser,
195202
// or false to abort download and handle it in table view extension with workspace.fs
@@ -240,13 +247,14 @@ function addData(table, tableData) {
240247
}
241248

242249
/**
243-
* Saves table data.
250+
* Saves table data as CSV or JSON for now.
244251
*/
245252
function saveData() {
246253
const dataFileType = saveFileTypeSelector.value;
247254
const dataFileName = fileName.substring(0, fileName.lastIndexOf('.') + 1);
248-
console.log('tabView:saveData(): saving data:', dataFileName + dataFileType);
249-
table.download(dataFileType, dataFileName + dataFileType);
255+
saveDataFileName = dataFileName + dataFileType;
256+
console.log('tabView:saveData(): saving data:', saveDataFileName);
257+
table.download(dataFileType, saveDataFileName);
250258
}
251259

252260
/**

0 commit comments

Comments
 (0)