-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathcreateTree.js
More file actions
42 lines (38 loc) · 1.03 KB
/
Copy pathcreateTree.js
File metadata and controls
42 lines (38 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import React from 'react'
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 }) => {
if (href) {
const isVisible = (diffElement === visibleElement)
const isViewed = isFileViewed(diffElement)
return (
<File
key={href}
name={nodeLabel}
href={href}
hasComments={hasComments}
isDeleted={isDeleted}
isVisible={isVisible}
diffStats={diffStats}
isViewed={isViewed}
filter={filter}
/>
)
}
const rawChildren = list.map(node => createTree({ ...node, visibleElement, filter }))
return (
<Folder
key={nodeLabel}
nodeLabel={nodeLabel}
isViewed={rawChildren.every(child => child.props.isViewed)}
filter={filter}
>
{rawChildren.map(node => (
<span key={node.key}>
{node}
</span>
))}
</Folder>
)
}