Merge branch 'master'
[arvados.git] / src / views-components / rename-file-dialog / rename-file-dialog.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import { compose } from 'redux';
7 import { reduxForm, InjectedFormProps, Field } from 'redux-form';
8 import { withDialog, WithDialogProps } from '~/store/dialog/with-dialog';
9 import { FormDialog } from '~/components/form-dialog/form-dialog';
10 import { DialogContentText } from '@material-ui/core';
11 import { TextField } from '~/components/text-field/text-field';
12 import { RENAME_FILE_DIALOG, RenameFileDialogData, renameFile } from '~/store/collection-panel/collection-panel-files/collection-panel-files-actions';
13 import { WarningCollection } from '~/components/warning-collection/warning-collection';
14
15 export const RenameFileDialog = compose(
16     withDialog(RENAME_FILE_DIALOG),
17     reduxForm({
18         form: RENAME_FILE_DIALOG,
19         onSubmit: (data: { name: string }, dispatch) => {
20             dispatch<any>(renameFile(data.name));
21         }
22     })
23 )((props: WithDialogProps<RenameFileDialogData> & InjectedFormProps<{ name: string }>) =>
24     <FormDialog
25         dialogTitle='Rename'
26         formFields={RenameDialogFormFields}
27         submitLabel='Ok'
28         {...props}
29     />);
30
31 const RenameDialogFormFields = (props: WithDialogProps<RenameFileDialogData>) => <>
32     <DialogContentText>
33         {`Please, enter a new name for ${props.data.name}`}
34     </DialogContentText>
35     <Field
36         name='name'
37         component={TextField}
38         autoFocus={true}
39     />
40     <WarningCollection text="Renaming a file will change content adress." />
41 </>;