mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-01 19:15:52 +01:00
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:
@@ -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>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user