This repository was 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 pathTable.tsx
54 lines (48 loc) · 2.09 KB
/
Table.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
/*---------------------------------------------------------------------------------------------
* 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 { IModelConnection } from "@bentley/imodeljs-frontend";
import { Table } from "@bentley/ui-components";
import {
IPresentationTableDataProvider,
PresentationTableDataProvider,
tableWithUnifiedSelection,
} from "@bentley/presentation-components";
// create a HOC table component that supports unified selection
// tslint:disable-next-line:variable-name
const SimpleTable = tableWithUnifiedSelection(Table);
/** React properties for the table component, that accepts an iModel connection with ruleset id */
export interface IModelConnectionProps {
/** iModel whose contents should be displayed in the table */
imodel: IModelConnection;
/** ID of the presentation rule set to use for creating the content displayed in the table */
rulesetId: string;
}
/** React properties for the table component, that accepts a data provider */
export interface DataProviderProps {
/** Custom property pane data provider. */
dataProvider: IPresentationTableDataProvider;
}
/** React properties for the table component */
export type Props = IModelConnectionProps | DataProviderProps;
/** Table component for the viewer app */
export default class SimpleTableComponent 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 PresentationTableDataProvider({ imodel: imodelProps.imodel, ruleset: imodelProps.rulesetId });
}
}
public render() {
return (
<div style={{ height: "100%" }}>
<SimpleTable dataProvider={this.getDataProvider(this.props)} />
</div>
);
}
}