15685: Adds file path validation on rename file dialog.
[arvados-workbench2.git] / src / views-components / rename-file-dialog / rename-file-dialog.tsx
index 0abdb5d6c2cf91027ece9024ec534fc6e3bbeded..9fbf6c9c8347c78fee27e263e7e0b2e37d1a104e 100644 (file)
@@ -11,16 +11,17 @@ import { DialogContentText } from '@material-ui/core';
 import { TextField } from '~/components/text-field/text-field';
 import { RENAME_FILE_DIALOG, RenameFileDialogData, renameFile } from '~/store/collection-panel/collection-panel-files/collection-panel-files-actions';
 import { WarningCollection } from '~/components/warning-collection/warning-collection';
+import { RENAME_FILE_VALIDATION } from '~/validators/validators';
 
 export const RenameFileDialog = compose(
     withDialog(RENAME_FILE_DIALOG),
     reduxForm({
         form: RENAME_FILE_DIALOG,
-        onSubmit: (data: { name: string }, dispatch) => {
-            dispatch<any>(renameFile(data.name));
+        onSubmit: (data: { path: string }, dispatch) => {
+            dispatch<any>(renameFile(data.path));
         }
     })
-)((props: WithDialogProps<RenameFileDialogData> & InjectedFormProps<{ name: string }>) =>
+)((props: WithDialogProps<RenameFileDialogData> & InjectedFormProps<{ name: string, path: string }>) =>
     <FormDialog
         dialogTitle='Rename'
         formFields={RenameDialogFormFields}
@@ -33,8 +34,10 @@ const RenameDialogFormFields = (props: WithDialogProps<RenameFileDialogData>) =>
         {`Please, enter a new name for ${props.data.name}`}
     </DialogContentText>
     <Field
-        name='name'
+        name='path'
         component={TextField}
+        autoFocus={true}
+        validate={RENAME_FILE_VALIDATION}
     />
-    <WarningCollection text="Renaming a file will change content adress." />
+    <WarningCollection text="Renaming a file will change the collection's content address." />
 </>;