Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement file count display for folders #200

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/js/components/folder/index.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
import React from 'react'
import TreeView from 'react-treeview'
import { StorageSync } from '../../lib'

class Folder extends React.Component {
constructor (props) {
super(props)
this.state = {}
}

async componentDidMount () {
const options = await StorageSync.get()

if (this.unmounted) {
return
}

this.setState({ options })
}

render () {
const { children, nodeLabel, isViewed } = this.props
const { children, nodeLabel, isViewed, fileCount } = this.props
const { options = {} } = this.state
const fileCountLabel = fileCount > 1 ? 'files' : 'file'

const display = (
<div>
{nodeLabel}
<div className='github-pr-folder-label'>
{nodeLabel} {options.fileCount && fileCount && <span className='github-pr-folder-count-label'>({fileCount} {fileCountLabel})</span>}
{isViewed
? (
<svg className='github-pr-file-checkmark octicon octicon-check' viewBox='0 0 12 16' version='1.1' width='12' height='16' aria-hidden='true'>
Expand Down
9 changes: 9 additions & 0 deletions src/js/components/options/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ class Options extends React.Component {
/>
<span className='label-body'>Show <strong>Diff Stats</strong> next to files</span>
</label>
<label className='label-enabled'>
<input
id='fileCount'
type='checkbox'
checked={Boolean(this.state.fileCount)}
onChange={this.handleOptions}
/>
<span className='label-body'>Show <strong>File Count</strong> next to folders</span>
</label>
</div>
</div>
)
Expand Down
4 changes: 2 additions & 2 deletions src/js/createTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isFileViewed } from './lib'
import File from './components/file'
import Folder from './components/folder'

export const createTree = ({ nodeLabel, list, href, hasComments, isDeleted, diffElement, diffStats, visibleElement, filter }) => {
export const createTree = ({ nodeLabel, list, href, hasComments, isDeleted, diffElement, diffStats, visibleElement, filter, fileCount }) => {
if (href) {
const isVisible = (diffElement === visibleElement)
const isViewed = isFileViewed(diffElement)
Expand All @@ -26,7 +26,7 @@ export const createTree = ({ nodeLabel, list, href, hasComments, isDeleted, diff
const rawChildren = list.map(node => createTree({ ...node, visibleElement, filter }))

return (
<Folder key={nodeLabel} nodeLabel={nodeLabel} isViewed={rawChildren.every(child => child.props.isViewed)}>
<Folder key={nodeLabel} nodeLabel={nodeLabel} fileCount={fileCount} isViewed={rawChildren.every(child => child.props.isViewed)}>
{rawChildren.map(node => (
<span key={node.key}>
{node}
Expand Down
10 changes: 8 additions & 2 deletions src/js/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,13 @@ export const createFileTree = (filter = EMPTY_FILTER) => {
hasComments,
isDeleted,
diffElement,
fileCount: 1,
diffStats: getDiffStatsForDiffElement(diffElement)
}
location.list.push(node)
}
} else {
node.fileCount = (node.fileCount || 0) + 1
}
location.list = location.list.sort(sorter)
location = node
Expand Down Expand Up @@ -204,8 +207,10 @@ export const StorageSync = {
save () {
return new Promise(resolve => {
const diffStats = document.getElementById('diffStats').checked
const fileCount = document.getElementById('fileCount').checked
const options = {
diffStats
diffStats,
fileCount
}

if (window.chrome) {
Expand All @@ -218,7 +223,8 @@ export const StorageSync = {
get () {
return new Promise(resolve => {
const defaults = {
diffStats: false
diffStats: false,
fileCount: true
}
if (window.chrome) {
window.chrome.storage.sync.get(defaults, resolve)
Expand Down
9 changes: 9 additions & 0 deletions src/js/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,12 @@
color: #2cbe4e;
margin-left: 5px;
}

.github-pr-folder-count-label {
color: #999;
margin-left: 3px;
}

.github-pr-folder-label {
white-space: nowrap;
}