Skip to main content

How Procode Materials Call Data Source Methods

Solution

Add the following configuration to the material to provide a reloadDataSource parameter by default:

{
title: {
label: {
type: 'i18n',
'en-US': 'reloadDataSource',
'zh-CN': 'reloadDataSource',
},
},
name: 'reloadDataSource',
setter: 'StringSetter',
initialValue: () => (
{
"type": "JSFunction",
"value": "function(){ return this.reloadDataSource; }"
}
),
},

In the material component, call the following to obtain the method:

const reloadDataSource = props.getReloadDataSource()

FAQ

Hide this configuration from the settings panel

Add:

condition: () => false,

Full example:

{
title: {
label: {
type: 'i18n',
'en-US': 'reloadDataSource',
'zh-CN': 'reloadDataSource',
},
},
name: 'reloadDataSource',
setter: 'StringSetter',
condition: () => false,
initialValue: () => (
{
"type": "JSFunction",
"value": "function(){ return this.reloadDataSource; }"
}
),
},

Configuration did not take effect

Inspect the component schema and verify the configuration was applied correctly.

image.png

If it was not applied, possible causes:

  1. No default value in snippets

Add default parameter configuration as in the example below:

const snippets: Snippet[] = [
{
title: 'Field',
screenshot: '',
schema: {
componentName: 'ProField',
props: {
type: 'textarea',
value: 'Test value',
getReloadDataSource: {
"type": "JSFunction",
"value": "function(){ return this.reloadDataSource; }"
}
},
},
},
];

Apply globally

Use the registerMetadataTransducer API to modify metadata. If snippets are involved, update those configurations as well.