Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show save/discard for created record when updateRecords is unavailable #3215

Merged
merged 3 commits into from
Feb 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions packages/toolpad-components/src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,11 @@ function useDataProviderDataGridProps(
// Blurring the cell shouldn't end edit mode
if (params.reason === GridRowEditStopReasons.rowFocusOut) {
event.defaultMuiPrevented = true;
} else {
setRowModesModel({});
setDraftRow(null);
}
if (params.reason === GridRowEditStopReasons.escapeKeyDown) {
setRowModesModel({});
setDraftRow(null);
}
};
Expand Down Expand Up @@ -784,7 +788,7 @@ function useDataProviderDataGridProps(
return newRecord;
} catch (error) {
setActionResult({ action, error: errorFrom(error) });
throw error;
return oldRow;
}
} else {
try {
Expand All @@ -798,7 +802,7 @@ function useDataProviderDataGridProps(
return newRecord;
} catch (error) {
setActionResult({ action, id, error: errorFrom(error) });
throw error;
return oldRow;
}
}
} finally {
Expand All @@ -814,14 +818,14 @@ function useDataProviderDataGridProps(
);

const getActions = React.useMemo<GridActionsColDef['getActions'] | undefined>(() => {
if (!dataProvider?.deleteRecord && !dataProvider?.updateRecord) {
if (!dataProvider?.deleteRecord && !dataProvider?.updateRecord && !dataProvider?.createRecord) {
return undefined;
}

return ({ id, row }) => {
const result = [];

if (dataProvider.updateRecord) {
if (dataProvider.updateRecord || dataProvider.createRecord) {
const rowIsInEditMode = rowModesModel[id]?.mode === GridRowModes.Edit;
const rowIsUpdating = rowUpdating[id];

Expand Down Expand Up @@ -855,7 +859,7 @@ function useDataProviderDataGridProps(
];
}

if (!isEditing) {
if (!isEditing && dataProvider.updateRecord) {
result.push(
<IconButton
key="update"
Expand Down
Loading