From 1a9080272185ba7bbaab1609c96109cfb17f4032 Mon Sep 17 00:00:00 2001 From: olivier Dufour Date: Sat, 23 Mar 2024 14:28:52 +0100 Subject: [PATCH] export : download csv #26 --- CHANGES.md | 2 ++ addon/data-export.js | 17 +++++++++++++++++ addon/data-load.js | 3 ++- addon/log.js | 3 ++- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c9c4285b..ab92bdda 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/addon/data-export.js b/addon/data-export.js index b505123b..3e5b03d0 100644 --- a/addon/data-export.js +++ b/addon/data-export.js @@ -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, " ")); } @@ -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); @@ -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(); @@ -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)"), diff --git a/addon/data-load.js b/addon/data-load.js index 55ea3e53..4f4dc187 100644 --- a/addon/data-load.js +++ b/addon/data-load.js @@ -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); diff --git a/addon/log.js b/addon/log.js index 8615e960..529968d7 100644 --- a/addon/log.js +++ b/addon/log.js @@ -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(); }