This repository was archived by the owner on May 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathTable.tsx
52 lines (47 loc) · 2.25 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/* eslint-disable no-duplicate-imports */
import * as React from "react";
import { useCallback } from "react";
import { IModelConnection } from "@bentley/imodeljs-frontend";
import { useOptionalDisposable } from "@bentley/ui-core";
import { Table } from "@bentley/ui-components";
import {
IPresentationTableDataProvider,
PresentationTableDataProvider,
tableWithUnifiedSelection,
} from "@bentley/presentation-components";
// eslint-disable-next-line @typescript-eslint/no-var-requires
const RULESET_TABLE = require("./Table.ruleset.json");
// create a HOC table component that supports unified selection
// eslint-disable-next-line @typescript-eslint/naming-convention
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;
}
/** 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 function SimpleTableComponent(props: Props) { // eslint-disable-line @typescript-eslint/naming-convention
const imodel = (props as IModelConnectionProps).imodel;
const imodelDataProvider = useOptionalDisposable(useCallback(() => {
if (imodel)
return new PresentationTableDataProvider({ imodel, ruleset: RULESET_TABLE });
return undefined;
}, [imodel]));
const dataProvider: IPresentationTableDataProvider = imodelDataProvider ?? ((props as any).dataProvider).dataProvider;
return (
<div style={{ height: "100%" }}>
<SimpleTable dataProvider={dataProvider} />
</div>
);
}