nocobase/docs/en-US/api/client/extensions/collection-manager.md
2023-02-18 23:53:19 +08:00

5.5 KiB

CollectionManager

Components

CollectionManagerProvider

<CollectionManagerProvider interfaces={{}} collections={[]}></CollectionManagerProvider>

CollectionProvider

const collection = {
  name: 'tests',
  fields: [
    {
      type: 'string',
      name: 'title',
      interface: 'input',
      uiSchema: {
        type: 'string',
        'x-component': 'Input'
      },
    },
  ],
};
<CollectionProvider collection={collection}></CollectionProvider>

If there is no collection parameter passed in, get the collection from CollectionManagerProvider with the corresponding name.

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

const field = {
  type: 'string',
  name: 'title',
  interface: 'input',
  uiSchema: {
    type: 'string',
    'x-component': 'Input'
  },
};
<CollectionFieldProvider field={field}></CollectionFieldProvider>

If there is no field parameter passed in, get the field from CollectionProvider with the corresponding name.

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

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.

{
  name: 'title',
  'x-decorator': 'FormItem',
  'x-decorator-props': {},
  'x-component': 'CollectionField',
  'x-component-props': {},
  properties: {},
}

Hooks

useCollectionManager()

Use with <CollectionManagerProvider/>.

const { collections, get } = useCollectionManager();

useCollection()

Use with <CollectionProvider/>.

const { name, fields, getField, findField, resource } = useCollection();

useCollectionField()

Use with <CollectionFieldProvider/>.

const { name, uiSchema, resource } = useCollectionField();

The resource needs to be used with <RecordProvider/> to provide context of the record of the current data table row.

CollectionManager

Components

CollectionManagerProvider

<CollectionManagerProvider interfaces={{}} collections={[]}></CollectionManagerProvider>

CollectionProvider

const collection = {
  name: 'tests',
  fields: [
    {
      type: 'string',
      name: 'title',
      interface: 'input',
      uiSchema: {
        type: 'string',
        'x-component': 'Input'
      },
    },
  ],
};
<CollectionProvider collection={collection}></CollectionProvider>

If there is no collection parameter passed in, get the collection from CollectionManagerProvider with the corresponding name.

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

const field = {
  type: 'string',
  name: 'title',
  interface: 'input',
  uiSchema: {
    type: 'string',
    'x-component': 'Input'
  },
};
<CollectionFieldProvider field={field}></CollectionFieldProvider>

If there is no field parameter passed in, get the field from CollectionProvider with the corresponding name.

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

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.

{
  name: 'title',
  'x-decorator': 'FormItem',
  'x-decorator-props': {},
  'x-component': 'CollectionField',
  'x-component-props': {},
  properties: {},
}

Hooks

useCollectionManager()

Use with <CollectionManagerProvider/>.

const { collections, get } = useCollectionManager();

useCollection()

Use with <CollectionProvider/>.

const { name, fields, getField, findField, resource } = useCollection();

useCollectionField()

Use with <CollectionFieldProvider/>.

const { name, uiSchema, resource } = useCollectionField();

The resource needs to be used with <RecordProvider/> to provide context of the record of the current data table row.