Skip to content

Commit 86f559d

Browse files
committed
add a button to support download processed data
1 parent 48141a5 commit 86f559d

1 file changed

Lines changed: 34 additions & 2 deletions

File tree

src/views/SelectableDataGrid.tsx

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { FieldSource } from '../components/ComponentType';
2929

3030
import ChevronLeftIcon from '@mui/icons-material/ChevronLeft';
3131
import DeleteIcon from '@mui/icons-material/Delete';
32+
import FileDownloadIcon from '@mui/icons-material/FileDownload';
3233
import { dfActions, dfSelectors } from '../app/dfSlice';
3334
import { useDispatch, useSelector } from 'react-redux';
3435
import { getUrls } from '../app/utils';
@@ -266,13 +267,15 @@ export const SelectableDataGrid: React.FC<SelectableDataGridProps> = ({ rows, ta
266267
{`${rowsToDisplay.length} matches`}
267268
</Typography>: ''}
268269
</Box>
269-
<Tooltip key="delete-action" title={`Delete ${tableName}\n(note: all charts and concepts based on this table will be deleted)`}>
270+
{/* <Tooltip key="delete-action" title={`Delete ${tableName}\n(note: all charts and concepts based on this table will be deleted)`}>
270271
<IconButton size="small" color="warning" sx={{marginRight: 1}} onClick={() => {
271272
dispatch(dfActions.deleteTable(tableName))
272273
}}>
273274
<DeleteIcon/>
274275
</IconButton>
275-
</Tooltip>
276+
</Tooltip> */}
277+
278+
276279
<IconButton size="small" color="primary"
277280
onClick={() => {
278281
console.log(`[fyi] just sent request to process load data`);
@@ -452,6 +455,35 @@ export const SelectableDataGrid: React.FC<SelectableDataGridProps> = ({ rows, ta
452455
{footerActionsItems}
453456
</Collapse>
454457
<Box sx={{display: 'flex', alignItems: 'center', marginRight: 1}}>
458+
<Tooltip title={`Download ${tableName} as CSV`}>
459+
<IconButton size="small" color="primary" sx={{marginRight: 1}}
460+
onClick={() => {
461+
// Create CSV content
462+
const csvContent = [
463+
Object.keys(rows[0]).join(','), // Header row
464+
...rows.map(row => Object.values(row).map(value =>
465+
// Handle values that need quotes (contain commas or quotes)
466+
typeof value === 'string' && (value.includes(',') || value.includes('"'))
467+
? `"${value.replace(/"/g, '""')}"`
468+
: value
469+
).join(','))
470+
].join('\n');
471+
472+
// Create and trigger download
473+
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
474+
const link = document.createElement('a');
475+
const url = URL.createObjectURL(blob);
476+
link.setAttribute('href', url);
477+
link.setAttribute('download', `${tableName}.csv`);
478+
link.style.visibility = 'hidden';
479+
document.body.appendChild(link);
480+
link.click();
481+
document.body.removeChild(link);
482+
}}
483+
>
484+
<FileDownloadIcon/>
485+
</IconButton>
486+
</Tooltip>
455487
<Typography className="table-footer-number">
456488
{`${rows.length} rows`}
457489
</Typography>

0 commit comments

Comments
 (0)