2018-11-26 15:20:44 +01:00
|
|
|
// @flow
|
|
|
|
|
import React from "react";
|
2018-11-26 16:39:26 +01:00
|
|
|
import type {
|
|
|
|
|
File,
|
|
|
|
|
Changeset,
|
|
|
|
|
Repository,
|
|
|
|
|
PagedCollection
|
|
|
|
|
} from "@scm-manager/ui-types";
|
2018-11-28 10:33:06 +01:00
|
|
|
import {
|
|
|
|
|
ErrorNotification,
|
|
|
|
|
Loading,
|
2018-12-10 08:45:59 +01:00
|
|
|
StatePaginator,
|
|
|
|
|
ChangesetList
|
2018-11-28 10:33:06 +01:00
|
|
|
} from "@scm-manager/ui-components";
|
2018-11-26 15:56:41 +01:00
|
|
|
import { getHistory } from "./history";
|
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 16:39:26 +01:00
|
|
|
page: number,
|
|
|
|
|
pageCollection?: PagedCollection,
|
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,
|
2018-11-26 16:48:25 +01:00
|
|
|
page: 1,
|
2018-11-26 15:56:41 +01:00
|
|
|
changesets: []
|
2018-11-26 15:20:44 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
const { file } = this.props;
|
2018-11-28 08:53:48 +01:00
|
|
|
this.updateHistory(file._links.history.href);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateHistory(link: string) {
|
|
|
|
|
getHistory(link)
|
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,
|
2018-11-26 16:39:26 +01:00
|
|
|
changesets: result.changesets,
|
2018-11-26 16:48:25 +01:00
|
|
|
pageCollection: result.pageCollection,
|
2018-11-28 08:53:48 +01:00
|
|
|
page: result.pageCollection.page
|
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
|
|
|
}
|
|
|
|
|
|
2018-11-28 08:53:48 +01:00
|
|
|
updatePage(page: number) {
|
|
|
|
|
const { file } = this.props;
|
2018-11-28 08:59:18 +01:00
|
|
|
const internalPage = page - 1;
|
|
|
|
|
this.updateHistory(
|
|
|
|
|
file._links.history.href + "?page=" + internalPage.toString()
|
|
|
|
|
);
|
2018-11-28 08:53:48 +01:00
|
|
|
}
|
|
|
|
|
|
2018-11-26 15:20:44 +01:00
|
|
|
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;
|
2018-11-28 08:59:18 +01:00
|
|
|
const currentPage = page + 1;
|
2018-11-26 16:39:26 +01:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<ChangesetList repository={repository} changesets={changesets} />
|
2018-11-28 08:53:48 +01:00
|
|
|
<StatePaginator
|
|
|
|
|
page={currentPage}
|
|
|
|
|
collection={pageCollection}
|
|
|
|
|
updatePage={(newPage: number) => this.updatePage(newPage)}
|
|
|
|
|
/>
|
2018-11-26 16:39:26 +01:00
|
|
|
</>
|
|
|
|
|
);
|
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 16:39:26 +01:00
|
|
|
export default HistoryView;
|