nocobase/docs/en-US/api/client/extensions/collection-manager.md

269 lines
5.5 KiB
Markdown
Raw Normal View History

# CollectionManager
## Components
### CollectionManagerProvider
```jsx | pure
<CollectionManagerProvider interfaces={{}} collections={[]}></CollectionManagerProvider>
```
### CollectionProvider
```jsx | pure
const collection = {
name: 'tests',
fields: [
{
type: 'string',
name: 'title',
interface: 'input',
uiSchema: {
type: 'string',
'x-component': 'Input'
},
},
],
};
<CollectionProvider collection={collection}></CollectionProvider>
```
2023-02-18 15:53:19 +00:00
If there is no collection parameter passed in, get the collection from CollectionManagerProvider with the corresponding name.
```jsx | pure
const collections = [
{
name: 'tests',
fields: [
{
type: 'string',
name: 'title',
interface: 'input',
uiSchema: {
type: 'string',
'x-component': 'Input'
},
},
],
}
];
<CollectionManagerProvider collections={collections}>
<CollectionProvider name={'tests'}></CollectionProvider>
</CollectionManagerProvider>
```
### CollectionFieldProvider
```jsx | pure
const field = {
type: 'string',
name: 'title',
interface: 'input',
uiSchema: {
type: 'string',
'x-component': 'Input'
},
};
<CollectionFieldProvider field={field}></CollectionFieldProvider>
```
2023-02-18 15:53:19 +00:00
If there is no field parameter passed in, get the field from CollectionProvider with the corresponding name.
```jsx | pure
const collection = {
name: 'tests',
fields: [
{
type: 'string',
name: 'title',
interface: 'input',
uiSchema: {
type: 'string',
'x-component': 'Input'
},
},
],
};
<CollectionProvider collection={collection}>
<CollectionFieldProvider name={'title'}></CollectionFieldProvider>
</CollectionProvider>
```
### CollectionField
2023-02-18 15:53:19 +00:00
Universal field component that needs to be used with `<CollectionProvider/>`, but only in schema scenarios. Get the field schema from CollectionProvider with the corresponding name. Extend the configuration via the schema where the CollectionField is located.
```ts
{
name: 'title',
'x-decorator': 'FormItem',
'x-decorator-props': {},
'x-component': 'CollectionField',
'x-component-props': {},
properties: {},
}
```
## Hooks
### useCollectionManager()
2023-02-18 15:53:19 +00:00
Use with `<CollectionManagerProvider/>`.
```jsx | pure
const { collections, get } = useCollectionManager();
```
### useCollection()
2023-02-18 15:53:19 +00:00
Use with `<CollectionProvider/>`.
```jsx | pure
const { name, fields, getField, findField, resource } = useCollection();
```
### useCollectionField()
2023-02-18 15:53:19 +00:00
Use with `<CollectionFieldProvider/>`.
```jsx | pure
const { name, uiSchema, resource } = useCollectionField();
```
2023-02-18 15:53:19 +00:00
The resource needs to be used with `<RecordProvider/>` to provide context of the record of the current data table row.
# CollectionManager
## Components
### CollectionManagerProvider
```jsx | pure
<CollectionManagerProvider interfaces={{}} collections={[]}></CollectionManagerProvider>
```
### CollectionProvider
```jsx | pure
const collection = {
name: 'tests',
fields: [
{
type: 'string',
name: 'title',
interface: 'input',
uiSchema: {
type: 'string',
'x-component': 'Input'
},
},
],
};
<CollectionProvider collection={collection}></CollectionProvider>
```
2023-02-18 15:53:19 +00:00
If there is no collection parameter passed in, get the collection from CollectionManagerProvider with the corresponding name.
```jsx | pure
const collections = [
{
name: 'tests',
fields: [
{
type: 'string',
name: 'title',
interface: 'input',
uiSchema: {
type: 'string',
'x-component': 'Input'
},
},
],
}
];
<CollectionManagerProvider collections={collections}>
<CollectionProvider name={'tests'}></CollectionProvider>
</CollectionManagerProvider>
```
### CollectionFieldProvider
```jsx | pure
const field = {
type: 'string',
name: 'title',
interface: 'input',
uiSchema: {
type: 'string',
'x-component': 'Input'
},
};
<CollectionFieldProvider field={field}></CollectionFieldProvider>
```
2023-02-18 15:53:19 +00:00
If there is no field parameter passed in, get the field from CollectionProvider with the corresponding name.
```jsx | pure
const collection = {
name: 'tests',
fields: [
{
type: 'string',
name: 'title',
interface: 'input',
uiSchema: {
type: 'string',
'x-component': 'Input'
},
},
],
};
<CollectionProvider collection={collection}>
<CollectionFieldProvider name={'title'}></CollectionFieldProvider>
</CollectionProvider>
```
### CollectionField
2023-02-18 15:53:19 +00:00
Universal field component that needs to be used with `<CollectionProvider/>`, but only in schema scenarios. Get the field schema from CollectionProvider with the corresponding name. Extend the configuration via the schema where the CollectionField is located.
```ts
{
name: 'title',
'x-decorator': 'FormItem',
'x-decorator-props': {},
'x-component': 'CollectionField',
'x-component-props': {},
properties: {},
}
```
## Hooks
### useCollectionManager()
2023-02-18 15:53:19 +00:00
Use with `<CollectionManagerProvider/>`.
```jsx | pure
const { collections, get } = useCollectionManager();
```
### useCollection()
2023-02-18 15:53:19 +00:00
Use with `<CollectionProvider/>`.
```jsx | pure
const { name, fields, getField, findField, resource } = useCollection();
```
### useCollectionField()
2023-02-18 15:53:19 +00:00
Use with `<CollectionFieldProvider/>`.
```jsx | pure
const { name, uiSchema, resource } = useCollectionField();
```
2023-02-18 15:53:19 +00:00
The resource needs to be used with `<RecordProvider/>` to provide context of the record of the current data table row.