From 63137ff5c50e0a6822a2a80ddd18f00487eee1cc Mon Sep 17 00:00:00 2001 From: Florian Scholdei Date: Wed, 3 Apr 2019 17:16:55 +0200 Subject: [PATCH] ordered branches in selectfield and added first form validation --- scm-ui/public/locales/en/repos.json | 5 ++++- .../repos/branches/components/BranchForm.js | 20 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/scm-ui/public/locales/en/repos.json b/scm-ui/public/locales/en/repos.json index 4eeddea8b2..ad59f2b5e0 100644 --- a/scm-ui/public/locales/en/repos.json +++ b/scm-ui/public/locales/en/repos.json @@ -11,7 +11,10 @@ "validation": { "namespace-invalid": "The repository namespace is invalid", "name-invalid": "The repository name is invalid", - "contact-invalid": "Contact must be a valid mail address" + "contact-invalid": "Contact must be a valid mail address", + "branch": { + "nameInvalid": "The branch name is invalid" + } }, "help": { "namespaceHelpText": "The namespace of the repository. This name will be part of the repository url.", diff --git a/scm-ui/src/repos/branches/components/BranchForm.js b/scm-ui/src/repos/branches/components/BranchForm.js index fa14192c07..1c7409e8a7 100644 --- a/scm-ui/src/repos/branches/components/BranchForm.js +++ b/scm-ui/src/repos/branches/components/BranchForm.js @@ -8,6 +8,7 @@ import { SubmitButton, validation as validator } from "@scm-manager/ui-components"; +import { orderBranches } from "../util/orderBranches"; type Props = { submitForm: Branch => void, @@ -32,8 +33,17 @@ class BranchForm extends React.Component { }; } + isFalsy(value) { + return !value; + } + isValid = () => { - return true; //TODO + const { source, name } = this.state; + return !( + this.state.nameValidationError || + this.isFalsy(source) || + this.isFalsy(name) + ); }; submit = (event: Event) => { @@ -44,8 +54,9 @@ class BranchForm extends React.Component { }; render() { - const { t, branches } = this.props; - const { loading } = this.state; + const { t, branches, loading } = this.props; + const { name } = this.state; + orderBranches(branches); const options = branches.map(branch => ({ label: branch.name, value: branch.name @@ -67,6 +78,9 @@ class BranchForm extends React.Component { name="name" label={t("branches.create.name")} onChange={this.handleNameChange} + value={name ? name : ""} + validationError={this.state.nameValidationError} + errorMessage={t("validation.branch.nameInvalid")} />