check if sources view should redirect to defaultBranch

This commit is contained in:
Eduard Heimbuch
2019-09-04 13:34:30 +02:00
parent 13dccf4729
commit b5769ae693

View File

@@ -69,7 +69,7 @@ class Sources extends React.Component<Props, State> {
fetchBranches(repository);
fetchSources(repository, revision, path);
if (branches) {
if (this.shouldRedirect()) {
const defaultBranches = branches.filter(b => b.defaultBranch);
if (defaultBranches.length > 0)
@@ -91,12 +91,7 @@ class Sources extends React.Component<Props, State> {
fetchSources(repository, revision, path);
}
const currentUrl = this.props.location.pathname;
if (
branches &&
(currentUrl.endsWith("sources") || currentUrl.endsWith("sources/"))
) {
if (this.shouldRedirect()) {
const defaultBranches = branches.filter(b => b.defaultBranch);
if (defaultBranches.length > 0)
@@ -105,6 +100,15 @@ class Sources extends React.Component<Props, State> {
}
}
shouldRedirect = () => {
const { branches, location } = this.props;
return (
branches &&
(location.pathname.endsWith("sources") ||
location.pathname.endsWith("sources/"))
);
};
branchSelected = (branch?: Branch) => {
const { baseUrl, history, path } = this.props;
let url;