From 32d4b74a2b798b01b7aa1f46a69fe3088150486a Mon Sep 17 00:00:00 2001 From: Gildas Garcia <1122076+djhi@users.noreply.github.com> Date: Fri, 18 Dec 2020 11:19:07 +0100 Subject: [PATCH] Fix Empty Component Display When No Create --- .../src/dataProvider/useQueryWithStore.ts | 1 + packages/ra-ui-materialui/src/list/Empty.tsx | 22 +++++++++++-------- .../ra-ui-materialui/src/list/ListView.tsx | 7 +----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/ra-core/src/dataProvider/useQueryWithStore.ts b/packages/ra-core/src/dataProvider/useQueryWithStore.ts index 109c9e4654e..0ef65e71952 100644 --- a/packages/ra-core/src/dataProvider/useQueryWithStore.ts +++ b/packages/ra-core/src/dataProvider/useQueryWithStore.ts @@ -158,6 +158,7 @@ const useQueryWithStore = ( data, total, loaded: true, + loading: false, })); } } diff --git a/packages/ra-ui-materialui/src/list/Empty.tsx b/packages/ra-ui-materialui/src/list/Empty.tsx index 9d13594efac..91f901290fd 100644 --- a/packages/ra-ui-materialui/src/list/Empty.tsx +++ b/packages/ra-ui-materialui/src/list/Empty.tsx @@ -33,7 +33,7 @@ const useStyles = makeStyles( ); const Empty: FC = props => { - const { basePath } = useListContext(props); + const { basePath, hasCreate } = useListContext(props); const resource = useResourceContext(props); const classes = useStyles(props); const translate = useTranslate(); @@ -61,15 +61,19 @@ const Empty: FC = props => { _: emptyMessage, })} - - {translate(`resources.${resource}.invite`, { - _: inviteMessage, - })} - - -
- + {hasCreate && ( + + {translate(`resources.${resource}.invite`, { + _: inviteMessage, + })} + + )}
+ {hasCreate && ( +
+ +
+ )} ); }; diff --git a/packages/ra-ui-materialui/src/list/ListView.tsx b/packages/ra-ui-materialui/src/list/ListView.tsx index c70baa6ac98..6a7baa503ee 100644 --- a/packages/ra-ui-materialui/src/list/ListView.tsx +++ b/packages/ra-ui-materialui/src/list/ListView.tsx @@ -46,7 +46,6 @@ export const ListView = (props: ListViewProps) => { total, loaded, loading, - hasCreate, filterValues, selectedIds, } = listContext; @@ -88,11 +87,7 @@ export const ListView = (props: ListViewProps) => { ); const shouldRenderEmptyPage = - hasCreate && - loaded && - !loading && - total === 0 && - !Object.keys(filterValues).length; + loaded && !loading && total === 0 && !Object.keys(filterValues).length; return (