-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathTableTreeWithSchema.tsx
More file actions
55 lines (52 loc) · 2.52 KB
/
TableTreeWithSchema.tsx
File metadata and controls
55 lines (52 loc) · 2.52 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
43
44
45
46
47
48
49
50
51
52
53
54
import React from "react";
import { TableMetadata, LakehouseExplorerTablesTreeProps } from "src/models/LakehouseExplorerModel";
import { ArrowCircleDownSplitRegular, Table20Regular } from "@fluentui/react-icons";
import { Tree, TreeItem, TreeItemLayout, Tooltip } from "@fluentui/react-components";
export function TableTreeWithSchema(props: LakehouseExplorerTablesTreeProps) {
const {allTablesInLakehouse, onSelectTableCallback} = props;
// group the tables by schema
const tablesInLakehouseGroupedBySchema: { [key: string]: TableMetadata[] } =
allTablesInLakehouse.reduce((acc: { [key: string]: TableMetadata[] }, table) => {
if (!acc[table.schema]) {
acc[table.schema] = [];
}
acc[table.schema].push(table);
return acc;
}, {});
return (
<>
{tablesInLakehouseGroupedBySchema &&
Object.keys(tablesInLakehouseGroupedBySchema).map((schema) => (
<TreeItem id={schema} key={schema} itemType="branch">
<Tooltip
relationship="label"
content={schema}>
<TreeItemLayout id={schema} iconBefore={<ArrowCircleDownSplitRegular />}>
{schema}
</TreeItemLayout>
</Tooltip>
<Tree selectionMode="single" size='medium'>
{tablesInLakehouseGroupedBySchema[schema].map((table) => (
<TreeItem
key={table.name}
accessKey={table.path}
itemType="leaf"
onClick={() => onSelectTableCallback(table)}
>
<Tooltip
relationship='label'
content={table.name}>
<TreeItemLayout
className={(table.isSelected ? "selected" : "")}
iconBefore={<Table20Regular />}>
{table.name}
</TreeItemLayout>
</Tooltip>
</TreeItem>
))}
</Tree>
</TreeItem>
))}
</>
);
}