From 250503f74b3d2697c69d301edc35d146c9f98141 Mon Sep 17 00:00:00 2001 From: Eduard Heimbuch Date: Mon, 9 Sep 2019 08:31:37 +0200 Subject: [PATCH 1/2] select defaultBranch on sources and commits when not yet selected --- scm-ui/src/repos/containers/ChangesetsRoot.js | 21 +++++++++++++++++++ .../src/repos/sources/containers/Sources.js | 11 ++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/scm-ui/src/repos/containers/ChangesetsRoot.js b/scm-ui/src/repos/containers/ChangesetsRoot.js index 8e0b44afbe..db440b17c0 100644 --- a/scm-ui/src/repos/containers/ChangesetsRoot.js +++ b/scm-ui/src/repos/containers/ChangesetsRoot.js @@ -43,8 +43,29 @@ type Props = { class ChangesetsRoot extends React.Component { 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); diff --git a/scm-ui/src/repos/sources/containers/Sources.js b/scm-ui/src/repos/sources/containers/Sources.js index d09e18e5be..065dfb5a51 100644 --- a/scm-ui/src/repos/sources/containers/Sources.js +++ b/scm-ui/src/repos/sources/containers/Sources.js @@ -80,20 +80,17 @@ class Sources extends React.Component { } 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; }; From 0b3afd197d9269b0ffa92c53c9c3e603ac7c8120 Mon Sep 17 00:00:00 2001 From: Eduard Heimbuch Date: Thu, 19 Sep 2019 06:45:17 +0000 Subject: [PATCH 2/2] Close branch feature/sources_commits_default_branch