@itwin/presentation-hierarchies-react 2.0.0-alpha.1 → 2.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +131 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.d.ts +28 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.js +66 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.d.ts +22 -7
- package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.js +8 -5
- package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.d.ts +31 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.js +38 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.d.ts +19 -8
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.js +32 -57
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts +23 -18
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js +31 -13
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.d.ts +3 -2
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.js +61 -4
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react.d.ts +2 -2
- package/lib/esm/presentation-hierarchies-react.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react.js +2 -2
- package/lib/esm/presentation-hierarchies-react.js.map +1 -1
- package/package.json +36 -34
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButtons.d.ts +0 -12
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButtons.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButtons.js +0 -19
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButtons.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeLevelRenderer.d.ts +0 -12
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeLevelRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeLevelRenderer.js +0 -10
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeLevelRenderer.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,106 @@
|
|
|
1
1
|
# @itwin/presentation-hierarchies-react
|
|
2
2
|
|
|
3
|
+
## 2.0.0-alpha.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#916](https://github.com/iTwin/presentation/pull/916): Fix tree nodes overlapping when nodes with and without sublabel are rendered alongside.
|
|
8
|
+
- [#920](https://github.com/iTwin/presentation/pull/920): Changed error display for node errors to match new design system.
|
|
9
|
+
|
|
10
|
+
## 2.0.0-alpha.10
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [#913](https://github.com/iTwin/presentation/pull/913): Removed outline showed after node expander is clicked.
|
|
15
|
+
|
|
16
|
+
## 2.0.0-alpha.9
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- [#906](https://github.com/iTwin/presentation/pull/906): Replaced `TreeNodeRenderer.getIcon` prop with `getDecorations` prop.
|
|
21
|
+
|
|
22
|
+
The `getIcon` prop took either an icon URI, or a `ReactElement`. The new `getDecorations` prop allows passing multiple React elements, allowing consumers to render not just the icon, but also addition components like a tag or a color swatch. Migration:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
// previously, when `getIcon` returned a `ReactElement`:
|
|
26
|
+
function myGetIcon(node: PresentationHierarchyNode): React.ReactElement {
|
|
27
|
+
// implementation...
|
|
28
|
+
}
|
|
29
|
+
<TreeNodeRenderer getIcon={myGetIcon} />
|
|
30
|
+
|
|
31
|
+
// now:
|
|
32
|
+
<TreeNodeRenderer getDecorations={myGetIcon} />
|
|
33
|
+
|
|
34
|
+
// previously, when `getIcon` returned an icon URI:
|
|
35
|
+
function myGetIconUri(node: PresentationHierarchyNode): string {
|
|
36
|
+
// implementation...
|
|
37
|
+
}
|
|
38
|
+
<TreeNodeRenderer getIcon={myGetIconUri} />
|
|
39
|
+
|
|
40
|
+
// now:
|
|
41
|
+
<TreeNodeRenderer getDecorations={(node) => <Icon href={myGetIconUri(node)} />} />
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- [#911](https://github.com/iTwin/presentation/pull/911): Fix incorrect left padding on tree items
|
|
45
|
+
|
|
46
|
+
## 2.0.0-alpha.8
|
|
47
|
+
|
|
48
|
+
### Patch Changes
|
|
49
|
+
|
|
50
|
+
- [#903](https://github.com/iTwin/presentation/pull/903): Added `activeDescription` optional property to TreeItemAction interface, which when provided a value will display a dot above the button indicating an active state. The provided value is used to set accesible description and should explain why the action item is active.
|
|
51
|
+
- [#903](https://github.com/iTwin/presentation/pull/903): Changed `createFilterAction` function to a React hook and renamed it to `useFilterAction`.
|
|
52
|
+
|
|
53
|
+
## 2.0.0-alpha.7
|
|
54
|
+
|
|
55
|
+
### Patch Changes
|
|
56
|
+
|
|
57
|
+
- [#892](https://github.com/iTwin/presentation/pull/892): Fix focus outline for tree items not being visible on action items click.
|
|
58
|
+
- [#894](https://github.com/iTwin/presentation/pull/894): Fix `treeRenderer` property `getSublabel` not being used.
|
|
59
|
+
|
|
60
|
+
## 2.0.0-alpha.6
|
|
61
|
+
|
|
62
|
+
### Patch Changes
|
|
63
|
+
|
|
64
|
+
- [#890](https://github.com/iTwin/presentation/pull/890): Fix alpha peer dependencies to no longer have caret.
|
|
65
|
+
|
|
66
|
+
## 2.0.0-alpha.5
|
|
67
|
+
|
|
68
|
+
### Minor Changes
|
|
69
|
+
|
|
70
|
+
- [#883](https://github.com/iTwin/presentation/pull/883): Trees rendered with `TreeRenderer` will now be virtualized.
|
|
71
|
+
|
|
72
|
+
## 2.0.0-alpha.4
|
|
73
|
+
|
|
74
|
+
### Minor Changes
|
|
75
|
+
|
|
76
|
+
- [#878](https://github.com/iTwin/presentation/pull/878): Tree node renderer now uses `Tree.ItemAction`. `Show` property now takes in undefined values, values behave like this:
|
|
77
|
+
|
|
78
|
+
- `undefined` - visible on hover/focus,
|
|
79
|
+
- `true` - visible at all times,
|
|
80
|
+
- `false` - hidden at all times.
|
|
81
|
+
|
|
82
|
+
Updated peer dependencies:
|
|
83
|
+
|
|
84
|
+
- itwinui-icons to 5.0.0-alpha.3,
|
|
85
|
+
- itwinui-react to 5.0.0-alpha.6,
|
|
86
|
+
|
|
87
|
+
## 2.0.0-alpha.3
|
|
88
|
+
|
|
89
|
+
### Patch Changes
|
|
90
|
+
|
|
91
|
+
- [#870](https://github.com/iTwin/presentation/pull/870): `TreeRenderer` and `TreeNodeRenderer` now take actions as specification function array.
|
|
92
|
+
|
|
93
|
+
- `label`: Action item's label.
|
|
94
|
+
- `action`: The action performed when the button is clicked.
|
|
95
|
+
- `show` A boolean determining whether the button should be displayed.
|
|
96
|
+
- `icon`: The button's icon.
|
|
97
|
+
|
|
98
|
+
## 2.0.0-alpha.2
|
|
99
|
+
|
|
100
|
+
### Major Changes
|
|
101
|
+
|
|
102
|
+
- [#864](https://github.com/iTwin/presentation/pull/864): Add `@itwin/itwinui-icons` as optional peer dependency (only required when using iTwinUI-based tree / node renderers).
|
|
103
|
+
|
|
3
104
|
## 2.0.0-alpha.1
|
|
4
105
|
|
|
5
106
|
### Patch Changes
|
|
@@ -20,6 +121,36 @@
|
|
|
20
121
|
|
|
21
122
|
- [#847](https://github.com/iTwin/presentation/pull/847): Moving tree rendering components to a new design systems.
|
|
22
123
|
|
|
124
|
+
## 1.6.4
|
|
125
|
+
|
|
126
|
+
### Patch Changes
|
|
127
|
+
|
|
128
|
+
- [#909](https://github.com/iTwin/presentation/pull/909): Do not use `dev` versions of `@itwin/*` packages.
|
|
129
|
+
- Updated dependencies:
|
|
130
|
+
- @itwin/unified-selection@1.4.1
|
|
131
|
+
- @itwin/presentation-hierarchies@1.4.2
|
|
132
|
+
- @itwin/presentation-shared@1.2.1
|
|
133
|
+
|
|
134
|
+
## 1.6.3
|
|
135
|
+
|
|
136
|
+
### Patch Changes
|
|
137
|
+
|
|
138
|
+
- Updated dependencies:
|
|
139
|
+
- @itwin/unified-selection@1.4.0
|
|
140
|
+
|
|
141
|
+
## 1.6.2
|
|
142
|
+
|
|
143
|
+
### Patch Changes
|
|
144
|
+
|
|
145
|
+
- [#873](https://github.com/iTwin/presentation/pull/873): Fix hierarchy level size exceeds limit info message wrapping in narrow Tree on Safari browser.
|
|
146
|
+
- [#873](https://github.com/iTwin/presentation/pull/873): Do not require two clicks to expand node with filter buttons on touch devices.
|
|
147
|
+
|
|
148
|
+
## 1.6.1
|
|
149
|
+
|
|
150
|
+
### Patch Changes
|
|
151
|
+
|
|
152
|
+
- [#866](https://github.com/iTwin/presentation/pull/866): Updated hierarchy level size exceeded info message styling in narrow tree component to avoid cutting out text.
|
|
153
|
+
|
|
23
154
|
## 1.6.0
|
|
24
155
|
|
|
25
156
|
### Minor Changes
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PresentationHierarchyNode, PresentationInfoNode, PresentationTreeNode } from "../TreeNode.js";
|
|
2
|
+
/** @alpha */
|
|
3
|
+
interface PlaceholderNode {
|
|
4
|
+
id: string;
|
|
5
|
+
level: number;
|
|
6
|
+
placeholder: true;
|
|
7
|
+
}
|
|
8
|
+
/** @alpha */
|
|
9
|
+
export type FlatNode = {
|
|
10
|
+
level: number;
|
|
11
|
+
levelSize: number;
|
|
12
|
+
posInLevel: number;
|
|
13
|
+
} & PresentationHierarchyNode;
|
|
14
|
+
/** @alpha */
|
|
15
|
+
export interface ErrorNode {
|
|
16
|
+
error: PresentationInfoNode;
|
|
17
|
+
parent?: PresentationHierarchyNode;
|
|
18
|
+
expandTo: (expandNode: (nodeId: string) => void) => void;
|
|
19
|
+
}
|
|
20
|
+
/** @alpha */
|
|
21
|
+
export type FlatTreeNode = FlatNode | PlaceholderNode;
|
|
22
|
+
/** @alpha */
|
|
23
|
+
export declare function isPlaceholderNode(node: FlatTreeNode): node is PlaceholderNode;
|
|
24
|
+
/** @alpha */
|
|
25
|
+
export declare function flattenNodes(rootNodes: PresentationTreeNode[]): FlatTreeNode[];
|
|
26
|
+
export declare function getErrors(rootNodes: PresentationTreeNode[]): ErrorNode[];
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=FlatTreeNode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FlatTreeNode.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/FlatTreeNode.ts"],"names":[],"mappings":"AAKA,OAAO,EAA+B,yBAAyB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEpI,aAAa;AACb,UAAU,eAAe;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,IAAI,CAAC;CACnB;AAED,aAAa;AACb,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,GAAG,yBAAyB,CAAC;AAE9B,aAAa;AACb,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,oBAAoB,CAAC;IAC5B,MAAM,CAAC,EAAE,yBAAyB,CAAC;IACnC,QAAQ,EAAE,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,KAAK,IAAI,CAAC;CAC1D;AAED,aAAa;AACb,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,eAAe,CAAC;AAEtD,aAAa;AACb,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,IAAI,eAAe,CAE7E;AAED,aAAa;AACb,wBAAgB,YAAY,CAAC,SAAS,EAAE,oBAAoB,EAAE,kBAE7D;AAuBD,wBAAgB,SAAS,CAAC,SAAS,EAAE,oBAAoB,EAAE,GAAG,SAAS,EAAE,CAUxE"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import { isPresentationHierarchyNode } from "../TreeNode.js";
|
|
6
|
+
/** @alpha */
|
|
7
|
+
export function isPlaceholderNode(node) {
|
|
8
|
+
return "placeholder" in node;
|
|
9
|
+
}
|
|
10
|
+
/** @alpha */
|
|
11
|
+
export function flattenNodes(rootNodes) {
|
|
12
|
+
return getFlatNodes(rootNodes, 1);
|
|
13
|
+
}
|
|
14
|
+
function getFlatNodes(nodes, level) {
|
|
15
|
+
const flatNodes = [];
|
|
16
|
+
nodes.forEach((node, index) => {
|
|
17
|
+
if (!isPresentationHierarchyNode(node)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
flatNodes.push({ ...node, level, levelSize: nodes.length, posInLevel: index + 1 });
|
|
21
|
+
if (!node.isExpanded) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (node.children !== true) {
|
|
25
|
+
const childNodes = getFlatNodes(node.children, level + 1);
|
|
26
|
+
flatNodes.push(...childNodes);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
flatNodes.push({ id: `${node.id}-children-placeholder`, level: level + 1, placeholder: true });
|
|
30
|
+
});
|
|
31
|
+
return flatNodes;
|
|
32
|
+
}
|
|
33
|
+
export function getErrors(rootNodes) {
|
|
34
|
+
return rootNodes.flatMap((rootNode) => {
|
|
35
|
+
if (!isPresentationHierarchyNode(rootNode)) {
|
|
36
|
+
return [{ parent: undefined, error: rootNode, expandTo: (expandNode) => expandTo(expandNode, []) }];
|
|
37
|
+
}
|
|
38
|
+
if (rootNode.children === true) {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
return getErrorNodes(rootNode, !rootNode.isExpanded ? [rootNode.id] : []);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function getErrorNodes(parent, path) {
|
|
45
|
+
const errorList = [];
|
|
46
|
+
if (parent.children === true) {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
const pathToChild = [...path, ...(!parent.isExpanded ? [parent.id] : [])];
|
|
50
|
+
parent.children.forEach((node) => {
|
|
51
|
+
if (!isPresentationHierarchyNode(node)) {
|
|
52
|
+
errorList.push({ parent, error: node, expandTo: (expandNode) => expandTo(expandNode, path) });
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (node.children !== true) {
|
|
56
|
+
const childErrorList = getErrorNodes(node, pathToChild);
|
|
57
|
+
errorList.push(...childErrorList);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return errorList;
|
|
62
|
+
}
|
|
63
|
+
function expandTo(expandNode, path) {
|
|
64
|
+
path.forEach((nodeId) => expandNode(nodeId));
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=FlatTreeNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FlatTreeNode.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/FlatTreeNode.ts"],"names":[],"mappings":"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","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { isPresentationHierarchyNode, PresentationHierarchyNode, PresentationInfoNode, PresentationTreeNode } from \"../TreeNode.js\";\n\n/** @alpha */\ninterface PlaceholderNode {\n id: string;\n level: number;\n placeholder: true;\n}\n\n/** @alpha */\nexport type FlatNode = {\n level: number;\n levelSize: number;\n posInLevel: number;\n} & PresentationHierarchyNode;\n\n/** @alpha */\nexport interface ErrorNode {\n error: PresentationInfoNode;\n parent?: PresentationHierarchyNode;\n expandTo: (expandNode: (nodeId: string) => void) => void;\n}\n\n/** @alpha */\nexport type FlatTreeNode = FlatNode | PlaceholderNode;\n\n/** @alpha */\nexport function isPlaceholderNode(node: FlatTreeNode): node is PlaceholderNode {\n return \"placeholder\" in node;\n}\n\n/** @alpha */\nexport function flattenNodes(rootNodes: PresentationTreeNode[]) {\n return getFlatNodes(rootNodes, 1);\n}\n\nfunction getFlatNodes(nodes: PresentationTreeNode[], level: number) {\n const flatNodes: FlatTreeNode[] = [];\n nodes.forEach((node, index) => {\n if (!isPresentationHierarchyNode(node)) {\n return;\n }\n flatNodes.push({ ...node, level, levelSize: nodes.length, posInLevel: index + 1 });\n if (!node.isExpanded) {\n return;\n }\n if (node.children !== true) {\n const childNodes = getFlatNodes(node.children, level + 1);\n flatNodes.push(...childNodes);\n return;\n }\n\n flatNodes.push({ id: `${node.id}-children-placeholder`, level: level + 1, placeholder: true } satisfies PlaceholderNode);\n });\n return flatNodes;\n}\n\nexport function getErrors(rootNodes: PresentationTreeNode[]): ErrorNode[] {\n return rootNodes.flatMap((rootNode) => {\n if (!isPresentationHierarchyNode(rootNode)) {\n return [{ parent: undefined, error: rootNode, expandTo: (expandNode) => expandTo(expandNode, []) }];\n }\n if (rootNode.children === true) {\n return [];\n }\n return getErrorNodes(rootNode, !rootNode.isExpanded ? [rootNode.id] : []);\n });\n}\n\nfunction getErrorNodes(parent: PresentationHierarchyNode, path: string[]) {\n const errorList: ErrorNode[] = [];\n\n if (parent.children === true) {\n return [];\n }\n\n const pathToChild = [...path, ...(!parent.isExpanded ? [parent.id] : [])];\n parent.children.forEach((node) => {\n if (!isPresentationHierarchyNode(node)) {\n errorList.push({ parent, error: node, expandTo: (expandNode) => expandTo(expandNode, path) });\n return;\n }\n\n if (node.children !== true) {\n const childErrorList = getErrorNodes(node, pathToChild);\n errorList.push(...childErrorList);\n return;\n }\n });\n return errorList;\n}\n\nfunction expandTo(expandNode: (nodeId: string) => void, path: string[]) {\n path.forEach((nodeId) => expandNode(nodeId));\n}\n"]}
|
|
@@ -14,6 +14,11 @@ export interface LocalizedStrings {
|
|
|
14
14
|
* Default value: `Apply filter`.
|
|
15
15
|
*/
|
|
16
16
|
filterHierarchyLevel: string;
|
|
17
|
+
/**
|
|
18
|
+
* Accesible description for applied hierarchy filter button.
|
|
19
|
+
* Default value: `Filter is applied`.
|
|
20
|
+
*/
|
|
21
|
+
filterHierarchyLevelActiveDescription: string;
|
|
17
22
|
/**
|
|
18
23
|
* Title for clear hierarchy filter button.
|
|
19
24
|
* Default value: `Clear active filter`.
|
|
@@ -21,27 +26,37 @@ export interface LocalizedStrings {
|
|
|
21
26
|
clearHierarchyLevelFilter: string;
|
|
22
27
|
/**
|
|
23
28
|
* Message displayed when no nodes matching filter are found.
|
|
24
|
-
* Default value: `No
|
|
29
|
+
* Default value: `No matches for current filter for {{node}}`.
|
|
25
30
|
*/
|
|
26
31
|
noFilteredChildren: string;
|
|
32
|
+
/**
|
|
33
|
+
* Label for change filter action.
|
|
34
|
+
* Default value: `Change filter`.
|
|
35
|
+
*/
|
|
36
|
+
noFilteredChildrenChangeFilter: string;
|
|
37
|
+
/**
|
|
38
|
+
* Message displayed when hierarchy creation for a node failed.
|
|
39
|
+
* Default value: `Failed to create hierarchy for {{node}}`.
|
|
40
|
+
*/
|
|
41
|
+
failedToCreateHierarchy: string;
|
|
27
42
|
/**
|
|
28
43
|
* Message displayed when result limit exceeds hierarchy size limit.
|
|
29
|
-
* Default value: `
|
|
44
|
+
* Default value: `The hierarchy for {{node}} contains {{limit}}+ items. Try using filters or increase the limit`.
|
|
30
45
|
*/
|
|
31
46
|
resultLimitExceeded: string;
|
|
32
47
|
/**
|
|
33
|
-
*
|
|
34
|
-
* Default value: `
|
|
48
|
+
* Label displayed on error dropdown.
|
|
49
|
+
* Default value: `issues found`.
|
|
35
50
|
*/
|
|
36
|
-
|
|
51
|
+
issuesFound: string;
|
|
37
52
|
/**
|
|
38
53
|
* Message displayed when hierarchy size limit can be overridden.
|
|
39
|
-
* Default value:
|
|
54
|
+
* Default value: `Increase limit to {{limit}}`.
|
|
40
55
|
*/
|
|
41
56
|
increaseHierarchyLimit: string;
|
|
42
57
|
/**
|
|
43
58
|
* Message displayed when hierarchy size limit can be overridden and hierarchy filtering is enabled.
|
|
44
|
-
* Default value: `
|
|
59
|
+
* Default value: `Add Filter`.
|
|
45
60
|
*/
|
|
46
61
|
increaseHierarchyLimitWithFiltering: string;
|
|
47
62
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalizationContext.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/LocalizationContext.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAiB,iBAAiB,EAAmC,MAAM,OAAO,CAAC;AAE1F;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,yBAAyB,EAAE,MAAM,CAAC;IAClC;;;OAGG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,
|
|
1
|
+
{"version":3,"file":"LocalizationContext.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/LocalizationContext.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAiB,iBAAiB,EAAmC,MAAM,OAAO,CAAC;AAE1F;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,qCAAqC,EAAE,MAAM,CAAC;IAC9C;;;OAGG;IACH,yBAAyB,EAAE,MAAM,CAAC;IAClC;;;OAGG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,8BAA8B,EAAE,MAAM,CAAC;IACvC;;;OAGG;IACH,uBAAuB,EAAE,MAAM,CAAC;IAChC;;;OAGG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,sBAAsB,EAAE,MAAM,CAAC;IAC/B;;;OAGG;IACH,mCAAmC,EAAE,MAAM,CAAC;IAC5C;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED,gBAAgB;AAChB,MAAM,WAAW,mBAAmB;IAClC,gBAAgB,EAAE,gBAAgB,CAAC;CACpC;AAmBD;;;GAGG;AACH,UAAU,gCAAgC;IACxC,gDAAgD;IAChD,gBAAgB,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC9C;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,EAAE,gBAAgB,EAAE,QAAQ,EAAE,EAAE,iBAAiB,CAAC,gCAAgC,CAAC,2CAQ9H;AAED,gBAAgB;AAChB,wBAAgB,sBAAsB,wBAErC"}
|
|
@@ -7,12 +7,15 @@ import { createContext, useContext, useEffect, useState } from "react";
|
|
|
7
7
|
const defaultLocalizedStrings = {
|
|
8
8
|
loading: "Loading...",
|
|
9
9
|
filterHierarchyLevel: "Apply filter",
|
|
10
|
+
filterHierarchyLevelActiveDescription: "Filter is applied",
|
|
10
11
|
clearHierarchyLevelFilter: "Clear active filter",
|
|
11
|
-
noFilteredChildren: "No
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
noFilteredChildren: "No matches for current filter for {{node}}",
|
|
13
|
+
noFilteredChildrenChangeFilter: "Change filter",
|
|
14
|
+
failedToCreateHierarchy: "Failed to create hierarchy for {{node}}",
|
|
15
|
+
resultLimitExceeded: "The hierarchy for {{node}} contains {{limit}}+ items. Try using filters or increase the limit",
|
|
16
|
+
issuesFound: "issues found",
|
|
17
|
+
increaseHierarchyLimit: "Increase limit to {{limit}}",
|
|
18
|
+
increaseHierarchyLimitWithFiltering: "Add Filter",
|
|
16
19
|
retry: "Retry",
|
|
17
20
|
};
|
|
18
21
|
const localizationContext = createContext({ localizedStrings: defaultLocalizedStrings });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalizationContext.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/LocalizationContext.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,aAAa,EAAqB,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"LocalizationContext.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/LocalizationContext.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,aAAa,EAAqB,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AA0E1F,MAAM,uBAAuB,GAAqB;IAChD,OAAO,EAAE,YAAY;IACrB,oBAAoB,EAAE,cAAc;IACpC,qCAAqC,EAAE,mBAAmB;IAC1D,yBAAyB,EAAE,qBAAqB;IAChD,kBAAkB,EAAE,4CAA4C;IAChE,8BAA8B,EAAE,eAAe;IAC/C,uBAAuB,EAAE,yCAAyC;IAClE,mBAAmB,EAAE,+FAA+F;IACpH,WAAW,EAAE,cAAc;IAC3B,sBAAsB,EAAE,6BAA6B;IACrD,mCAAmC,EAAE,YAAY;IACjD,KAAK,EAAE,OAAO;CACf,CAAC;AAEF,MAAM,mBAAmB,GAAG,aAAa,CAAsB,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,CAAC,CAAC;AAW9G;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CAAC,EAAE,gBAAgB,EAAE,QAAQ,EAAuD;IAC7H,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,EAAE,gBAAgB,EAAE,EAAE,GAAG,uBAAuB,EAAE,GAAG,gBAAgB,EAAE,EAAE,CAAC,CAAC;IAE9G,SAAS,CAAC,GAAG,EAAE;QACb,QAAQ,CAAC,EAAE,gBAAgB,EAAE,EAAE,GAAG,uBAAuB,EAAE,GAAG,gBAAgB,EAAE,EAAE,CAAC,CAAC;IACtF,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAEvB,OAAO,KAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAgC,CAAC;AAC/F,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,sBAAsB;IACpC,OAAO,UAAU,CAAC,mBAAmB,CAAC,CAAC;AACzC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { createContext, PropsWithChildren, useContext, useEffect, useState } from \"react\";\n\n/**\n * Localized strings used in the components.\n * @public\n */\nexport interface LocalizedStrings {\n /**\n * Message displayed when nodes are loading.\n * Default value: `Loading...`.\n */\n loading: string;\n /**\n * Title for apply hierarchy filter button.\n * Default value: `Apply filter`.\n */\n filterHierarchyLevel: string;\n /**\n * Accesible description for applied hierarchy filter button.\n * Default value: `Filter is applied`.\n */\n filterHierarchyLevelActiveDescription: string;\n /**\n * Title for clear hierarchy filter button.\n * Default value: `Clear active filter`.\n */\n clearHierarchyLevelFilter: string;\n /**\n * Message displayed when no nodes matching filter are found.\n * Default value: `No matches for current filter for {{node}}`.\n */\n noFilteredChildren: string;\n /**\n * Label for change filter action.\n * Default value: `Change filter`.\n */\n noFilteredChildrenChangeFilter: string;\n /**\n * Message displayed when hierarchy creation for a node failed.\n * Default value: `Failed to create hierarchy for {{node}}`.\n */\n failedToCreateHierarchy: string;\n /**\n * Message displayed when result limit exceeds hierarchy size limit.\n * Default value: `The hierarchy for {{node}} contains {{limit}}+ items. Try using filters or increase the limit`.\n */\n resultLimitExceeded: string;\n /**\n * Label displayed on error dropdown.\n * Default value: `issues found`.\n */\n issuesFound: string;\n /**\n * Message displayed when hierarchy size limit can be overridden.\n * Default value: `Increase limit to {{limit}}`.\n */\n increaseHierarchyLimit: string;\n /**\n * Message displayed when hierarchy size limit can be overridden and hierarchy filtering is enabled.\n * Default value: `Add Filter`.\n */\n increaseHierarchyLimitWithFiltering: string;\n /**\n * Label for retry action.\n * Default value: `Retry`.\n */\n retry: string;\n}\n\n/** @internal */\nexport interface LocalizationContext {\n localizedStrings: LocalizedStrings;\n}\n\nconst defaultLocalizedStrings: LocalizedStrings = {\n loading: \"Loading...\",\n filterHierarchyLevel: \"Apply filter\",\n filterHierarchyLevelActiveDescription: \"Filter is applied\",\n clearHierarchyLevelFilter: \"Clear active filter\",\n noFilteredChildren: \"No matches for current filter for {{node}}\",\n noFilteredChildrenChangeFilter: \"Change filter\",\n failedToCreateHierarchy: \"Failed to create hierarchy for {{node}}\",\n resultLimitExceeded: \"The hierarchy for {{node}} contains {{limit}}+ items. Try using filters or increase the limit\",\n issuesFound: \"issues found\",\n increaseHierarchyLimit: \"Increase limit to {{limit}}\",\n increaseHierarchyLimitWithFiltering: \"Add Filter\",\n retry: \"Retry\",\n};\n\nconst localizationContext = createContext<LocalizationContext>({ localizedStrings: defaultLocalizedStrings });\n\n/**\n * Properties for `LocalizationContextProvider`.\n * @public\n */\ninterface LocalizationContextProviderProps {\n /** Localized strings used in the components. */\n localizedStrings?: Partial<LocalizedStrings>;\n}\n\n/**\n * Context provider for localized strings used in the components.\n * @public\n */\nexport function LocalizationContextProvider({ localizedStrings, children }: PropsWithChildren<LocalizationContextProviderProps>) {\n const [state, setState] = useState({ localizedStrings: { ...defaultLocalizedStrings, ...localizedStrings } });\n\n useEffect(() => {\n setState({ localizedStrings: { ...defaultLocalizedStrings, ...localizedStrings } });\n }, [localizedStrings]);\n\n return <localizationContext.Provider value={state}>{children}</localizationContext.Provider>;\n}\n\n/** @internal */\nexport function useLocalizationContext() {\n return useContext(localizationContext);\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PresentationHierarchyNode } from "../TreeNode.js";
|
|
2
|
+
import { HierarchyLevelDetails, useTree } from "../UseTree.js";
|
|
3
|
+
/** @alpha */
|
|
4
|
+
export interface TreeItemAction {
|
|
5
|
+
label: string;
|
|
6
|
+
action: () => void;
|
|
7
|
+
icon: string;
|
|
8
|
+
/**
|
|
9
|
+
* Determines action items visibility:
|
|
10
|
+
* - `False` - action item is hidden.
|
|
11
|
+
* - `True` - action item is visible at all times.
|
|
12
|
+
* - `Undefined` - action item is visible on hover/focus.
|
|
13
|
+
*/
|
|
14
|
+
show?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Provide a value when action button is in active state to display a dot above the button.
|
|
17
|
+
* Provided text value is used to set accessible description it should descibe why the action is in active state.
|
|
18
|
+
* If left undefined the action item will be rendered normally.
|
|
19
|
+
*/
|
|
20
|
+
activeDescription?: string;
|
|
21
|
+
}
|
|
22
|
+
/** @alpha */
|
|
23
|
+
export type FilterActionProps = {
|
|
24
|
+
/** Action to perform when the filter button is clicked for this node. */
|
|
25
|
+
onFilter?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;
|
|
26
|
+
} & Partial<Pick<ReturnType<typeof useTree>, "getHierarchyLevelDetails">>;
|
|
27
|
+
/** @internal */
|
|
28
|
+
export declare function TreeActionButton({ show, label, action, icon, activeDescription }: TreeItemAction): import("react/jsx-runtime").JSX.Element;
|
|
29
|
+
/** @alpha */
|
|
30
|
+
export declare function useFilterAction({ onFilter, getHierarchyLevelDetails }: FilterActionProps): (node: PresentationHierarchyNode) => TreeItemAction;
|
|
31
|
+
//# sourceMappingURL=TreeActionButton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeActionButton.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeActionButton.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAK/D,aAAa;AACb,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,aAAa;AACb,MAAM,MAAM,iBAAiB,GAAG;IAC9B,yEAAyE;IACzE,QAAQ,CAAC,EAAE,CAAC,qBAAqB,EAAE,qBAAqB,KAAK,IAAI,CAAC;CACnE,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,0BAA0B,CAAC,CAAC,CAAC;AAE1E,gBAAgB;AAChB,wBAAgB,gBAAgB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,EAAE,cAAc,2CAEhG;AAED,aAAa;AACb,wBAAgB,eAAe,CAAC,EAAE,QAAQ,EAAE,wBAAwB,EAAE,EAAE,iBAAiB,GAAG,CAAC,IAAI,EAAE,yBAAyB,KAAK,cAAc,CAwB9I"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
import { Tree } from "@itwin/itwinui-react/bricks";
|
|
7
|
+
import { useLocalizationContext } from "./LocalizationContext.js";
|
|
8
|
+
const filterSvg = new URL("@itwin/itwinui-icons/filter.svg", import.meta.url).href;
|
|
9
|
+
/** @internal */
|
|
10
|
+
export function TreeActionButton({ show, label, action, icon, activeDescription }) {
|
|
11
|
+
return _jsx(Tree.ItemAction, { label: label, dot: activeDescription, icon: icon, visible: show, onClick: action });
|
|
12
|
+
}
|
|
13
|
+
/** @alpha */
|
|
14
|
+
export function useFilterAction({ onFilter, getHierarchyLevelDetails }) {
|
|
15
|
+
const { localizedStrings } = useLocalizationContext();
|
|
16
|
+
return (node) => {
|
|
17
|
+
const handleVisibility = () => {
|
|
18
|
+
if (!onFilter || !node.isFilterable) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
if (node.isFiltered) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
label: localizedStrings.filterHierarchyLevel,
|
|
28
|
+
action: () => {
|
|
29
|
+
const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);
|
|
30
|
+
hierarchyLevelDetails && onFilter?.(hierarchyLevelDetails);
|
|
31
|
+
},
|
|
32
|
+
show: handleVisibility(),
|
|
33
|
+
activeDescription: node.isFiltered ? localizedStrings.filterHierarchyLevelActiveDescription : undefined,
|
|
34
|
+
icon: filterSvg,
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=TreeActionButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeActionButton.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeActionButton.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAGnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,iCAAiC,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;AA4BnF,gBAAgB;AAChB,MAAM,UAAU,gBAAgB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAkB;IAC/F,OAAO,KAAC,IAAI,CAAC,UAAU,IAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,iBAAiB,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,GAAI,CAAC;AAC/G,CAAC;AAED,aAAa;AACb,MAAM,UAAU,eAAe,CAAC,EAAE,QAAQ,EAAE,wBAAwB,EAAqB;IACvF,MAAM,EAAE,gBAAgB,EAAE,GAAG,sBAAsB,EAAE,CAAC;IACtD,OAAO,CAAC,IAAI,EAAE,EAAE;QACd,MAAM,gBAAgB,GAAG,GAAG,EAAE;YAC5B,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;gBACpC,OAAO,KAAK,CAAC;YACf,CAAC;YACD,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBACpB,OAAO,IAAI,CAAC;YACd,CAAC;YACD,OAAO,SAAS,CAAC;QACnB,CAAC,CAAC;QAEF,OAAO;YACL,KAAK,EAAE,gBAAgB,CAAC,oBAAoB;YAC5C,MAAM,EAAE,GAAG,EAAE;gBACX,MAAM,qBAAqB,GAAG,wBAAwB,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAClE,qBAAqB,IAAI,QAAQ,EAAE,CAAC,qBAAqB,CAAC,CAAC;YAC7D,CAAC;YACD,IAAI,EAAE,gBAAgB,EAAE;YACxB,iBAAiB,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,gBAAgB,CAAC,qCAAqC,CAAC,CAAC,CAAC,SAAS;YACvG,IAAI,EAAE,SAAS;SAChB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { Tree } from \"@itwin/itwinui-react/bricks\";\nimport { PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { HierarchyLevelDetails, useTree } from \"../UseTree.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\n\nconst filterSvg = new URL(\"@itwin/itwinui-icons/filter.svg\", import.meta.url).href;\n\n/** @alpha */\nexport interface TreeItemAction {\n label: string;\n action: () => void;\n icon: string;\n /**\n * Determines action items visibility:\n * - `False` - action item is hidden.\n * - `True` - action item is visible at all times.\n * - `Undefined` - action item is visible on hover/focus.\n */\n show?: boolean;\n /**\n * Provide a value when action button is in active state to display a dot above the button.\n * Provided text value is used to set accessible description it should descibe why the action is in active state.\n * If left undefined the action item will be rendered normally.\n */\n activeDescription?: string;\n}\n\n/** @alpha */\nexport type FilterActionProps = {\n /** Action to perform when the filter button is clicked for this node. */\n onFilter?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;\n} & Partial<Pick<ReturnType<typeof useTree>, \"getHierarchyLevelDetails\">>;\n\n/** @internal */\nexport function TreeActionButton({ show, label, action, icon, activeDescription }: TreeItemAction) {\n return <Tree.ItemAction label={label} dot={activeDescription} icon={icon} visible={show} onClick={action} />;\n}\n\n/** @alpha */\nexport function useFilterAction({ onFilter, getHierarchyLevelDetails }: FilterActionProps): (node: PresentationHierarchyNode) => TreeItemAction {\n const { localizedStrings } = useLocalizationContext();\n return (node) => {\n const handleVisibility = () => {\n if (!onFilter || !node.isFilterable) {\n return false;\n }\n if (node.isFiltered) {\n return true;\n }\n return undefined;\n };\n\n return {\n label: localizedStrings.filterHierarchyLevel,\n action: () => {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);\n hierarchyLevelDetails && onFilter?.(hierarchyLevelDetails);\n },\n show: handleVisibility(),\n activeDescription: node.isFiltered ? localizedStrings.filterHierarchyLevelActiveDescription : undefined,\n icon: filterSvg,\n };\n };\n}\n"]}
|
|
@@ -1,12 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { HierarchyLevelDetails, useTree } from "../UseTree.js";
|
|
2
|
+
import { ErrorNode } from "./FlatTreeNode.js";
|
|
3
|
+
/** @alpha */
|
|
4
|
+
export interface TreeErrorItemProps {
|
|
5
|
+
/** A callback to reload a hierarchy level when an error occurs and `retry` button is clicked. */
|
|
6
|
+
reloadTree?: (options: {
|
|
7
|
+
parentNodeId: string | undefined;
|
|
8
|
+
state: "reset";
|
|
9
|
+
}) => void;
|
|
10
|
+
/** Action to perform when the filter button is clicked for this node. */
|
|
11
|
+
onFilterClick?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;
|
|
12
|
+
}
|
|
5
13
|
interface TreeErrorRendererOwnProps {
|
|
6
|
-
|
|
14
|
+
errorList: ErrorNode[];
|
|
15
|
+
}
|
|
16
|
+
type TreeErrorRendererProps = TreeErrorRendererOwnProps & TreeErrorItemProps & Partial<Pick<ReturnType<typeof useTree>, "getHierarchyLevelDetails">> & Pick<LinkedNodeProps, "scrollToElement">;
|
|
17
|
+
export declare function TreeErrorRenderer({ errorList, scrollToElement, getHierarchyLevelDetails, onFilterClick }: TreeErrorRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
interface LinkedNodeProps {
|
|
19
|
+
errorNode: ErrorNode;
|
|
20
|
+
scrollToElement: (node: ErrorNode) => void;
|
|
7
21
|
}
|
|
8
|
-
type TreeErrorRendererProps = TreeErrorRendererOwnProps & Pick<TreeNodeRendererOwnProps, "onFilterClick" | "reloadTree"> & Partial<Pick<ReturnType<typeof useTree>, "getHierarchyLevelDetails">>;
|
|
9
|
-
/** @alpha */
|
|
10
|
-
export declare const TreeErrorRenderer: React.ForwardRefExoticComponent<TreeErrorRendererProps & RefAttributes<HTMLDivElement>>;
|
|
11
22
|
export {};
|
|
12
23
|
//# sourceMappingURL=TreeErrorRenderer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeErrorRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeErrorRenderer.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TreeErrorRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeErrorRenderer.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG9C,aAAa;AACb,MAAM,WAAW,kBAAkB;IACjC,iGAAiG;IACjG,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IACrF,yEAAyE;IACzE,aAAa,CAAC,EAAE,CAAC,qBAAqB,EAAE,qBAAqB,KAAK,IAAI,CAAC;CACxE;AAED,UAAU,yBAAyB;IACjC,SAAS,EAAE,SAAS,EAAE,CAAC;CACxB;AAED,KAAK,sBAAsB,GAAG,yBAAyB,GACrD,kBAAkB,GAClB,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,0BAA0B,CAAC,CAAC,GACrE,IAAI,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAC;AAE3C,wBAAgB,iBAAiB,CAAC,EAAE,SAAS,EAAE,eAAe,EAAE,wBAAwB,EAAE,aAAa,EAAE,EAAE,sBAAsB,2CA+BhI;AAqDD,UAAU,eAAe;IACvB,SAAS,EAAE,SAAS,CAAC;IACrB,eAAe,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;CAC5C"}
|
|
@@ -3,70 +3,45 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
4
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
5
|
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
import {
|
|
7
|
-
import { Anchor, Text, Tree } from "@itwin/itwinui-react/bricks";
|
|
6
|
+
import { Anchor, unstable_ErrorRegion as ErrorRegion, Text } from "@itwin/itwinui-react/bricks";
|
|
8
7
|
import { MAX_LIMIT_OVERRIDE } from "../internal/Utils.js";
|
|
9
8
|
import { useLocalizationContext } from "./LocalizationContext.js";
|
|
10
|
-
|
|
11
|
-
export const TreeErrorRenderer = forwardRef(({ node, getHierarchyLevelDetails, onFilterClick, reloadTree }, forwardedRef) => {
|
|
9
|
+
export function TreeErrorRenderer({ errorList, scrollToElement, getHierarchyLevelDetails, onFilterClick }) {
|
|
12
10
|
const { localizedStrings } = useLocalizationContext();
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const hierarchyLevelDetails = getHierarchyLevelDetails?.(
|
|
17
|
-
hierarchyLevelDetails && onFilterClick(hierarchyLevelDetails);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return _jsx(
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
return (_jsx(
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
11
|
+
const errorItems = errorList.map((errorNode) => {
|
|
12
|
+
if (errorNode.error.type === "ResultSetTooLarge") {
|
|
13
|
+
return (_jsx(ResultSetTooLarge, { onFilterClick: () => {
|
|
14
|
+
const hierarchyLevelDetails = getHierarchyLevelDetails?.(errorNode.parent?.id);
|
|
15
|
+
hierarchyLevelDetails && onFilterClick?.(hierarchyLevelDetails);
|
|
16
|
+
}, onOverrideLimit: getHierarchyLevelDetails ? (limit) => getHierarchyLevelDetails(errorNode.parent?.id)?.setSizeLimit(limit) : undefined, scrollToElement: scrollToElement, limit: errorNode.error.resultSetSizeLimit, errorNode: errorNode }, errorNode.error.id));
|
|
17
|
+
}
|
|
18
|
+
if (errorNode.error.type === "NoFilterMatches") {
|
|
19
|
+
return _jsx(NoFilterMatches, { scrollToElement: scrollToElement, errorNode: errorNode }, errorNode.error.id);
|
|
20
|
+
}
|
|
21
|
+
return _jsx(DefaultErrorContainer, { scrollToElement: scrollToElement, errorNode: errorNode }, errorNode.error.id);
|
|
22
|
+
});
|
|
23
|
+
return (_jsx(ErrorRegion.Root, { style: { width: "100%" }, label: errorList.length !== 0 ? `${errorList.length} ${localizedStrings?.issuesFound}` : undefined, items: errorItems }));
|
|
24
|
+
}
|
|
25
|
+
function NoFilterMatches({ onFilterClick, errorNode, scrollToElement }) {
|
|
26
|
+
const { localizedStrings } = useLocalizationContext();
|
|
27
|
+
return (_jsx(ErrorRegion.Item, { message: _jsx(MessageWithNode, { errorNode: errorNode, scrollToElement: scrollToElement, message: localizedStrings.noFilteredChildren }), actions: _jsx(Anchor, { onClick: () => onFilterClick, children: localizedStrings.noFilteredChildrenChangeFilter }) }));
|
|
28
|
+
}
|
|
29
|
+
function DefaultErrorContainer({ reloadTree, errorNode, scrollToElement }) {
|
|
30
|
+
const { localizedStrings } = useLocalizationContext();
|
|
31
|
+
return (_jsx(ErrorRegion.Item, { message: _jsx(MessageWithNode, { errorNode: errorNode, scrollToElement: scrollToElement, message: localizedStrings.failedToCreateHierarchy }), actions: _jsx(Anchor, { onClick: () => reloadTree, children: localizedStrings.retry }) }));
|
|
32
|
+
}
|
|
33
|
+
function ResultSetTooLarge({ errorNode, onFilterClick, limit, onOverrideLimit, scrollToElement }) {
|
|
33
34
|
const { localizedStrings } = useLocalizationContext();
|
|
34
35
|
const supportsFiltering = !!onFilterClick;
|
|
35
36
|
const supportsLimitOverride = !!onOverrideLimit && limit < MAX_LIMIT_OVERRIDE;
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
? createLocalizedMessage(supportsFiltering ? localizedStrings.increaseHierarchyLimitWithFiltering : localizedStrings.increaseHierarchyLimit, MAX_LIMIT_OVERRIDE, () => onOverrideLimit(MAX_LIMIT_OVERRIDE))
|
|
39
|
-
: { title: "", element: null };
|
|
40
|
-
const title = `${limitExceededMessage.title} ${increaseLimitMessage.title}`;
|
|
41
|
-
return (_jsxs("div", { style: { display: "flex", alignItems: "start" }, title: title, children: [limitExceededMessage.element, increaseLimitMessage.element] }));
|
|
37
|
+
const messageWithLimit = localizedStrings.resultLimitExceeded.replace("{{limit}}", limit.toString());
|
|
38
|
+
return (_jsx(ErrorRegion.Item, { message: _jsx(MessageWithNode, { errorNode: errorNode, scrollToElement: scrollToElement, message: messageWithLimit }), actions: _jsxs("div", { style: { display: "flex", flexDirection: "column" }, children: [supportsLimitOverride && (_jsx(Anchor, { onClick: () => onOverrideLimit(MAX_LIMIT_OVERRIDE), children: localizedStrings.increaseHierarchyLimit.replace("{{limit}}", MAX_LIMIT_OVERRIDE.toString()) })), supportsFiltering && _jsx(Anchor, { onClick: onFilterClick, children: localizedStrings.increaseHierarchyLimitWithFiltering })] }) }));
|
|
42
39
|
}
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
return (_jsxs("div", { style: { display: "flex" }, children: [_jsx(Text, { children: message }), onRetry ? _jsx(Anchor, { onClick: onRetry, children: localizedStrings?.retry }) : null] }));
|
|
40
|
+
function LinkedNode({ errorNode, scrollToElement }) {
|
|
41
|
+
return _jsx(Anchor, { onClick: () => scrollToElement(errorNode), children: errorNode.parent?.label });
|
|
46
42
|
}
|
|
47
|
-
function
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
const exp = new RegExp("<link>(.*)</link>");
|
|
51
|
-
const match = messageWithLimit.match(exp);
|
|
52
|
-
if (!match) {
|
|
53
|
-
return {
|
|
54
|
-
title: messageWithLimit,
|
|
55
|
-
element: (_jsx("div", { style: { display: "flex" }, children: _jsx(Text, { children: messageWithLimit }) })),
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
const [fullText, innerText] = match;
|
|
59
|
-
const [textBefore, textAfter] = messageWithLimit.split(fullText);
|
|
60
|
-
return {
|
|
61
|
-
title: messageWithLimit.replace(fullText, innerText),
|
|
62
|
-
element: (_jsxs("div", { style: { display: "flex" }, children: [textBefore ? _jsx(Text, { children: textBefore }) : null, _jsx(Anchor
|
|
63
|
-
// underline props does not exist in v5
|
|
64
|
-
, {
|
|
65
|
-
// underline props does not exist in v5
|
|
66
|
-
onClick: (e) => {
|
|
67
|
-
e.stopPropagation();
|
|
68
|
-
onClick?.();
|
|
69
|
-
}, children: innerText }), textAfter ? _jsx(Text, { children: textAfter }) : null] })),
|
|
70
|
-
};
|
|
43
|
+
function MessageWithNode({ errorNode, scrollToElement, message }) {
|
|
44
|
+
const splitMessage = message.split("{{node}}", 2);
|
|
45
|
+
return (_jsxs("div", { style: { display: "flex", whiteSpace: "pre", flexWrap: "wrap" }, children: [_jsx(Text, { variant: "body-sm", children: splitMessage[0] }), _jsx(LinkedNode, { errorNode: errorNode, scrollToElement: scrollToElement }), splitMessage[1] ? _jsx(Text, { variant: "body-sm", children: splitMessage[1] }) : null] }));
|
|
71
46
|
}
|
|
72
47
|
//# sourceMappingURL=TreeErrorRenderer.js.map
|