This repository has been archived by the owner on Sep 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathTree.tsx
57 lines (51 loc) · 2.18 KB
/
Tree.tsx
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
55
56
57
/*---------------------------------------------------------------------------------------------
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved.
* Licensed under the MIT License. See LICENSE.md in the project root for license terms.
*--------------------------------------------------------------------------------------------*/
import * as React from "react";
import { IModelApp, IModelConnection } from "@bentley/imodeljs-frontend";
import { Tree } from "@bentley/ui-components";
import {
IPresentationTreeDataProvider,
PresentationTreeDataProvider,
treeWithUnifiedSelection,
} from "@bentley/presentation-components";
// create a HOC tree component that supports unified selection
// tslint:disable-next-line:variable-name
const SimpleTree = treeWithUnifiedSelection(Tree);
/** React properties for the tree component, that accepts an iModel connection with ruleset id */
export interface IModelConnectionProps {
/** iModel whose contents should be displayed in the tree */
imodel: IModelConnection;
/** ID of the presentation rule set to use for creating the hierarchy in the tree */
rulesetId: string;
}
/** React properties for the tree component, that accepts a data provider */
export interface DataProviderProps {
/** Custom tree data provider. */
dataProvider: IPresentationTreeDataProvider;
}
/** React properties for the tree component */
export type Props = IModelConnectionProps | DataProviderProps;
/** Tree component for the viewer app */
export default class SimpleTreeComponent extends React.PureComponent<Props> {
private getDataProvider(props: Props) {
if ((props as any).dataProvider) {
const providerProps = props as DataProviderProps;
return providerProps.dataProvider;
} else {
const imodelProps = props as IModelConnectionProps;
return new PresentationTreeDataProvider(imodelProps.imodel, imodelProps.rulesetId);
}
}
public render() {
return (
<>
<h3 data-testid="tree-component-header">{IModelApp.i18n.translate("SimpleViewer:components.tree")}</h3>
<div style={{ flex: "1" }}>
<SimpleTree dataProvider={this.getDataProvider(this.props)}/>
</div>
</>
);
}
}