-
Notifications
You must be signed in to change notification settings - Fork 706
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andres Martinez Gotor
authored
Nov 14, 2019
1 parent
10e0b9b
commit a3809e6
Showing
12 changed files
with
363 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
dashboard/src/components/DeploymentFormBody/Differential.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { shallow } from "enzyme"; | ||
import * as React from "react"; | ||
import Differential from "./Differential"; | ||
|
||
it("should render a diff between two strings", () => { | ||
const wrapper = shallow( | ||
<Differential title="test" oldValues="foo" newValues="bar" emptyDiffText="empty" />, | ||
); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
it("should print the emptyDiffText if there are no changes", () => { | ||
const wrapper = shallow( | ||
<Differential title="test" oldValues="foo" newValues="foo" emptyDiffText="No differences!" />, | ||
); | ||
expect(wrapper.text()).toMatch("No differences!"); | ||
expect(wrapper.text()).not.toMatch("foo"); | ||
}); |
36 changes: 36 additions & 0 deletions
36
dashboard/src/components/DeploymentFormBody/Differential.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as jsdiff from "diff"; | ||
import { Diff2Html } from "diff2html"; | ||
import * as React from "react"; | ||
|
||
import "diff2html/dist/diff2html.css"; | ||
|
||
export interface IDifferentialProps { | ||
title: string; | ||
oldValues: string; | ||
newValues: string; | ||
emptyDiffText: string; | ||
} | ||
|
||
class Differential extends React.Component<IDifferentialProps> { | ||
public render = () => { | ||
const { oldValues, newValues, title, emptyDiffText } = this.props; | ||
const sdiff = jsdiff.createPatch(title, oldValues, newValues); | ||
const outputHtml = Diff2Html.getPrettyHtml(sdiff, { | ||
inputFormat: "diff", | ||
showFiles: false, | ||
matching: "lines", | ||
maxLineSizeInBlockForComparison: 20, | ||
}); | ||
return ( | ||
<div className="diff"> | ||
{oldValues === newValues ? ( | ||
<p>{emptyDiffText}</p> | ||
) : ( | ||
<div dangerouslySetInnerHTML={{ __html: outputHtml }} /> | ||
)} | ||
</div> | ||
); | ||
}; | ||
} | ||
|
||
export default Differential; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.