File picker issues on CSV parsing (#5025)

* fix: csv parsing for multiline values

* fix: remove escape characters while copying inspector values

* add: defalut value for null/undefined cells
This commit is contained in:
vjaris42 2023-01-24 11:45:57 +05:30 committed by GitHub
parent d5e7bbc53d
commit 82cad72fc3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 14 deletions

View file

@ -386,25 +386,18 @@ FilePicker.AcceptedFiles = ({ children, width, height }) => {
};
const processCSV = (str, delimiter = ',') => {
const headers = str.slice(0, str.indexOf('\n')).split(delimiter);
const rows = str.slice(str.indexOf('\n') + 1).split('\n');
try {
const newArray = rows.map((row) => {
const values = row.split(delimiter);
const eachObject = headers.reduce((obj, header, i) => {
obj[header] = values[i];
return obj;
}, {});
return eachObject;
});
return newArray;
const wb = XLSX.read(str, { type: 'string' });
const wsname = wb.SheetNames[0];
const ws = wb.Sheets[wsname];
const data = XLSX.utils.sheet_to_json(ws, { delimiter, defval: '' });
return data;
} catch (error) {
console.log(error);
handleErrors(error);
}
};
const processXls = (str) => {
try {
const wb = XLSX.read(str, { type: 'base64' });

View file

@ -122,7 +122,7 @@ export const LeftSidebarInspector = ({
};
const copyToClipboard = (data) => {
const stringified = JSON.stringify(data, null, 2);
const stringified = JSON.stringify(data, null, 2).replace(/\\/g, '');
navigator.clipboard.writeText(stringified);
return toast.success('Copied to the clipboard', { position: 'top-center' });
};