Skip to content

Commit 934fff4

Browse files
committed
Use Offline everywhere
1 parent 6778fd1 commit 934fff4

File tree

3 files changed

+13
-45
lines changed

3 files changed

+13
-45
lines changed

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

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { LinearProgress } from '../layout';
2525
import { Link } from '../Link';
2626
import type { FieldProps } from './types';
2727
import { genericMemo } from './genericMemo';
28+
import { Offline } from '../Offline';
2829

2930
/**
3031
* Fetch reference record, and render its representation, or delegate rendering to child component.
@@ -104,6 +105,7 @@ export interface ReferenceFieldProps<
104105

105106
// useful to prevent click bubbling in a datagrid with rowClick
106107
const stopPropagation = e => e.stopPropagation();
108+
const defaultOffline = <Offline />;
107109

108110
export const ReferenceFieldView = <
109111
RecordType extends Record<string, any> = Record<string, any>,
@@ -115,7 +117,7 @@ export const ReferenceFieldView = <
115117
children,
116118
className,
117119
emptyText,
118-
offline = 'ra.notification.offline',
120+
offline = defaultOffline,
119121
reference,
120122
sx,
121123
} = props;
@@ -148,32 +150,7 @@ export const ReferenceFieldView = <
148150
}
149151
if (!referenceRecord) {
150152
if (isPaused) {
151-
if (typeof offline === 'string') {
152-
return (
153-
<Stack direction="row" alignItems="center" gap={1}>
154-
<ErrorIcon
155-
role="presentation"
156-
color="error"
157-
fontSize="small"
158-
/>
159-
<Typography
160-
component="span"
161-
variant="body2"
162-
sx={{ color: 'error.main' }}
163-
>
164-
{typeof offline === 'string' ? (
165-
<Translate i18nKey={offline}>
166-
{offline}
167-
</Translate>
168-
) : (
169-
offline
170-
)}
171-
</Typography>
172-
</Stack>
173-
);
174-
}
175-
// We either have a ReactNode, a boolean or null|undefined
176-
return offline || null;
153+
return offline;
177154
}
178155
return emptyText ? (
179156
<Typography component="span" variant="body2">

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import ErrorIcon from '@mui/icons-material/Error';
1919
import { FieldProps } from './types';
2020
import { sanitizeFieldRestProps } from './sanitizeFieldRestProps';
2121
import { Link } from '../Link';
22+
import { Offline } from '../Offline';
23+
24+
const defaultOffline = <Offline />;
2225

2326
/**
2427
* Fetch and render the number of records related to the current one
@@ -43,7 +46,7 @@ export const ReferenceManyCount = <RecordType extends RaRecord = RaRecord>(
4346
filter,
4447
sort,
4548
link,
46-
offline,
49+
offline = defaultOffline,
4750
resource,
4851
source = 'id',
4952
timeout = 1000,
@@ -69,13 +72,7 @@ export const ReferenceManyCount = <RecordType extends RaRecord = RaRecord>(
6972
let body: ReactNode = total;
7073

7174
if (isPaused && total == null) {
72-
body = offline ?? (
73-
<ErrorIcon
74-
color="error"
75-
fontSize="small"
76-
titleAccess="ra.notification.offline"
77-
/>
78-
);
75+
body = offline;
7976
}
8077

8178
if (isPending && !isPaused && oneSecondHasPassed) {

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import {
1717

1818
import { FieldProps } from './types';
1919
import { ReferenceFieldView } from './ReferenceField';
20+
import { Offline } from '../Offline';
21+
22+
const defaultOffline = <Offline />;
2023

2124
/**
2225
* Render the related record in a one-to-one relationship
@@ -40,7 +43,7 @@ export const ReferenceOneField = <
4043
source = 'id',
4144
target,
4245
emptyText,
43-
offline: offlineProp = 'ra-references.single_offline',
46+
offline = defaultOffline,
4447
sort,
4548
filter,
4649
link,
@@ -84,15 +87,6 @@ export const ReferenceOneField = <
8487
emptyText
8588
) : null;
8689

87-
const offline =
88-
typeof offlineProp === 'string' ? (
89-
<Typography component="span" variant="body2">
90-
{offlineProp && translate(offlineProp, { _: offlineProp })}
91-
</Typography>
92-
) : offlineProp ? (
93-
offlineProp
94-
) : null;
95-
9690
if (
9791
!record ||
9892
(!controllerProps.isPending &&

0 commit comments

Comments
 (0)