Skip to content

Commit 2cd5c89

Browse files
authored
Merge pull request #5688 from marmelab/empty-with-no-create
Fix Empty Component Display When No Create
2 parents 880d952 + 32d4b74 commit 2cd5c89

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

packages/ra-core/src/dataProvider/useQueryWithStore.ts

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ const useQueryWithStore = <State extends ReduxState = ReduxState>(
158158
data,
159159
total,
160160
loaded: true,
161+
loading: false,
161162
}));
162163
}
163164
}

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

+13-9
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const useStyles = makeStyles(
3333
);
3434

3535
const Empty: FC<EmptyProps> = props => {
36-
const { basePath } = useListContext(props);
36+
const { basePath, hasCreate } = useListContext(props);
3737
const resource = useResourceContext(props);
3838
const classes = useStyles(props);
3939
const translate = useTranslate();
@@ -61,15 +61,19 @@ const Empty: FC<EmptyProps> = props => {
6161
_: emptyMessage,
6262
})}
6363
</Typography>
64-
<Typography variant="body1">
65-
{translate(`resources.${resource}.invite`, {
66-
_: inviteMessage,
67-
})}
68-
</Typography>
69-
</div>
70-
<div className={classes.toolbar}>
71-
<CreateButton variant="contained" basePath={basePath} />
64+
{hasCreate && (
65+
<Typography variant="body1">
66+
{translate(`resources.${resource}.invite`, {
67+
_: inviteMessage,
68+
})}
69+
</Typography>
70+
)}
7271
</div>
72+
{hasCreate && (
73+
<div className={classes.toolbar}>
74+
<CreateButton variant="contained" basePath={basePath} />
75+
</div>
76+
)}
7377
</>
7478
);
7579
};

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

+1-6
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export const ListView = (props: ListViewProps) => {
4646
total,
4747
loaded,
4848
loading,
49-
hasCreate,
5049
filterValues,
5150
selectedIds,
5251
} = listContext;
@@ -88,11 +87,7 @@ export const ListView = (props: ListViewProps) => {
8887
);
8988

9089
const shouldRenderEmptyPage =
91-
hasCreate &&
92-
loaded &&
93-
!loading &&
94-
total === 0 &&
95-
!Object.keys(filterValues).length;
90+
loaded && !loading && total === 0 && !Object.keys(filterValues).length;
9691

9792
return (
9893
<div

0 commit comments

Comments
 (0)