1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import { TreeItem, TreeItemStatus } from "../tree/tree";
7 import { VirtualTree as Tree } from "../tree/virtual-tree";
8 import { FileTreeData } from "./file-tree-data";
9 import { FileTreeItem } from "./file-tree-item";
11 export interface FileTreeProps {
12 items: Array<TreeItem<FileTreeData>>;
13 onMenuOpen: (event: React.MouseEvent<HTMLElement>, item: TreeItem<FileTreeData>) => void;
14 onSelectionToggle: (event: React.MouseEvent<HTMLElement>, item: TreeItem<FileTreeData>) => void;
15 onCollapseToggle: (id: string, status: TreeItemStatus) => void;
16 onFileClick: (id: string) => void;
17 currentItemUuid?: string;
20 export class FileTree extends React.Component<FileTreeProps> {
24 items={this.props.items}
26 render={this.renderItem}
27 onContextMenu={this.handleContextMenu}
28 toggleItemActive={this.handleToggleActive}
29 toggleItemOpen={this.handleToggle}
30 toggleItemSelection={this.handleSelectionChange}
31 currentItemUuid={this.props.currentItemUuid} />;
34 handleContextMenu = (event: React.MouseEvent<any>, item: TreeItem<FileTreeData>) => {
35 event.stopPropagation();
36 this.props.onMenuOpen(event, item);
39 handleToggle = (event: React.MouseEvent<{}>, { id, status }: TreeItem<{}>) => {
40 this.props.onCollapseToggle(id, status);
43 handleToggleActive = (_: React.MouseEvent<HTMLElement>, item: TreeItem<FileTreeData>) => {
44 this.props.onFileClick(item.id);
47 handleSelectionChange = (event: React.MouseEvent<HTMLElement>, item: TreeItem<FileTreeData>) => {
48 event.stopPropagation();
49 this.props.onSelectionToggle(event, item);
52 renderItem = (item: TreeItem<FileTreeData>) =>
55 onMoreClick={this.handleContextMenu} />