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

<DatagridBody> creates the <RecordContext> instead of <DatagridRow> #9808

54 changes: 28 additions & 26 deletions packages/ra-ui-materialui/src/list/datagrid/DatagridBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { cloneElement, memo, FC, ReactElement } from 'react';
import PropTypes from 'prop-types';
import { SxProps, TableBody, TableBodyProps } from '@mui/material';
import clsx from 'clsx';
import { Identifier, RaRecord } from 'ra-core';
import { Identifier, RaRecord, RecordContextProvider } from 'ra-core';

import { DatagridClasses } from './useDatagridStyles';
import DatagridRow, { PureDatagridRow, RowClickFunction } from './DatagridRow';
Expand Down Expand Up @@ -34,31 +34,33 @@ const DatagridBody: FC<DatagridBodyProps> = React.forwardRef(
className={clsx('datagrid-body', className, DatagridClasses.tbody)}
{...rest}
>
{data.map((record, rowIndex) =>
cloneElement(
row,
{
className: clsx(DatagridClasses.row, {
[DatagridClasses.rowEven]: rowIndex % 2 === 0,
[DatagridClasses.rowOdd]: rowIndex % 2 !== 0,
}),
expand,
hasBulkActions: hasBulkActions && !!selectedIds,
hover,
id: record.id ?? `row${rowIndex}`,
key: record.id ?? `row${rowIndex}`,
onToggleItem,
record,
fzaninotto marked this conversation as resolved.
Show resolved Hide resolved
resource,
rowClick,
selectable: !isRowSelectable || isRowSelectable(record),
selected: selectedIds?.includes(record.id),
sx: rowSx?.(record, rowIndex),
style: rowStyle?.(record, rowIndex),
},
children
)
)}
{data.map((record, rowIndex) => (
<RecordContextProvider value={record} key={record.id}>
adguernier marked this conversation as resolved.
Show resolved Hide resolved
{cloneElement(
row,
{
className: clsx(DatagridClasses.row, {
[DatagridClasses.rowEven]: rowIndex % 2 === 0,
[DatagridClasses.rowOdd]: rowIndex % 2 !== 0,
}),
expand,
hasBulkActions: hasBulkActions && !!selectedIds,
hover,
id: record.id ?? `row${rowIndex}`,
key: record.id ?? `row${rowIndex}`,
adguernier marked this conversation as resolved.
Show resolved Hide resolved
onToggleItem,
resource,
rowClick,
selectable:
!isRowSelectable || isRowSelectable(record),
selected: selectedIds?.includes(record.id),
sx: rowSx?.(record, rowIndex),
style: rowStyle?.(record, rowIndex),
},
children
)}
</RecordContextProvider>
))}
</TableBody>
)
);
Expand Down
Loading