From 1b352f94b6e45e49dfbf1518534585c2e72ca45f Mon Sep 17 00:00:00 2001 From: Jan Potoms <2109932+Janpot@users.noreply.github.com> Date: Tue, 16 Jan 2024 11:27:10 +0100 Subject: [PATCH] Tweak data providers UI in the grid (#3084) --- packages/toolpad-components/src/DataGrid.tsx | 53 ++++++++------------ 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/packages/toolpad-components/src/DataGrid.tsx b/packages/toolpad-components/src/DataGrid.tsx index a51b459ee72..42f4ceaea8b 100644 --- a/packages/toolpad-components/src/DataGrid.tsx +++ b/packages/toolpad-components/src/DataGrid.tsx @@ -66,9 +66,8 @@ import { IconButton, CircularProgress, Alert, - Collapse, Button, - useEventCallback, + Snackbar, } from '@mui/material'; import DeleteIcon from '@mui/icons-material/DeleteOutline'; import CloseIcon from '@mui/icons-material/Close'; @@ -91,6 +90,8 @@ import ErrorOverlay, { ErrorContent } from './components/ErrorOverlay'; const DRAFT_ROW_MARKER = Symbol('draftRow'); +const ACTIONS_COLUMN_FIELD = '___actions___'; + type MuiLicenseInfo = LicenseInfoProviderProps['info']; const LICENSE_INFO: MuiLicenseInfo = { @@ -982,7 +983,6 @@ interface ActionResultOverlayProps { } function ActionResultOverlay({ result, onClose, apiRef }: ActionResultOverlayProps) { - const [hovered, setHovered] = React.useState(false); const open = !!result; const actionError = result?.error; @@ -1034,36 +1034,24 @@ function ActionResultOverlay({ result, onClose, apiRef }: ActionResultOverlayPro } } - const handleClose = useEventCallback(() => { - onClose(); - }); - - React.useEffect(() => { - if (result && !hovered) { - const timeout = setTimeout(handleClose, 2000); - return () => { - clearTimeout(timeout); - }; - } - return () => {}; - }, [hovered, result, handleClose]); - return ( - - - - - } - onMouseEnter={() => setHovered(true)} - onMouseOut={() => setHovered(false)} - > + + + + } + > + {message} - + ); } @@ -1238,11 +1226,11 @@ const DataGridComponent = React.forwardRef(function DataGridComponent( if (getProviderActions) { result.push({ - field: '___actions', + field: ACTIONS_COLUMN_FIELD, type: 'actions', - headerName: '', - flex: 1, align: 'right', + resizable: false, + pinnable: false, getActions: getProviderActions, }); } @@ -1286,6 +1274,7 @@ const DataGridComponent = React.forwardRef(function DataGridComponent( getRowId={getRowId} onRowSelectionModelChange={onSelectionModelChange} rowSelectionModel={selectionModel} + initialState={{ pinnedColumns: { right: [ACTIONS_COLUMN_FIELD] } }} {...props} {...dataProviderProps} />