From b5769ae69350f9d93bf01bee37709b0995649d44 Mon Sep 17 00:00:00 2001 From: Eduard Heimbuch Date: Wed, 4 Sep 2019 13:34:30 +0200 Subject: [PATCH] check if sources view should redirect to defaultBranch --- scm-ui/src/repos/sources/containers/Sources.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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;