Add new default branch option with 'main' as default

This commit is contained in:
Florian Scholdei
2020-10-22 01:17:47 +02:00
committed by René Pfeuffer
parent b48bf24834
commit 196ea227d2
5 changed files with 43 additions and 4 deletions

View File

@@ -24,12 +24,13 @@
import React from "react";
import { WithTranslation, withTranslation } from "react-i18next";
import { Links } from "@scm-manager/ui-types";
import { InputField, Checkbox } from "@scm-manager/ui-components";
import { InputField, Checkbox, validation as validator } from "@scm-manager/ui-components";
type Configuration = {
repositoryDirectory?: string;
gcExpression?: string;
nonFastForwardDisallowed: boolean;
defaultBranch: string;
_links: Links;
};
@@ -68,8 +69,21 @@ class GitConfigurationForm extends React.Component<Props, State> {
);
};
onDefaultBranchChange = (value: string) => {
this.setState(
{
defaultBranch: value
},
() => this.props.onConfigurationChange(this.state, this.isValidDefaultBranch())
);
};
isValidDefaultBranch = () => {
return validator.isNameValid(this.state.defaultBranch);
};
render() {
const { gcExpression, nonFastForwardDisallowed } = this.state;
const { gcExpression, nonFastForwardDisallowed, defaultBranch } = this.state;
const { readOnly, t } = this.props;
return (
@@ -90,6 +104,15 @@ class GitConfigurationForm extends React.Component<Props, State> {
onChange={this.onNonFastForwardDisallowed}
disabled={readOnly}
/>
<InputField
name="defaultBranch"
label={t("scm-git-plugin.config.defaultBranch")}
value={defaultBranch}
onChange={this.onDefaultBranchChange}
disabled={readOnly}
validationError={!this.isValidDefaultBranch()}
errorMessage={t("scm-git-plugin.config.defaultBranchValidationError")}
/>
</>
);
}