-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show comments in the diff
- Loading branch information
Showing
11 changed files
with
321 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React from 'react' | ||
import styled from 'styled-components' | ||
import { removeAppPathPrefix, getVersionsInDiff } from '../../../utils' | ||
import Markdown from '../Markdown' | ||
|
||
const Container = styled.div` | ||
margin: 10px; | ||
border: 1px solid #ddd; | ||
padding: 16px; | ||
border-radius: 3px; | ||
color: #000; | ||
` | ||
|
||
const LINE_CHANGE_TYPES = { | ||
ADD: 'I', | ||
DELETE: 'D', | ||
NEUTRAL: 'N' | ||
} | ||
|
||
const getLineNumberWithType = ({ lineChangeType, lineNumber }) => | ||
`${LINE_CHANGE_TYPES[lineChangeType.toUpperCase()]}${lineNumber}` | ||
|
||
const getComments = ({ newPath, fromVersion, toVersion }) => { | ||
const newPathSanitized = removeAppPathPrefix(newPath) | ||
|
||
const versionsInDiff = getVersionsInDiff({ fromVersion, toVersion }).filter( | ||
({ comments }) => | ||
comments && | ||
comments.length > 0 && | ||
comments.some(({ fileName }) => fileName === newPathSanitized) | ||
) | ||
|
||
return versionsInDiff.reduce((allComments, version) => { | ||
const comments = version.comments.reduce( | ||
(versionComments, { fileName, lineChangeType, lineNumber, content }) => { | ||
if (fileName !== newPathSanitized) { | ||
return versionComments | ||
} | ||
|
||
return { | ||
...versionComments, | ||
[getLineNumberWithType({ lineChangeType, lineNumber })]: ( | ||
<DiffComment content={content} /> | ||
) | ||
} | ||
}, | ||
{} | ||
) | ||
|
||
return { | ||
...allComments, | ||
...comments | ||
} | ||
}, {}) | ||
} | ||
|
||
const DiffComment = ({ content }) => { | ||
return ( | ||
<Container> | ||
<Markdown>{content.props.children}</Markdown> | ||
</Container> | ||
) | ||
} | ||
|
||
export { getComments } | ||
export default DiffComment |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from 'react' | ||
import Markdown from 'markdown-to-jsx' | ||
import styled from 'styled-components' | ||
|
||
export const Link = styled(props => ( | ||
// eslint-disable-next-line jsx-a11y/anchor-has-content | ||
<a target="_blank" {...props} rel="noopener" /> | ||
))` | ||
text-decoration: none; | ||
color: #045dc1; | ||
` | ||
|
||
const InlineCode = styled.em` | ||
font-style: normal; | ||
background-color: rgba(27, 31, 35, 0.07); | ||
border-radius: 3px; | ||
font-size: 85%; | ||
margin: 0; | ||
padding: 0.2em 0.4em; | ||
` | ||
|
||
export default ({ forceBlock, options = {}, ...props }) => ( | ||
<Markdown | ||
{...props} | ||
options={{ | ||
...options, | ||
forceBlock, | ||
overrides: { | ||
...options.overrides, | ||
a: Link, | ||
em: InlineCode, | ||
code: InlineCode, | ||
p: styled.p` | ||
margin-bottom: 0; | ||
` | ||
} | ||
}} | ||
/> | ||
) |
Oops, something went wrong.