Skip to content
Snippets Groups Projects
Commit 1819c3df16ea authored by Elodie Thiéblin's avatar Elodie Thiéblin
Browse files

feat: add Person in demo

parent bfc15c82519d
No related branches found
No related tags found
No related merge requests found
Pipeline #40150 passed
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
SimpleShowLayout, SimpleShowLayout,
DataProvider, DataProvider,
ReferenceArrayField, ReferenceArrayField,
AutocompleteArrayInput,
ReferenceArrayInput,
FunctionField,
SingleFieldList,
} from "react-admin"; } from "react-admin";
import { client } from "@logilab/cwclientlibjs"; import { client } from "@logilab/cwclientlibjs";
import { createDataProvider } from "ra-cubicweb/dist"; import { createDataProvider } from "ra-cubicweb/dist";
...@@ -28,6 +32,7 @@ ...@@ -28,6 +32,7 @@
} from "react-admin"; } from "react-admin";
import { client } from "@logilab/cwclientlibjs"; import { client } from "@logilab/cwclientlibjs";
import { createDataProvider } from "ra-cubicweb/dist"; import { createDataProvider } from "ra-cubicweb/dist";
import Chip from "@material-ui/core/Chip";
import { schema } from "./schema"; import { schema } from "./schema";
import { formHelpers } from "./formHelpers"; import { formHelpers } from "./formHelpers";
...@@ -41,6 +46,17 @@ ...@@ -41,6 +46,17 @@
<ReferenceField label="City" link="show" reference="City" source="is_in"> <ReferenceField label="City" link="show" reference="City" source="is_in">
<TextField source="name" /> <TextField source="name" />
</ReferenceField> </ReferenceField>
<ReferenceArrayField
label="Director"
reference="Person"
source="director"
>
<SingleFieldList>
<FunctionField<{ id: string; name: string }>
render={(person) => person && <Chip label={`${person.name}`} />}
/>
</SingleFieldList>
</ReferenceArrayField>
<NumberField source="longitude" /> <NumberField source="longitude" />
<NumberField source="latitude" /> <NumberField source="latitude" />
</SimpleShowLayout> </SimpleShowLayout>
...@@ -80,6 +96,15 @@ ...@@ -80,6 +96,15 @@
> >
<AutocompleteInput optionText="name" /> <AutocompleteInput optionText="name" />
</ReferenceInput> </ReferenceInput>
<ReferenceArrayInput
label="Director"
source="director"
reference="Person"
sort={{ field: "name", order: "ASC" }}
filterToQuery={(text: string) => ({ name: text })}
>
<AutocompleteArrayInput optionText="name" />
</ReferenceArrayInput>
</SimpleForm> </SimpleForm>
</Create> </Create>
); );
...@@ -160,6 +185,59 @@ ...@@ -160,6 +185,59 @@
</Show> </Show>
); );
const PersonList = (props: ListProps) => (
<List {...props}>
<Datagrid rowClick="show">
<TextField source="id" />
<TextField source="name" />
<TextField source="email" />
</Datagrid>
</List>
);
const PersonEdit = (props: ListProps) => {
const inputProps = formHelpers["Person"].getInputProps;
return (
<Edit {...props}>
<SimpleForm>
<TextInput {...inputProps("name")} />
<TextInput {...inputProps("email")} />
</SimpleForm>
</Edit>
);
};
const PersonCreate = (props: ListProps) => {
const inputProps = formHelpers["Person"].getInputProps;
return (
<Create {...props}>
<SimpleForm>
<TextInput {...inputProps("name")} />
<TextInput {...inputProps("email")} />
</SimpleForm>
</Create>
);
};
const PersonShow = (props: ShowProps) => (
<Show {...props}>
<SimpleShowLayout>
<TextField source="id" />
<TextField source="name" />
<TextField source="email" />
<ReferenceArrayField
label="Museum"
reference="Museum"
source="reverse_director"
>
<Datagrid rowClick="show">
<TextField source="name" />
</Datagrid>
</ReferenceArrayField>
</SimpleShowLayout>
</Show>
);
const httpClient = new client.CwSimpleHttpClient("http://localhost:8080", true); const httpClient = new client.CwSimpleHttpClient("http://localhost:8080", true);
const rqlClient = new client.CwRqlClient(httpClient); const rqlClient = new client.CwRqlClient(httpClient);
...@@ -186,6 +264,13 @@ ...@@ -186,6 +264,13 @@
edit={CityEdit} edit={CityEdit}
create={CityCreate} create={CityCreate}
/> />
<Resource
name="Person"
list={PersonList}
show={PersonShow}
edit={PersonEdit}
create={PersonCreate}
/>
</Admin> </Admin>
); );
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
country: { type: "String", default: "France" }, country: { type: "String", default: "France" },
}, },
Person: { Person: {
name: { type: "String" }, name: { type: "String", required: true },
email: { type: "String" }, email: { type: "String" },
}, },
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment