@@ -120,24 +120,7 @@ export interface ReferenceFieldProps<RecordType extends RaRecord = any>
120
120
*/
121
121
export const NonEmptyReferenceField : FC <
122
122
Omit < ReferenceFieldProps , 'source' > & { id : Identifier }
123
- > = ( { children, id, record, reference, link, ...props } ) => {
124
- const createPath = useCreatePath ( ) ;
125
- const resourceDefinition = useResourceDefinition ( { resource : reference } ) ;
126
-
127
- const resourceLinkPath =
128
- link === false ||
129
- ( link === 'edit' && ! resourceDefinition . hasEdit ) ||
130
- ( link === 'show' && ! resourceDefinition . hasShow )
131
- ? false
132
- : createPath ( {
133
- resource : reference ,
134
- id,
135
- type :
136
- typeof link === 'function'
137
- ? link ( record , reference )
138
- : link ,
139
- } ) ;
140
-
123
+ > = ( { children, id, record, reference, ...props } ) => {
141
124
return (
142
125
< ResourceContextProvider value = { reference } >
143
126
< PureReferenceFieldView
@@ -147,7 +130,6 @@ export const NonEmptyReferenceField: FC<
147
130
reference,
148
131
id,
149
132
} ) }
150
- resourceLinkPath = { resourceLinkPath }
151
133
>
152
134
{ children }
153
135
</ PureReferenceFieldView >
@@ -167,11 +149,13 @@ export const ReferenceFieldView: FC<ReferenceFieldViewProps> = props => {
167
149
isLoading,
168
150
reference,
169
151
referenceRecord,
170
- resourceLinkPath ,
152
+ link ,
171
153
sx,
172
154
} = props ;
173
155
const getRecordRepresentation = useGetRecordRepresentation ( reference ) ;
174
156
const translate = useTranslate ( ) ;
157
+ const createPath = useCreatePath ( ) ;
158
+ const resourceDefinition = useResourceDefinition ( { resource : reference } ) ;
175
159
176
160
if ( error ) {
177
161
return (
@@ -194,6 +178,20 @@ export const ReferenceFieldView: FC<ReferenceFieldViewProps> = props => {
194
178
) : null ;
195
179
}
196
180
181
+ const resourceLinkPath =
182
+ link === false ||
183
+ ( link === 'edit' && ! resourceDefinition . hasEdit ) ||
184
+ ( link === 'show' && ! resourceDefinition . hasShow )
185
+ ? false
186
+ : createPath ( {
187
+ resource : reference ,
188
+ id : referenceRecord . id ,
189
+ type :
190
+ typeof link === 'function'
191
+ ? link ( referenceRecord , reference )
192
+ : link ,
193
+ } ) ;
194
+
197
195
let child = children || (
198
196
< Typography component = "span" variant = "body2" >
199
197
{ getRecordRepresentation ( referenceRecord ) }
@@ -227,10 +225,12 @@ ReferenceFieldView.propTypes = {
227
225
reference : PropTypes . string ,
228
226
referenceRecord : PropTypes . any ,
229
227
resource : PropTypes . string ,
230
- resourceLinkPath : PropTypes . oneOfType ( [
228
+ // @ts -ignore
229
+ link : PropTypes . oneOfType ( [
231
230
PropTypes . string ,
232
- PropTypes . oneOf ( [ false ] ) ,
233
- ] ) as React . Validator < string | false > ,
231
+ PropTypes . bool ,
232
+ PropTypes . func ,
233
+ ] ) ,
234
234
source : PropTypes . string ,
235
235
translateChoice : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . bool ] ) ,
236
236
} ;
@@ -242,7 +242,7 @@ export interface ReferenceFieldViewProps
242
242
reference : string ;
243
243
resource ?: string ;
244
244
translateChoice ?: Function | boolean ;
245
- resourceLinkPath ?: string | false ;
245
+ link ?: LinkToType ;
246
246
children ?: ReactNode ;
247
247
sx ?: SxProps ;
248
248
}
0 commit comments