Skip to content

Commit

Permalink
Fix warnings in simple example
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto committed Nov 3, 2020
1 parent a2db79a commit ab94f50
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 70 deletions.
135 changes: 69 additions & 66 deletions examples/simple/src/posts/PostShow.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ReferenceManyField,
RichTextField,
SelectField,
ShowContextProvider,
ShowView,
SingleFieldList,
Tab,
Expand Down Expand Up @@ -39,72 +40,74 @@ const CreateRelatedComment = ({ record }) => (
const PostShow = props => {
const controllerProps = useShowController(props);
return (
<ShowView {...controllerProps} title={<PostTitle />}>
<TabbedShowLayout>
<Tab label="post.form.summary">
<TextField source="id" />
<TextField source="title" />
{controllerProps.record &&
controllerProps.record.title ===
'Fusce massa lorem, pulvinar a posuere ut, accumsan ac nisi' && (
<TextField source="teaser" />
)}
<ArrayField source="backlinks">
<Datagrid>
<DateField source="date" />
<UrlField source="url" />
</Datagrid>
</ArrayField>
</Tab>
<Tab label="post.form.body">
<RichTextField
source="body"
stripTags={false}
label=""
addLabel={false}
/>
</Tab>
<Tab label="post.form.miscellaneous">
<ReferenceArrayField
reference="tags"
source="tags"
sort={{ field: 'name', order: 'ASC' }}
>
<SingleFieldList>
<ChipField source="name" />
</SingleFieldList>
</ReferenceArrayField>
<DateField source="published_at" />
<SelectField
source="category"
choices={[
{ name: 'Tech', id: 'tech' },
{ name: 'Lifestyle', id: 'lifestyle' },
]}
/>
<NumberField source="average_note" />
<BooleanField source="commentable" />
<TextField source="views" />
<CloneButton />
</Tab>
<Tab label="post.form.comments">
<ReferenceManyField
addLabel={false}
reference="comments"
target="post_id"
sort={{ field: 'created_at', order: 'DESC' }}
>
<Datagrid>
<DateField source="created_at" />
<TextField source="author.name" />
<TextField source="body" />
<EditButton />
</Datagrid>
</ReferenceManyField>
<CreateRelatedComment />
</Tab>
</TabbedShowLayout>
</ShowView>
<ShowContextProvider value={controllerProps}>
<ShowView title={<PostTitle />}>
<TabbedShowLayout>
<Tab label="post.form.summary">
<TextField source="id" />
<TextField source="title" />
{controllerProps.record &&
controllerProps.record.title ===
'Fusce massa lorem, pulvinar a posuere ut, accumsan ac nisi' && (
<TextField source="teaser" />
)}
<ArrayField source="backlinks">
<Datagrid>
<DateField source="date" />
<UrlField source="url" />
</Datagrid>
</ArrayField>
</Tab>
<Tab label="post.form.body">
<RichTextField
source="body"
stripTags={false}
label=""
addLabel={false}
/>
</Tab>
<Tab label="post.form.miscellaneous">
<ReferenceArrayField
reference="tags"
source="tags"
sort={{ field: 'name', order: 'ASC' }}
>
<SingleFieldList>
<ChipField source="name" />
</SingleFieldList>
</ReferenceArrayField>
<DateField source="published_at" />
<SelectField
source="category"
choices={[
{ name: 'Tech', id: 'tech' },
{ name: 'Lifestyle', id: 'lifestyle' },
]}
/>
<NumberField source="average_note" />
<BooleanField source="commentable" />
<TextField source="views" />
<CloneButton />
</Tab>
<Tab label="post.form.comments">
<ReferenceManyField
addLabel={false}
reference="comments"
target="post_id"
sort={{ field: 'created_at', order: 'DESC' }}
>
<Datagrid>
<DateField source="created_at" />
<TextField source="author.name" />
<TextField source="body" />
<EditButton />
</Datagrid>
</ReferenceManyField>
<CreateRelatedComment />
</Tab>
</TabbedShowLayout>
</ShowView>
</ShowContextProvider>
);
};

Expand Down
13 changes: 9 additions & 4 deletions packages/ra-ui-materialui/src/detail/ShowView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ShowControllerProps,
useResourceDefinition,
useShowContext,
useResourceContext,
} from 'ra-core';

import DefaultActions from './ShowActions';
Expand All @@ -26,16 +27,20 @@ export const ShowView = (props: ShowViewProps) => {
classes: classesOverride,
className,
component: Content,
resource,
title,
...rest
} = props;

const classes = useStyles(props);

const { basePath, defaultTitle, hasList, record, version } = useShowContext(
props
);
const {
basePath,
defaultTitle,
hasList,
record,
resource,
version,
} = useShowContext(props);
const { hasEdit } = useResourceDefinition(props);

const finalActions =
Expand Down

0 comments on commit ab94f50

Please sign in to comment.