2018-11-26 15:20:44 +01:00
|
|
|
// @flow
|
|
|
|
|
import React from "react";
|
2018-11-26 15:56:41 +01:00
|
|
|
import type { File, Changeset, Repository } from "@scm-manager/ui-types";
|
2018-11-26 15:20:44 +01:00
|
|
|
import { ErrorNotification, Loading } from "@scm-manager/ui-components";
|
2018-11-26 15:56:41 +01:00
|
|
|
import { getHistory } from "./history";
|
|
|
|
|
import ChangesetList from "../../components/changesets/ChangesetList";
|
2018-11-26 15:20:44 +01:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
file: File,
|
2018-11-26 15:56:41 +01:00
|
|
|
repository: Repository
|
2018-11-26 15:20:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
|
loaded: boolean,
|
2018-11-26 15:56:41 +01:00
|
|
|
changesets: Changeset[],
|
2018-11-26 15:20:44 +01:00
|
|
|
error?: Error
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class HistoryView extends React.Component<Props, State> {
|
|
|
|
|
constructor(props: Props) {
|
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
this.state = {
|
2018-11-26 15:56:41 +01:00
|
|
|
loaded: false,
|
|
|
|
|
changesets: []
|
2018-11-26 15:20:44 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
const { file } = this.props;
|
2018-11-26 15:56:41 +01:00
|
|
|
getHistory(file._links.history.href)
|
2018-11-26 15:20:44 +01:00
|
|
|
.then(result => {
|
|
|
|
|
if (result.error) {
|
|
|
|
|
this.setState({
|
|
|
|
|
...this.state,
|
|
|
|
|
error: result.error,
|
|
|
|
|
loaded: true
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
this.setState({
|
|
|
|
|
...this.state,
|
2018-11-26 15:56:41 +01:00
|
|
|
loaded: true,
|
|
|
|
|
changesets: result.changesets
|
2018-11-26 15:20:44 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
})
|
2018-11-26 15:56:41 +01:00
|
|
|
.catch(err => {});
|
2018-11-26 15:20:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showHistory() {
|
2018-11-26 15:56:41 +01:00
|
|
|
const { repository } = this.props;
|
|
|
|
|
const { changesets } = this.state;
|
|
|
|
|
return <ChangesetList repository={repository} changesets={changesets} />;
|
2018-11-26 15:20:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2018-11-26 15:56:41 +01:00
|
|
|
const { file } = this.props;
|
2018-11-26 15:20:44 +01:00
|
|
|
const { loaded, error } = this.state;
|
|
|
|
|
|
|
|
|
|
if (!file || !loaded) {
|
|
|
|
|
return <Loading />;
|
|
|
|
|
}
|
|
|
|
|
if (error) {
|
|
|
|
|
return <ErrorNotification error={error} />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const history = this.showHistory();
|
|
|
|
|
|
|
|
|
|
return <>{history}</>;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-26 15:56:41 +01:00
|
|
|
export default (HistoryView);
|