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[];
16 // Validation behavior depends on the value of ForwardSlashNameSubstitution.
18 // Redux form doesn't let you pass anonymous functions to 'validate'
19 // -- it fails with a very confusing recursive-update-exceeded error.
20 // So we can't construct the validation function on the fly.
22 // As a workaround, use ForwardSlashNameSubstitution to choose between one of two const-defined validators.
24 export const ProjectNameField = connect(
25 (state: RootState) => {
27 validate: (state.auth.config.clusterConfig.Collections.ForwardSlashNameSubstitution === "" ?
28 PROJECT_NAME_VALIDATION : PROJECT_NAME_VALIDATION_ALLOW_SLASH)
30 })((props: ProjectNameFieldProps) =>
31 <span data-cy='name-field'><Field
34 validate={props.validate}
36 autoFocus={true} /></span>
39 export const ProjectDescriptionField = () =>
42 component={RichEditorTextField}
43 label="Description - optional" />;