21224: fixed info button first click fail Arvados-DCO-1.1-Signed-off-by: Lisa Knox...
[arvados.git] / services / workbench2 / src / views-components / dialog-upload / dialog-collection-files-upload.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 } from 'store/collections/collection-create-actions';
9 import { FormDialog } from 'components/form-dialog/form-dialog';
10 import { require } from 'validators/require';
11 import { FileUploaderField } from 'views-components/file-uploader/file-uploader';
12 import { WarningCollection } from 'components/warning-collection/warning-collection';
13 import { fileUploaderActions } from 'store/file-uploader/file-uploader-actions';
14 import { progressIndicatorActions } from 'store/progress-indicator/progress-indicator-actions';
15
16 type DialogCollectionFilesUploadProps = WithDialogProps<{}> & InjectedFormProps<CollectionCreateFormDialogData>;
17
18 export const DialogCollectionFilesUpload = (props: DialogCollectionFilesUploadProps) => {
19
20     return <FormDialog
21         dialogTitle='Upload data'
22         formFields={UploadCollectionFilesFields}
23         submitLabel='Upload data'
24         doNotDisableCancel
25         cancelCallback={() => {
26             const { submitting, dispatch } = (props as any);
27
28             if (submitting) {
29                 dispatch(progressIndicatorActions.STOP_WORKING('uploadCollectionFilesDialog'));
30                 dispatch(fileUploaderActions.CANCEL_FILES_UPLOAD());
31                 dispatch(fileUploaderActions.CLEAR_UPLOAD());
32             }
33         }}
34         {...props}
35     />;
36 }
37
38 const UploadCollectionFilesFields = () => <>
39     <Field
40         name='files'
41         validate={FILES_FIELD_VALIDATION}
42         component={FileUploaderField} />
43     <WarningCollection text="Uploading new files will change content address." />
44 </>;
45
46 const FILES_FIELD_VALIDATION = [require];
47
48