Compare branches, tags and revisions (#1920)

Add branch/tag/revision compare to see diffs and changesets between the source and target revisions. This feature is reachable from the branch/tag detail page and also the source code view.

Co-authored-by: Florian Scholdei <florian.scholdei@cloudogu.com>
Co-authored-by: Sebastian Sdorra <sebastian.sdorra@cloudogu.com>
This commit is contained in:
Eduard Heimbuch
2022-01-20 11:00:49 +01:00
committed by GitHub
parent 6e555a855a
commit 49844d1595
41 changed files with 1488 additions and 175 deletions

View File

@@ -24,14 +24,14 @@
import React, { FC } from "react";
import { useRouteMatch } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { Branch, Repository } from "@scm-manager/ui-types";
import { Branch, ChangesetCollection, Repository } from "@scm-manager/ui-types";
import {
ChangesetList,
ErrorNotification,
urls,
LinkPaginator,
Loading,
Notification
Notification,
urls
} from "@scm-manager/ui-components";
import { useChangesets } from "@scm-manager/ui-api";
@@ -40,16 +40,29 @@ type Props = {
branch?: Branch;
};
const usePage = () => {
type ChangesetProps = Props & {
error: Error | null;
isLoading: boolean;
data?: ChangesetCollection;
};
export const usePage = () => {
const match = useRouteMatch();
return urls.getPageFromMatch(match);
};
const Changesets: FC<Props> = ({ repository, branch }) => {
const page = usePage();
const { isLoading, error, data } = useChangesets(repository, { branch, page: page - 1 });
return <ChangesetsPanel repository={repository} branch={branch} error={error} isLoading={isLoading} data={data} />;
};
export const ChangesetsPanel: FC<ChangesetProps> = ({ repository, error, isLoading, data }) => {
const [t] = useTranslation("repos");
const changesets = data?._embedded.changesets;
const page = usePage();
const changesets = data?._embedded?.changesets;
if (error) {
return <ErrorNotification error={error} />;
@@ -59,23 +72,19 @@ const Changesets: FC<Props> = ({ repository, branch }) => {
return <Loading />;
}
if (!data || !changesets || changesets.length === 0) {
return (
<div className="panel-block">
<Notification type="info">{t("changesets.noChangesets")}</Notification>
</div>
);
if (!changesets || changesets.length === 0) {
return <Notification type="info">{t("changesets.noChangesets")}</Notification>;
}
return (
<>
<div className="panel">
<div className="panel-block">
<ChangesetList repository={repository} changesets={changesets} />
</div>
<div className="panel-footer">
<LinkPaginator page={page} collection={data} />
</div>
</>
</div>
);
};