Skip to content

Commit

Permalink
export : download csv #26
Browse files Browse the repository at this point in the history
  • Loading branch information
dufoli committed Mar 23, 2024
1 parent 2aeea16 commit 1a90802
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
- Export: Support comments in SOQL / SOSL
- Export: format query SOQL/ SOSL
- Export: keep header on top of result on scrolling
- Export: Add download CSV
- Inspect: suggest value for picklist
- Import: assignment rule for Lead, Case and Account
- Popup: increase height of pannel and move it heigher
- Fix misc bugs (conecteed app,...)
- Log: Fix encoding for log dowload

## Version 1.23

Expand Down
17 changes: 17 additions & 0 deletions addon/data-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,16 @@ class Model {
let separator = getSeparator();
copyToClipboard(this.exportedData.csvSerialize(separator));
}
downloadCsv() {
let separator = getSeparator();
let downloadLink = document.createElement("a");
const date = new Date();
const timestamp = date.toISOString().replace(/[^0-9]/g, "");
downloadLink.download = `export${timestamp}.csv`;
let BOM = "\uFEFF";
downloadLink.href = "data:text/csv;charset=utf-8," + BOM + encodeURI(this.exportedData.csvSerialize(separator));
downloadLink.click();
}
copyAsJson() {
copyToClipboard(JSON.stringify(this.exportedData.records, null, " "));
}
Expand Down Expand Up @@ -1669,6 +1679,7 @@ class App extends React.Component {
this.onQueryPlan = this.onQueryPlan.bind(this);
this.onCopyAsExcel = this.onCopyAsExcel.bind(this);
this.onCopyAsCsv = this.onCopyAsCsv.bind(this);
this.onDownloadCsv = this.onDownloadCsv.bind(this);
this.onCopyAsJson = this.onCopyAsJson.bind(this);
this.onDeleteRecords = this.onDeleteRecords.bind(this);
this.onResultsFilterInput = this.onResultsFilterInput.bind(this);
Expand Down Expand Up @@ -1792,6 +1803,11 @@ class App extends React.Component {
model.copyAsCsv();
model.didUpdate();
}
onDownloadCsv() {
let {model} = this.props;
model.downloadCsv();
model.didUpdate();
}
onCopyAsJson() {
let {model} = this.props;
model.copyAsJson();
Expand Down Expand Up @@ -1986,6 +2002,7 @@ class App extends React.Component {
h("div", {className: "result-bar"},
h("h1", {}, "Export Result"),
h("div", {className: "button-group"},
h("button", {disabled: !model.canCopy(), onClick: this.onDownloadCsv, title: "Download csv file of exported data"}, "Download (CSV format)"),
h("button", {disabled: !model.canCopy(), onClick: this.onCopyAsExcel, title: "Copy exported data to clipboard for pasting into Excel or similar"}, "Copy (Excel format)"),
h("button", {disabled: !model.canCopy(), onClick: this.onCopyAsCsv, title: "Copy exported data to clipboard for saving as a CSV file"}, "Copy (CSV)"),
h("button", {disabled: !model.canCopy(), onClick: this.onCopyAsJson, title: "Copy raw API output to clipboard"}, "Copy (JSON)"),
Expand Down
3 changes: 2 additions & 1 deletion addon/data-load.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ function renderCell(rt, cell, td) {
sfConn.rest(e.target.id, {responseType: "text/csv"}).then(data => {
let downloadLink = document.createElement("a");
downloadLink.download = recordId.split("/")[6];
downloadLink.href = "data:text/csv;charset=utf-8," + data;
let BOM = "\uFEFF";
downloadLink.href = "data:text/csv;charset=utf-8," + BOM + encodeURI(data);
downloadLink.click();
});
td.removeChild(pop);
Expand Down
3 changes: 2 additions & 1 deletion addon/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,8 @@ class App extends React.Component {
let {model} = this.props;
let downloadLink = document.createElement("a");
downloadLink.download = model.recordId + ".txt";
downloadLink.href = "data:text/plain;charset=utf-8," + model.logData;
let BOM = "\uFEFF";
downloadLink.href = "data:text/plain;charset=utf-8," + BOM + encodeURI(model.logData);
downloadLink.click();
}

Expand Down

0 comments on commit 1a90802

Please sign in to comment.