Disable default branch config without permission

This commit is contained in:
René Pfeuffer
2019-03-11 14:56:59 +01:00
parent 087aa35617
commit 6cf79bf5c6
2 changed files with 13 additions and 8 deletions

View File

@@ -18,7 +18,8 @@ type State = {
error?: Error,
branches: Branch[],
selectedBranchName?: string,
defaultBranchChanged: boolean
defaultBranchChanged: boolean,
disabled: boolean
};
const GIT_CONFIG_CONTENT_TYPE = "application/vnd.scmm-gitConfig+json";
@@ -33,7 +34,8 @@ class RepositoryConfig extends React.Component<Props, State> {
loadingDefaultBranch: true,
submitPending: false,
branches: [],
defaultBranchChanged: false
defaultBranchChanged: false,
disabled: true
};
}
@@ -53,11 +55,11 @@ class RepositoryConfig extends React.Component<Props, State> {
apiClient
.get(repository._links.configuration.href)
.then(response => response.json())
.then(payload => payload.defaultBranch)
.then(selectedBranchName =>
.then(payload =>
this.setState({
...this.state,
selectedBranchName,
selectedBranchName: payload.defaultBranch,
disabled: !payload._links.update,
loadingDefaultBranch: false
})
)
@@ -98,7 +100,7 @@ class RepositoryConfig extends React.Component<Props, State> {
render() {
const { t } = this.props;
const { loadingBranches, loadingDefaultBranch, submitPending, error } = this.state;
const { loadingBranches, loadingDefaultBranch, submitPending, error, disabled } = this.state;
if (error) {
return (
@@ -121,11 +123,12 @@ class RepositoryConfig extends React.Component<Props, State> {
branches={this.state.branches}
selected={this.branchSelected}
selectedBranch={this.state.selectedBranchName}
disabled={disabled}
/>
<SubmitButton
label={t("scm-git-plugin.repo-config.submit")}
loading={submitPending}
disabled={!this.state.selectedBranchName}
disabled={!this.state.selectedBranchName || disabled}
/>
</form>
<hr />

View File

@@ -26,6 +26,7 @@ type Props = {
selected: (branch?: Branch) => void,
selectedBranch?: string,
label: string,
disabled?: boolean,
// context props
classes: Object
@@ -47,7 +48,7 @@ class BranchSelector extends React.Component<Props, State> {
}
render() {
const { branches, classes, label } = this.props;
const { branches, classes, label, disabled } = this.props;
if (branches) {
return (
@@ -79,6 +80,7 @@ class BranchSelector extends React.Component<Props, State> {
className="is-fullwidth"
options={branches.map(b => b.name)}
optionSelected={this.branchSelected}
disabled={!!disabled}
preselectedOption={
this.state.selectedBranch
? this.state.selectedBranch.name