@@ -34,7 +34,7 @@ import Header from "../../components/Headers/Header.jsx";
34
34
35
35
import { getServerConfig } from '../../utils/getConfig'
36
36
37
- import { Input , Row , Col , Affix , Descriptions , Modal , Icon , message , Popover , Progress , Menu , Dropdown , Radio , Tabs , Table } from 'antd' ;
37
+ import { Input , Row , Col , Affix , Descriptions , Modal , Icon , message , Popover , Progress , Menu , Dropdown , Radio , Tabs , Table , Collapse } from 'antd' ;
38
38
39
39
import axios from 'axios' ;
40
40
import TestCaseEditor from './TestCaseEditor'
@@ -204,7 +204,7 @@ class OutboundRequest extends React.Component {
204
204
loadSampleDialogVisible : false ,
205
205
loadSampleFiles : { } ,
206
206
loadSampleChecked : { } ,
207
- loadSampleTypes : [ 'hub' , 'dfsp' , 'provisioning' ]
207
+ loadSampleCollectionTypes : [ 'hub' , 'dfsp' , 'provisioning' ]
208
208
} ;
209
209
}
210
210
@@ -223,14 +223,20 @@ class OutboundRequest extends React.Component {
223
223
this . collectionFileSelector = buildFileSelector ( true ) ;
224
224
this . environmentFileSelector = buildFileSelector ( ) ;
225
225
this . collectionFileSelector . addEventListener ( 'input' , ( e ) => {
226
- if ( e . target . files . length == 1 ) {
227
- this . handleImportCollectionFile ( e . target . files [ 0 ] )
228
- } else if ( e . target . files . length > 1 ) {
229
- this . handleImportCollectionFileMulti ( e . target . files )
226
+ if ( e . target . files ) {
227
+ if ( e . target . files . length == 1 ) {
228
+ this . handleImportCollectionFile ( e . target . files [ 0 ] )
229
+ } else if ( e . target . files . length > 1 ) {
230
+ this . handleImportCollectionFileMulti ( e . target . files )
231
+ }
232
+ this . collectionFileSelector . value = null
230
233
}
231
234
} )
232
235
this . environmentFileSelector . addEventListener ( 'input' , ( e ) => {
233
- this . handleImportEnvironmentFile ( e . target . files [ 0 ] )
236
+ if ( e . target . files ) {
237
+ this . handleImportEnvironmentFile ( e . target . files [ 0 ] )
238
+ this . environmentFileSelector . value = null
239
+ }
234
240
} )
235
241
236
242
// const sampleTemplate = require('./sample1.json')
@@ -653,7 +659,7 @@ class OutboundRequest extends React.Component {
653
659
this . state . loadSampleChecked . environment = null
654
660
}
655
661
const { apiBaseUrl } = getConfig ( )
656
- const resp = await axios . get ( apiBaseUrl + '/api/outbound/ samples/data ' , {
662
+ const resp = await axios . get ( apiBaseUrl + '/api/samples/load ' , {
657
663
params : this . state . loadSampleChecked
658
664
} )
659
665
if ( resp . data . body . name ) {
@@ -676,36 +682,57 @@ class OutboundRequest extends React.Component {
676
682
677
683
loadSampleContent = async ( ) => {
678
684
const { apiBaseUrl } = getConfig ( )
679
- for ( const index in this . state . loadSampleTypes ) {
680
- const type = this . state . loadSampleTypes [ index ]
681
- if ( ! this . state . loadSampleFiles [ type ] ) {
682
- const resp = await axios . get ( apiBaseUrl + `/api/outbound/samples?type=${ type } ` )
683
- this . state . loadSampleFiles [ type ] = resp . data . body
684
- this . state . loadSampleFiles [ type ] . environments . push ( 'none' )
685
+ if ( ! this . state . loadSampleCollections ) {
686
+ this . state . loadSampleCollections = { }
687
+ for ( const index in this . state . loadSampleCollectionTypes ) {
688
+ const resp = await axios . get ( apiBaseUrl + `/api/samples/load/collections?type=${ this . state . loadSampleCollectionTypes [ index ] } ` )
689
+ this . state . loadSampleCollections [ this . state . loadSampleCollectionTypes [ index ] ] = resp . data . body
685
690
}
686
691
}
692
+ if ( ! this . state . loadSampleEnvironments ) {
693
+ const resp = await axios . get ( apiBaseUrl + `/api/samples/load/environments` )
694
+ resp . data . body . push ( 'none' )
695
+ this . state . loadSampleEnvironments = resp . data . body
696
+ }
687
697
}
688
698
689
699
loadSampleCollections = ( type ) => {
690
700
const collections = [ ]
691
- if ( this . state . loadSampleFiles [ type ] ) {
692
- for ( const i in this . state . loadSampleFiles [ type ] . collections ) {
693
- collections . push ( { key : i , collection : this . state . loadSampleFiles [ type ] . collections [ i ] } )
701
+ if ( this . state . loadSampleCollections && this . state . loadSampleCollections [ type ] ) {
702
+ for ( const i in this . state . loadSampleCollections [ type ] ) {
703
+ collections . push ( { key : i , collection : this . state . loadSampleCollections [ type ] [ i ] } )
694
704
}
695
705
}
696
706
return collections
697
707
}
698
708
699
- loadSampleEnvironments = ( type ) => {
709
+ loadSampleEnvironments = ( ) => {
700
710
const environments = [ ]
701
- if ( this . state . loadSampleFiles [ type ] ) {
702
- for ( const i in this . state . loadSampleFiles [ type ] . environments ) {
703
- environments . push ( { key : i , environment : this . state . loadSampleFiles [ type ] . environments [ i ] } )
711
+ if ( this . state . loadSampleEnvironments ) {
712
+ for ( const i in this . state . loadSampleEnvironments ) {
713
+ environments . push ( { key : i , environment : this . state . loadSampleEnvironments [ i ] } )
704
714
}
705
715
}
706
716
return environments
707
717
}
708
718
719
+ loadSampleCollectionsTabContent = ( ) => {
720
+ return this . state . loadSampleCollectionTypes . map ( type => {
721
+ return (
722
+ < Tabs . TabPane tab = { type } key = { type } >
723
+ < Table
724
+ rowSelection = { { type : 'checkbox' , selectedRowKeys : this . state . selectedCollections , onChange : ( selectedRowKeys , selectedRows ) => {
725
+ this . setState ( { selectedCollections : selectedRowKeys } )
726
+ this . state . loadSampleChecked . collections = selectedRows . map ( selectedRow => { return selectedRow . collection } )
727
+ } } }
728
+ columns = { [ { title : 'Select all' , dataIndex : 'collection' , render : text => < a > { text } </ a > } ] }
729
+ dataSource = { this . loadSampleCollections ( type ) }
730
+ />
731
+ </ Tabs . TabPane >
732
+ )
733
+ } )
734
+ }
735
+
709
736
clearSampleSelectionState = ( ) => {
710
737
this . setState ( { selectedCollections : [ ] } )
711
738
this . setState ( { selectedEnvironments : [ ] } )
@@ -910,6 +937,7 @@ class OutboundRequest extends React.Component {
910
937
< Row >
911
938
< Col span = { 8 } >
912
939
< Button color = "primary" size = "sm" onClick = { async ( e ) => {
940
+
913
941
await this . loadSampleContent ( )
914
942
this . setState ( { loadSampleDialogVisible : true } )
915
943
} } >
@@ -918,7 +946,7 @@ class OutboundRequest extends React.Component {
918
946
< Modal
919
947
title = "Loaded Samples"
920
948
visible = { this . state . loadSampleDialogVisible }
921
- width = '90 %'
949
+ width = '50 %'
922
950
onOk = { async ( ) => {
923
951
await this . handleLoadSample ( )
924
952
this . clearSampleSelectionState ( )
@@ -929,11 +957,25 @@ class OutboundRequest extends React.Component {
929
957
this . setState ( { loadSampleDialogVisible : false } )
930
958
} }
931
959
>
932
- < Tabs defaultActiveKey = { this . state . loadSampleTypes [ 0 ] } onChange = { ( ) => {
933
- this . clearSampleSelectionState ( )
934
- } } >
935
- { this . loadSampleTabContent ( ) }
936
- </ Tabs >
960
+ < Collapse defaultActiveKey = { [ '1' ] } >
961
+ < Collapse . Panel header = "Collections" key = "1" >
962
+ < Tabs defaultActiveKey = { this . state . loadSampleCollectionTypes [ 0 ] } onChange = { ( ) => {
963
+ this . setState ( { selectedCollections : [ ] } )
964
+ } } >
965
+ { this . loadSampleCollectionsTabContent ( ) }
966
+ </ Tabs >
967
+ </ Collapse . Panel >
968
+ < Collapse . Panel header = "Environments" key = "2" >
969
+ < Table
970
+ rowSelection = { { type : 'radio' , disabled : true , selectedRowKeys : this . state . selectedEnvironments , onChange : ( selectedRowKeys , selectedRows ) => {
971
+ this . setState ( { selectedEnvironments : selectedRowKeys } )
972
+ this . state . loadSampleChecked . environment = selectedRows [ 0 ] . environment
973
+ } } }
974
+ columns = { [ { dataIndex : 'environment' , render : text => < a > { text } </ a > } ] }
975
+ dataSource = { this . loadSampleEnvironments ( ) }
976
+ />
977
+ </ Collapse . Panel >
978
+ </ Collapse >
937
979
</ Modal >
938
980
< Button
939
981
color = "success"
0 commit comments