mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 23:45:44 +01:00
redirect missing branch to default branch if available on sourcesView
This commit is contained in:
@@ -4,7 +4,12 @@ import {connect} from "react-redux";
|
|||||||
import { withRouter } from "react-router-dom";
|
import { withRouter } from "react-router-dom";
|
||||||
import type { Branch, Repository } from "@scm-manager/ui-types";
|
import type { Branch, Repository } from "@scm-manager/ui-types";
|
||||||
import FileTree from "../components/FileTree";
|
import FileTree from "../components/FileTree";
|
||||||
import {BranchSelector, Breadcrumb, ErrorNotification, Loading} from "@scm-manager/ui-components";
|
import {
|
||||||
|
BranchSelector,
|
||||||
|
Breadcrumb,
|
||||||
|
ErrorNotification,
|
||||||
|
Loading
|
||||||
|
} from "@scm-manager/ui-components";
|
||||||
import { translate } from "react-i18next";
|
import { translate } from "react-i18next";
|
||||||
import {
|
import {
|
||||||
fetchBranches,
|
fetchBranches,
|
||||||
@@ -33,6 +38,7 @@ type Props = {
|
|||||||
// Context props
|
// Context props
|
||||||
history: any,
|
history: any,
|
||||||
match: any,
|
match: any,
|
||||||
|
location: any,
|
||||||
t: string => string
|
t: string => string
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -55,17 +61,48 @@ class Sources extends React.Component<Props, State> {
|
|||||||
repository,
|
repository,
|
||||||
revision,
|
revision,
|
||||||
path,
|
path,
|
||||||
|
branches,
|
||||||
|
baseUrl,
|
||||||
fetchSources
|
fetchSources
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
fetchBranches(repository);
|
fetchBranches(repository);
|
||||||
fetchSources(repository, revision, path);
|
fetchSources(repository, revision, path);
|
||||||
|
|
||||||
|
if (branches) {
|
||||||
|
const defaultBranches = branches.filter(b => b.defaultBranch);
|
||||||
|
|
||||||
|
if (defaultBranches.length > 0)
|
||||||
|
this.setState({ selectedBranch: defaultBranches[0] });
|
||||||
|
this.props.history.push(`${baseUrl}/${defaultBranches[0].name}/`);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
const { fetchSources, repository, revision, path } = this.props;
|
const {
|
||||||
|
fetchSources,
|
||||||
|
repository,
|
||||||
|
revision,
|
||||||
|
path,
|
||||||
|
branches,
|
||||||
|
baseUrl
|
||||||
|
} = this.props;
|
||||||
if (prevProps.revision !== revision || prevProps.path !== path) {
|
if (prevProps.revision !== revision || prevProps.path !== path) {
|
||||||
fetchSources(repository, revision, path);
|
fetchSources(repository, revision, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const currentUrl = this.props.location.pathname;
|
||||||
|
|
||||||
|
if (
|
||||||
|
branches &&
|
||||||
|
(currentUrl.endsWith("sources") || currentUrl.endsWith("sources/"))
|
||||||
|
) {
|
||||||
|
const defaultBranches = branches.filter(b => b.defaultBranch);
|
||||||
|
|
||||||
|
if (defaultBranches.length > 0)
|
||||||
|
this.setState({ selectedBranch: defaultBranches[0] });
|
||||||
|
this.props.history.push(`${baseUrl}/${defaultBranches[0].name}/`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
branchSelected = (branch?: Branch) => {
|
branchSelected = (branch?: Branch) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user