-
Notifications
You must be signed in to change notification settings - Fork 2
/
ArrayValueRenderer.tsx
49 lines (45 loc) · 1.82 KB
/
ArrayValueRenderer.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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Properties
*/
import * as React from "react";
import type { ArrayValue } from "@itwin/appui-abstract";
import { NonPrimitivePropertyRenderer } from "../../NonPrimitivePropertyRenderer";
import type { TableSpecificValueRendererProps } from "./NonPrimitiveValueRenderer";
import { TableNonPrimitiveValueRenderer as TableValueRenderer } from "./NonPrimitiveValueRenderer";
/** A react component which renders array property value as a button with text
* @public
*/
export class TableArrayValueRenderer extends React.PureComponent<TableSpecificValueRendererProps> {
private getButtonLabel(props: TableSpecificValueRendererProps) {
const value = props.propertyRecord.value as ArrayValue;
return value.items.length !== 0
? `${value.itemsTypeName}[${value.items.length}]`
: "[]";
}
private getDialogContents() {
return (
<NonPrimitivePropertyRenderer
uniqueKey={`table_array_${this.props.propertyRecord.property.name}`}
orientation={this.props.orientation}
propertyRecord={this.props.propertyRecord}
/>
);
}
/** @internal */
public override render() {
const typeName = (this.props.propertyRecord.value as ArrayValue)
.itemsTypeName;
return (
<TableValueRenderer
buttonLabel={this.getButtonLabel(this.props)}
dialogContents={this.getDialogContents()}
dialogTitle={`Array of type "${typeName}"`}
onDialogOpen={this.props.onDialogOpen}
/>
);
}
}