17782: Disabling typechecking for some common Field component usage.
[arvados-workbench2.git] / src / views-components / form-fields / collection-form-fields.tsx
index af240fc5666c1735bf4938ade1b0bffe3ad358fe..b882d684f79b0d4fd8a83f1dd0137a7268f95eab 100644 (file)
@@ -2,33 +2,56 @@
 //
 // 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 } from "~/views-components/project-tree-picker/project-tree-picker";
+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 } 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" />;
+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" />;
 
-export const CollectionProjectPickerField = () =>
+export const CollectionProjectPickerField = (props: PickerIdProp) =>
     <Field
         name="projectUuid"
-        component={ProjectPicker}
+        pickerId={props.pickerId}
+        component={ProjectTreePickerField}
         validate={COLLECTION_PROJECT_VALIDATION} />;
 
-const ProjectPicker = (props: WrappedFieldProps) =>
-    <div style={{ width: '400px', height: '144px', display: 'flex', flexDirection: 'column' }}>
-        <ProjectTreePicker onChange={projectUuid => props.input.onChange(projectUuid)} />
-    </div>;
+export const CollectionPickerField = (props: PickerIdProp) =>
+    <Field
+        name="collectionUuid"
+        pickerId={props.pickerId}
+        component={CollectionTreePickerField}
+        validate={COLLECTION_PROJECT_VALIDATION} />;