18123: Use update project dialog for creating groups and remove create group dialog.
[arvados-workbench2.git] / src / views-components / form-fields / project-form-fields.tsx
index 6446c763a81300850c026ed3889ed4d86872837a..48348bab12d5f25d9e6ddca35808f7e063f63364 100644 (file)
@@ -2,22 +2,57 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from "react";
-import { Field } from "redux-form";
-import { TextField } from "~/components/text-field/text-field";
-import { PROJECT_NAME_VALIDATION, PROJECT_DESCRIPTION_VALIDATION } from "~/validators/validators";
+import React from "react";
+import { Field, FieldArray, Validator, WrappedFieldArrayProps } from "redux-form";
+import { TextField, RichEditorTextField } from "components/text-field/text-field";
+import { PROJECT_NAME_VALIDATION, PROJECT_NAME_VALIDATION_ALLOW_SLASH } from "validators/validators";
+import { connect } from "react-redux";
+import { RootState } from "store/store";
+import { Participant, ParticipantSelect } from "views-components/sharing-dialog/participant-select";
 
-export const ProjectNameField = () =>
-    <Field
-        name='name'
-        component={TextField}
-        validate={PROJECT_NAME_VALIDATION}
-        label="Project Name"
-        autoFocus={true} />;
+interface ProjectNameFieldProps {
+    validate: Validator[];
+    label?: string;
+}
+
+// Validation behavior depends on the value of ForwardSlashNameSubstitution.
+//
+// Redux form doesn't let you pass anonymous functions to 'validate'
+// -- it fails with a very confusing recursive-update-exceeded error.
+// So we can't construct the validation function on the fly.
+//
+// As a workaround, use ForwardSlashNameSubstitution to choose between one of two const-defined validators.
+
+export const ProjectNameField = connect(
+    (state: RootState) => {
+        return {
+            validate: (state.auth.config.clusterConfig.Collections.ForwardSlashNameSubstitution === "" ?
+                PROJECT_NAME_VALIDATION : PROJECT_NAME_VALIDATION_ALLOW_SLASH)
+        };
+    })((props: ProjectNameFieldProps) =>
+        <span data-cy='name-field'><Field
+            name='name'
+            component={TextField as any}
+            validate={props.validate}
+            label={props.label || "Project Name"}
+            autoFocus={true} /></span>
+    );
 
 export const ProjectDescriptionField = () =>
     <Field
         name='description'
-        component={TextField}
-        validate={PROJECT_DESCRIPTION_VALIDATION}
+        component={RichEditorTextField as any}
         label="Description - optional" />;
+
+export const UsersField = () =>
+        <span data-cy='users-field'><FieldArray
+            name="users"
+            component={UsersSelect as any} /></span>;
+
+export const UsersSelect = ({ fields }: WrappedFieldArrayProps<Participant>) =>
+        <ParticipantSelect
+            onlyPeople
+            label='Enter email adresses '
+            items={fields.getAll() || []}
+            onSelect={fields.push}
+            onDelete={fields.remove} />;