Skip to content

Commit aa2ae67

Browse files
committed
Backport ReferenceFieldView fix
1 parent 5ccd5ed commit aa2ae67

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

packages/ra-ui-materialui/src/field/ReferenceField.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export const NonEmptyReferenceField = <
136136
id,
137137
reference,
138138
queryOptions,
139+
link,
139140
...props
140141
}: Omit<ReferenceFieldProps<RecordType, ReferenceRecordType>, 'source'> & {
141142
id: Identifier;
@@ -151,6 +152,7 @@ export const NonEmptyReferenceField = <
151152
id,
152153
options: queryOptions,
153154
})}
155+
resourceLinkPath={link}
154156
>
155157
{children}
156158
</PureReferenceFieldView>
@@ -174,7 +176,7 @@ export const ReferenceFieldView = <
174176
isLoading,
175177
reference,
176178
referenceRecord,
177-
link,
179+
resourceLinkPath,
178180
sx,
179181
} = props;
180182
const getRecordRepresentation = useGetRecordRepresentation(reference);
@@ -203,18 +205,18 @@ export const ReferenceFieldView = <
203205
) : null;
204206
}
205207

206-
const resourceLinkPath =
207-
link === false ||
208-
(link === 'edit' && !resourceDefinition.hasEdit) ||
209-
(link === 'show' && !resourceDefinition.hasShow)
208+
const link =
209+
resourceLinkPath === false ||
210+
(resourceLinkPath === 'edit' && !resourceDefinition.hasEdit) ||
211+
(resourceLinkPath === 'show' && !resourceDefinition.hasShow)
210212
? false
211213
: createPath({
212214
resource: reference,
213215
id: referenceRecord.id,
214216
type:
215-
typeof link === 'function'
216-
? link(referenceRecord, reference)
217-
: link,
217+
typeof resourceLinkPath === 'function'
218+
? resourceLinkPath(referenceRecord, reference)
219+
: resourceLinkPath,
218220
});
219221

220222
let child = children || (
@@ -223,11 +225,11 @@ export const ReferenceFieldView = <
223225
</Typography>
224226
);
225227

226-
return resourceLinkPath ? (
228+
return link ? (
227229
<Root className={className} sx={sx}>
228230
<RecordContextProvider value={referenceRecord}>
229231
<Link
230-
to={resourceLinkPath.toString()}
232+
to={link.toString()}
231233
className={ReferenceFieldClasses.link}
232234
onClick={stopPropagation}
233235
>
@@ -251,7 +253,7 @@ ReferenceFieldView.propTypes = {
251253
referenceRecord: PropTypes.any,
252254
resource: PropTypes.string,
253255
// @ts-ignore
254-
link: PropTypes.oneOfType([
256+
resourceLinkPath: PropTypes.oneOfType([
255257
PropTypes.string,
256258
PropTypes.bool,
257259
PropTypes.func,
@@ -269,7 +271,7 @@ export interface ReferenceFieldViewProps<
269271
reference: string;
270272
resource?: string;
271273
translateChoice?: Function | boolean;
272-
link?: LinkToType<ReferenceRecordType>;
274+
resourceLinkPath?: LinkToType<ReferenceRecordType>;
273275
sx?: SxProps;
274276
}
275277

packages/ra-ui-materialui/src/field/ReferenceOneField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const ReferenceOneField = <
8787
isLoading={isLoading}
8888
isFetching={isFetching}
8989
referenceRecord={referenceRecord}
90-
link={resourceLinkPath}
90+
resourceLinkPath={resourceLinkPath}
9191
reference={reference}
9292
refetch={refetch}
9393
error={error}

0 commit comments

Comments
 (0)