diff --git a/scm-ui/src/repos/sources/containers/Sources.js b/scm-ui/src/repos/sources/containers/Sources.js index 9a485459a6..33301b6a43 100644 --- a/scm-ui/src/repos/sources/containers/Sources.js +++ b/scm-ui/src/repos/sources/containers/Sources.js @@ -69,7 +69,7 @@ class Sources extends React.Component { 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 { 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 { } } + 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;