Skip to content

Commit 179e63b

Browse files
committed
feat: script component schema definition
Related to #1102
1 parent 1aefe5e commit 179e63b

File tree

6 files changed

+163
-6
lines changed

6 files changed

+163
-6
lines changed

packages/form-json-schema/src/defs/field-types/inputs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"taglist",
1212
"textfield",
1313
"textarea",
14-
"expression"
14+
"expression",
15+
"script"
1516
]
1617
}
1718
},

packages/form-json-schema/src/defs/rules/rules-required-properties.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,46 @@
4949
"computeOn"
5050
]
5151
}
52+
},
53+
{
54+
"if": {
55+
"properties": {
56+
"type": {
57+
"const": "script"
58+
}
59+
},
60+
"required": [
61+
"type"
62+
]
63+
},
64+
"then": {
65+
"allOf": [
66+
{
67+
"required": [
68+
"jsFunction",
69+
"functionParameters",
70+
"computeOn"
71+
]
72+
},
73+
{
74+
"if": {
75+
"properties": {
76+
"computeOn": {
77+
"const": "interval"
78+
}
79+
},
80+
"required": [
81+
"computeOn"
82+
]
83+
},
84+
"then": {
85+
"required": [
86+
"interval"
87+
]
88+
}
89+
}
90+
]
91+
}
5292
}
5393
]
5494
}

packages/form-json-schema/src/defs/type.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"separator",
2323
"table",
2424
"iframe",
25-
"expression"
25+
"expression",
26+
"script"
2627
]
2728
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
export const form = {
2+
type: 'default',
3+
'components': [
4+
{
5+
type: 'script',
6+
key: 'myField',
7+
jsFunction: 'return 42',
8+
functionParameters: '={\n value: 42\n}',
9+
computeOn: 'interval'
10+
}
11+
]
12+
};
13+
14+
export const errors = [
15+
{
16+
instancePath: '/components/0',
17+
keyword: 'required',
18+
message: "must have required property 'interval'",
19+
params: {
20+
missingProperty: 'interval'
21+
},
22+
schemaPath: '#/properties/components/items/allOf/0/allOf/3/then/allOf/1/then/required'
23+
},
24+
{
25+
instancePath: '/components/0',
26+
keyword: 'if',
27+
message: 'must match "then" schema',
28+
params: {
29+
failingKeyword: 'then'
30+
},
31+
schemaPath: '#/properties/components/items/allOf/0/allOf/3/then/allOf/1/if'
32+
},
33+
{
34+
instancePath: '/components/0',
35+
keyword: 'if',
36+
message: 'must match "then" schema',
37+
params: {
38+
failingKeyword: 'then'
39+
},
40+
schemaPath: '#/properties/components/items/allOf/0/allOf/3/if'
41+
}
42+
];
43+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
export const form = {
2+
type: 'default',
3+
'components': [
4+
{
5+
type: 'script',
6+
}
7+
]
8+
};
9+
10+
export const errors = [
11+
{
12+
instancePath: '/components/0',
13+
keyword: 'required',
14+
message: "must have required property 'key'",
15+
params: {
16+
missingProperty: 'key'
17+
},
18+
schemaPath: '#/properties/components/items/allOf/0/allOf/0/then/required'
19+
},
20+
{
21+
instancePath: '/components/0',
22+
keyword: 'if',
23+
message: 'must match "then" schema',
24+
params: {
25+
failingKeyword: 'then'
26+
},
27+
schemaPath: '#/properties/components/items/allOf/0/allOf/0/if'
28+
},
29+
{
30+
instancePath: '/components/0',
31+
keyword: 'required',
32+
message: "must have required property 'jsFunction'",
33+
params: {
34+
missingProperty: 'jsFunction'
35+
},
36+
schemaPath: '#/properties/components/items/allOf/0/allOf/3/then/allOf/0/required'
37+
},
38+
{
39+
instancePath: '/components/0',
40+
keyword: 'required',
41+
message: "must have required property 'functionParameters'",
42+
params: {
43+
missingProperty: 'functionParameters'
44+
},
45+
schemaPath: '#/properties/components/items/allOf/0/allOf/3/then/allOf/0/required'
46+
},
47+
{
48+
instancePath: '/components/0',
49+
keyword: 'required',
50+
message: "must have required property 'computeOn'",
51+
params: {
52+
missingProperty: 'computeOn'
53+
},
54+
schemaPath: '#/properties/components/items/allOf/0/allOf/3/then/allOf/0/required'
55+
},
56+
{
57+
instancePath: '/components/0',
58+
keyword: 'if',
59+
message: 'must match "then" schema',
60+
params: {
61+
failingKeyword: 'then'
62+
},
63+
schemaPath: '#/properties/components/items/allOf/0/allOf/3/if'
64+
}
65+
];
66+
67+

packages/form-json-schema/test/spec/validation.spec.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,17 @@ describe('validation', function() {
110110

111111
describe('rules - required properties', function() {
112112

113-
114113
testForm('no-key');
115114

115+
116+
testForm('expression-field-expression-required');
117+
118+
119+
testForm('js-interval-no-interval');
120+
121+
122+
testForm('js-no-props');
123+
116124
});
117125

118126

@@ -136,9 +144,6 @@ describe('validation', function() {
136144
testForm('disabled-not-allowed');
137145

138146

139-
testForm('expression-field-expression-required');
140-
141-
142147
testForm('action-not-allowed');
143148

144149

0 commit comments

Comments
 (0)