1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import { Field, Validator } from "redux-form";
7 import { TextField } from "components/text-field/text-field";
9 COLLECTION_NAME_VALIDATION, COLLECTION_NAME_VALIDATION_ALLOW_SLASH,
10 COLLECTION_DESCRIPTION_VALIDATION, COLLECTION_PROJECT_VALIDATION
11 } from "validators/validators";
12 import { ProjectTreePickerField, CollectionTreePickerField, DirectoryTreePickerField } from "views-components/projects-tree-picker/tree-picker-field";
13 import { PickerIdProp } from 'store/tree-picker/picker-id';
14 import { connect } from "react-redux";
15 import { RootState } from "store/store";
16 import { MultiCheckboxField } from "components/checkbox-field/checkbox-field";
17 import { getStorageClasses } from "common/config";
18 import { ERROR_MESSAGE } from "validators/require";
20 interface CollectionNameFieldProps {
21 validate: Validator[];
24 // See implementation note on declaration of ProjectNameField
26 export const CollectionNameField = connect(
27 (state: RootState) => {
29 validate: (state.auth.config.clusterConfig.Collections.ForwardSlashNameSubstitution === "" ?
30 COLLECTION_NAME_VALIDATION : COLLECTION_NAME_VALIDATION_ALLOW_SLASH)
32 })((props: CollectionNameFieldProps) =>
33 <span data-cy='name-field'><Field
35 component={TextField as any}
36 validate={props.validate}
37 label="Collection Name"
38 autoFocus={true} /></span>
41 export const CollectionDescriptionField = () =>
44 component={TextField as any}
45 validate={COLLECTION_DESCRIPTION_VALIDATION}
46 label="Description" />;
48 export const CollectionProjectPickerField = (props: PickerIdProp) =>
51 pickerId={props.pickerId}
52 component={ProjectTreePickerField}
53 validate={COLLECTION_PROJECT_VALIDATION} />;
55 export const CollectionPickerField = (props: PickerIdProp) =>
58 pickerId={props.pickerId}
59 component={CollectionTreePickerField}
60 validate={COLLECTION_PROJECT_VALIDATION} />;
62 const validateDirectory = (val) => (val && val.uuid ? undefined : ERROR_MESSAGE);
64 export const DirectoryPickerField = (props: PickerIdProp) =>
67 pickerId={props.pickerId}
68 component={DirectoryTreePickerField as any}
69 validate={validateDirectory} />;
71 interface StorageClassesProps {
73 defaultClasses?: string[];
76 export const CollectionStorageClassesField = connect(
77 (state: RootState) => {
79 items: getStorageClasses(state.auth.config)
82 (props: StorageClassesProps) =>
84 name='storageClassesDesired'
85 label='Storage classes'
88 defaultValues={props.defaultClasses}
89 helperText='At least one class should be selected'
90 component={MultiCheckboxField}
91 items={props.items} />);