@@ -29,20 +29,10 @@ interface IProps {
2929function Connections ( props : IProps ) {
3030 const { connectionModel, workspaceModel, dispatch } = props ;
3131 const { connectionList } = connectionModel ;
32+ const { curWorkspaceParams } = workspaceModel ;
3233 const volatileRef = useRef < any > ( ) ;
33- // const [connectionList, setConnectionList] = useState<IConnectionDetails[]>();
3434 const [ curConnection , setCurConnection ] = useState < Partial < IConnectionDetails > > ( { } ) ;
3535
36- useEffect ( ( ) => {
37- getConnectionList ( ) ;
38- } , [ ] ) ;
39-
40- const getConnectionList = ( ) => {
41- dispatch ( {
42- type : 'connection/fetchConnectionList' ,
43- } ) ;
44- } ;
45-
4636 function handleCreateConnections ( database : IDatabase ) {
4737 setCurConnection ( {
4838 type : database . code ,
@@ -100,25 +90,42 @@ function Connections(props: IProps) {
10090 {
10191 key : 'EnterWorkSpace' ,
10292 label : i18n ( 'connection.button.connect' ) ,
103- onClick : ( ) => {
93+ onClick : ( { domEvent } ) => {
94+ domEvent . stopPropagation ( ) ;
10495 handleMenuItemDoubleClick ( t ) ;
10596 } ,
10697 } ,
10798 {
10899 key : 'Delete' ,
109100 label : i18n ( 'common.button.delete' ) ,
110- onClick : async ( { domEvent } ) => {
101+ onClick : ( { domEvent } ) => {
111102 // 禁止冒泡到menuItem
112103 domEvent . stopPropagation ( ) ;
113- await connectionService . remove ( { id : key } ) ;
114- setCurConnection ( { } ) ;
115- getConnectionList ( ) ;
104+ connectionService . remove ( { id : key } ) . then ( ( ) => {
105+ if ( curConnection . id === key ) {
106+ setCurConnection ( { } ) ;
107+ }
108+ // // 如果当前工作区正好选中了这个连接,那么就把当前工作区的记录清空
109+ // if (curWorkspaceParams.dataSourceId === key) {
110+ // dispatch({
111+ // type: 'workspace/setCurWorkspaceParams',
112+ // payload: {}
113+ // })
114+ // dispatch({
115+ // type: 'connection/setCurConnection',
116+ // payload: {}
117+ // })
118+ // }
119+ dispatch ( {
120+ type : 'connection/fetchConnectionList' ,
121+ } ) ;
122+ } )
116123 } ,
117124 } ,
118125 ] ,
119126 } }
120127 >
121- < div className = { styles . moreButton } >
128+ < div className = { styles . moreButton } onClick = { ( e ) => { e . stopPropagation ( ) } } >
122129 < Iconfont code = "" > </ Iconfont >
123130 </ div >
124131 </ Dropdown >
@@ -161,7 +168,14 @@ function Connections(props: IProps) {
161168 closeCreateConnection = { ( ) => {
162169 setCurConnection ( { } ) ;
163170 } }
164- submitCallback = { getConnectionList }
171+ submitCallback = { ( ) => {
172+ dispatch ( {
173+ type : 'connection/fetchConnectionList' ,
174+ callback : ( res : any ) => {
175+ setCurConnection ( res . data [ res . data ?. length - 1 ] ) ;
176+ }
177+ } ) ;
178+ } }
165179 />
166180 }
167181 </ div >
0 commit comments