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 pathProperties.tsx
59 lines (55 loc) · 2.55 KB
/
Properties.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
58
59
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from "react";
import { IModelApp, IModelConnection } from "@bentley/imodeljs-frontend";
import { FillCentered, Orientation, useOptionalDisposable } from "@bentley/ui-core";
import {
IPresentationPropertyDataProvider,
PresentationPropertyDataProvider,
usePropertyDataProviderWithUnifiedSelection,
} from "@bentley/presentation-components";
import { VirtualizedPropertyGridWithDataProvider } from "@bentley/ui-components";
/** React properties for the property pane component, that accepts an iModel connection with ruleset id */
export interface IModelConnectionProps {
/** iModel whose contents should be displayed in the property pane */
imodel: IModelConnection;
}
/** React properties for the property pane component, that accepts a data provider */
export interface DataProviderProps {
/** Custom property pane data provider. */
dataProvider: IPresentationPropertyDataProvider;
}
/** React properties for the property pane component */
export type Props = IModelConnectionProps | DataProviderProps;
/** Property grid component for the viewer app */
export default function SimplePropertiesComponent(props: Props) { // eslint-disable-line @typescript-eslint/naming-convention
const imodel = (props as IModelConnectionProps).imodel;
const imodelDataProvider = useOptionalDisposable(React.useCallback(() => {
if (imodel)
return new PresentationPropertyDataProvider({ imodel });
return undefined;
}, [imodel]));
const dataProvider: IPresentationPropertyDataProvider = imodelDataProvider ?? (props as any).dataProvider;
const { isOverLimit } = usePropertyDataProviderWithUnifiedSelection({ dataProvider });
let content: JSX.Element;
if (isOverLimit) {
content = (<FillCentered>{"Too many elements."}</FillCentered>);
} else {
content = (<VirtualizedPropertyGridWithDataProvider
dataProvider={dataProvider}
isPropertyHoverEnabled={true}
orientation={Orientation.Horizontal}
horizontalOrientationMinWidth={500}
/>);
}
return (
<>
<h3 data-testid="property-pane-component-header">{IModelApp.i18n.translate("SimpleViewer:components.properties")}</h3>
<div style={{ flex: "1", height: "calc(100% - 50px)" }}>
{content}
</div>
</>
);
}