@@ -29,6 +29,7 @@ import { FieldSource } from '../components/ComponentType';
2929
3030import ChevronLeftIcon from '@mui/icons-material/ChevronLeft' ;
3131import DeleteIcon from '@mui/icons-material/Delete' ;
32+ import FileDownloadIcon from '@mui/icons-material/FileDownload' ;
3233import { dfActions , dfSelectors } from '../app/dfSlice' ;
3334import { useDispatch , useSelector } from 'react-redux' ;
3435import { 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