@@ -13,6 +13,7 @@ import {
1313 Form ,
1414 Icon ,
1515 Checkbox ,
16+ notification ,
1617} from 'antd'
1718import classnames from 'classnames'
1819import CodeMirror from 'react-codemirror'
@@ -67,20 +68,19 @@ class RequestPage extends React.Component {
6768 keys : [ 1 ] ,
6869 result : null ,
6970 visible : true ,
71+ code : '' ,
7072 }
7173 }
7274
7375 constructAPIDomain = ( ) => {
7476 const alias = _get ( this . props . config , [ 'misc' , 'alias' ] , '' )
75- console . log ( '...l..' , this . props . config )
7677 return '//' + alias + '.stg-api.covenantsql.io:15153'
7778 }
7879
7980 constructTableSelection = ( ) => {
80- const tables = _get ( this . props . config , [ 'misc' , 'tables' ] , [ ] )
81- return tables . map ( t => ( { } ) )
81+ const tables = _get ( this . props . config , [ 'tables' ] , [ ] )
8282 return (
83- < Select placeholder = "Please select a country" >
83+ < Select placeholder = "Select a table" style = { { minWidth : '160px' } } >
8484 { tables . map ( t => {
8585 if ( ! t . config . is_deleted ) {
8686 return (
@@ -103,26 +103,47 @@ class RequestPage extends React.Component {
103103 this . props . form . validateFields ( ( err , values ) => {
104104 if ( ! err ) {
105105 const params = { }
106- console . log ( './//' , values )
107- if ( values . key ) {
108- values . key . forEach ( ( item , index ) => {
109- if ( item && values . check [ index ] ) {
110- params [ item ] = values . value [ index ]
111- }
112- } )
113106
114- if ( values . value . data ) {
115- console . log ( 'parsing, ' , values . value . data )
116- params . data = JSON . parse ( values . value . data )
107+ if ( this . state . url . indexOf ( ':table' ) > - 1 ) {
108+ const { table_value, data_value } = values
109+ params . table = table_value
110+ try {
111+ let d = data_value . replace ( / [ \n \r ] + / g, '' )
112+ params . data = data_value && JSON . parse ( d )
113+ } catch ( e ) {
114+ notification . error ( {
115+ message : 'Table change `data` JSON parse error' ,
116+ duration : 10 ,
117+ } )
118+ return
119+ }
120+ } else {
121+ if ( values . key ) {
122+ values . key . forEach ( ( item , index ) => {
123+ if ( item && values . check [ index ] ) {
124+ params [ item ] = values . value [ index ]
125+ }
126+ } )
117127 }
118128 }
119129
120130 console . log ( params )
121-
122- request ( { method, url, data : params } ) . then ( data => {
123- this . setState ( {
124- result : JSON . stringify ( data ) ,
131+ request ( { method, url, data : params } )
132+ . then ( data => {
133+ this . setState ( {
134+ result : JSON . stringify ( data ) ,
135+ } )
125136 } )
137+ . catch ( e => {
138+ notification . error ( {
139+ message : e . message ,
140+ duration : 10 ,
141+ } )
142+ } )
143+ } else {
144+ notification . error ( {
145+ message : 'Please input required fields' ,
146+ description : '' ,
126147 } )
127148 }
128149 } )
@@ -171,10 +192,15 @@ class RequestPage extends React.Component {
171192 } )
172193 }
173194
195+ onCodeMirrorChange = v => {
196+ this . setState ( {
197+ code : v ,
198+ } )
199+ }
200+
174201 render ( ) {
175202 const { result, url, method, keys, visible } = this . state
176203 const { getFieldDecorator } = this . props . form
177- console . log ( '///////////' , this . state )
178204
179205 return (
180206 < Page inner >
@@ -304,42 +330,35 @@ class RequestPage extends React.Component {
304330 </ Col >
305331 < Col style = { { marginTop : 8 } } >
306332 { getFieldDecorator ( `key[table]` ) (
307- < Input placeholder = "table" value = { 'table' } disabled />
333+ < Input placeholder = "table" disabled />
308334 ) }
309335 </ Col >
310336 < Col style = { { marginTop : 8 } } >
311- { getFieldDecorator ( `value[table]` ) (
312- < Input placeholder = "Value" />
313- ) }
337+ { getFieldDecorator ( `table_value` , {
338+ rules : [
339+ {
340+ required : true ,
341+ message : 'Please select a table' ,
342+ } ,
343+ ] ,
344+ } ) ( this . constructTableSelection ( ) ) }
314345 </ Col >
315346 </ Row >
316347 < Row gutter = { 8 } >
317348 < div style = { { padding : '15px 10px 5px' , fontWeight : '600' } } >
318349 Data:
319350 </ div >
320- { getFieldDecorator ( 'value[data]' , {
321- rules : [
322- {
323- required : true ,
324- message : 'Please input table data' ,
325- type : 'json' ,
326- } ,
327- ] ,
328- } ) (
329- < div style = { { margin : '10px 0' } } >
330- < CodeMirror
331- value = { this . state . rules }
332- onChange = { this . onCodeMirrorChange }
333- options = { {
334- lineNumbers : true ,
335- matchBrackets : true ,
336- autoCloseBrackets : true ,
337- mode : 'application/ld+json' ,
338- lineWrapping : true ,
339- theme : 'monokai' ,
340- } }
341- />
342- </ div >
351+ { getFieldDecorator ( 'data_value' ) (
352+ < CodeMirror
353+ options = { {
354+ lineNumbers : true ,
355+ matchBrackets : true ,
356+ autoCloseBrackets : true ,
357+ mode : 'application/ld+json' ,
358+ lineWrapping : true ,
359+ theme : 'monokai' ,
360+ } }
361+ />
343362 ) }
344363 </ Row >
345364 </ div >
0 commit comments