-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlavors.jsx
103 lines (95 loc) · 3.06 KB
/
Flavors.jsx
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
import Typography from "@material-ui/core/Typography";
import { Kitchen } from "@material-ui/icons";
import React from "react";
import {
Create,
Datagrid,
DeleteButton,
Edit,
EditButton,
Filter,
List,
Pagination,
ReferenceField,
ReferenceManyField,
Show,
ShowButton,
SimpleForm,
Tab,
TabbedShowLayout,
TextField,
TextInput,
required
} from "react-admin";
import { ColorField, ColorInput } from "react-admin-color-input";
export const FlavorIcon = Kitchen;
const FlavorFilter = props => (
<Filter {...props}>
<TextInput label="Search" source="q" alwaysOn />
</Filter>
);
const FlavorPagination = props => <Pagination rowsPerPageOptions={[10, 20]} {...props} />;
const FlavorListSidePanel = () => (
<div style={{ width: 200, margin: "1em" }}>
<Typography component="h2" variant="subtitle1">Using icons?</Typography>
<Typography component="h4" variant="body1">Flavors will need a matching image. Not all flavors have an image yet.</Typography>
</div>
);
export const FlavorShow = props => (
<Show title={<FlavorTitle />} {...props}>
<TabbedShowLayout>
<Tab label="info">
<h2>Product kinds with this Flavor</h2>
<ReferenceManyField
reference="kinds-to-flavors"
target="flavor_id"
addLabel={false}
pagination={<FlavorPagination />}
perPage={20}
>
<Datagrid>
<ReferenceField label="Product Kind" source="kind_id" reference="kinds" linkType="show">
<TextField source="name" />
</ReferenceField>
<EditButton />
<DeleteButton />
</Datagrid>
</ReferenceManyField>
</Tab>
</TabbedShowLayout>
</Show>
);
export const FlavorList = props => (
<List aside={<FlavorListSidePanel />} {...props} perPage={100} filters={<FlavorFilter />}>
<Datagrid>
<TextField source="name" />
<TextField source="icon" />
<ColorField source="color" />
<ShowButton />
<EditButton />
<DeleteButton />
</Datagrid>
</List>
);
const FlavorTitle = ({ record }) => {
return <span>Flavor {record ? `"${record.name}"` : ""}</span>;
};
export const FlavorEdit = props => (
<Edit title={<FlavorTitle />} {...props}>
<SimpleForm>
<TextInput disabled source="id" />
<TextInput source="name" autoFocus validate={required()} />
<TextInput source="icon" />
<ColorInput source="color" />
</SimpleForm>
</Edit>
);
export const FlavorCreate = props => (
<Create title="Create a Flavor" {...props}>
<SimpleForm>
<TextInput source="name" autoFocus validate={required()} />
<TextInput source="icon" />
<ColorInput source="color" />
</SimpleForm>
</Create>
);