Files
SCM-Manager/scm-ui/src/repos/sources/containers/HistoryView.js

92 lines
1.8 KiB
JavaScript
Raw Normal View History

// @flow
import React from "react";
2018-11-26 16:39:26 +01:00
import type {
File,
Changeset,
Repository,
PagedCollection
} from "@scm-manager/ui-types";
import {
ErrorNotification,
Loading,
LinkPaginator
} from "@scm-manager/ui-components";
2018-11-26 15:56:41 +01:00
import { getHistory } from "./history";
import ChangesetList from "../../components/changesets/ChangesetList";
type Props = {
file: File,
2018-11-26 15:56:41 +01:00
repository: Repository
};
type State = {
loaded: boolean,
2018-11-26 15:56:41 +01:00
changesets: Changeset[],
2018-11-26 16:39:26 +01:00
page: number,
pageCollection?: PagedCollection,
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,
2018-11-26 16:39:26 +01:00
page: 0,
2018-11-26 15:56:41 +01:00
changesets: []
};
}
componentDidMount() {
const { file } = this.props;
2018-11-26 15:56:41 +01:00
getHistory(file._links.history.href)
.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,
2018-11-26 16:39:26 +01:00
changesets: result.changesets,
pageCollection: result.pageCollection
});
}
})
2018-11-26 15:56:41 +01:00
.catch(err => {});
}
showHistory() {
2018-11-26 15:56:41 +01:00
const { repository } = this.props;
2018-11-26 16:39:26 +01:00
const { changesets, page, pageCollection } = this.state;
return (
<>
<ChangesetList repository={repository} changesets={changesets} />
<LinkPaginator page={page} collection={pageCollection} />
</>
);
}
render() {
2018-11-26 15:56:41 +01:00
const { file } = this.props;
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 16:39:26 +01:00
export default HistoryView;