AdminForthResource
Resource describes one table or collection in database. AdminForth generates set of pages for 'list', 'show', 'edit', 'create', 'filter' operations for each resource.
Extends
Omit<AdminForthResourceInput,"options"|"columns">
Properties
columns
columns:
AdminForthResourceColumn[]
dataSource
dataSource:
string
ID of datasource which will be used to fetch data from.
Inherited from
AdminForthResourceInputCommon.dataSource
dataSourceColumns
dataSourceColumns:
AdminForthResourceColumn[]
Overrides
AdminForthResourceInput.dataSourceColumns
hooks?
optionalhooks:object
Hooks allow you to change the data on different stages of resource lifecycle. Hooks are functions which will be called on backend side (only backend side).
create?
optionalcreate:object
create.afterSave?
optionalafterSave:AfterCreateSaveFunction[]
Typical use-cases:
- Initiate some trigger after record saved to database (e.g sync to another datasource)
create.beforeSave?
optionalbeforeSave:BeforeCreateSaveFunction[]
Should return ok: true to continue saving pipeline and allow creating record in database, and ok: false to interrupt pipeline and prevent record creation.
If you need to show error on UI, set error: \<error message\> in response.
Typical use-cases:
- Create record by custom code (return
{ ok: false, newRecordId: <id of created record from custom code> }) - Validate record before saving to database and interrupt execution if validation failed (return
{ ok: false, error: <validation error> }), thoughallowedActions.createshould be preferred in most cases - fill-in adminUser as creator of record (set
record.<some field> = x; return \{ ok: true \}) - Attach additional data to record before saving to database (mostly fillOnCreate should be used instead)
delete?
optionaldelete:object
delete.afterSave?
optionalafterSave:BeforeDeleteSaveFunction[]
Typical use-cases:
- Initiate some trigger after record deleted from database (e.g sync to another datasource)
delete.beforeSave?
optionalbeforeSave:BeforeDeleteSaveFunction[]
Typical use-cases:
- Validate that record can be deleted and interrupt execution if validation failed (
allowedActions.deleteshould be preferred in most cases)
edit?
optionaledit:object
edit.afterSave?
optionalafterSave:AfterEditSaveFunction[]
Typical use-cases:
- Same as hooks.create.afterSave but for edit page
edit.beforeSave?
optionalbeforeSave:BeforeEditSaveFunction[]
Typical use-cases:
- Same as hooks.create.beforeSave but for edit page
list?
optionallist:object
list.afterDatasourceResponse?
optionalafterDatasourceResponse:AfterDataSourceResponseFunction[]
Typical use-cases:
- Same as hooks.show.afterDatasourceResponse but applied for all records returned from database for showing in list view, e.g. add new field to each record in list view
list.beforeDatasourceRequest?
optionalbeforeDatasourceRequest:BeforeDataSourceRequestFunction[]
Typical use-cases:
- add additional filters in addition to what user selected before fetching data from database.
- same as hooks.show.beforeDatasourceRequest
show?
optionalshow:object
show.afterDatasourceResponse?
optionalafterDatasourceResponse:AfterDataSourceResponseFunction[]
Typical use-cases:
- Transform value for some field for record returned from database before returning to frontend (minimize, sanitize, etc)
- If some-why you can't use
backendOnlyyou can cleanup sensitive fields here - Attach additional data to record before returning to frontend
show.beforeDatasourceRequest?
optionalbeforeDatasourceRequest:BeforeDataSourceRequestFunction[]
Typical use-cases:
- request additional data from database before returning to frontend for soft-join
Overrides
Omit.hooks
label
label:
string
Label for resource which will be displayed in the admin panel. By default it equals to table name in database.
Overrides
AdminForthResourceInputCommon.label
options
options:
ResourceOptions
plugins?
optionalplugins:IAdminForthPlugin[]
Array of plugins which will be used to modify resource configuration.
Overrides
AdminForthResourceInput.plugins
recordLabel()
recordLabel: (
record) =>string
Hook which allow you to modify record label
Example:
recordLabel: (record) => `${record.name} - ${record.id}`,
Parameters
| Parameter | Type |
|---|---|
record | any |
Returns
string
Overrides
AdminForthResourceInputCommon.recordLabel
resourceId
resourceId:
string
Unique identifier of resource. By default it equals to table name in database. If you wish you can explicitly set it to any string. We added to support cases when 2 datasources have tables with the same name.
Overrides
AdminForthResourceInputCommon.resourceId
table
table:
string
Table name in database which will be used to fetch data from. Might be case sensitive.