18219: Adds property editor to groups create dialog.
[arvados-workbench2.git] / src / views-components / dialog-create / dialog-project-create.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from 'react';
6 import { InjectedFormProps } from 'redux-form';
7 import { WithDialogProps } from 'store/dialog/with-dialog';
8 import { ProjectCreateFormDialogData, PROJECT_CREATE_FORM_NAME } from 'store/projects/project-create-actions';
9 import { FormDialog } from 'components/form-dialog/form-dialog';
10 import { ProjectNameField, ProjectDescriptionField, UsersField } from 'views-components/form-fields/project-form-fields';
11 import { CreateProjectPropertiesForm } from 'views-components/project-properties/create-project-properties-form';
12 import { ResourceParentField } from '../form-fields/resource-form-fields';
13 import { FormGroup, FormLabel } from '@material-ui/core';
14 import { resourcePropertiesList } from 'views-components/resource-properties/resource-properties-list';
15 import { GroupClass } from 'models/group';
16
17 type DialogProjectProps = WithDialogProps<{sourcePanel: GroupClass}> & InjectedFormProps<ProjectCreateFormDialogData>;
18
19 export const DialogProjectCreate = (props: DialogProjectProps) => {
20     let title = 'New Project';
21     let fields = ProjectAddFields;
22     const sourcePanel = props.data.sourcePanel || '';
23
24     if (sourcePanel === GroupClass.ROLE) {
25         title = 'New Group';
26         fields = GroupAddFields;
27     }
28
29     return <FormDialog
30         dialogTitle={title}
31         formFields={fields}
32         submitLabel='Create'
33         {...props}
34     />;
35 };
36
37 const CreateProjectPropertiesList = resourcePropertiesList(PROJECT_CREATE_FORM_NAME);
38
39 const ProjectAddFields = () => <span>
40     <ResourceParentField />
41     <ProjectNameField />
42     <ProjectDescriptionField />
43     <FormLabel>Properties</FormLabel>
44     <FormGroup>
45         <CreateProjectPropertiesForm />
46         <CreateProjectPropertiesList />
47     </FormGroup>
48 </span>;
49
50 const GroupAddFields = () => <span>
51     <ProjectNameField />
52     <UsersField />
53     <ProjectDescriptionField />
54     <FormLabel>Properties</FormLabel>
55     <FormGroup>
56         <CreateProjectPropertiesForm />
57         <CreateProjectPropertiesList />
58     </FormGroup>
59 </span>;