mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 06:25:45 +01:00
create a separate LoadingDiff component
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Diff2Html } from "diff2html";
|
import { Diff2Html } from "diff2html";
|
||||||
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
diff: string,
|
diff: string,
|
||||||
sideBySide: boolean
|
sideBySide: boolean
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
//@flow
|
||||||
|
import React from "react";
|
||||||
|
import { apiClient } from "../apiclient";
|
||||||
|
import ErrorNotification from "../ErrorNotification";
|
||||||
|
import Loading from "../Loading";
|
||||||
|
import Diff from "./Diff";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
url: string,
|
||||||
|
sideBySide: boolean
|
||||||
|
};
|
||||||
|
|
||||||
|
type State = {
|
||||||
|
diff?: string,
|
||||||
|
loading: boolean,
|
||||||
|
error?: Error
|
||||||
|
};
|
||||||
|
|
||||||
|
class LoadingDiff extends React.Component<Props, State> {
|
||||||
|
|
||||||
|
static defaultProps = {
|
||||||
|
sideBySide: false
|
||||||
|
};
|
||||||
|
|
||||||
|
constructor(props: Props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
loading: true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
const { url } = this.props;
|
||||||
|
apiClient
|
||||||
|
.get(url)
|
||||||
|
.then(response => response.text())
|
||||||
|
.then(text => {
|
||||||
|
this.setState({
|
||||||
|
loading: false,
|
||||||
|
diff: text
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
this.setState({
|
||||||
|
loading: false,
|
||||||
|
error
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { diff, loading, error } = this.state;
|
||||||
|
if (error) {
|
||||||
|
return <ErrorNotification error={error} />;
|
||||||
|
} else if (loading || !diff) {
|
||||||
|
return <Loading />;
|
||||||
|
} else {
|
||||||
|
return <Diff diff={diff} />;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LoadingDiff;
|
||||||
@@ -1,29 +1,18 @@
|
|||||||
//@flow
|
//@flow
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import type { Changeset } from "@scm-manager/ui-types";
|
import type { Changeset } from "@scm-manager/ui-types";
|
||||||
import { apiClient } from "../../apiclient";
|
import LoadingDiff from "../LoadingDiff";
|
||||||
import ErrorNotification from "../../ErrorNotification";
|
import Notification from "../../Notification";
|
||||||
import Loading from "../../Loading";
|
import {translate} from "react-i18next";
|
||||||
import Diff from "../Diff";
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
changeset: Changeset
|
changeset: Changeset,
|
||||||
|
|
||||||
|
// context props
|
||||||
|
t: string => string
|
||||||
};
|
};
|
||||||
|
|
||||||
type State = {
|
class ChangesetDiff extends React.Component<Props> {
|
||||||
diff?: string,
|
|
||||||
loading: boolean,
|
|
||||||
error?: Error
|
|
||||||
};
|
|
||||||
|
|
||||||
class ChangesetDiff extends React.Component<Props, State> {
|
|
||||||
|
|
||||||
constructor(props: Props) {
|
|
||||||
super(props);
|
|
||||||
this.state = {
|
|
||||||
loading: false
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
isDiffSupported(changeset: Changeset) {
|
isDiffSupported(changeset: Changeset) {
|
||||||
return !!changeset._links.diff;
|
return !!changeset._links.diff;
|
||||||
@@ -33,51 +22,16 @@ class ChangesetDiff extends React.Component<Props, State> {
|
|||||||
return changeset._links.diff.href + "?format=GIT";
|
return changeset._links.diff.href + "?format=GIT";
|
||||||
}
|
}
|
||||||
|
|
||||||
loadDiff(changeset: Changeset) {
|
|
||||||
this.setState({
|
|
||||||
loading: true
|
|
||||||
});
|
|
||||||
const url = this.createUrl(changeset);
|
|
||||||
apiClient
|
|
||||||
.get(url)
|
|
||||||
.then(response => response.text())
|
|
||||||
.then(text => {
|
|
||||||
this.setState({
|
|
||||||
loading: false,
|
|
||||||
diff: text
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
this.setState({
|
|
||||||
loading: false,
|
|
||||||
error
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
const { changeset } = this.props;
|
|
||||||
if (!this.isDiffSupported(changeset)) {
|
|
||||||
this.setState({
|
|
||||||
error: new Error("diff is not supported")
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.loadDiff(changeset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { diff, loading, error } = this.state;
|
const { changeset, t } = this.props;
|
||||||
if (error) {
|
if (!this.isDiffSupported(changeset)) {
|
||||||
return <ErrorNotification error={error} />;
|
return <Notification type="danger">{t("changesets.diff.not-supported")}</Notification>;
|
||||||
} else if (loading || !diff) {
|
|
||||||
return <Loading />;
|
|
||||||
} else {
|
} else {
|
||||||
return <Diff diff={diff} />;
|
const url = this.createUrl(changeset);
|
||||||
|
return <LoadingDiff url={url} />;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ChangesetDiff;
|
export default translate("repos")(ChangesetDiff);
|
||||||
|
|||||||
@@ -2,3 +2,4 @@
|
|||||||
|
|
||||||
export * from "./changesets";
|
export * from "./changesets";
|
||||||
export { default as Diff } from "./Diff";
|
export { default as Diff } from "./Diff";
|
||||||
|
export { default as LoadingDiff } from "./LoadingDiff";
|
||||||
|
|||||||
@@ -66,6 +66,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"changesets": {
|
"changesets": {
|
||||||
|
"diff": {
|
||||||
|
"not-supported": "Diff of changesets is not supported by the type of repository"
|
||||||
|
},
|
||||||
"error-title": "Error",
|
"error-title": "Error",
|
||||||
"error-subtitle": "Could not fetch changesets",
|
"error-subtitle": "Could not fetch changesets",
|
||||||
"changeset": {
|
"changeset": {
|
||||||
|
|||||||
Reference in New Issue
Block a user