Blocks are divided into simple blocks and blocks containing various data.
Simple blocks such as Markdown blocks.
It only has text content, no other more complex data, and the text content is stored in schema, not in the database.
Data blocks refer to blocks whose data is stored in server-side data tables, such as the Table component.
Field information and list data in Table are all stored in the database.
To facilitate data management for data blocks, we provide the DataBlockProvider component, which internally encapsulates:
DataBlockProvider: Encapsulates all the components below and provides block properties
DataBlockProvider and passes them onDataBlockProvider for CRUD operations on block dataresource.get() or resource.list() provided by BlockResourceProvider based on context information provided by DataBlockProvider to initiate requests, get block data, and pass it on
resource.get() scenarios, will automatically nest CollectionRecordProvider and pass the resource.get() request result down. For resource.list() scenarios, you need to use CollectionRecordProvider yourself to provide data recordsThe above components are encapsulated inside DataBlockProvider. You only need to use DataBlockProvider to automatically get the above data.
It is mainly used in the x-decorator of block schema, for example:
x-decorator-props in schema is called static properties, it is a regular object that records block configuration informationx-use-decorator-props in schema are called dynamic properties, it is a React hook that can be used to get for example ID on URL, or parent context dataWhen both exist, they will be deeply merged as properties of DataBlockProvider.
x-decorator-props): Block's collection table name, used to get block's field information and block datax-decorator-props): Block's relationship field name, used to get block's relationship field information and relationship field datax-decorator-props): Data sourcex-decorator-props): Block's request type, list or getx-decorator-props and x-use-decorator-props): Block's request parameters, exists in bothx-use-decorator-props): Equivalent to params.filterByTk, can be understood as id, used to get single datax-use-decorator-props): Block's sourceId, used with association to get block's relationship field datax-use-decorator-props): When record is provided, will use record as block's data, no request will be initiatedx-use-decorator-props): When parentRecord is provided, will use parentRecord as relationship field's table data, no request will be initiatedThese properties have 8 combinations according to different scenarios:
collectioncollection + action: get + paramscollection + action: list + paramsrecord as data: collection + recordFor Get single data and Get list data, params is not required.
association + sourceIdassociation + sourceId + action: get + params + parentRecordassociation + sourceId + action: list + params + parentRecordrecord as data: association + sourceId + record + parentRecordFor Get single data and Get list data, params and parentRecord are not required. When there is no parentRecord, the corresponding collection will be queried based on association, then the corresponding parentRecord will be queried based on collection.
Can be used to get and modify properties of DataBlockProvider.
props corresponds to the AllDataBlockProps above.
dn is the Designable object, can be used to modify the UI schema of DataBlockProvider, see Designable for details.
Equivalent to useDataBlock().props.
association is similar to collection, just needs to provide sourceId. We take Table list as an example.
If sourceId is not provided, then parentRecord needs to be provided. We take Table list as an example.