Skip to content

Commit 58273e8

Browse files
committed
Revert usage on <ListIterator> in ra-ui-materialui
Fixes #10900
1 parent df42551 commit 58273e8

File tree

4 files changed

+46
-31
lines changed

4 files changed

+46
-31
lines changed

packages/ra-ui-materialui/src/list/SimpleList/SimpleList.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import {
1313
useThemeProps,
1414
} from '@mui/material/styles';
1515
import {
16-
ListIterator,
1716
type RaRecord,
17+
RecordContextProvider,
1818
sanitizeListRestProps,
1919
useGetRecordRepresentation,
2020
useListContextWithProps,
@@ -122,10 +122,8 @@ export const SimpleList = <RecordType extends RaRecord = any>(
122122

123123
return (
124124
<Root className={className} {...sanitizeListRestProps(rest)}>
125-
<ListIterator<RecordType>
126-
data={data}
127-
total={total}
128-
render={(record, rowIndex) => (
125+
{data.map((record, rowIndex) => (
126+
<RecordContextProvider key={record.id} value={record}>
129127
<SimpleListItem
130128
key={record.id}
131129
rowIndex={rowIndex}
@@ -146,8 +144,8 @@ export const SimpleList = <RecordType extends RaRecord = any>(
146144
rowIndex={rowIndex}
147145
/>
148146
</SimpleListItem>
149-
)}
150-
/>
147+
</RecordContextProvider>
148+
))}
151149
</Root>
152150
);
153151
};

packages/ra-ui-materialui/src/list/SingleFieldList.spec.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ListContext, ResourceContextProvider } from 'ra-core';
55
import { AdminContext } from '../AdminContext';
66
import { SingleFieldList } from './SingleFieldList';
77
import { ChipField } from '../field';
8-
import { Empty } from './SingleFieldList.stories';
8+
import { Divider, Empty } from './SingleFieldList.stories';
99

1010
describe('<SingleFieldList />', () => {
1111
it('should render a link to the Edit page of the related record by default', () => {
@@ -189,4 +189,12 @@ describe('<SingleFieldList />', () => {
189189
expect(screen.queryByText('No genres')).toBeNull();
190190
});
191191
});
192+
193+
it('should accept MUI Stack props', async () => {
194+
render(<Divider />);
195+
const item = await screen.findByText('Horror');
196+
expect(
197+
item.closest('.MuiStack-root').querySelectorAll('[data-separator]')
198+
).toHaveLength(2);
199+
});
192200
});

packages/ra-ui-materialui/src/list/SingleFieldList.stories.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ export const Gap = () => (
146146
export const Divider = () => (
147147
<Wrapper>
148148
<SingleFieldList
149-
divider={<MuiDivider orientation="vertical" flexItem />}
149+
divider={
150+
<MuiDivider orientation="vertical" data-separator flexItem />
151+
}
150152
/>
151153
</Wrapper>
152154
);

packages/ra-ui-materialui/src/list/SingleFieldList.tsx

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
type RaRecord,
1515
RecordRepresentation,
1616
useCreatePath,
17-
ListIterator,
17+
RecordContextProvider,
1818
} from 'ra-core';
1919

2020
import { LinearProgress } from '../layout/LinearProgress';
@@ -89,21 +89,21 @@ export const SingleFieldList = <RecordType extends RaRecord = any>(
8989
className={className}
9090
{...sanitizeListRestProps(rest)}
9191
>
92-
<ListIterator<RecordType>
93-
data={data}
94-
total={total}
95-
isPending={isPending}
96-
render={record => {
97-
const resourceLinkPath = !linkType
98-
? false
99-
: createPath({
100-
resource,
101-
type: linkType,
102-
id: record.id,
103-
});
104-
105-
if (resourceLinkPath) {
106-
return (
92+
{data.map((record, rowIndex) => {
93+
const resourceLinkPath = !linkType
94+
? false
95+
: createPath({
96+
resource,
97+
type: linkType,
98+
id: record.id,
99+
});
100+
101+
if (resourceLinkPath) {
102+
return (
103+
<RecordContextProvider
104+
value={record}
105+
key={record.id ?? `row${rowIndex}`}
106+
>
107107
<Link
108108
className={SingleFieldListClasses.link}
109109
to={resourceLinkPath}
@@ -113,12 +113,19 @@ export const SingleFieldList = <RecordType extends RaRecord = any>(
113113
<DefaultChildComponent clickable />
114114
)}
115115
</Link>
116-
);
117-
}
118-
119-
return children || <DefaultChildComponent />;
120-
}}
121-
/>
116+
</RecordContextProvider>
117+
);
118+
}
119+
120+
return (
121+
<RecordContextProvider
122+
value={record}
123+
key={record.id ?? `row${rowIndex}`}
124+
>
125+
{children || <DefaultChildComponent />}
126+
</RecordContextProvider>
127+
);
128+
})}
122129
</Root>
123130
);
124131
};

0 commit comments

Comments
 (0)