-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
PostShow.tsx
116 lines (113 loc) · 4.08 KB
/
PostShow.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import * as React from 'react';
import {
ArrayField,
BooleanField,
CloneButton,
ChipField,
Datagrid,
DateField,
EditButton,
NumberField,
ReferenceArrayField,
ReferenceManyField,
RichTextField,
SelectField,
ShowContextProvider,
ShowView,
SingleFieldList,
Tab,
TabbedShowLayout,
TextField,
UrlField,
useShowController,
useLocale,
} from 'react-admin';
import { Link } from 'react-router-dom';
import { Button } from '@material-ui/core';
import PostTitle from './PostTitle';
const CreateRelatedComment = ({ record }) => (
<Button
component={Link}
to={{
pathname: '/comments/create',
state: { record: { post_id: record.id } },
}}
>
Add comment
</Button>
);
const PostShow = props => {
const controllerProps = useShowController(props);
const locale = useLocale();
return (
<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.${locale}`, order: 'ASC' }}
>
<SingleFieldList>
<ChipField source={`name.${locale}`} />
</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>
);
};
export default PostShow;