// @flow import React, {Component} from "react"; import {buildTree} from "./commitUtils"; import type {CommitData, FileTree} from "./commitUtils"; export class FileExplorer extends Component<{ selectedPath: string, onSelectPath: (newPath: string) => void, data: CommitData, }> { render() { // within the FileExplorer, paths start with "./", outside they don't // which is hacky and should be cleaned up const fileNames = Object.keys(this.props.data.fileToCommits).sort(); const tree = buildTree(fileNames); const selectPath = (path) => { if (path.startsWith("./")) { path = path.slice(2); } this.props.onSelectPath(path); }; return (

File Explorer

); } } class FileEntry extends Component< { name: string, path: string, alwaysExpand: boolean, tree: FileTree, selectedPath: string, onSelectPath: (newPath: string) => void, }, { expanded: boolean, } > { constructor() { super(); this.state = {expanded: false}; } render() { const topLevels = Object.keys(this.props.tree); const subEntries = topLevels.map((x) => ( )); const isFolder = topLevels.length > 0 && !this.props.alwaysExpand; const toggleExpand = () => this.setState({expanded: !this.state.expanded}); const isSelected = this.props.path === this.props.selectedPath; const selectTarget = isSelected ? "." : this.props.path; const onClick = () => this.props.onSelectPath(selectTarget); return (

{isFolder && ( )} {this.props.name}

{(this.state.expanded || this.props.alwaysExpand) && subEntries}
); } }