diff --git a/scm-ui-components/packages/ui-components/src/Breadcrumb.js b/scm-ui-components/packages/ui-components/src/Breadcrumb.js index d81a4cbf63..b9011f5936 100644 --- a/scm-ui-components/packages/ui-components/src/Breadcrumb.js +++ b/scm-ui-components/packages/ui-components/src/Breadcrumb.js @@ -77,7 +77,12 @@ class Breadcrumb extends React.Component { b.name === revision).length > 0 }} + props={{ + baseUrl, + branch: branch ? branch : defaultBranch, + path, + isBranchUrl: branches && + branches.filter(b => b.name.replace("/", "%2F") === revision).length > 0 }} renderAll={true} /> diff --git a/scm-ui/src/repos/sources/containers/Sources.js b/scm-ui/src/repos/sources/containers/Sources.js index 33301b6a43..ddf71e9315 100644 --- a/scm-ui/src/repos/sources/containers/Sources.js +++ b/scm-ui/src/repos/sources/containers/Sources.js @@ -61,44 +61,36 @@ class Sources extends React.Component { repository, revision, path, - branches, - baseUrl, fetchSources } = this.props; fetchBranches(repository); fetchSources(repository, revision, path); - if (this.shouldRedirect()) { - const defaultBranches = branches.filter(b => b.defaultBranch); - - if (defaultBranches.length > 0) - this.setState({ selectedBranch: defaultBranches[0] }); - this.props.history.push(`${baseUrl}/${defaultBranches[0].name}/`); - } + this.redirectToDefaultBranch(); } componentDidUpdate(prevProps) { - const { - fetchSources, - repository, - revision, - path, - branches, - baseUrl - } = this.props; + const { fetchSources, repository, revision, path } = this.props; if (prevProps.revision !== revision || prevProps.path !== path) { fetchSources(repository, revision, path); } + this.redirectToDefaultBranch(); + } + + redirectToDefaultBranch = () => { + const { branches, baseUrl } = this.props; if (this.shouldRedirect()) { const defaultBranches = branches.filter(b => b.defaultBranch); if (defaultBranches.length > 0) this.setState({ selectedBranch: defaultBranches[0] }); - this.props.history.push(`${baseUrl}/${defaultBranches[0].name}/`); + this.props.history.push( + `${baseUrl}/${defaultBranches[0].name.replace("/", "%2F")}/` + ); } - } + }; shouldRedirect = () => { const { branches, location } = this.props;