15672: Merge branch 'master' into 15672-subprocess-list-v2
[arvados-workbench2.git] / src / views-components / form-fields / collection-form-fields.tsx
index f6dc5d5545e4c13d284578221ccb847c7e8872c3..b3a3c224dbb097023906cdef0eac14df34da366a 100644 (file)
@@ -3,19 +3,37 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from "react";
-import { Field } from "redux-form";
+import { Field, Validator } 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 {
+    COLLECTION_NAME_VALIDATION, COLLECTION_NAME_VALIDATION_ALLOW_SLASH,
+    COLLECTION_DESCRIPTION_VALIDATION, COLLECTION_PROJECT_VALIDATION
+} from "~/validators/validators";
 import { ProjectTreePickerField, CollectionTreePickerField } 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";
 
-export const CollectionNameField = () =>
-    <Field
-        name='name'
-        component={TextField}
-        validate={COLLECTION_NAME_VALIDATION}
-        label="Collection Name"
-        autoFocus={true} />;
+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) =>
+        <Field
+            name='name'
+            component={TextField}
+            validate={props.validate}
+            label="Collection Name"
+            autoFocus={true} />
+    );
 
 export const CollectionDescriptionField = () =>
     <Field