mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-05 22:38:48 +00:00
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:
parent
d5e7bbc53d
commit
82cad72fc3
2 changed files with 7 additions and 14 deletions
|
|
@ -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' });
|
||||
|
|
|
|||
|
|
@ -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' });
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue