15768: fixed rerun bug Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa.knox@curii...
[arvados.git] / src / views-components / dialog-copy / dialog-copy.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 { memoize } from "lodash/fp";
7 import { InjectedFormProps, Field } from "redux-form";
8 import { WithDialogProps } from "store/dialog/with-dialog";
9 import { FormDialog } from "components/form-dialog/form-dialog";
10 import { ProjectTreePickerField } from "views-components/projects-tree-picker/tree-picker-field";
11 import { COPY_NAME_VALIDATION, COPY_FILE_VALIDATION } from "validators/validators";
12 import { TextField } from "components/text-field/text-field";
13 import { CopyFormDialogData } from "store/copy-dialog/copy-dialog";
14 import { PickerIdProp } from "store/tree-picker/picker-id";
15
16 type CopyFormDialogProps = WithDialogProps<string> & InjectedFormProps<CopyFormDialogData>;
17
18 export const DialogCopy = (props: CopyFormDialogProps & PickerIdProp) => {
19     return (
20         <FormDialog
21             dialogTitle="Make a copy"
22             formFields={CopyDialogFields(props.pickerId)}
23             submitLabel="Copy"
24             {...props}
25         />
26     );
27 };
28
29 const CopyDialogFields = memoize((pickerId: string) => () => (
30     <>
31         <Field
32             name="name"
33             component={TextField as any}
34             validate={COPY_NAME_VALIDATION}
35             label="Enter a new name for the copy"
36         />
37         <Field
38             name="ownerUuid"
39             component={ProjectTreePickerField}
40             validate={COPY_FILE_VALIDATION}
41             pickerId={pickerId}
42         />
43     </>
44 ));
45
46 export const DialogMultiCopy = (props: CopyFormDialogProps & PickerIdProp) => {
47     return (
48         <FormDialog
49             dialogTitle="Make Copies"
50             formFields={CopyMultiDialogFields(props.pickerId)}
51             submitLabel="Copy"
52             {...props}
53         />
54     );
55 };
56
57 const CopyMultiDialogFields = memoize((pickerId: string) => () => (
58     <Field
59         name="ownerUuid"
60         component={ProjectTreePickerField}
61         validate={COPY_FILE_VALIDATION}
62         pickerId={pickerId}
63     />
64 ));