2020-03-23 15:35:58 +01:00
|
|
|
/*
|
|
|
|
|
* MIT License
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
|
|
|
|
*/
|
2019-10-20 18:02:52 +02:00
|
|
|
import React from "react";
|
2019-10-23 15:47:08 +02:00
|
|
|
import { connect } from "react-redux";
|
|
|
|
|
import { compose } from "redux";
|
2020-02-28 13:15:27 +01:00
|
|
|
import { withRouter, RouteComponentProps } from "react-router-dom";
|
2019-10-23 15:47:08 +02:00
|
|
|
import { WithTranslation, withTranslation } from "react-i18next";
|
2019-10-21 10:57:56 +02:00
|
|
|
import { Branch, Changeset, PagedCollection, Repository } from "@scm-manager/ui-types";
|
2019-02-01 10:50:05 +01:00
|
|
|
import {
|
2020-01-08 15:57:13 +01:00
|
|
|
ChangesetList,
|
2019-02-01 10:50:05 +01:00
|
|
|
ErrorNotification,
|
|
|
|
|
getPageFromMatch,
|
|
|
|
|
LinkPaginator,
|
2019-04-09 15:19:43 +02:00
|
|
|
Loading,
|
2019-10-20 18:02:52 +02:00
|
|
|
Notification
|
|
|
|
|
} from "@scm-manager/ui-components";
|
2019-10-23 15:47:08 +02:00
|
|
|
import {
|
|
|
|
|
fetchChangesets,
|
|
|
|
|
getChangesets,
|
|
|
|
|
getFetchChangesetsFailure,
|
|
|
|
|
isFetchChangesetsPending,
|
|
|
|
|
selectListAsCollection
|
|
|
|
|
} from "../modules/changesets";
|
2018-09-17 14:03:13 +02:00
|
|
|
|
2020-02-28 13:15:27 +01:00
|
|
|
type Props = RouteComponentProps &
|
|
|
|
|
WithTranslation & {
|
|
|
|
|
repository: Repository;
|
|
|
|
|
branch: Branch;
|
|
|
|
|
page: number;
|
2018-10-16 20:19:22 +02:00
|
|
|
|
2020-02-28 13:15:27 +01:00
|
|
|
// State props
|
|
|
|
|
changesets: Changeset[];
|
|
|
|
|
list: PagedCollection;
|
|
|
|
|
loading: boolean;
|
|
|
|
|
error: Error;
|
2018-10-16 20:19:22 +02:00
|
|
|
|
2020-02-28 13:15:27 +01:00
|
|
|
// Dispatch props
|
|
|
|
|
fetchChangesets: (p1: Repository, p2: Branch, p3: number) => void;
|
|
|
|
|
};
|
2018-09-27 16:29:33 +02:00
|
|
|
|
2018-10-17 10:38:46 +02:00
|
|
|
class Changesets extends React.Component<Props> {
|
2018-09-17 14:03:13 +02:00
|
|
|
componentDidMount() {
|
2018-10-17 10:38:46 +02:00
|
|
|
const { fetchChangesets, repository, branch, page } = this.props;
|
|
|
|
|
fetchChangesets(repository, branch, page);
|
|
|
|
|
}
|
2018-10-16 17:04:28 +02:00
|
|
|
|
2020-03-02 14:13:51 +01:00
|
|
|
shouldComponentUpdate(nextProps: Readonly<Props>): boolean {
|
2020-05-14 10:56:16 +02:00
|
|
|
return this.props.changesets !== nextProps.changesets ||
|
|
|
|
|
this.props.loading !== nextProps.loading ||
|
|
|
|
|
this.props.error !== nextProps.error;
|
2020-02-28 13:15:27 +01:00
|
|
|
}
|
|
|
|
|
|
2018-10-16 17:04:28 +02:00
|
|
|
render() {
|
2019-04-09 15:19:43 +02:00
|
|
|
const { changesets, loading, error, t } = this.props;
|
2018-10-16 17:04:28 +02:00
|
|
|
|
2018-09-27 16:29:33 +02:00
|
|
|
if (error) {
|
2018-10-17 11:55:47 +02:00
|
|
|
return <ErrorNotification error={error} />;
|
2018-09-27 16:29:33 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-10 19:26:29 +02:00
|
|
|
if (loading) {
|
2018-09-18 16:51:31 +02:00
|
|
|
return <Loading />;
|
2018-09-17 14:03:13 +02:00
|
|
|
}
|
2018-10-17 11:55:47 +02:00
|
|
|
|
2018-10-10 19:26:29 +02:00
|
|
|
if (!changesets || changesets.length === 0) {
|
2019-04-09 15:19:43 +02:00
|
|
|
return (
|
|
|
|
|
<div className="panel-block">
|
2019-10-21 10:57:56 +02:00
|
|
|
<Notification type="info">{t("changesets.noChangesets")}</Notification>
|
2019-04-09 15:19:43 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
2018-10-10 19:26:29 +02:00
|
|
|
}
|
2018-09-18 16:51:31 +02:00
|
|
|
return (
|
2018-10-10 19:26:29 +02:00
|
|
|
<>
|
2018-10-04 15:52:17 +02:00
|
|
|
{this.renderList()}
|
2018-09-19 13:49:04 +02:00
|
|
|
{this.renderPaginator()}
|
2018-10-10 19:26:29 +02:00
|
|
|
</>
|
2018-09-18 16:51:31 +02:00
|
|
|
);
|
2018-09-18 09:22:08 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-04 15:52:17 +02:00
|
|
|
renderList = () => {
|
2018-10-10 19:26:29 +02:00
|
|
|
const { repository, changesets } = this.props;
|
2019-02-01 10:50:05 +01:00
|
|
|
return (
|
|
|
|
|
<div className="panel-block">
|
|
|
|
|
<ChangesetList repository={repository} changesets={changesets} />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2018-09-18 09:22:08 +02:00
|
|
|
};
|
|
|
|
|
|
2018-10-10 19:26:29 +02:00
|
|
|
renderPaginator = () => {
|
2018-10-17 10:57:01 +02:00
|
|
|
const { page, list } = this.props;
|
2018-09-19 13:49:04 +02:00
|
|
|
if (list) {
|
2019-02-01 10:50:05 +01:00
|
|
|
return (
|
|
|
|
|
<div className="panel-footer">
|
|
|
|
|
<LinkPaginator page={page} collection={list} />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2018-09-19 13:49:04 +02:00
|
|
|
}
|
|
|
|
|
return null;
|
2018-09-17 14:03:13 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-07 10:30:46 +01:00
|
|
|
const mapDispatchToProps = (dispatch: any) => {
|
2018-09-17 14:03:13 +02:00
|
|
|
return {
|
2018-10-17 10:38:46 +02:00
|
|
|
fetchChangesets: (repo: Repository, branch: Branch, page: number) => {
|
|
|
|
|
dispatch(fetchChangesets(repo, branch, page));
|
2019-10-20 18:02:52 +02:00
|
|
|
}
|
2018-09-18 16:51:31 +02:00
|
|
|
};
|
2018-09-17 14:03:13 +02:00
|
|
|
};
|
|
|
|
|
|
2018-10-10 19:26:29 +02:00
|
|
|
const mapStateToProps = (state: any, ownProps: Props) => {
|
2018-10-17 10:38:46 +02:00
|
|
|
const { repository, branch, match } = ownProps;
|
2018-10-10 19:26:29 +02:00
|
|
|
const changesets = getChangesets(state, repository, branch);
|
|
|
|
|
const loading = isFetchChangesetsPending(state, repository, branch);
|
|
|
|
|
const error = getFetchChangesetsFailure(state, repository, branch);
|
|
|
|
|
const list = selectListAsCollection(state, repository, branch);
|
2018-10-17 11:55:47 +02:00
|
|
|
const page = getPageFromMatch(match);
|
2018-10-17 10:38:46 +02:00
|
|
|
|
2019-10-19 16:38:07 +02:00
|
|
|
return {
|
|
|
|
|
changesets,
|
|
|
|
|
list,
|
|
|
|
|
page,
|
|
|
|
|
loading,
|
2019-10-20 18:02:52 +02:00
|
|
|
error
|
2019-10-19 16:38:07 +02:00
|
|
|
};
|
2018-10-10 19:26:29 +02:00
|
|
|
};
|
2018-10-17 10:38:46 +02:00
|
|
|
|
2020-01-07 10:30:46 +01:00
|
|
|
export default compose(withTranslation("repos"), withRouter, connect(mapStateToProps, mapDispatchToProps))(Changesets);
|