diff --git a/scm-ui-components/packages/ui-components/src/forms/Select.js b/scm-ui-components/packages/ui-components/src/forms/Select.js index 38e1cdab33..5d37e3d631 100644 --- a/scm-ui-components/packages/ui-components/src/forms/Select.js +++ b/scm-ui-components/packages/ui-components/src/forms/Select.js @@ -15,7 +15,8 @@ type Props = { value?: string, onChange: (value: string, name?: string) => void, loading?: boolean, - helpText?: string + helpText?: string, + disabled?: boolean }; class Select extends React.Component { @@ -34,7 +35,7 @@ class Select extends React.Component { }; render() { - const { options, value, label, helpText, loading } = this.props; + const { options, value, label, helpText, loading, disabled } = this.props; const loadingClass = loading ? "is-loading" : ""; @@ -51,6 +52,7 @@ class Select extends React.Component { }} value={value} onChange={this.handleInput} + disabled={disabled} > {options.map(opt => { return ( diff --git a/scm-ui/src/repos/branches/components/BranchForm.js b/scm-ui/src/repos/branches/components/BranchForm.js index d72e2196ba..1219511345 100644 --- a/scm-ui/src/repos/branches/components/BranchForm.js +++ b/scm-ui/src/repos/branches/components/BranchForm.js @@ -16,6 +16,7 @@ type Props = { branches: Branch[], loading?: boolean, transmittedName?: string, + disabled?: boolean, t: string => string }; @@ -59,7 +60,7 @@ class BranchForm extends React.Component { }; render() { - const { t, branches, loading, transmittedName } = this.props; + const { t, branches, loading, transmittedName, disabled } = this.props; const { name } = this.state; orderBranches(branches); const options = branches.map(branch => ({ @@ -78,6 +79,7 @@ class BranchForm extends React.Component { options={options} onChange={this.handleSourceChange} loading={loading} + disabled={disabled} /> { value={name ? name : ""} validationError={this.state.nameValidationError} errorMessage={t("validation.branch.nameInvalid")} - disabled={!!transmittedName} + disabled={!!transmittedName || disabled} />
diff --git a/scm-ui/src/repos/branches/containers/BranchesOverview.js b/scm-ui/src/repos/branches/containers/BranchesOverview.js index f8c8be7529..5f11f87116 100644 --- a/scm-ui/src/repos/branches/containers/BranchesOverview.js +++ b/scm-ui/src/repos/branches/containers/BranchesOverview.js @@ -4,7 +4,8 @@ import { fetchBranches, getBranches, getFetchBranchesFailure, - isFetchBranchesPending + isFetchBranchesPending, + isPermittedToCreateBranches } from "../modules/branches"; import { orderBranches } from "../util/orderBranches"; import { connect } from "react-redux"; @@ -67,8 +68,7 @@ class BranchesOverview extends React.Component { renderCreateButton() { const { showCreateButton, t } = this.props; - if (showCreateButton || true) { - // TODO + if (showCreateButton) { return ( { const loading = isFetchBranchesPending(state, repository); const error = getFetchBranchesFailure(state, repository); const branches = getBranches(state, repository); + const showCreateButton = isPermittedToCreateBranches(state, repository); return { repository, loading, error, - branches + branches, + showCreateButton }; }; diff --git a/scm-ui/src/repos/branches/containers/CreateBranch.js b/scm-ui/src/repos/branches/containers/CreateBranch.js index 3bfc4ac651..cefa712bad 100644 --- a/scm-ui/src/repos/branches/containers/CreateBranch.js +++ b/scm-ui/src/repos/branches/containers/CreateBranch.js @@ -30,6 +30,7 @@ type Props = { repository: Repository, branches: Branch[], createBranchesLink: string, + isPermittedToCreateBranches: boolean, // dispatcher functions fetchBranches: Repository => void, @@ -78,7 +79,7 @@ class CreateBranch extends React.Component { }; render() { - const { t, loading, error, repository, branches, location } = this.props; + const { t, loading, error, repository, branches, createBranchesLink, location } = this.props; if (error) { return ; @@ -97,6 +98,7 @@ class CreateBranch extends React.Component { repository={repository} branches={branches} transmittedName={this.transmittedName(location.search)} + disabled={!createBranchesLink} /> ); diff --git a/scm-ui/src/repos/branches/modules/branches.js b/scm-ui/src/repos/branches/modules/branches.js index 660a3e007c..054a303a05 100644 --- a/scm-ui/src/repos/branches/modules/branches.js +++ b/scm-ui/src/repos/branches/modules/branches.js @@ -119,7 +119,7 @@ export function getBranches(state: Object, repository: Repository) { export function getBranchCreateLink(state: Object, repository: Repository) { const repoState = getRepoState(state, repository); - if (repoState && repoState.list) { + if (repoState && repoState.list && repoState.list._links && repoState.list._links.create) { return repoState.list._links.create.href; } }