using json-2-csv package for the csv export now since the old package has not been updated in 4 years
This commit is contained in:
parent
eb5fd127e3
commit
cf559d48a2
4 changed files with 64 additions and 23 deletions
43
package-lock.json
generated
43
package-lock.json
generated
|
|
@ -22,6 +22,7 @@
|
||||||
"axios": "^1.7.7",
|
"axios": "^1.7.7",
|
||||||
"dayjs": "^1.11.13",
|
"dayjs": "^1.11.13",
|
||||||
"deep-object-diff": "^1.1.9",
|
"deep-object-diff": "^1.1.9",
|
||||||
|
"json-2-csv": "^5.5.8",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"moment": "^2.30.1",
|
"moment": "^2.30.1",
|
||||||
"moment-timezone": "^0.5.46",
|
"moment-timezone": "^0.5.46",
|
||||||
|
|
@ -44,6 +45,7 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/types": "^7.25.8",
|
"@babel/types": "^7.25.8",
|
||||||
"@eslint/js": "^9.11.1",
|
"@eslint/js": "^9.11.1",
|
||||||
|
"@types/jsonexport": "^3.0.5",
|
||||||
"@types/lodash": "^4.17.13",
|
"@types/lodash": "^4.17.13",
|
||||||
"@types/react": "^18.3.10",
|
"@types/react": "^18.3.10",
|
||||||
"@types/react-color": "^3.0.13",
|
"@types/react-color": "^3.0.13",
|
||||||
|
|
@ -3544,6 +3546,16 @@
|
||||||
"integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==",
|
"integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/jsonexport": {
|
||||||
|
"version": "3.0.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/jsonexport/-/jsonexport-3.0.5.tgz",
|
||||||
|
"integrity": "sha512-+zDVaDqNguePOU11YNEsuf/ZRS1ciHeKVYGjfvDFmgG6aCy/s4W4Wy1MiXJIbiyMJLuakGLENCndvmGZpVTV1w==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@types/lodash": {
|
"node_modules/@types/lodash": {
|
||||||
"version": "4.17.13",
|
"version": "4.17.13",
|
||||||
"integrity": "sha512-lfx+dftrEZcdBPczf9d0Qv0x+j/rfNCMuC6OcfXmO8gkfeNAY88PgKUbvG56whcN23gc27yenwF6oJZXGFpYxg==",
|
"integrity": "sha512-lfx+dftrEZcdBPczf9d0Qv0x+j/rfNCMuC6OcfXmO8gkfeNAY88PgKUbvG56whcN23gc27yenwF6oJZXGFpYxg==",
|
||||||
|
|
@ -4787,6 +4799,15 @@
|
||||||
"integrity": "sha512-qIMFpTMZmny+MMIitAB6D7iVPEorVw6YQRWkvarTkT4tBeSLLiHzcwj6q0MmYSFCiVpiqPJTJEYIrpcPzVEIvg==",
|
"integrity": "sha512-qIMFpTMZmny+MMIitAB6D7iVPEorVw6YQRWkvarTkT4tBeSLLiHzcwj6q0MmYSFCiVpiqPJTJEYIrpcPzVEIvg==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/deeks": {
|
||||||
|
"version": "3.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/deeks/-/deeks-3.1.0.tgz",
|
||||||
|
"integrity": "sha512-e7oWH1LzIdv/prMQ7pmlDlaVoL64glqzvNgkgQNgyec9ORPHrT2jaOqMtRyqJuwWjtfb6v+2rk9pmaHj+F137A==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 16"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/deep-eql": {
|
"node_modules/deep-eql": {
|
||||||
"version": "5.0.2",
|
"version": "5.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-5.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-5.0.2.tgz",
|
||||||
|
|
@ -4878,6 +4899,15 @@
|
||||||
"node": ">=0.4.0"
|
"node": ">=0.4.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/doc-path": {
|
||||||
|
"version": "4.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/doc-path/-/doc-path-4.1.1.tgz",
|
||||||
|
"integrity": "sha512-h1ErTglQAVv2gCnOpD3sFS6uolDbOKHDU1BZq+Kl3npPqroU3dYL42lUgMfd5UimlwtRgp7C9dLGwqQ5D2HYgQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=16"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/dom-helpers": {
|
"node_modules/dom-helpers": {
|
||||||
"version": "5.2.1",
|
"version": "5.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/dom-helpers/-/dom-helpers-5.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/dom-helpers/-/dom-helpers-5.2.1.tgz",
|
||||||
|
|
@ -6479,6 +6509,19 @@
|
||||||
"node": ">=6"
|
"node": ">=6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/json-2-csv": {
|
||||||
|
"version": "5.5.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/json-2-csv/-/json-2-csv-5.5.8.tgz",
|
||||||
|
"integrity": "sha512-eMQHOwV+av8Sgo+fkbEbQWOw/kwh89AZ5fNA8TYfcooG6TG1ZOL2WcPUrngIMIK8dBJitQ8QEU0zbncQ0CX4CQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"deeks": "3.1.0",
|
||||||
|
"doc-path": "4.1.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 16"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/json-buffer": {
|
"node_modules/json-buffer": {
|
||||||
"version": "3.0.1",
|
"version": "3.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz",
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@
|
||||||
"axios": "^1.7.7",
|
"axios": "^1.7.7",
|
||||||
"dayjs": "^1.11.13",
|
"dayjs": "^1.11.13",
|
||||||
"deep-object-diff": "^1.1.9",
|
"deep-object-diff": "^1.1.9",
|
||||||
|
"json-2-csv": "^5.5.8",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"moment": "^2.30.1",
|
"moment": "^2.30.1",
|
||||||
"moment-timezone": "^0.5.46",
|
"moment-timezone": "^0.5.46",
|
||||||
|
|
@ -54,6 +55,7 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/types": "^7.25.8",
|
"@babel/types": "^7.25.8",
|
||||||
"@eslint/js": "^9.11.1",
|
"@eslint/js": "^9.11.1",
|
||||||
|
"@types/jsonexport": "^3.0.5",
|
||||||
"@types/lodash": "^4.17.13",
|
"@types/lodash": "^4.17.13",
|
||||||
"@types/react": "^18.3.10",
|
"@types/react": "^18.3.10",
|
||||||
"@types/react-color": "^3.0.13",
|
"@types/react-color": "^3.0.13",
|
||||||
|
|
|
||||||
|
|
@ -93,14 +93,11 @@ class ExportDataSettings extends React.Component<Props, State> {
|
||||||
};
|
};
|
||||||
|
|
||||||
submit = () => {
|
submit = () => {
|
||||||
console.log("submit export request")
|
|
||||||
const { device, component, newMeasurements, user } = this.props;
|
const { device, component, newMeasurements, user } = this.props;
|
||||||
const { startDate, endDate } = this.state;
|
const { startDate, endDate } = this.state;
|
||||||
const { sampleMeasurements, listUnitMeasurements } = this.context;
|
const { sampleMeasurements, listUnitMeasurements } = this.context;
|
||||||
|
|
||||||
this.setState({ isLoading: true });
|
this.setState({ isLoading: true });
|
||||||
console.log("Device")
|
|
||||||
console.log(device)
|
|
||||||
// if (newMeasurements) {
|
// if (newMeasurements) {
|
||||||
listUnitMeasurements(
|
listUnitMeasurements(
|
||||||
device.id(),
|
device.id(),
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
// import * as save from "save-svg-as-png";
|
// import * as save from "save-svg-as-png";
|
||||||
// import * as jsonexport from "jsonexport";
|
|
||||||
import { or } from "./types";
|
import { or } from "./types";
|
||||||
// const jsonexport = require("jsonexport");
|
|
||||||
// const save = require("save-svg-as-png")
|
// const save = require("save-svg-as-png")
|
||||||
|
import { json2csv } from 'json-2-csv';
|
||||||
|
|
||||||
export function saveSVG(element: string, filename: string, options: Object) {
|
export function saveSVG(element: string, filename: string, options: Object) {
|
||||||
// save.saveSvgAsPng(document.getElementById(element), filename, options);
|
// save.saveSvgAsPng(document.getElementById(element), filename, options);
|
||||||
|
|
@ -52,25 +51,25 @@ export function exportDataToCSV(filename: string, data: Array<any>) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// jsonexport(data, function(err: any, csv: any) {
|
let csv = json2csv(data)
|
||||||
// if (err) return console.log(err);
|
//console.log(csv)
|
||||||
// var blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
|
var blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
|
||||||
// var link = document.createElement("a");
|
var link = document.createElement("a");
|
||||||
// link.href = window.URL.createObjectURL(blob);
|
link.href = window.URL.createObjectURL(blob);
|
||||||
// link.download = or(filename, "generated") + ".csv";
|
link.download = or(filename, "generated") + ".csv";
|
||||||
// document.body.appendChild(link);
|
document.body.appendChild(link);
|
||||||
// link.click();
|
link.click();
|
||||||
// setTimeout(function() {
|
setTimeout(function() {
|
||||||
// document.body.removeChild(link);
|
document.body.removeChild(link);
|
||||||
// window.URL.revokeObjectURL(link.href);
|
window.URL.revokeObjectURL(link.href);
|
||||||
// }, 100);
|
}, 100);
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function exportJSON(filename: string, data: Array<any>) {
|
//deprecated function
|
||||||
if (!data || !data.length) {
|
// export function exportJSON(filename: string, data: Array<any>) {
|
||||||
return;
|
// if (!data || !data.length) {
|
||||||
}
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
// jsonexport(data, function(err: any, csv: any) {
|
// jsonexport(data, function(err: any, csv: any) {
|
||||||
// if (err) return console.log(err);
|
// if (err) return console.log(err);
|
||||||
|
|
@ -85,4 +84,4 @@ export function exportJSON(filename: string, data: Array<any>) {
|
||||||
// window.URL.revokeObjectURL(link.href);
|
// window.URL.revokeObjectURL(link.href);
|
||||||
// }, 100);
|
// }, 100);
|
||||||
// });
|
// });
|
||||||
}
|
//}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue