Tree Page¶
The Tree Module contains a Tree Page Component that we can use to display the hierarchy of an entity.
The Tree Page uses the TreePageEffect
, which has a default implementation for
working with GraphQL Queries.
Adding a Tree Page for a GQL Query¶
The Tree Page needs a class for configuring the tree and handling it's actions.
We call that a TreePageEffect
. For creating Tree Page, we need to create a
class implementing TreePageEffect
. Also, for displaying the tree properly,
make sure to implement a hierarchical query as stated
here.
Once we do this, we need to register the Effect in our Feature Module.
TypeScript | |
---|---|
Finally, in our Routing module we can use createTreeRoute
to render a Form by
ID at a path:
TypeScript | |
---|---|
Note
If you don't have a routing module, you'll need to create it and use it in AdminCenter (or other app)
Customizing the Tree¶
Once we have our tree, we might want need to perform some customizations
according to our business requirements. We can call this.customizeTree
in the
constructor, and will receive a TreeBuilder
that we'll use to customize the
tree.
TypeScript | |
---|---|
The most common thing to do is to customize the tree fields, that being said, before customizing anything make sure the defaults don't fit for your case, since for most cases the defaults are fine.
Customizing Actions¶
To define actions that can be performed for each item of the tree we can use
either the addItemAction
or addItemActions
methods of the TreeBuilder
.
TypeScript | |
---|---|
The user then can trigger certain action by clicking the corresponding button rendered on each node of the tree.
Toolbar actions¶
In a similar way we can define toolbar actions, whose buttons will appear on
the toolbar of the tree, by using the addToolbarAction
or addToolbarActions
methods of the TreeBuilder
.
If a field is an object type, we can keep calling field
on the
TreeFieldBuilder
just like we did with the TreeBuilder
.
Hidden By Default¶
The Tree allows the user to choose which fields they want to see at any given
time. However, we usually want to provide a sane set of default fields to show
for our trees. We can do that by using the hiddenByDefault()
method:
TypeScript | |
---|---|
The hiddenByDefault()
method, will hide the field unless the user has chosen
to show it, by using the fields chooser, or if a pre-selected "folder
definition" (UX Roles, concept we don't have yet) is showing the field.
If the field is an object type, hiding the field will hide all of the children as well. This is a feature.
Child fields can override the parent by calling hiddenByDefault(true)
, which
is what we usually do for object fields: we hide all fields, and show a field
that represent the object, like it's name.
TypeScript | |
---|---|
Overriding the default behavior¶
By default, the tree will show all fields, unless hiddenByDefault
has been
called on them.
If we want the opposite behavior, we can call hiddenByDefault
on the
TreeBuilder
, which causes all fields to be hidden by default unless overridden
by using hiddenByDefault(true)
on the field.
TypeScript | |
---|---|
Display Name¶
The display name is the label that is displayed to the user to represent the
field. By default, it will be calculated from the name
.
The default is to convert aPascalCasedField
to A Pascal Cased Field
. In the
case of nested objects, the parent's name is appended.
TypeScript | |
---|---|