import { Tab, Tabs } from 'nextra-theme-docs'
Configuration per Entity
<Tabs items={['Overview', 'Type definition']}>
| Option | Type | default | description |
|---|---|---|---|
| listTitle | string | humanized plural of entity | the term for the collection of items |
| itemTitle | string | humanized singular of entity | the term for a single items |
| itemName | Function | first found indication attribute of an item | function to return the value for a specific item to be used in views when referencing or displaying it |
| indication | string|string[] | pre-defined list of common indication terms (name, title, key, ...) | which attribute should be used in queries and views to obtain the "name" of an item |
| path | string | plural of entity | the path in the routes for this entity |
| hideField | Function | returns wheter a certain field should be shown (based on the action and item attributes) | |
| breadcrumbs | string[]|BreadcrumbsConfigType | parent / child | the breadcrumb path to the actions of this entity |
| rootIndex | boolean | true | whether the UI should a "parent-less" index view for this entity |
| index | UiConfig | configuration of the index view | |
| show | UiShowConfig | configuration of the show view | |
| create | UiConfig | configuration of the create view | |
| edit | UiConfig | configuration of the edit view |
export type EntityViewConfig = {
listTitle?: string | (() => string)
itemTitle?: string | (() => string)
itemName?: (item:any) => string
indication?:string|string[]
path?:string
index?: UiConfig
show?: UiShowConfig
create?: UiConfig
edit?: UiConfig
hideField?: (action:string, field:FieldConfig, item:any) => boolean
breadcrumbs?: string[]|BreadcrumbsConfigType
rootIndex?: boolean
}itemName
With the following configuration at any place where a Car item is displayed it would render the color and brand of this car. E.g. red BMW or green Mercedes.
{
Car: {
itemName: (item:any) => `${item.color} ${item.brand}`
}
}hideField
Given you want to hide the license number on any view when the status of the Car item is discarded.
{
Car: {
hide: (action:string, field:FieldConfig, item:any) => {
if( field.name !== 'license' ) return true;
return item.status !== 'discarded';
}
}
}breadcrumbs
When rendering an action of an entity, the breadcrumbs will show the path to the action as follows:
| index | / Home / cars |
| show | / Home / cars / red bmw |
| edit | / Home / cars / red bmw / edit |
| create | / Home / cars / red bmw / new |
When you followed a parent child route the breadcrumb will automatically include the parent paths as follows:
Given an assocTo relation from Car to Driver
| index | / Home / drivers / Adam Apple / cars |
| show | / Home / drivers / Adam Apple / cars / red bmw |
| edit | / Home / drivers / Adam Apple / cars / red bmw / edit |
| create | / Home / drivers / Adam Apple / cars / red bmw / new |
But when adding another assocTo relation to Car let's say Accessory we would loose the information that the red bmw is the car of Adam Apple.
| index | / Home / cars / red bmw / accessories |
| show | / Home / cars / red bmw / accessories / trailer |
| edit | / Home / cars / red bmw / accessories / trailer / edit |
| create | / Home / cars / red bmw / accessories / trailer / new |
If it is important in your business domain to see that the trailer is part of a car of the driver Adam Apple you can add this path to the breadcumbs option as follows:
{
Accessory: {
breadcrumbs: ['Driver', 'Car', 'Accessory']
}
}You can only use entities with an assocTo relation from right to left. You can state as many entities as necessary. The last entry (this entity itself) is optional and will be added by the configuration resolver.
Given this the breadcrumbs for the entity Accessory would now give you the full relationship of the trailer accessory.
| index | / Home / drivers / Adam Apple / cars / red bmw / accessories |
| show | / Home / drivers / Adam Apple / cars / red bmw / accessories / trailer |
| edit | / Home / drivers / Adam Apple / cars / red bmw / accessories / trailer / edit |
| create | / Home / drivers / Adam Apple / cars / red bmw / accessories / trailer / new |
BreadcrumbsConfigType
Using the entity names as in the former example is usually sufficient. But there may be the situation where you want to render more information in the breadcrumb/entries than just the listTitles and itemName as in the default implementation. For this you can provide you own query and build function.
| Option | ||
|---|---|---|
| entites | string[] | list of entities; config { breadcrumbs: ['Car', 'Driver'] } is the same as { breadcrumbs: {entities: ['Car', 'Driver'] } } |
| query | (entities:string[], itemId?:string, parentId?:string, acs?:AdminConfigService) => object|string } | returns the GraphQL query as string or json-to-graphql (opens in a new tab) object; will be called by the BreadcrumComponent; default implementation queries for the indication of the items |
| build | (entities:string[], data:any, action:string, acs:AdminConfigService) => BreadcrumbsType[] | returns the breadcrumbs as BreadcrumbsType; will be called by the BreadcrumComponent |
BreadcrumbsType
export type BreadcrumbsType = {
label: string
link: string[]
class?: string|string[]
}rootIndex
When you follow a parent-child relationship, the index of this view would filter the child-entity's items for the parent-item. Per default a "Show all" action menu is offered. If in your business domain a list of an entity's items without the parent makes no sense you can set rootIndex to false to prevent this. Be aware the route still exists, so you could nonetheless still call this parent-less index view from a custom action or component.