2018-12-11 13:25:35 +01:00
|
|
|
//@flow
|
|
|
|
|
import React from "react";
|
|
|
|
|
import type { Changeset } from "@scm-manager/ui-types";
|
2018-12-11 14:13:32 +01:00
|
|
|
import LoadingDiff from "../LoadingDiff";
|
|
|
|
|
import Notification from "../../Notification";
|
|
|
|
|
import {translate} from "react-i18next";
|
2018-12-11 13:25:35 +01:00
|
|
|
|
|
|
|
|
type Props = {
|
2018-12-11 14:13:32 +01:00
|
|
|
changeset: Changeset,
|
2018-12-11 13:25:35 +01:00
|
|
|
|
2018-12-11 14:13:32 +01:00
|
|
|
// context props
|
|
|
|
|
t: string => string
|
2018-12-11 13:25:35 +01:00
|
|
|
};
|
|
|
|
|
|
2018-12-11 14:13:32 +01:00
|
|
|
class ChangesetDiff extends React.Component<Props> {
|
2018-12-11 13:25:35 +01:00
|
|
|
|
|
|
|
|
isDiffSupported(changeset: Changeset) {
|
|
|
|
|
return !!changeset._links.diff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createUrl(changeset: Changeset) {
|
|
|
|
|
return changeset._links.diff.href + "?format=GIT";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2018-12-11 14:13:32 +01:00
|
|
|
const { changeset, t } = this.props;
|
|
|
|
|
if (!this.isDiffSupported(changeset)) {
|
|
|
|
|
return <Notification type="danger">{t("changesets.diff.not-supported")}</Notification>;
|
2018-12-11 13:25:35 +01:00
|
|
|
} else {
|
2018-12-11 14:13:32 +01:00
|
|
|
const url = this.createUrl(changeset);
|
|
|
|
|
return <LoadingDiff url={url} />;
|
2018-12-11 13:25:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-11 14:13:32 +01:00
|
|
|
export default translate("repos")(ChangesetDiff);
|