Skip to content

Commit 825b970

Browse files
committed
refactor: update editable logic to new function
1 parent 684f0f2 commit 825b970

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

packages/toolpad-studio-components/src/DataGrid.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,11 @@ function getNarrowedColType(type?: string): GridColType | undefined {
479479
return (type && type in DEFAULT_COLUMN_TYPES ? type : undefined) as GridColType | undefined;
480480
}
481481

482-
export function parseColumns(columns: SerializableGridColumns, isEditable?: boolean): GridColDef[] {
482+
export function parseColumns(columns: SerializableGridColumns): GridColDef[] {
483483
return columns.map(({ type: colType, ...column }) => {
484484
const isIdColumn = column.field === 'id';
485485

486-
let baseColumn: Omit<GridColDef, 'field'> = { editable: isEditable };
486+
let baseColumn: Omit<GridColDef, 'field'> = {};
487487

488488
if (isIdColumn) {
489489
baseColumn = {
@@ -1244,8 +1244,8 @@ const DataGridComponent = React.forwardRef(function DataGridComponent(
12441244
);
12451245

12461246
const columns: GridColDef[] = React.useMemo(
1247-
() => (columnsProp ? parseColumns(columnsProp, isRowUpdateModelAvailable) : []),
1248-
[columnsProp, isRowUpdateModelAvailable],
1247+
() => (columnsProp ? parseColumns(columnsProp) : []),
1248+
[columnsProp],
12491249
);
12501250

12511251
React.useEffect(() => {
@@ -1270,7 +1270,17 @@ const DataGridComponent = React.forwardRef(function DataGridComponent(
12701270
}, [nodeRuntime, rows]);
12711271

12721272
const renderedColumns = React.useMemo<GridColDef[]>(() => {
1273-
const result = [...columns];
1273+
const mapEditableToColumns = columns.map((column) => {
1274+
if (column.editable || column.editable === false) {
1275+
return column;
1276+
}
1277+
1278+
column.editable = isRowUpdateModelAvailable;
1279+
1280+
return column;
1281+
});
1282+
1283+
const result = [...mapEditableToColumns];
12741284

12751285
if (getProviderActions) {
12761286
result.push({
@@ -1284,7 +1294,7 @@ const DataGridComponent = React.forwardRef(function DataGridComponent(
12841294
}
12851295

12861296
return result;
1287-
}, [columns, getProviderActions]);
1297+
}, [columns, getProviderActions, isRowUpdateModelAvailable]);
12881298

12891299
const appHost = useAppHost();
12901300
const isProPlan = appHost.plan === 'pro';

0 commit comments

Comments
 (0)