Merge remote-tracking branch 'origin/main' into 18207-Workbench2-is-not-clearing...
[arvados-workbench2.git] / src / views-components / dialog-create / dialog-collection-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, Field } from 'redux-form';
7 import { WithDialogProps } from 'store/dialog/with-dialog';
8 import { CollectionCreateFormDialogData, COLLECTION_CREATE_FORM_NAME } from 'store/collections/collection-create-actions';
9 import { FormDialog } from 'components/form-dialog/form-dialog';
10 import {
11     CollectionNameField,
12     CollectionDescriptionField,
13     CollectionStorageClassesField
14 } from 'views-components/form-fields/collection-form-fields';
15 import { FileUploaderField } from '../file-uploader/file-uploader';
16 import { ResourceParentField } from '../form-fields/resource-form-fields';
17 import { CreateCollectionPropertiesForm } from 'views-components/collection-properties/create-collection-properties-form';
18 import { FormGroup, FormLabel, StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
19 import { resourcePropertiesList } from 'views-components/resource-properties/resource-properties-list';
20
21 type CssRules = 'propertiesForm';
22
23 const styles: StyleRulesCallback<CssRules> = theme => ({
24     propertiesForm: {
25         marginTop: theme.spacing.unit * 2,
26         marginBottom: theme.spacing.unit * 2,
27     },
28 });
29
30 type DialogCollectionProps = WithDialogProps<{}> & InjectedFormProps<CollectionCreateFormDialogData>;
31
32 export const DialogCollectionCreate = (props: DialogCollectionProps) =>
33     <FormDialog
34         dialogTitle='New collection'
35         formFields={CollectionAddFields as any}
36         submitLabel='Create a Collection'
37         {...props}
38     />;
39
40 const CreateCollectionPropertiesList = resourcePropertiesList(COLLECTION_CREATE_FORM_NAME);
41
42 const CollectionAddFields = withStyles(styles)(
43     ({ classes }: WithStyles<CssRules>) => <span>
44         <ResourceParentField />
45         <CollectionNameField />
46         <CollectionDescriptionField />
47         <div className={classes.propertiesForm}>
48             <FormLabel>Properties</FormLabel>
49             <FormGroup>
50                 <CreateCollectionPropertiesForm />
51                 <CreateCollectionPropertiesList />
52             </FormGroup>
53         </div>
54         <CollectionStorageClassesField defaultClasses={['default']} />
55         <Field
56             name='files'
57             label='Files'
58             component={FileUploaderField} />
59     </span>);
60