Get Component Configuration Forms
This API will scan all the components registered to the registrar, and get the component definition and form configuration information according to the agreed method. It is used for rule chain visual configuration, component material loading.
# Component Configuration Form API
Return a list of all registered component definitions and their form configuration information.
rulego.Registry.GetComponentForms().Values()
Return type: []types.ComponentForm
Reference example: examples/ui_api/ (opens new window)
Example return result: testdata/components.json (opens new window)
# types.ComponentForm
Field | Type | Description | Default value |
---|---|---|---|
type | string | Component type | The value of the Type() function implemented by the component, globally unique |
category | string | Component category | |
fields | []ComponentFormField | Component configuration field list | The default is to get the Config field of the component |
label | string | Component display name | Empty |
desc | string | Component description | Empty |
icon | string | Icon | Empty |
relationTypes | []string | The list of connection names that can be generated with the next node | The default for filter node types is: True/False/Failure; the default for other node types is Success/Failure, if it is empty, it means that the user can customize the connection relationship |
The Label and Desc fields involve internationalization, and the framework does not provide the information of these fields at present. Users can set them by custom methods, or set them on the front end.
# types.ComponentFormField
Field | Type | Description | Default value |
---|---|---|---|
name | string | Field name | |
type | string | Field type | Such as: string, int, bool, etc. |
defaultValue | any | Default value | The default value of the corresponding field of the component implementation method node.New(), Config, will be filled in this value |
label | string | Field display name | Empty, can be specified by tag:Label |
desc | string | Field description | Empty, can be specified by tag:Desc |
validate | string | Field validation rules | Empty, obtained by tag:Validate. For example: Validate:"required" |
fields | []ComponentFormField | Nested fields, Type=struct, nested fields | Empty |
The Label, Desc, and Validate fields involve internationalization, and the framework does not provide the information of these fields at present. Users can set them by custom methods, or set them on the front end.
type: field type, currently provides the following types
string
bool
int
int8
int16
int32
int64
uint
uint8
uint16
uint32
uint64
float32
float64
array
: Slice type will also be converted to: arraymap
struct
: nested fields
# Customize component form configuration information
Custom components can provide custom component form definitions by implementing an interface, which is an optional interface. If not provided, the component form configuration information will be built according to the agreed method:
type ComponentDefGetter interface {
Def() ComponentForm
}
2
3
Example:
// With default value configuration
type DefaultValueConfig struct {
Num int
Url string `label:"Server address" desc:"broker server address" validate:"required" `
IsSsl bool
Params []string
A int32
B int64
C float64
D map[string]string
E TestE
F uint16
}
type TestE struct {
A string
}
type DefaultValueNode struct {
BaseNode
Config DefaultValueConfig
}
func (n *DefaultValueNode) Type() string {
return "test/defaultConfig"
}
func (n *DefaultValueNode) New() types.Node {
return &DefaultValueNode{
Config: DefaultValueConfig{
Url: "http://localhost:8080",
Num: 5,
E: TestE{
A: "Test",
},
},
}
}
func (n *DefaultValueNode) Def() types.ComponentForm {
relationTypes := &[]string{"aa", "bb"}
return types.ComponentForm{
Label: "Default test component",
Desc: "Usage xxxxx",
RelationTypes: relationTypes,
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
You can also modify it and return it to the front end. Example:
items := Registry.GetComponentForms()
componentForm, ok := items.GetComponent("test/configHasPtr")
assert.Equal(t, true, ok)
componentForm.Label = "Chinese Label"
items[componentForm.Type] = componentForm
2
3
4
5