File tree Expand file tree Collapse file tree 3 files changed +53
-40
lines changed
packages/plugin-datasource-pane/src
components/DataSourceImport Expand file tree Collapse file tree 3 files changed +53
-40
lines changed Original file line number Diff line number Diff line change @@ -9,39 +9,39 @@ preference.set('DataSourcePane', {
9
9
dataSourceTypes : [
10
10
{
11
11
type : 'fetch' ,
12
- schema : {
13
- type : "object" ,
14
- properties : {
15
- id : {
16
- type : "string"
17
- } ,
18
- type : {
19
- type : "string"
20
- } ,
21
- isInit : {
22
- type : "boolean" ,
23
- } ,
24
- options : {
25
- type : "object" ,
26
- properties : {
27
- method : {
28
- type : "string" ,
29
- } ,
30
- isCors : {
31
- type : "boolean" ,
32
- } ,
33
- timeout : {
34
- type : "number" ,
35
- } ,
36
- uri : {
37
- type : "string" ,
38
- } ,
39
- } ,
40
- required : [ "method" , "isCors" , "timeout" , "uri" ]
41
- }
42
- } ,
43
- required : [ "id" , "type" , "isInit" , "options" ]
44
- }
12
+ // schema: {
13
+ // type: "object",
14
+ // properties: {
15
+ // id: {
16
+ // type: "string"
17
+ // },
18
+ // type: {
19
+ // type: "string"
20
+ // },
21
+ // isInit: {
22
+ // type: "boolean",
23
+ // },
24
+ // options: {
25
+ // type: "object",
26
+ // properties: {
27
+ // method: {
28
+ // type: "string",
29
+ // },
30
+ // isCors: {
31
+ // type: "boolean",
32
+ // },
33
+ // timeout: {
34
+ // type: "number",
35
+ // },
36
+ // uri: {
37
+ // type: "string",
38
+ // },
39
+ // },
40
+ // required: ["method", "isCors", "timeout", "uri"]
41
+ // }
42
+ // },
43
+ // required: ["id", "type", "isInit", "options"]
44
+ // }
45
45
} ,
46
46
{
47
47
type : 'jsonp' ,
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ export class DataSourceImport extends PureComponent<
67
67
68
68
constructor ( props : DataSourceImportProps ) {
69
69
super ( props ) ;
70
- this . state . code = JSON . stringify ( this . deriveValue ( this . props . defaultValue ) ) ;
70
+ this . state . code = JSON . stringify ( this . deriveValue ( this . props . defaultValue ) , null , 2 ) ;
71
71
this . handleEditorDidMount = this . handleEditorDidMount . bind ( this ) ;
72
72
this . handleEditorChange = this . handleEditorChange . bind ( this ) ;
73
73
this . handleComplete = this . handleComplete . bind ( this ) ;
@@ -97,11 +97,17 @@ export class DataSourceImport extends PureComponent<
97
97
98
98
if ( ! dataSourceType ) return false ;
99
99
100
- // 校验失败的数据源,给予用户提示
101
- const validate = ajv . compile ( dataSourceType . schema )
102
- const valid = validate ( dataSource )
103
- if ( ! valid ) console . warn ( validate . errors )
104
- return valid
100
+ // 向下兼容
101
+ if ( dataSourceType . schema ) {
102
+ // 校验失败的数据源,给予用户提示
103
+ const validate = ajv . compile ( dataSourceType . schema )
104
+ const valid = validate ( dataSource )
105
+ if ( ! valid ) console . warn ( validate . errors )
106
+ return valid
107
+ } else {
108
+ // 用户不传入 schema 校验规则,默认返回 true
109
+ return true
110
+ }
105
111
} ) ;
106
112
} ;
107
113
Original file line number Diff line number Diff line change @@ -161,7 +161,14 @@ export const createStateMachine = (dataSourceList: DataSourceConfig[] = []) => c
161
161
target : 'idle' ,
162
162
actions : assign ( {
163
163
dataSourceList : ( context , event ) => {
164
- return context . dataSourceList . concat ( event . payload ) ;
164
+ // 直接 concat 会出现重复
165
+ const filterDataSourceList = context . dataSourceList . filter ( ( item ) => {
166
+ return ! event . payload . find (
167
+ ( dataSource : DataSourceConfig ) => dataSource . id === item . id ,
168
+ )
169
+ } )
170
+
171
+ return filterDataSourceList . concat ( event . payload ) ;
165
172
} ,
166
173
detail : {
167
174
visible : false ,
You can’t perform that action at this time.
0 commit comments