1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from "react";
6 import { Tree, TreeItem, TreeItemStatus } from "../tree/tree";
7 import { FileTreeData } from "./file-tree-data";
8 import { FileTreeItem } from "./file-tree-item";
10 export interface FileTreeProps {
11 items: Array<TreeItem<FileTreeData>>;
12 onMenuOpen: (event: React.MouseEvent<HTMLElement>, item: TreeItem<FileTreeData>) => void;
13 onSelectionToggle: (event: React.MouseEvent<HTMLElement>, item: TreeItem<FileTreeData>) => void;
14 onCollapseToggle: (id: string, status: TreeItemStatus) => void;
17 export class FileTree extends React.Component<FileTreeProps> {
21 items={this.props.items}
23 render={this.renderItem}
24 onContextMenu={this.handleContextMenu}
25 toggleItemActive={this.handleToggleActive}
26 toggleItemOpen={this.handleToggle}
27 onSelectionChange={this.handleSelectionChange} />;
30 handleContextMenu = (event: React.MouseEvent<any>, item: TreeItem<FileTreeData>) => {
31 event.stopPropagation();
32 this.props.onMenuOpen(event, item);
35 handleToggle = (id: string, status: TreeItemStatus) => {
36 this.props.onCollapseToggle(id, status);
39 handleToggleActive = () => { return; };
41 handleSelectionChange = (event: React.MouseEvent<HTMLElement>, item: TreeItem<FileTreeData>) => {
42 event.stopPropagation();
43 this.props.onSelectionToggle(event, item);
46 renderItem = (item: TreeItem<FileTreeData>) =>
49 onMoreClick={this.handleContextMenu} />