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.
|
|
|
|
|
*/
|
2021-02-24 08:17:40 +01:00
|
|
|
import React, { FC } from "react";
|
2022-08-02 10:30:07 +02:00
|
|
|
import { Redirect, useRouteMatch } from "react-router-dom";
|
2021-02-24 08:17:40 +01:00
|
|
|
import { useTranslation } from "react-i18next";
|
2022-08-02 10:30:07 +02:00
|
|
|
import { useChangesets } from "@scm-manager/ui-api";
|
|
|
|
|
import { Branch, 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,
|
|
|
|
|
LinkPaginator,
|
2019-04-09 15:19:43 +02:00
|
|
|
Loading,
|
2022-01-20 11:00:49 +01:00
|
|
|
Notification,
|
2022-08-02 10:30:07 +02:00
|
|
|
urls,
|
2019-10-20 18:02:52 +02:00
|
|
|
} from "@scm-manager/ui-components";
|
2022-01-20 11:00:49 +01:00
|
|
|
|
|
|
|
|
export const usePage = () => {
|
2021-02-24 08:17:40 +01:00
|
|
|
const match = useRouteMatch();
|
|
|
|
|
return urls.getPageFromMatch(match);
|
|
|
|
|
};
|
2018-10-16 20:19:22 +02:00
|
|
|
|
2022-08-02 10:30:07 +02:00
|
|
|
type Props = {
|
|
|
|
|
repository: Repository;
|
|
|
|
|
branch?: Branch;
|
|
|
|
|
url: string;
|
2022-01-20 11:00:49 +01:00
|
|
|
};
|
|
|
|
|
|
2022-08-02 10:30:07 +02:00
|
|
|
const Changesets: FC<Props> = ({ repository, branch, url }) => {
|
2022-01-20 11:00:49 +01:00
|
|
|
const page = usePage();
|
2022-08-02 10:30:07 +02:00
|
|
|
const { isLoading, error, data } = useChangesets(repository, { branch, page: page - 1 });
|
|
|
|
|
const [t] = useTranslation("repos");
|
2022-01-20 11:00:49 +01:00
|
|
|
const changesets = data?._embedded?.changesets;
|
2018-09-27 16:29:33 +02:00
|
|
|
|
2021-02-24 08:17:40 +01:00
|
|
|
if (error) {
|
|
|
|
|
return <ErrorNotification error={error} />;
|
2018-10-17 10:38:46 +02:00
|
|
|
}
|
2018-10-16 17:04:28 +02:00
|
|
|
|
2021-02-24 08:17:40 +01:00
|
|
|
if (isLoading) {
|
|
|
|
|
return <Loading />;
|
2020-02-28 13:15:27 +01:00
|
|
|
}
|
|
|
|
|
|
2022-08-02 10:30:07 +02:00
|
|
|
if (data && data.pageTotal < page && page > 1) {
|
|
|
|
|
return <Redirect to={`${urls.unescapeUrlForRoute(url)}/${data.pageTotal}`} />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!data || !changesets || changesets.length === 0) {
|
2022-01-20 11:00:49 +01:00
|
|
|
return <Notification type="info">{t("changesets.noChangesets")}</Notification>;
|
2018-09-18 09:22:08 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-24 08:17:40 +01:00
|
|
|
return (
|
2022-01-20 11:00:49 +01:00
|
|
|
<div className="panel">
|
2019-02-01 10:50:05 +01:00
|
|
|
<div className="panel-block">
|
|
|
|
|
<ChangesetList repository={repository} changesets={changesets} />
|
|
|
|
|
</div>
|
2021-02-24 08:17:40 +01:00
|
|
|
<div className="panel-footer">
|
2022-08-02 10:30:07 +02:00
|
|
|
<LinkPaginator collection={data} page={page} />
|
2021-02-24 08:17:40 +01:00
|
|
|
</div>
|
2022-01-20 11:00:49 +01:00
|
|
|
</div>
|
2021-02-24 08:17:40 +01:00
|
|
|
);
|
2018-10-10 19:26:29 +02:00
|
|
|
};
|
2018-10-17 10:38:46 +02:00
|
|
|
|
2021-02-24 08:17:40 +01:00
|
|
|
export default Changesets;
|