11import React , { useEffect , useMemo , useRef , useState } from 'react' ;
22import { Button , Input , Table , Popconfirm , message , Drawer } from 'antd' ;
33import { SearchOutlined , PlusOutlined } from '@ant-design/icons' ;
4- import ConnectionServer from '@/service/connection'
4+ import ConnectionServer from '@/service/connection' ;
55import { createDataSource , deleteDataSource , getDataSourceList , updateDataSource } from '@/service/team' ;
66import { IConnectionDetails } from '@/typings' ;
77import { AffiliationType , IDataSourceVO } from '@/typings/team' ;
@@ -23,13 +23,13 @@ function DataSourceManagement() {
2323 showQuickJumper : true ,
2424 // pageSizeOptions: ['10', '20', '30', '40'],
2525 } ) ;
26- const [ showCreateConnection , setShowCreateConnection ] = useState ( false )
26+ const [ showCreateConnection , setShowCreateConnection ] = useState ( false ) ;
2727 const connectionInfo = useRef < IConnectionDetails > ( ) ;
2828
2929 const [ drawerInfo , setDrawerInfo ] = useState < { open : boolean ; type : AffiliationType ; id ?: number } > ( {
3030 open : false ,
31- type : AffiliationType [ 'DATASOURCE_USER/TEAM' ]
32- } )
31+ type : AffiliationType [ 'DATASOURCE_USER/TEAM' ] ,
32+ } ) ;
3333
3434 const columns = useMemo (
3535 ( ) => [
@@ -49,18 +49,24 @@ function DataSourceManagement() {
4949 width : 300 ,
5050 render : ( _ : any , record : IDataSourceVO ) => (
5151 < >
52- < Button type = 'link' onClick = { ( ) => {
53- handleEdit ( record )
54- } } >
52+ < Button
53+ type = "link"
54+ onClick = { ( ) => {
55+ handleEdit ( record ) ;
56+ } }
57+ >
5558 { i18n ( 'common.button.edit' ) }
5659 </ Button >
57- < Button type = 'link' onClick = { ( ) => {
58- setDrawerInfo ( {
59- ...drawerInfo ,
60- open : true ,
61- id : record . id ,
62- } )
63- } } >
60+ < Button
61+ type = "link"
62+ onClick = { ( ) => {
63+ setDrawerInfo ( {
64+ ...drawerInfo ,
65+ open : true ,
66+ id : record . id ,
67+ } ) ;
68+ } }
69+ >
6470 { i18n ( 'team.action.rightManagement' ) }
6571 </ Button >
6672 < Popconfirm
@@ -89,6 +95,10 @@ function DataSourceManagement() {
8995 let res = await getDataSourceList ( { searchKey, pageNo, pageSize } ) ;
9096 if ( res ) {
9197 setDataSource ( res ?. data ?? [ ] ) ;
98+ setPagination ( {
99+ ...pagination ,
100+ total : res ?. total ?? 0 ,
101+ } as any ) ;
92102 }
93103 } ;
94104
@@ -100,7 +110,6 @@ function DataSourceManagement() {
100110 } ;
101111
102112 const handleTableChange = ( p : any ) => {
103-
104113 setPagination ( {
105114 ...pagination ,
106115 ...p ,
@@ -110,22 +119,22 @@ function DataSourceManagement() {
110119 const handleAddDataSource = ( ) => {
111120 connectionInfo . current = undefined ;
112121 setShowCreateConnection ( true ) ;
113- }
122+ } ;
114123
115124 const handleEdit = async ( record : IDataSourceVO ) => {
116125 const { id } = record ;
117126 if ( ! id ) {
118127 return ;
119128 }
120129
121- let detail = await ConnectionServer . getDetails ( { id } )
130+ let detail = await ConnectionServer . getDetails ( { id } ) ;
122131 connectionInfo . current = detail ;
123- setShowCreateConnection ( true )
124- }
132+ setShowCreateConnection ( true ) ;
133+ } ;
125134
126135 const handleDelete = async ( id ?: number ) => {
127136 if ( isNumber ( id ) ) {
128- await deleteDataSource ( { id } )
137+ await deleteDataSource ( { id } ) ;
129138 message . success ( i18n ( 'common.text.successfullyDelete' ) ) ;
130139 queryDataSourceList ( ) ;
131140 }
@@ -140,14 +149,12 @@ function DataSourceManagement() {
140149 const isUpdate = isValid ( connectionInfo ?. current ?. id ) ;
141150 const requestApi = isUpdate ? updateDataSource : createDataSource ;
142151 try {
143- await requestApi ( { ...connectionInfo . current } )
144- message . success ( isUpdate ? i18n ( 'common.tips.updateSuccess' ) : i18n ( 'common.tips.createSuccess' ) )
145- setShowCreateConnection ( false )
146- queryDataSourceList ( )
147- } catch {
148-
149- }
150- }
152+ await requestApi ( { ...connectionInfo . current } ) ;
153+ message . success ( isUpdate ? i18n ( 'common.tips.updateSuccess' ) : i18n ( 'common.tips.createSuccess' ) ) ;
154+ setShowCreateConnection ( false ) ;
155+ queryDataSourceList ( ) ;
156+ } catch { }
157+ } ;
151158
152159 return (
153160 < div >
@@ -163,6 +170,11 @@ function DataSourceManagement() {
163170 </ Button >
164171 </ div >
165172 < Table
173+ style = { {
174+ maxHeight : '82vh' ,
175+ overflow : 'auto' ,
176+ } }
177+ sticky
166178 rowKey = { 'id' }
167179 dataSource = { dataSource }
168180 columns = { columns }
@@ -185,11 +197,11 @@ function DataSourceManagement() {
185197 onClose = { ( ) => {
186198 setDrawerInfo ( {
187199 ...drawerInfo ,
188- open : false
189- } )
200+ open : false ,
201+ } ) ;
190202 } }
191203 />
192- </ div >
204+ </ div >
193205 ) ;
194206}
195207
0 commit comments