CLOSE_PROJECT_CREATOR: ofType<{}>(),
CREATE_PROJECT: ofType<Partial<ProjectResource>>(),
CREATE_PROJECT_SUCCESS: ofType<ProjectResource>(),
- CREATE_PROJECT_ERROR: ofType<string>(),
REMOVE_PROJECT: ofType<string>(),
PROJECTS_REQUEST: ofType<string>(),
PROJECTS_SUCCESS: ofType<{ projects: ProjectResource[], parentItemId?: string }>(),
dispatch(actions.CREATE_PROJECT(projectData));
return projectService
.create(projectData)
- .then(project => dispatch(actions.CREATE_PROJECT_SUCCESS(project)))
- .catch(errors => dispatch(actions.CREATE_PROJECT_ERROR(errors.errors.join(''))));
+ .then(project => dispatch(actions.CREATE_PROJECT_SUCCESS(project)));
};
export type ProjectAction = UnionOf<typeof actions>;
return actions.match(action, {
OPEN_PROJECT_CREATOR: ({ ownerUuid }) => updateCreator(state, { ownerUuid, opened: true }),
CLOSE_PROJECT_CREATOR: () => updateCreator(state, { opened: false }),
- CREATE_PROJECT: () => updateCreator(state, { pending: true, error: undefined }),
- CREATE_PROJECT_SUCCESS: () => updateCreator(state, { opened: false, ownerUuid: "", pending: false }),
- CREATE_PROJECT_ERROR: error => updateCreator(state, { pending: false, error }),
+ CREATE_PROJECT: () => updateCreator(state, { error: undefined }),
+ CREATE_PROJECT_SUCCESS: () => updateCreator(state, { opened: false, ownerUuid: "" }),
REMOVE_PROJECT: () => state,
PROJECTS_REQUEST: itemId => {
const items = _.cloneDeep(state.items);
+++ /dev/null
-// Copyright (C) The Arvados Authors. All rights reserved.
-//
-// SPDX-License-Identifier: AGPL-3.0
-
-import * as React from 'react';
-import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
-
-type ValidatorProps = {
- value: string,
- render: (hasError: boolean) => React.ReactElement<any>;
- isUniqName?: boolean;
- validators: Array<(value: string) => string>;
-};
-
-class Validator extends React.Component<ValidatorProps & WithStyles<CssRules>> {
- render() {
- const { classes, value, isUniqName } = this.props;
-
- return (
- <span>
- {this.props.render(!this.isValid(value))}
- {isUniqName ? <span className={classes.formInputError}>Project with this name already exists</span> : null}
- {this.props.validators.map(validate => {
- const errorMsg = validate(value);
- return errorMsg ? <span className={classes.formInputError}>{errorMsg}</span> : null;
- })}
- </span>
- );
- }
-
- isValid(value: string) {
- return this.props.validators.every(validate => validate(value).length === 0);
- }
-}
-
-export const required = (value: string) => value.length > 0 ? "" : "This value is required";
-export const maxLength = (max: number) => (value: string) => value.length <= max ? "" : `This field should have max ${max} characters.`;
-export const isUniq = (getError: () => string) => (value: string) => getError() ? "Project with this name already exists" : "";
-
-type CssRules = "formInputError";
-
-const styles: StyleRulesCallback<CssRules> = theme => ({
- formInputError: {
- color: "#ff0000",
- marginLeft: "5px",
- fontSize: "11px",
- }
-});
-
-export default withStyles(styles)(Validator);
\ No newline at end of file
+++ /dev/null
-// Copyright (C) The Arvados Authors. All rights reserved.
-//
-// SPDX-License-Identifier: AGPL-3.0
-
-export const isUniqName = (error: string) => {
- return sleep(1000).then(() => {
- if (error.includes("UniqueViolation")) {
- throw { error: 'Project with this name already exists.' };
- }
- });
- };
-
-const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
// TODO types for require
const require: any = (value: string, errorMessage = ERROR_MESSAGE) => {
- return value && value.toString().length > 0 ? void 0 : ERROR_MESSAGE;
+ return value && value.toString().length > 0 ? undefined : ERROR_MESSAGE;
};
export default require;
// SPDX-License-Identifier: AGPL-3.0
import { connect } from "react-redux";
-import { Dispatch } from "../../../node_modules/redux";
+import { Dispatch } from "redux";
+import { SubmissionError } from "redux-form";
+
import { RootState } from "../../store/store";
import DialogProjectCreate from "../dialog-create/dialog-project-create";
import actions, { createProject, getProjectList } from "../../store/project/project-action";
import { PROJECT_PANEL_ID } from "../../views/project-panel/project-panel";
const mapStateToProps = (state: RootState) => ({
- open: state.projects.creator.opened,
- pending: state.projects.creator.pending,
- error: state.projects.creator.error
+ open: state.projects.creator.opened
});
-const submit = (data: { name: string, description: string }) =>
+export const addProject = (data: { name: string, description: string }) =>
(dispatch: Dispatch, getState: () => RootState) => {
const { ownerUuid } = getState().projects.creator;
- dispatch<any>(createProject(data)).then(() => {
+ return dispatch<any>(createProject(data)).then(() => {
dispatch(dataExplorerActions.REQUEST_ITEMS({ id: PROJECT_PANEL_ID }));
dispatch<any>(getProjectList(ownerUuid));
});
dispatch(actions.CLOSE_PROJECT_CREATOR());
},
onSubmit: (data: { name: string, description: string }) => {
- dispatch<any>(submit(data));
+ return dispatch<any>(addProject(data))
+ .catch((e: any) => {
+ throw new SubmissionError({ name: e.errors.join("").includes("UniqueViolation") ? "Project with this name already exists." : "" });
+ });
}
});
import { Button, StyleRulesCallback, WithStyles, withStyles, CircularProgress } from '@material-ui/core';
import { NAME, DESCRIPTION } from '../../validators/create-project/create-project-validator';
-import { isUniqName } from '../../validators/is-uniq-name';
-interface ProjectCreateProps {
+interface DialogProjectProps {
open: boolean;
- pending: boolean;
handleClose: () => void;
onSubmit: (data: { name: string, description: string }) => void;
handleSubmit: any;
+ submitting: boolean;
}
interface TextFieldProps {
meta?: any;
}
-class DialogProjectCreate extends React.Component<ProjectCreateProps & WithStyles<CssRules>> {
- /*componentWillReceiveProps(nextProps: ProjectCreateProps) {
- const { error } = nextProps;
-
- TODO: Validation for other errors
- if (this.props.error !== error && error && error.includes("UniqueViolation")) {
- this.setState({ isUniqName: error });
- }
-}*/
-
+class DialogProjectCreate extends React.Component<DialogProjectProps & WithStyles<CssRules>> {
render() {
- const { classes, open, handleClose, pending, handleSubmit, onSubmit } = this.props;
+ const { classes, open, handleClose, handleSubmit, onSubmit, submitting } = this.props;
return (
<Dialog
open={open}
- onClose={handleClose}>
+ onClose={handleClose}
+ disableBackdropClick={true}
+ disableEscapeKeyDown={true}>
<div className={classes.dialog}>
<form onSubmit={handleSubmit((data: any) => onSubmit(data))}>
<DialogTitle id="form-dialog-title" className={classes.dialogTitle}>Create a project</DialogTitle>
label="Project Name" />
<Field name="description"
component={this.renderTextField}
- floatinglabeltext="Description"
+ floatinglabeltext="Description - optional"
validate={DESCRIPTION}
className={classes.textField}
- label="Description" />
+ label="Description - optional" />
</DialogContent>
- <DialogActions>
- <Button onClick={handleClose} className={classes.button} color="primary" disabled={pending}>CANCEL</Button>
+ <DialogActions className={classes.dialogActions}>
+ <Button onClick={handleClose} className={classes.button} color="primary" disabled={submitting}>CANCEL</Button>
<Button type="submit"
className={classes.lastButton}
color="primary"
- disabled={pending}
+ disabled={submitting}
variant="contained">
CREATE A PROJECT
</Button>
- {pending && <CircularProgress size={20} className={classes.createProgress} />}
+ {submitting && <CircularProgress size={20} className={classes.createProgress} />}
</DialogActions>
</form>
</div>
);
}
- // TODO Make it separate file
renderTextField = ({ input, label, meta: { touched, error }, ...custom }: TextFieldProps) => (
<TextField
- helperText={touched && error ? error : void 0}
+ helperText={touched && error}
label={label}
className={this.props.classes.textField}
- error={touched && !!error}
+ error={touched && !!error}
autoComplete='off'
{...input}
{...custom}
)
}
-type CssRules = "button" | "lastButton" | "formContainer" | "textField" | "dialog" | "dialogTitle" | "createProgress";
+type CssRules = "button" | "lastButton" | "formContainer" | "textField" | "dialog" | "dialogTitle" | "createProgress" | "dialogActions";
const styles: StyleRulesCallback<CssRules> = theme => ({
button: {
minWidth: "20px",
right: "95px"
},
+ dialogActions: {
+ marginBottom: "24px"
+ }
});
export default compose(
- reduxForm({ form: 'projectCreateDialog',/* asyncValidate: isUniqName, asyncBlurFields: ["name"] */}),
+ reduxForm({ form: 'projectCreateDialog' }),
withStyles(styles)
)(DialogProjectCreate);
\ No newline at end of file