-
Notifications
You must be signed in to change notification settings - Fork 2
/
MutableCategorizedArrayProperty.ts
96 lines (88 loc) · 2.97 KB
/
MutableCategorizedArrayProperty.ts
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module PropertyGrid
*/
import type { PropertyRecord } from "@itwin/appui-abstract";
import type {
IMutableCategorizedPropertyItem,
IMutableFlatGridItem,
} from "./MutableFlatGridItem";
import {
FlatGridItemType,
MutableCategorizedProperty,
} from "./MutableFlatGridItem";
import type { IMutableGridItemFactory } from "./MutableGridItemFactory";
/**
* Mutable wrapper object for PropertyRecord with array valueFormat which provides methods for working with and managing record children hierarchies.
* @public
*/
export class MutableCategorizedArrayProperty
extends MutableCategorizedProperty
implements IMutableCategorizedPropertyItem
{
private _renderLabel: boolean;
private _children: IMutableCategorizedPropertyItem[];
public constructor(
record: PropertyRecord,
parentSelectionKey: string,
parentCategorySelectionKey: string,
depth: number,
gridItemFactory: IMutableGridItemFactory,
overrideName?: string,
overrideDisplayLabel?: string
) {
super(
FlatGridItemType.Array,
record,
parentSelectionKey,
parentCategorySelectionKey,
depth,
overrideName,
overrideDisplayLabel
);
this._renderLabel = !record.property.hideCompositePropertyLabel;
const childrenDepth = depth + (this._renderLabel ? 1 : 0);
this._children = record.getChildrenRecords().map((child, index) => {
const newName = `${child.property.name}_${index}`;
const newDisplayLabel = `[${index + 1}]`;
return gridItemFactory.createCategorizedProperty(
child,
this.selectionKey,
parentCategorySelectionKey,
childrenDepth,
newName,
newDisplayLabel
);
});
}
public get type(): FlatGridItemType.Array {
return FlatGridItemType.Array;
}
public getChildren(): IMutableCategorizedPropertyItem[] {
return this._children;
}
public override getDescendantsAndSelf() {
return this._renderLabel
? super.getDescendantsAndSelf()
: this.getDescendants();
}
public override getVisibleDescendants(): IMutableFlatGridItem[] {
const descendants: IMutableFlatGridItem[] = [];
if (this.isExpanded || !this._renderLabel) {
// always render children if not rendering the label, otherwise there's no way to expand
// this item to make children visible
this.getChildren().forEach((child) =>
descendants.push(...child.getVisibleDescendantsAndSelf())
);
}
return descendants;
}
public override getVisibleDescendantsAndSelf() {
return this._renderLabel
? super.getVisibleDescendantsAndSelf()
: this.getVisibleDescendants();
}
}