File tree Expand file tree Collapse file tree 1 file changed +50
-30
lines changed
packages/ra-ui-materialui/src/list Expand file tree Collapse file tree 1 file changed +50
-30
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,8 @@ import {
1414 type RaRecord ,
1515 RecordRepresentation ,
1616 useCreatePath ,
17- ListIterator ,
17+ WithListContext ,
18+ RecordContextProvider ,
1819} from 'ra-core' ;
1920
2021import { LinearProgress } from '../layout/LinearProgress' ;
@@ -89,35 +90,54 @@ export const SingleFieldList = <RecordType extends RaRecord = any>(
8990 className = { className }
9091 { ...sanitizeListRestProps ( rest ) }
9192 >
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 (
107- < Link
108- className = { SingleFieldListClasses . link }
109- to = { resourceLinkPath }
110- onClick = { stopPropagation }
111- >
112- { children || (
113- < DefaultChildComponent clickable />
114- ) }
115- </ Link >
116- ) ;
117- }
118-
119- return children || < DefaultChildComponent /> ;
120- } }
93+ < WithListContext < RecordType >
94+ render = { ( { isPending, data } ) =>
95+ ! isPending && (
96+ < Stack direction = "row" spacing = { 1 } >
97+ { data ?. map ( record => {
98+ const resourceLinkPath = ! linkType
99+ ? false
100+ : createPath ( {
101+ resource,
102+ type : linkType ,
103+ id : record . id ,
104+ } ) ;
105+
106+ if ( resourceLinkPath ) {
107+ return (
108+ < RecordContextProvider
109+ value = { record }
110+ key = { record . id }
111+ >
112+ < Link
113+ className = {
114+ SingleFieldListClasses . link
115+ }
116+ to = { resourceLinkPath }
117+ onClick = { stopPropagation }
118+ >
119+ { children || (
120+ < DefaultChildComponent
121+ clickable
122+ />
123+ ) }
124+ </ Link >
125+ </ RecordContextProvider >
126+ ) ;
127+ }
128+
129+ return (
130+ < RecordContextProvider
131+ value = { record }
132+ key = { record . id }
133+ >
134+ { children || < DefaultChildComponent /> }
135+ </ RecordContextProvider >
136+ ) ;
137+ } ) }
138+ </ Stack >
139+ )
140+ }
121141 />
122142 </ Root >
123143 ) ;
You can’t perform that action at this time.
0 commit comments