feat: structure text data for csv format
This commit is contained in:
@@ -194,17 +194,27 @@ export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRe
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Function to convert table data to CSV format
|
// Function to convert table data to CSV format
|
||||||
const convertToCSV = (data: any[], columns: string[]): string => {
|
const convertToCSV = (data: any[], columns: string[], isSchemaData: boolean = false): string => {
|
||||||
const header = columns.join(',');
|
if (isSchemaData) {
|
||||||
const rows = data.map(row =>
|
// For schema data, export as Label-Value pairs
|
||||||
columns.map(col => JSON.stringify(row[col] || "", null, 2)).join(',')
|
const header = 'Label,Value';
|
||||||
);
|
const rows = columns.map(column =>
|
||||||
return [header, ...rows].join('\n');
|
`"${column}","${data[0][column] || ""}"`
|
||||||
|
);
|
||||||
|
return [header, ...rows].join('\n');
|
||||||
|
} else {
|
||||||
|
// For regular table data, export as normal table
|
||||||
|
const header = columns.join(',');
|
||||||
|
const rows = data.map(row =>
|
||||||
|
columns.map(col => JSON.stringify(row[col] || "", null, 2)).join(',')
|
||||||
|
);
|
||||||
|
return [header, ...rows].join('\n');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function to download a specific dataset as CSV
|
// Function to download a specific dataset as CSV
|
||||||
const downloadCSV = (data: any[], columns: string[], filename: string) => {
|
const downloadCSV = (data: any[], columns: string[], filename: string, isSchemaData: boolean = false) => {
|
||||||
const csvContent = convertToCSV(data, columns);
|
const csvContent = convertToCSV(data, columns, isSchemaData);
|
||||||
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
|
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
|
||||||
const url = URL.createObjectURL(blob);
|
const url = URL.createObjectURL(blob);
|
||||||
|
|
||||||
@@ -304,7 +314,7 @@ export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRe
|
|||||||
|
|
||||||
<Button
|
<Button
|
||||||
component="a"
|
component="a"
|
||||||
onClick={() => downloadCSV(currentData, currentColumns, csvFilename)}
|
onClick={() => downloadCSV(currentData, currentColumns, csvFilename, isSchemaData)}
|
||||||
sx={{
|
sx={{
|
||||||
color: '#FF00C3',
|
color: '#FF00C3',
|
||||||
textTransform: 'none',
|
textTransform: 'none',
|
||||||
|
|||||||
Reference in New Issue
Block a user