Merge branch '19143-project-list-workflows'
[arvados-workbench2.git] / src / views-components / dialog-copy / dialog-copy.tsx
index 0333e127c4639f8daa881c7e55f142c65da66ea6..5605e6caa866c266990caa9722ac94be96004aef 100644 (file)
@@ -2,33 +2,38 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from "react";
+import React from "react";
+import { memoize } from 'lodash/fp';
 import { InjectedFormProps, Field } from 'redux-form';
-import { WithDialogProps } from '~/store/dialog/with-dialog';
-import { FormDialog } from '~/components/form-dialog/form-dialog';
-import { ProjectTreePickerField } from '~/views-components/project-tree-picker/project-tree-picker';
-import { COPY_NAME_VALIDATION, COPY_PROJECT_VALIDATION } from '~/validators/validators';
-import { TextField } from "~/components/text-field/text-field";
-import { CollectionCopyFormDialogData } from "~/store/collections/copy/collection-copy-actions";
+import { WithDialogProps } from 'store/dialog/with-dialog';
+import { FormDialog } from 'components/form-dialog/form-dialog';
+import { ProjectTreePickerField } from 'views-components/projects-tree-picker/tree-picker-field';
+import { COPY_NAME_VALIDATION, COPY_FILE_VALIDATION } from 'validators/validators';
+import { TextField } from "components/text-field/text-field";
+import { CopyFormDialogData } from 'store/copy-dialog/copy-dialog';
+import { PickerIdProp } from 'store/tree-picker/picker-id';
 
-type CopyFormDialogProps = WithDialogProps<string> & InjectedFormProps<CollectionCopyFormDialogData>;
+type CopyFormDialogProps = WithDialogProps<string> & InjectedFormProps<CopyFormDialogData>;
 
-export const DialogCopy = (props: CopyFormDialogProps) =>
+export const DialogCopy = (props: CopyFormDialogProps & PickerIdProp) =>
     <FormDialog
         dialogTitle='Make a copy'
-        formFields={DialogCopyFields}
+        formFields={CopyDialogFields(props.pickerId)}
         submitLabel='Copy'
         {...props}
     />;
 
-const DialogCopyFields = () => <span>
-    <Field
-        name='name'
-        component={TextField}
-        validate={COPY_NAME_VALIDATION}
-        label="Enter a new name for the copy" />
-    <Field
-        name="ownerUuid"
-        component={ProjectTreePickerField}
-        validate={COPY_PROJECT_VALIDATION} />
-</span>;
+const CopyDialogFields = memoize((pickerId: string) =>
+    () =>
+        <span>
+            <Field
+                name='name'
+                component={TextField as any}
+                validate={COPY_NAME_VALIDATION}
+                label="Enter a new name for the copy" />
+            <Field
+                name="ownerUuid"
+                component={ProjectTreePickerField}
+                validate={COPY_FILE_VALIDATION}
+                pickerId={pickerId}/>
+        </span>);