@@ -124,6 +124,28 @@ const ConnectionSidebar = () => {
124124 }
125125 } , [ schemaList , currentConversation ] ) ;
126126
127+ const syncDatabaseList = async ( ) => {
128+ if ( ! currentConnectionCtx ?. connection ) {
129+ return ;
130+ }
131+
132+ const prevDatabase = currentConnectionCtx . database ;
133+ const databaseList = await connectionStore . getOrFetchDatabaseList ( currentConnectionCtx . connection , true ) ;
134+
135+ // Retain the existing database if it exists in the new database list.
136+ const database = databaseList . find ( ( database ) => database . name === prevDatabase ?. name ) ;
137+ connectionStore . setCurrentConnectionCtx ( {
138+ connection : currentConnectionCtx . connection ,
139+ database : database ? database : head ( databaseList ) ,
140+ } ) ;
141+ if ( database ) {
142+ tableSchemaLoadingState . setLoading ( ) ;
143+ connectionStore . getOrFetchDatabaseSchema ( database ) . then ( ( ) => {
144+ tableSchemaLoadingState . setFinish ( ) ;
145+ } ) ;
146+ }
147+ } ;
148+
127149 const handleDatabaseNameSelect = async ( databaseName : string ) => {
128150 if ( ! currentConnectionCtx ?. connection ) {
129151 return ;
@@ -192,13 +214,23 @@ const ConnectionSidebar = () => {
192214 < div className = "relative p-4 pb-0 w-64 h-full overflow-y-auto flex flex-col justify-start items-start bg-gray-100 dark:bg-zinc-700" >
193215 < img className = "px-4 shrink-0" src = "/chat-logo.webp" alt = "" />
194216 < div className = "w-full grow" >
195- { isRequestingDatabase && (
196- < div className = "w-full h-12 flex flex-row justify-start items-center px-4 sticky top-0 border z-1 mb-4 mt-2 rounded-lg text-sm text-gray-600 dark:text-gray-400" >
217+ { isRequestingDatabase ? (
218+ < div className = "w-full h-12 flex flex-row justify-start items-center px-4 sticky top-0 border z-1 mb-4 mt-4 rounded-lg text-sm text-gray-600 dark:text-gray-400" >
197219 < Icon . BiLoaderAlt className = "w-4 h-auto animate-spin mr-1" /> { t ( "common.loading" ) }
198220 </ div >
221+ ) : (
222+ currentConnectionCtx && (
223+ < button
224+ onClick = { ( ) => syncDatabaseList ( ) }
225+ className = "flex space-x-1 items-center justify-center mb-4 mt-4 w-full px-2 py-1 border rounded-lg dark:text-gray-300 bg-white dark:bg-zinc-700 hover:bg-gray-100 dark:hover:bg-zinc-800"
226+ >
227+ < Icon . BiRefresh className = "h-6 w-auto" />
228+ < span > { t ( "connection.refresh-schema" ) } </ span >
229+ </ button >
230+ )
199231 ) }
200232 { databaseList . length > 0 && (
201- < div className = "w-full sticky top-0 z-1 mt-4 " >
233+ < div className = "w-full sticky top-0 z-1" >
202234 < Select
203235 className = "w-full px-4 py-3 !text-base"
204236 value = { currentConnectionCtx ?. database ?. name }
0 commit comments