reload historyView on branch switch // cleanup Sources

This commit is contained in:
Eduard Heimbuch
2020-01-15 10:04:30 +01:00
parent 38d5de7435
commit bafa25f025
2 changed files with 31 additions and 21 deletions

View File

@@ -14,6 +14,7 @@ type State = {
page: number; page: number;
pageCollection?: PagedCollection; pageCollection?: PagedCollection;
error?: Error; error?: Error;
currentRevision: string;
}; };
class HistoryView extends React.Component<Props, State> { class HistoryView extends React.Component<Props, State> {
@@ -23,35 +24,44 @@ class HistoryView extends React.Component<Props, State> {
this.state = { this.state = {
loaded: false, loaded: false,
page: 1, page: 1,
changesets: [] changesets: [],
currentRevision: ""
}; };
} }
componentDidMount() { componentDidMount() {
const { file } = this.props; 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) { updateHistory(link: string) {
const { file } = this.props;
getHistory(link) getHistory(link)
.then(result => { .then(result => {
if (result.error) { this.setState({
this.setState({ ...this.state,
...this.state, loaded: true,
error: result.error, changesets: result.changesets,
loaded: true pageCollection: result.pageCollection,
}); page: result.pageCollection.page,
} else { currentRevision: file.revision
this.setState({ });
...this.state,
loaded: true,
changesets: result.changesets,
pageCollection: result.pageCollection,
page: result.pageCollection.page
});
}
}) })
.catch(err => {}); .catch(error =>
this.setState({
...this.state,
error,
loaded: true
})
);
} }
updatePage(page: number) { updatePage(page: number) {

View File

@@ -49,7 +49,7 @@ class Sources extends React.Component<Props> {
return revision ? decodeURIComponent(revision) : revision; return revision ? decodeURIComponent(revision) : revision;
}; };
onSelectBranch = (branch?: Branch, replaceHistory?: boolean) => { onSelectBranch = (branch?: Branch) => {
const { baseUrl, history, path } = this.props; const { baseUrl, history, path } = this.props;
let url; let url;
if (branch) { if (branch) {
@@ -66,8 +66,8 @@ class Sources extends React.Component<Props> {
}; };
evaluateSwitchViewLink = () => { evaluateSwitchViewLink = () => {
const { baseUrl, selectedBranch } = this.props; const { baseUrl, selectedBranch, branches } = this.props;
if (selectedBranch) { if (selectedBranch && branches?.filter(b => b.name === selectedBranch).length !== 0) {
return `${baseUrl}/branch/${encodeURIComponent(selectedBranch)}/changesets/`; return `${baseUrl}/branch/${encodeURIComponent(selectedBranch)}/changesets/`;
} }
return `${baseUrl}/changesets/`; return `${baseUrl}/changesets/`;