-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HPCC-29934 ECL Watch v9 file explorer component
Signed-off-by: Jeremy Clements <[email protected]>
- Loading branch information
Showing
11 changed files
with
358 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import * as React from "react"; | ||
import { ConnectVirtualMachineIcon, FolderIcon, OfflineStorageIcon } from "@fluentui/react-icons-mdl2"; | ||
import { FlatTree as Tree, TreeItem, TreeItemLayout, TreeItemValue, TreeOpenChangeData, TreeOpenChangeEvent, useHeadlessFlatTree_unstable, HeadlessFlatTreeItemProps, useId, } from "@fluentui/react-components"; | ||
|
||
export enum BranchIcon { | ||
None, | ||
Directory, | ||
Dropzone, | ||
Network, | ||
} | ||
|
||
const getIcon = (iconStr: BranchIcon): React.ReactElement | null => { | ||
switch (iconStr) { | ||
case BranchIcon.Directory: | ||
return <FolderIcon />; | ||
case BranchIcon.Dropzone: | ||
return <OfflineStorageIcon />; | ||
case BranchIcon.Network: | ||
return <ConnectVirtualMachineIcon />; | ||
case BranchIcon.None: | ||
default: | ||
return null; | ||
} | ||
}; | ||
|
||
export type FlatItem = HeadlessFlatTreeItemProps & { | ||
label?: string, | ||
icon?: BranchIcon, | ||
data?: { [id: string]: any } | ||
}; | ||
|
||
interface TreeViewProps { | ||
treeItems: FlatItem[]; | ||
openItems: Iterable<TreeItemValue>; | ||
onOpenChange?: (_: TreeOpenChangeEvent, data: TreeOpenChangeData) => void; | ||
ariaLabel: string; | ||
} | ||
|
||
export const TreeView: React.FunctionComponent<TreeViewProps> = ({ | ||
treeItems, | ||
openItems, | ||
onOpenChange, | ||
ariaLabel | ||
}) => { | ||
|
||
const flatTree = useHeadlessFlatTree_unstable(treeItems, { onOpenChange: onOpenChange ? onOpenChange : null, openItems }); | ||
const key = useId("FileExplorer"); | ||
if (!treeItems || treeItems.length < 1) return null; | ||
|
||
return <Tree key={key} aria-label={ariaLabel} {...flatTree.getTreeProps()}> | ||
{Array.from(flatTree.items(), (item, idx) => { | ||
const { icon, label, data, ...treeItemProps } = item.getTreeItemProps(); | ||
return <TreeItem key={`${label?.replace(/\s+/g, "")}_${idx}`} data-tree={JSON.stringify(data)} {...treeItemProps}> | ||
<TreeItemLayout iconBefore={getIcon(icon)}>{label}</TreeItemLayout> | ||
</TreeItem>; | ||
})} | ||
</Tree>; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters