This commit is contained in:
Eduard Heimbuch
2019-09-19 11:23:33 +02:00
2 changed files with 25 additions and 7 deletions

View File

@@ -43,8 +43,29 @@ type Props = {
class ChangesetsRoot extends React.Component<Props> {
componentDidMount() {
this.props.fetchBranches(this.props.repository);
this.redirectToDefaultBranch();
}
redirectToDefaultBranch = () => {
if (this.shouldRedirectToDefaultBranch()) {
const defaultBranches = this.props.branches.filter(
b => b.defaultBranch === true
);
if (defaultBranches.length > 0) {
this.branchSelected(defaultBranches[0]);
}
}
};
shouldRedirectToDefaultBranch = () => {
return (
this.props.branches &&
this.props.branches.length > 0 &&
this.props.selected !==
this.props.branches.filter(b => b.defaultBranch === true)[0]
);
};
stripEndingSlash = (url: string) => {
if (url.endsWith("/")) {
return url.substring(0, url.length - 1);

View File

@@ -80,20 +80,17 @@ class Sources extends React.Component<Props, State> {
}
redirectToDefaultBranch = () => {
const { branches, baseUrl } = this.props;
if (this.shouldRedirect()) {
const { branches } = this.props;
if (this.shouldRedirectToDefaultBranch()) {
const defaultBranches = branches.filter(b => b.defaultBranch);
if (defaultBranches.length > 0) {
this.props.history.push(
`${baseUrl}/${encodeURIComponent(defaultBranches[0].name)}/`
);
this.setState({ selectedBranch: defaultBranches[0] });
this.branchSelected(defaultBranches[0]);
}
}
};
shouldRedirect = () => {
shouldRedirectToDefaultBranch = () => {
const { branches, revision } = this.props;
return branches && !revision;
};