reimplement diff and move it to ui-components

This commit is contained in:
Sebastian Sdorra
2018-12-11 13:25:35 +01:00
parent ee3e3d4ecc
commit b22cb46ac2
18 changed files with 192 additions and 125 deletions

View File

@@ -9,14 +9,14 @@ import {
ChangesetId,
ChangesetTag,
ChangesetAuthor,
ChangesetDiff,
AvatarWrapper,
AvatarImage,
changesets
changesets,
} from "@scm-manager/ui-components";
import classNames from "classnames";
import type { Tag } from "@scm-manager/ui-types";
import ScmDiff from "../../containers/ScmDiff";
const styles = {
spacing: {
@@ -78,7 +78,7 @@ class ChangesetDetails extends React.Component<Props> {
</p>
</div>
<div>
<ScmDiff changeset={changeset} sideBySide={false}/>
<ChangesetDiff changeset={changeset} />
</div>
</div>
);

View File

@@ -1,51 +0,0 @@
// @flow
import React from "react";
import { apiClient } from "@scm-manager/ui-components";
import type { Changeset } from "@scm-manager/ui-types";
import { Diff2Html } from "diff2html";
type Props = {
changeset: Changeset,
sideBySide: boolean
};
type State = {
diff: string,
error?: Error
};
class ScmDiff extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = { diff: "" };
}
componentDidMount() {
const { changeset } = this.props;
const url = changeset._links.diff.href+"?format=GIT";
apiClient
.get(url)
.then(response => response.text())
.then(text => this.setState({ ...this.state, diff: text }))
.catch(error => this.setState({ ...this.state, error }));
}
render() {
const options = {
inputFormat: "diff",
outputFormat: this.props.sideBySide ? "side-by-side" : "line-by-line",
showFiles: false,
matching: "lines"
};
const outputHtml = Diff2Html.getPrettyHtml(this.state.diff, options);
return (
// eslint-disable-next-line react/no-danger
<div dangerouslySetInnerHTML={{ __html: outputHtml }} />
);
}
}
export default ScmDiff;