Skip to content

Commit 10567ef

Browse files
stewskeugene-andreevrenejeglinsky
authored
Tree view (#2277)
Co-authored-by: Evgeny Andreev <[email protected]> Co-authored-by: René Jeglinsky <[email protected]>
1 parent 239f0c5 commit 10567ef

File tree

2 files changed

+55
-32
lines changed

2 files changed

+55
-32
lines changed
47.3 KB
Loading

advanced/fiori.md

Lines changed: 55 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -745,9 +745,9 @@ Cache Control feature is currently supported on the Java runtime only.
745745

746746
## Hierarchical Tree Views
747747

748-
Recursive hierarchies are parent-child hierarchies, where each entity references its parent and through that defines the hierarchical structure. A common example is a company organization structure or HR reporting, where each employee entity references another employee as a direct report or manager.
748+
Recursive hierarchies are parent-child related structures: each entity references its parent and through that defines the hierarchical structure. A common example is a company organization structure or HR reporting, where each employee entity references another employee as a direct report or manager.
749749

750-
A generic hierarchy implementation for hierarchies is available on all relational datases supported by the CAP runtimes.
750+
A generic hierarchy implementation for hierarchies is available on all relational databases supported by the CAP runtimes.
751751

752752
::: warning
753753
On H2, only small hierarchies should be used for performance reasons.
@@ -761,6 +761,7 @@ Let's assume we have the following domain model and its projection in a service:
761761
namespace my.bookshop;
762762
763763
entity Genres { //...
764+
ID : UUID;
764765
parent : Association to Genres;
765766
}
766767
```
@@ -774,19 +775,67 @@ service AdminService {
774775
```
775776
:::
776777

778+
In this example, there is a managed to-one association `parent` that defines the parent-child hierarchy
779+
based on a single key element. In such a situation you can define the Tree View via the annotation `@hierarchy`:
777780

778-
Annotate/extend the entity in the service as follows:
781+
```cds
782+
annotate AdminService.Genres with @hierarchy : parent;
783+
```
784+
785+
If the entity contains only one such association, you can even omit the value:
786+
787+
```cds
788+
annotate AdminService.Genres with @hierarchy;
789+
```
790+
791+
Configure the TreeTable in UI5's _manifest.json_ file:
792+
793+
```jsonc
794+
"sap.ui5": { ...
795+
"routing": { ...
796+
"targets": { ...
797+
"GenresList": { ...
798+
"options": {
799+
"settings": { ...
800+
"controlConfiguration": {
801+
"@com.sap.vocabularies.UI.v1.LineItem": {
802+
"tableSettings": {
803+
"hierarchyQualifier": "GenresHierarchy", // [!code focus]
804+
"type": "TreeTable" // [!code focus]
805+
}
806+
}
807+
}
808+
}
809+
}
810+
},
811+
},
812+
},
813+
```
814+
815+
> Note: construct the `hierarchyQualifier` with the following pattern: <br>
816+
> `<entity name in service>Hierarchy`
817+
818+
You can now start the server with `cds watch` and see the hierarchical tree view in action in the [_Browse Genres_](http://localhost:4004/fiori-apps.html#Genres-display) app.
819+
820+
![Fiori UI with hierarchical tree view.](assets/hierarchical-tree-view.png) {style="filter: drop-shadow(0 2px 5px rgba(0,0,0,.40));"}
821+
822+
The compiler automatically expands the shortcut annotation `@hierarchy` to the
823+
following `annotate` and `extend` statements.
824+
825+
### Manual Approach
826+
827+
The following documents what happens behind the scenes, done by the compiler as described before. You can also use it, if you cannot use the `@hierarchy` annotation, for example, because you only have an unmanaged parent association.
779828
780829
```cds
781830
// declare a hierarchy with the qualifier "GenresHierarchy"
782-
annotate AdminService.Genres with @Aggregation.RecursiveHierarchy #GenresHierarchy : {
831+
annotate AdminService.Genres with @Aggregation.RecursiveHierarchy #GenresHierarchy: {
783832
NodeProperty : ID, // identifies a node, usually the key
784833
ParentNavigationProperty : parent // navigates to a node's parent
785834
};
786835

787836
extend AdminService.Genres with @(
788837
// The computed properties expected by Fiori to be present in hierarchy entities
789-
Hierarchy.RecursiveHierarchy #GenresHierarchy : {
838+
Hierarchy.RecursiveHierarchy #GenresHierarchy: {
790839
LimitedDescendantCount : LimitedDescendantCount,
791840
DistanceFromRoot : DistanceFromRoot,
792841
DrillState : DrillState,
@@ -797,7 +846,7 @@ extend AdminService.Genres with @(
797846
'LimitedDescendantCount', 'DistanceFromRoot', 'DrillState', 'LimitedRank'
798847
],
799848
// Disallow sorting on these properties from Fiori UIs
800-
Capabilities.SortRestrictions.NonSortableProperties : [
849+
Capabilities.SortRestrictions.NonSortableProperties: [
801850
'LimitedDescendantCount', 'DistanceFromRoot', 'DrillState', 'LimitedRank'
802851
],
803852
) columns { // Ensure we can query these columns from the database
@@ -811,31 +860,5 @@ extend AdminService.Genres with @(
811860
> Note: When naming the hierarchy qualifier, use the following pattern: <br>
812861
> `<entity name in service>Hierarchy`
813862
814-
Configure the TreeTable in UI5's _manifest.json_ file:
815-
816-
```jsonc
817-
"sap.ui5": { ...
818-
"routing": { ...
819-
"targets": { ...
820-
"GenresList": { ...
821-
"options": {
822-
"settings": { ...
823-
"controlConfiguration": {
824-
"@com.sap.vocabularies.UI.v1.LineItem": {
825-
"tableSettings": {
826-
"hierarchyQualifier": "GenresHierarchy", // [!code focus]
827-
"type": "TreeTable" // [!code focus]
828-
}
829-
}
830-
}
831-
}
832-
}
833-
},
834-
},
835-
},
836-
```
837-
838-
> Note: use the `hierarchyQualifier` declared earlier
839-
840863
<div id="reserved-words" />
841864

0 commit comments

Comments
 (0)