const collName = `[Test collection (${Math.floor(999999 * Math.random())})]`;
cy.get('[data-cy=form-dialog]')
.should('contain', 'New collection')
+ .and('contain', 'Storage classes')
+ .and('contain', 'default')
+ .and('contain', 'foo')
+ .and('contain', 'bar')
.within(() => {
cy.get('[data-cy=parent-field]').within(() => {
cy.get('input').should('have.value', 'Home project');
- })
+ });
cy.get('[data-cy=name-field]').within(() => {
cy.get('input').type(collName);
- })
+ });
+ cy.get('[data-cy=checkbox-foo]').click();
})
cy.get('[data-cy=form-submit-btn]').click();
// Confirm that the user was taken to the newly created thing
cy.get('[data-cy=form-dialog]').should('not.exist');
cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
cy.get('[data-cy=breadcrumb-last]').should('contain', collName);
+ cy.get('[data-cy=collection-info-panel]')
+ .should('contain', 'default')
+ .and('contain', 'foo')
+ .and('not.contain', 'bar');
});
it('shows responsible person for collection if available', () => {
type MultiCheckboxFieldProps = {
items: string[];
+ defaultValues?: string[];
label?: string;
minSelection?: number;
maxSelection?: number;
export const MultiCheckboxField = (props: WrappedFieldProps & MultiCheckboxFieldProps) => {
const isValid = (items: string[]) => (items.length >= (props.minSelection || 0)) &&
(items.length <= (props.maxSelection || items.length));
+ if (props.input.value.length === 0 && (props.defaultValues || []).length !== 0) {
+ props.input.value = props.defaultValues ? [...props.defaultValues] : [];
+ }
return <FormControl error={!isValid(props.input.value)}>
<FormLabel component='label'>{props.label}</FormLabel>
<FormGroup row={props.rowLayout}>
{ props.items.map((item, idx) =>
<FormControlLabel
+ key={`label-${idx}`}
control={
<Checkbox
data-cy={`checkbox-${item}`}
- key={idx}
+ key={`control-${idx}`}
name={`${props.input.name}[${idx}]`}
value={item}
- checked={props.input.value.indexOf(item) !== -1}
+ checked={
+ props.input.value.indexOf(item) !== -1 ||
+ (props.input.value.length === 0 &&
+ (props.defaultValues || []).indexOf(item) !== -1)
+ }
onChange={e => {
const newValue = [...props.input.value];
if (e.target.checked) {
ownerUuid: string;
name: string;
description: string;
+ storageClassesDesired: string[];
}
export const COLLECTION_CREATE_FORM_NAME = "collectionCreateFormName";
import { WithDialogProps } from 'store/dialog/with-dialog';
import { CollectionCreateFormDialogData } from 'store/collections/collection-create-actions';
import { FormDialog } from 'components/form-dialog/form-dialog';
-import { CollectionNameField, CollectionDescriptionField } from 'views-components/form-fields/collection-form-fields';
+import {
+ CollectionNameField,
+ CollectionDescriptionField,
+ CollectionStorageClassesField
+} from 'views-components/form-fields/collection-form-fields';
import { FileUploaderField } from '../file-uploader/file-uploader';
import { ResourceParentField } from '../form-fields/resource-form-fields';
<ResourceParentField />
<CollectionNameField />
<CollectionDescriptionField />
+ <CollectionStorageClassesField defaultClasses={['default']} />
<Field
name='files'
label='Files'
onSubmit: (data, dispatch) => {
// Somehow an extra field called 'files' gets added, copy
// the data object to get rid of it.
- dispatch(createCollection({ ownerUuid: data.ownerUuid, name: data.name, description: data.description }));
+ dispatch(createCollection({ ownerUuid: data.ownerUuid, name: data.name, description: data.description, storageClassesDesired: data.storageClassesDesired }));
}
})
)(DialogCollectionCreate);
interface StorageClassesProps {
items: string[];
+ defaultClasses?: string[];
}
export const CollectionStorageClassesField = connect(
label='Storage classes'
minSelection={1}
rowLayout={true}
+ defaultValues={props.defaultClasses}
helperText='At least one class should be selected'
component={MultiCheckboxField}
items={props.items} />);
\ No newline at end of file