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 |
disabled | bool | Whether to disable, if disabled, it will not be displayed in the rulego-editor | false |
# 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 |
rules | []Object | Front-end interface validation rules, example: {required: true, message: "This field is required"} | Empty |
fields | []ComponentFormField | Nested fields, Type=struct, for nested fields | Empty |
component | Object | Form component configuration, example: {"type": "codeEditor"} | Empty |
type: Field type, currently provides the following types, the rulego-editor
front-end will automatically select form components based on the type.
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
You can also explicitly specify the form component type through the component field:
codeEditor
: Code Editortextarea
: Text Areaselect
: Dropdown box, example:
{
"type": "select",
"filterable": true,
"allowCreate": false,
"multiple": false,
"options": [
{
"label": "TCP",
"value": "tcp"
},
{
"label": "UDP",
"value": "udp"
}
]
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Component Configuration Form Conventions
Component Configuration Form Conventions
# Customize component form configuration information
Custom components can implement the following optional interface to override the definitions from the Component Configuration Form Conventions :
type ComponentDefGetter interface {
Def() ComponentForm
}
2
3
Example:
// Configuration item, supports the following types
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
}
//Custom Components
type DefaultValueNode struct {
BaseNode
// Return form configuration item definition information based on the definition of this field
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",
},
},
}
}
//Implement the ComponentDefGetter interface to modify component names and descriptions
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
47
48
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