X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/123bae90530147cf31e220066999b416d3610ae2..4c34de655fc7f8839b205b48f460a168f302dd63:/src/views-components/form-fields/collection-form-fields.tsx

diff --git a/src/views-components/form-fields/collection-form-fields.tsx b/src/views-components/form-fields/collection-form-fields.tsx
index 2d2a7c8088..7d5fcf8035 100644
--- a/src/views-components/form-fields/collection-form-fields.tsx
+++ b/src/views-components/form-fields/collection-form-fields.tsx
@@ -2,25 +2,46 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from "react";
-import { Field, WrappedFieldProps } from "redux-form";
-import { TextField } from "~/components/text-field/text-field";
-import { COLLECTION_NAME_VALIDATION, COLLECTION_DESCRIPTION_VALIDATION, COLLECTION_PROJECT_VALIDATION } from "~/validators/validators";
-import { ProjectTreePicker, ProjectTreePickerField } from "~/views-components/project-tree-picker/project-tree-picker";
-import { PickerIdProp } from '../../store/tree-picker/picker-id';
-
-export const CollectionNameField = () =>
-    <Field
-        name='name'
-        component={TextField}
-        validate={COLLECTION_NAME_VALIDATION}
-        label="Collection Name"
-        autoFocus={true} />;
+import React from "react";
+import { Field, Validator } from "redux-form";
+import { TextField } from "components/text-field/text-field";
+import {
+    COLLECTION_NAME_VALIDATION, COLLECTION_NAME_VALIDATION_ALLOW_SLASH,
+    COLLECTION_DESCRIPTION_VALIDATION, COLLECTION_PROJECT_VALIDATION
+} from "validators/validators";
+import { ProjectTreePickerField, CollectionTreePickerField, DirectoryTreePickerField } from "views-components/projects-tree-picker/tree-picker-field";
+import { PickerIdProp } from 'store/tree-picker/picker-id';
+import { connect } from "react-redux";
+import { RootState } from "store/store";
+import { MultiCheckboxField } from "components/checkbox-field/checkbox-field";
+import { getStorageClasses } from "common/config";
+import { ERROR_MESSAGE } from "validators/require";
+
+interface CollectionNameFieldProps {
+    validate: Validator[];
+}
+
+// See implementation note on declaration of ProjectNameField
+
+export const CollectionNameField = connect(
+    (state: RootState) => {
+        return {
+            validate: (state.auth.config.clusterConfig.Collections.ForwardSlashNameSubstitution === "" ?
+                COLLECTION_NAME_VALIDATION : COLLECTION_NAME_VALIDATION_ALLOW_SLASH)
+        };
+    })((props: CollectionNameFieldProps) =>
+        <span data-cy='name-field'><Field
+            name='name'
+            component={TextField as any}
+            validate={props.validate}
+            label="Collection Name"
+            autoFocus={true} /></span>
+    );
 
 export const CollectionDescriptionField = () =>
     <Field
         name='description'
-        component={TextField}
+        component={TextField as any}
         validate={COLLECTION_DESCRIPTION_VALIDATION}
         label="Description - optional" />;
 
@@ -30,3 +51,41 @@ export const CollectionProjectPickerField = (props: PickerIdProp) =>
         pickerId={props.pickerId}
         component={ProjectTreePickerField}
         validate={COLLECTION_PROJECT_VALIDATION} />;
+
+export const CollectionPickerField = (props: PickerIdProp) =>
+    <Field
+        name="collectionUuid"
+        pickerId={props.pickerId}
+        component={CollectionTreePickerField}
+        validate={COLLECTION_PROJECT_VALIDATION} />;
+
+const validateDirectory = (val) => (val && val.uuid ? undefined : ERROR_MESSAGE);
+
+export const DirectoryPickerField = (props: PickerIdProp) =>
+    <Field
+        name="destination"
+        pickerId={props.pickerId}
+        component={DirectoryTreePickerField as any}
+        validate={validateDirectory} />;
+
+interface StorageClassesProps {
+    items: string[];
+    defaultClasses?: string[];
+}
+
+export const CollectionStorageClassesField = connect(
+    (state: RootState) => {
+        return {
+            items: getStorageClasses(state.auth.config)
+        };
+    })(
+    (props: StorageClassesProps) =>
+        <Field
+            name='storageClassesDesired'
+            label='Storage classes'
+            minSelection={1}
+            rowLayout={true}
+            defaultValues={props.defaultClasses}
+            helperText='At least one class should be selected'
+            component={MultiCheckboxField}
+            items={props.items} />);
