diff --git a/scm-ui/ui-webapp/src/repos/sources/containers/HistoryView.tsx b/scm-ui/ui-webapp/src/repos/sources/containers/HistoryView.tsx index 7633a7d84d..ac46b91938 100644 --- a/scm-ui/ui-webapp/src/repos/sources/containers/HistoryView.tsx +++ b/scm-ui/ui-webapp/src/repos/sources/containers/HistoryView.tsx @@ -14,6 +14,7 @@ type State = { page: number; pageCollection?: PagedCollection; error?: Error; + currentRevision: string; }; class HistoryView extends React.Component { @@ -23,35 +24,44 @@ class HistoryView extends React.Component { this.state = { loaded: false, page: 1, - changesets: [] + changesets: [], + currentRevision: "" }; } componentDidMount() { const { file } = this.props; - this.updateHistory(file._links.history.href); + file && this.updateHistory(file._links.history.href); + } + + componentDidUpdate() { + const { file } = this.props; + const { currentRevision } = this.state; + if (file?.revision !== currentRevision) { + this.updateHistory(file._links.history.href); + } } updateHistory(link: string) { + const { file } = this.props; getHistory(link) .then(result => { - if (result.error) { - this.setState({ - ...this.state, - error: result.error, - loaded: true - }); - } else { - this.setState({ - ...this.state, - loaded: true, - changesets: result.changesets, - pageCollection: result.pageCollection, - page: result.pageCollection.page - }); - } + this.setState({ + ...this.state, + loaded: true, + changesets: result.changesets, + pageCollection: result.pageCollection, + page: result.pageCollection.page, + currentRevision: file.revision + }); }) - .catch(err => {}); + .catch(error => + this.setState({ + ...this.state, + error, + loaded: true + }) + ); } updatePage(page: number) { diff --git a/scm-ui/ui-webapp/src/repos/sources/containers/Sources.tsx b/scm-ui/ui-webapp/src/repos/sources/containers/Sources.tsx index 5ce82200f6..b2563fce7c 100644 --- a/scm-ui/ui-webapp/src/repos/sources/containers/Sources.tsx +++ b/scm-ui/ui-webapp/src/repos/sources/containers/Sources.tsx @@ -49,7 +49,7 @@ class Sources extends React.Component { return revision ? decodeURIComponent(revision) : revision; }; - onSelectBranch = (branch?: Branch, replaceHistory?: boolean) => { + onSelectBranch = (branch?: Branch) => { const { baseUrl, history, path } = this.props; let url; if (branch) { @@ -66,8 +66,8 @@ class Sources extends React.Component { }; evaluateSwitchViewLink = () => { - const { baseUrl, selectedBranch } = this.props; - if (selectedBranch) { + const { baseUrl, selectedBranch, branches } = this.props; + if (selectedBranch && branches?.filter(b => b.name === selectedBranch).length !== 0) { return `${baseUrl}/branch/${encodeURIComponent(selectedBranch)}/changesets/`; } return `${baseUrl}/changesets/`;