Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check team and project name validity #3034

Merged
merged 11 commits into from
Aug 13, 2018
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.md).
- Added the possibility to copy volume tracings to own account
- During the import of multiple NML files, the user can select an option to automatically create a group per file so that the imported trees are organized in a hierarchy. [#2908](https://github.com/scalableminds/webknossos/pull/2908)
- Added functions to the front-end API to activate a tree and to change the color of a tree. [#2997](https://github.com/scalableminds/webknossos/pull/2997)
- When a new team is created invalid names will be directly marked in red [#2591](https://github.com/scalableminds/webknossos/issues/2591)
- Comments can now contain references to nodes (`#<nodeid>`) or positions (`#(<x,y,z>)`). Clicking on such a reference activates the respective node or position and centers it. [#2950](https://github.com/scalableminds/webknossos/pull/2950)

### Changed
Expand Down
8 changes: 7 additions & 1 deletion app/assets/javascripts/admin/project/project_create_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,14 @@ class ProjectCreateView extends React.PureComponent<Props, State> {
rules: [
{
required: true,
pattern: "^[a-zA-Z0-9_-]*$",
message: "invalide project name, there are no whitespaces allowed",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "The project name must not contain whitespace." (with fullstop), since this is a user-facing message.

},
{
min: 3,
required: true,
message: "project name must be at least 3 characters long",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Project name [...] ." (capitalization and full stop)

},
{ min: 3 },
],
})(<Input autoFocus disabled={isEditMode} />)}
</FormItem>
Expand Down
67 changes: 29 additions & 38 deletions app/assets/javascripts/admin/team/create_team_modal_view.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,60 @@
// @flow
import * as React from "react";
import { Modal, Input, Button } from "antd";
import { Modal, Input, Form } from "antd";
import { createTeam } from "admin/admin_rest_api";

const FormItem = Form.Item;

type Props = {
onOk: Function,
onCancel: Function,
isVisible: boolean,
form: Object,
};

type State = {
newTeamName: string,
};

class CreateTeamModalView extends React.PureComponent<Props, State> {
state = {
newTeamName: "",
};

class CreateTeamModalForm extends React.PureComponent<Props> {
onOk = async () => {
if (this.state.newTeamName !== "") {
this.props.form.validateFields(async (err, values) => {
if (err) {
return;
}
const newTeam = {
name: this.state.newTeamName,
name: values["Team Name"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This syntax (having a string instead of a variable inside the square brackets) is usually a sign that something is weird :) In this case, you should rename "Team Name" to "teamName" in your getFieldDecorator call. Then, you can access `values.teamName" here.

roles: [{ name: "admin" }, { name: "user" }],
};

const team = await createTeam(newTeam);
this.setState({
newTeamName: "",
});

this.props.onOk(team);
}
});
};

isInputValid(): boolean {
return this.state.newTeamName !== "";
}

render() {
const { getFieldDecorator } = this.props.form;
return (
<Modal
title="Add a New Team"
visible={this.props.isVisible}
title="Add a New Team"
okText="Ok"
onCancel={this.props.onCancel}
footer={
<div>
<Button onClick={this.props.onCancel}>Cancel</Button>
<Button type="primary" onClick={this.onOk} disabled={!this.isInputValid()}>
Ok
</Button>
</div>
}
onOk={this.onOk}
>
<Input
value={this.state.newTeamName}
onChange={(event: SyntheticInputEvent<*>) =>
this.setState({ newTeamName: event.target.value })
}
icon="tag-o"
placeholder="Team Name"
autoFocus
/>
<Form layout="vertical">
<FormItem label="Team Name">
{getFieldDecorator("Team Name", {
rules: [
{
required: true,
pattern: "^[A-Za-z0-9\\-_\\. ß]+$",
message: "Please enter a valide team name.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valid without e :)

},
],
})(<Input icon="tag-o" placeholder="Team Name" autoFocus />)}
</FormItem>
</Form>
</Modal>
);
}
}
const CreateTeamModalView = Form.create()(CreateTeamModalForm);
export default CreateTeamModalView;