mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-26 01:09:10 +01:00
merged
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user