1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from "react";
6 import { Field, Validator } from "redux-form";
7 import { TextField, RichEditorTextField } from "~/components/text-field/text-field";
8 import { PROJECT_NAME_VALIDATION, PROJECT_NAME_VALIDATION_ALLOW_SLASH } from "~/validators/validators";
9 import { connect } from "react-redux";
10 import { RootState } from "~/store/store";
12 interface ProjectNameFieldProps {
13 validate: Validator[];
17 // Validation behavior depends on the value of ForwardSlashNameSubstitution.
19 // Redux form doesn't let you pass anonymous functions to 'validate'
20 // -- it fails with a very confusing recursive-update-exceeded error.
21 // So we can't construct the validation function on the fly.
23 // As a workaround, use ForwardSlashNameSubstitution to choose between one of two const-defined validators.
25 export const ProjectNameField = connect(
26 (state: RootState) => {
28 validate: (state.auth.config.clusterConfig.Collections.ForwardSlashNameSubstitution === "" ?
29 PROJECT_NAME_VALIDATION : PROJECT_NAME_VALIDATION_ALLOW_SLASH)
31 })((props: ProjectNameFieldProps) =>
32 <span data-cy='name-field'><Field
35 validate={props.validate}
36 label={props.label || "Project Name"}
37 autoFocus={true} /></span>
40 export const ProjectDescriptionField = () =>
43 component={RichEditorTextField}
44 label="Description - optional" />;