Skip to content

Commit

Permalink
Fix Empty Component Display When No Create
Browse files Browse the repository at this point in the history
  • Loading branch information
djhi committed Dec 18, 2020
1 parent 880d952 commit 32d4b74
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
1 change: 1 addition & 0 deletions packages/ra-core/src/dataProvider/useQueryWithStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const useQueryWithStore = <State extends ReduxState = ReduxState>(
data,
total,
loaded: true,
loading: false,
}));
}
}
Expand Down
22 changes: 13 additions & 9 deletions packages/ra-ui-materialui/src/list/Empty.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const useStyles = makeStyles(
);

const Empty: FC<EmptyProps> = props => {
const { basePath } = useListContext(props);
const { basePath, hasCreate } = useListContext(props);
const resource = useResourceContext(props);
const classes = useStyles(props);
const translate = useTranslate();
Expand Down Expand Up @@ -61,15 +61,19 @@ const Empty: FC<EmptyProps> = props => {
_: emptyMessage,
})}
</Typography>
<Typography variant="body1">
{translate(`resources.${resource}.invite`, {
_: inviteMessage,
})}
</Typography>
</div>
<div className={classes.toolbar}>
<CreateButton variant="contained" basePath={basePath} />
{hasCreate && (
<Typography variant="body1">
{translate(`resources.${resource}.invite`, {
_: inviteMessage,
})}
</Typography>
)}
</div>
{hasCreate && (
<div className={classes.toolbar}>
<CreateButton variant="contained" basePath={basePath} />
</div>
)}
</>
);
};
Expand Down
7 changes: 1 addition & 6 deletions packages/ra-ui-materialui/src/list/ListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export const ListView = (props: ListViewProps) => {
total,
loaded,
loading,
hasCreate,
filterValues,
selectedIds,
} = listContext;
Expand Down Expand Up @@ -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 (
<div
Expand Down

0 comments on commit 32d4b74

Please sign in to comment.