11import React , { memo , useState , useEffect } from 'react' ;
22import styles from './index.less' ;
33import classnames from 'classnames' ;
4- import { i18n , isEn } from '@/i18n' ;
4+ import { i18n } from '@/i18n' ;
55import { Form , Modal , Input , Select } from 'antd' ;
66import connectionService , { IDriverResponse } from '@/service/connection' ;
7- import { DatabaseTypeCode , ConnectionEnvType , databaseMap } from '@/constants' ;
87import UploadDriver from '@/components/UploadDriver' ;
98import LoadingGracile from '@/components/Loading/LoadingGracile' ;
109const { Option } = Select ;
@@ -19,10 +18,10 @@ enum DownloadStatus {
1918 Default ,
2019 Loading ,
2120 Error ,
22- Success
21+ Success ,
2322}
2423
25- export default memo < IProps > ( function Driver ( props ) {
24+ export default memo < IProps > ( ( props ) => {
2625 const { className, backfillData, onChange } = props ;
2726 const [ downloadStatus , setDownloadStatus ] = useState < DownloadStatus > ( DownloadStatus . Default ) ;
2827 const [ driverForm ] = Form . useForm ( ) ;
@@ -34,135 +33,146 @@ export default memo<IProps>(function Driver(props) {
3433 if ( backfillData ) {
3534 getDriverList ( ) ;
3635 }
37- } , [ backfillData ?. type ] )
36+ } , [ backfillData ?. type ] ) ;
3837
3938 useEffect ( ( ) => {
4039 if ( backfillData ) {
4140 const data = {
4241 jdbcDriverClass : backfillData ?. driverConfig ?. jdbcDriverClass ,
43- jdbcDriver : backfillData ?. driverConfig ?. jdbcDriver
44- }
45- driverForm . setFieldsValue ( data )
42+ jdbcDriver : backfillData ?. driverConfig ?. jdbcDriver ,
43+ } ;
44+ driverForm . setFieldsValue ( data ) ;
4645 onChange ( data ) ;
4746 }
48-
49- } , [ backfillData ?. driverConfig , backfillData ?. id ] )
47+ } , [ backfillData ?. driverConfig , backfillData ?. id ] ) ;
5048
5149 function getDriverList ( ) {
52- connectionService . getDriverList ( { dbType : backfillData . type } ) . then ( res => {
50+ connectionService . getDriverList ( { dbType : backfillData . type } ) . then ( ( res ) => {
5351 if ( ! res ) {
54- return
52+ return ;
5553 }
5654 setDriverObj ( {
5755 ...res ,
58- driverConfigList : res . driverConfigList || [ ]
56+ driverConfigList : res . driverConfigList || [ ] ,
5957 } ) ;
6058 if ( res . driverConfigList ?. length && ! backfillData ?. driverConfig ?. jdbcDriver ) {
6159 const data = {
6260 jdbcDriverClass : res . driverConfigList [ 0 ] ?. jdbcDriverClass ,
63- jdbcDriver : res . driverConfigList [ 0 ] ?. jdbcDriver
64- }
61+ jdbcDriver : res . driverConfigList [ 0 ] ?. jdbcDriver ,
62+ } ;
6563 driverForm . setFieldsValue ( data ) ;
6664 onChange ( data ) ;
6765 }
68- } )
66+ } ) ;
6967 }
7068
7169 function formChange ( data : any ) {
7270 setDriverSaved ( data ) ;
7371 }
7472
7573 function saveDriver ( ) {
76- connectionService . saveDriver ( driverSaved ) . then ( res => {
74+ connectionService . saveDriver ( driverSaved ) . then ( ( ) => {
7775 setUploadDriverModal ( false ) ;
7876 getDriverList ( ) ;
79- } )
77+ } ) ;
8078 }
8179
8280 function downloadDrive ( ) {
8381 setDownloadStatus ( DownloadStatus . Loading ) ;
84- connectionService . downloadDriver ( { dbType : backfillData . type } ) . then ( res => {
85- setDownloadStatus ( DownloadStatus . Success ) ;
86- getDriverList ( ) ;
87- } ) . catch ( ( ) => {
88- setDownloadStatus ( DownloadStatus . Error )
89- } )
82+ connectionService
83+ . downloadDriver ( { dbType : backfillData . type } )
84+ . then ( ( ) => {
85+ setDownloadStatus ( DownloadStatus . Success ) ;
86+ getDriverList ( ) ;
87+ } )
88+ . catch ( ( ) => {
89+ setDownloadStatus ( DownloadStatus . Error ) ;
90+ } ) ;
9091 }
9192
9293 function onValuesChange ( data : any ) {
93- const selected = driverObj ?. driverConfigList . find ( t => t . jdbcDriver === data . jdbcDriver ) ;
94+ const selected = driverObj ?. driverConfigList . find ( ( t ) => t . jdbcDriver === data . jdbcDriver ) ;
9495 driverForm . setFieldsValue ( {
95- jdbcDriverClass : selected ?. jdbcDriverClass
96+ jdbcDriverClass : selected ?. jdbcDriverClass ,
9697 } ) ;
9798 onChange ( {
9899 jdbcDriverClass : selected ?. jdbcDriverClass ,
99- jdbcDriver : data . jdbcDriver
100- } )
100+ jdbcDriver : data . jdbcDriver ,
101+ } ) ;
101102 }
102103
103- return < div className = { classnames ( styles . box , className ) } >
104- < Form
105- form = { driverForm }
106- onValuesChange = { onValuesChange }
107- colon = { false }
108- >
109- < Form . Item labelAlign = "left" name = "jdbcDriver" label = { i18n ( 'connection.title.driver' ) } >
110- < Select >
111- { driverObj ?. driverConfigList ?. map ( ( t ) => (
112- < Option key = { t . jdbcDriver } value = { t . jdbcDriver } >
113- { t . jdbcDriver }
114- </ Option >
115- ) ) }
116- </ Select >
117- </ Form . Item >
118- < Form . Item labelAlign = "left" name = "jdbcDriverClass" label = "Class" >
119- < Input disabled />
120- </ Form . Item >
121- </ Form >
122- < div className = { styles . downloadDriveFooter } >
123- {
124- ( ( driverObj ?. driverConfigList && ! driverObj ?. driverConfigList ?. length ) || downloadStatus === DownloadStatus . Success ) ? < div onClick = { downloadDrive } className = { styles . downloadDrive } >
125- {
126- ( downloadStatus === DownloadStatus . Default ) && < div className = { classnames ( styles . downloadText , styles . downloadTextDownload ) } > { i18n ( 'connection.text.downloadDriver' ) } </ div >
127- }
128- {
129- ( downloadStatus === DownloadStatus . Loading ) &&
130- < div className = { classnames ( styles . downloadText , styles . downloadTextLoading ) } >
131- < LoadingGracile > </ LoadingGracile >
132- < div className = { styles . text } >
133- { i18n ( 'connection.text.downloading' ) }
104+ return (
105+ < div className = { classnames ( styles . box , className ) } >
106+ < Form form = { driverForm } onValuesChange = { onValuesChange } colon = { false } >
107+ < Form . Item labelAlign = "left" name = "jdbcDriver" label = { i18n ( 'connection.title.driver' ) } >
108+ < Select >
109+ { driverObj ?. driverConfigList ?. map ( ( t ) => (
110+ < Option key = { t . jdbcDriver } value = { t . jdbcDriver } >
111+ { t . jdbcDriver }
112+ </ Option >
113+ ) ) }
114+ </ Select >
115+ </ Form . Item >
116+ < Form . Item labelAlign = "left" name = "jdbcDriverClass" label = "Class" >
117+ < Input disabled />
118+ </ Form . Item >
119+ </ Form >
120+ < div className = { styles . downloadDriveFooter } >
121+ { ( driverObj ?. driverConfigList && ! driverObj ?. driverConfigList ?. length ) ||
122+ downloadStatus === DownloadStatus . Success ? (
123+ < div onClick = { downloadDrive } className = { styles . downloadDrive } >
124+ { downloadStatus === DownloadStatus . Default && (
125+ < div className = { classnames ( styles . downloadText , styles . downloadTextDownload ) } >
126+ { i18n ( 'connection.text.downloadDriver' ) }
134127 </ div >
135- </ div >
136- }
137- {
138- ( downloadStatus === DownloadStatus . Error ) && < div className = { classnames ( styles . downloadText , styles . downloadTextError ) } > { i18n ( 'connection.text.tryAgainDownload' ) } </ div >
139- }
140- {
141- ( downloadStatus === DownloadStatus . Success ) && < div className = { classnames ( styles . downloadText , styles . downloadTextSuccess ) } > { i18n ( 'connection.text.downloadSuccess' ) } </ div >
142- }
143-
144- </ div > : < div />
145- }
128+ ) }
129+ { downloadStatus === DownloadStatus . Loading && (
130+ < div className = { classnames ( styles . downloadText , styles . downloadTextLoading ) } >
131+ < LoadingGracile />
132+ < div className = { styles . text } > { i18n ( 'connection.text.downloading' ) } </ div >
133+ </ div >
134+ ) }
135+ { downloadStatus === DownloadStatus . Error && (
136+ < div className = { classnames ( styles . downloadText , styles . downloadTextError ) } >
137+ { i18n ( 'connection.text.tryAgainDownload' ) }
138+ </ div >
139+ ) }
140+ { downloadStatus === DownloadStatus . Success && (
141+ < div className = { classnames ( styles . downloadText , styles . downloadTextSuccess ) } >
142+ { i18n ( 'connection.text.downloadSuccess' ) }
143+ </ div >
144+ ) }
145+ </ div >
146+ ) : (
147+ < div />
148+ ) }
146149
147- < div
148- className = { styles . uploadCustomDrive }
149- onClick = { ( ) => { setUploadDriverModal ( true ) } }
150- >
151- { i18n ( 'connection.tips.customUpload' ) }
150+ < div
151+ className = { styles . uploadCustomDrive }
152+ onClick = { ( ) => {
153+ setUploadDriverModal ( true ) ;
154+ } }
155+ >
156+ { i18n ( 'connection.tips.customUpload' ) }
157+ </ div >
152158 </ div >
159+ < Modal
160+ destroyOnClose = { true }
161+ title = { i18n ( 'connection.title.uploadDriver' ) }
162+ open = { uploadDriverModal }
163+ onOk = { ( ) => {
164+ saveDriver ( ) ;
165+ } }
166+ onCancel = { ( ) => {
167+ setUploadDriverModal ( false ) ;
168+ } }
169+ >
170+ < UploadDriver
171+ jdbcDriverClass = { driverObj ?. defaultDriverConfig ?. jdbcDriverClass }
172+ formChange = { formChange }
173+ databaseType = { backfillData . type }
174+ />
175+ </ Modal >
153176 </ div >
154- < Modal
155- destroyOnClose = { true }
156- title = { i18n ( 'connection.title.uploadDriver' ) }
157- open = { uploadDriverModal }
158- onOk = { ( ) => { saveDriver ( ) } }
159- onCancel = { ( ) => { setUploadDriverModal ( false ) } }
160- >
161- < UploadDriver
162- jdbcDriverClass = { driverObj ?. defaultDriverConfig ?. jdbcDriverClass }
163- formChange = { formChange }
164- databaseType = { backfillData . type }
165- > </ UploadDriver >
166- </ Modal >
167- </ div >
168- } )
177+ ) ;
178+ } ) ;
0 commit comments