-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from berzniz/diff_stats
Add configurable diff stats
- Loading branch information
Showing
7 changed files
with
108 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#!/bin/bash -e | ||
|
||
yarn | ||
yarn test-ci | ||
OUTPUT=extension.zip | ||
NODE_ENV=production yarn build | ||
zip -r $OUTPUT build |
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,24 @@ | ||
import React from 'react' | ||
|
||
const AdditionBlock = (props) => <span className='change-block addition' {...props} /> | ||
const DeletionBlock = (props) => <span className='change-block deletion' {...props} /> | ||
|
||
const DiffStats = ({ diffStats }) => { | ||
const changeBlocks = [] | ||
for (let i = 0; i < Math.log(diffStats.additions); i++) { | ||
changeBlocks.push(<AdditionBlock key={`addition-${i}`} />) | ||
} | ||
for (let i = 0; i < Math.log(diffStats.deletions); i++) { | ||
changeBlocks.push(<DeletionBlock key={`deletion-${i}`} />) | ||
} | ||
const changeNumber = (diffStats.additions + diffStats.deletions).toLocaleString() | ||
|
||
return ( | ||
<span className='changes'> | ||
<span className='number'>{changeNumber}</span> | ||
{changeBlocks} | ||
</span> | ||
) | ||
} | ||
|
||
export default DiffStats |
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 |
---|---|---|
@@ -1,21 +1,49 @@ | ||
import React from 'react' | ||
import fileIcons from 'file-icons-js' | ||
import DiffStats from './diffStats' | ||
import { StorageSync } from '../lib' | ||
|
||
const highlightColor = '#ebebeb' | ||
const transparentColor = 'transparent' | ||
|
||
const File = ({ name, href, hasComments, isDeleted, isVisible }) => { | ||
const className = fileIcons.getClassWithColor(name) | ||
const style = { | ||
background: isVisible ? highlightColor : transparentColor, | ||
textDecoration: isDeleted ? 'line-through' : null | ||
class File extends React.Component { | ||
constructor (props) { | ||
super(props) | ||
this.state = {} | ||
} | ||
|
||
async componentDidMount () { | ||
const options = await StorageSync.get() | ||
|
||
if (this.unmounted) { | ||
return | ||
} | ||
|
||
this.setState({ options }) | ||
} | ||
|
||
componentWillUnmount () { | ||
this.unmounted = true | ||
} | ||
|
||
render () { | ||
const { name, href, hasComments, isDeleted, isVisible, diffStats } = this.props | ||
const { options = {} } = this.state | ||
const className = fileIcons.getClassWithColor(name) | ||
const style = { | ||
background: isVisible ? highlightColor : transparentColor, | ||
textDecoration: isDeleted ? 'line-through' : null | ||
} | ||
|
||
return ( | ||
<div className='github-pr-file' style={style}> | ||
<span className={`icon ${className}`} /> | ||
<a href={href} className='link-gray-dark'>{name}</a> | ||
{options.diffStats && diffStats && <DiffStats diffStats={diffStats} />} | ||
{hasComments ? ' 💬' : ''} | ||
</div> | ||
) | ||
} | ||
return ( | ||
<div className='github-pr-file' style={style}> | ||
<span className={`icon ${className}`} /> | ||
<a href={href} className='link-gray-dark'>{name}</a> {hasComments ? ' 💬' : ''} | ||
</div> | ||
) | ||
} | ||
|
||
export default File |
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