From 5ace26c979414056745cacbf63b26c1d0cf1c61d Mon Sep 17 00:00:00 2001 From: Markus Wagner Date: Fri, 4 Mar 2022 21:48:48 +0100 Subject: [PATCH] Implement file count display for folders --- src/js/components/folder/index.jsx | 19 ++++++++++++++++--- src/js/components/options/index.jsx | 9 +++++++++ src/js/createTree.js | 4 ++-- src/js/lib.js | 10 ++++++++-- src/js/style.css | 9 +++++++++ 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/js/components/folder/index.jsx b/src/js/components/folder/index.jsx index d250431..42a8ac0 100644 --- a/src/js/components/folder/index.jsx +++ b/src/js/components/folder/index.jsx @@ -1,5 +1,6 @@ import React from 'react' import TreeView from 'react-treeview' +import { StorageSync } from '../../lib' class Folder extends React.Component { constructor (props) { @@ -7,12 +8,24 @@ class Folder extends React.Component { 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 = ( -
- {nodeLabel} +
+ {nodeLabel} {options.fileCount && fileCount && ({fileCount} {fileCountLabel})} {isViewed ? ( Show Diff Stats next to files +
) diff --git a/src/js/createTree.js b/src/js/createTree.js index 25fcaca..727b43d 100644 --- a/src/js/createTree.js +++ b/src/js/createTree.js @@ -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) @@ -26,7 +26,7 @@ export const createTree = ({ nodeLabel, list, href, hasComments, isDeleted, diff const rawChildren = list.map(node => createTree({ ...node, visibleElement, filter })) return ( - child.props.isViewed)}> + child.props.isViewed)}> {rawChildren.map(node => ( {node} diff --git a/src/js/lib.js b/src/js/lib.js index e459cd0..e4c7ed8 100644 --- a/src/js/lib.js +++ b/src/js/lib.js @@ -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 @@ -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) { @@ -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) diff --git a/src/js/style.css b/src/js/style.css index 87faa07..7ada3a9 100644 --- a/src/js/style.css +++ b/src/js/style.css @@ -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; +}