From bbb90c949a6e3aad99d2787e8a5ee1469d9c39b8 Mon Sep 17 00:00:00 2001 From: Tianzhou Chen Date: Fri, 9 Jun 2023 08:58:45 +0800 Subject: [PATCH] feat: add a manual refresh schema button --- src/components/ConnectionSidebar.tsx | 38 +++++++++++++++++++++++++--- src/locales/en.json | 1 + src/locales/zh.json | 1 + src/store/connection.ts | 1 - 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/components/ConnectionSidebar.tsx b/src/components/ConnectionSidebar.tsx index 4db1464..301d8a8 100644 --- a/src/components/ConnectionSidebar.tsx +++ b/src/components/ConnectionSidebar.tsx @@ -124,6 +124,28 @@ const ConnectionSidebar = () => { } }, [schemaList, currentConversation]); + const syncDatabaseList = async () => { + if (!currentConnectionCtx?.connection) { + return; + } + + const prevDatabase = currentConnectionCtx.database; + const databaseList = await connectionStore.getOrFetchDatabaseList(currentConnectionCtx.connection, true); + + // Retain the existing database if it exists in the new database list. + const database = databaseList.find((database) => database.name === prevDatabase?.name); + connectionStore.setCurrentConnectionCtx({ + connection: currentConnectionCtx.connection, + database: database ? database : head(databaseList), + }); + if (database) { + tableSchemaLoadingState.setLoading(); + connectionStore.getOrFetchDatabaseSchema(database).then(() => { + tableSchemaLoadingState.setFinish(); + }); + } + }; + const handleDatabaseNameSelect = async (databaseName: string) => { if (!currentConnectionCtx?.connection) { return; @@ -192,13 +214,23 @@ const ConnectionSidebar = () => {
- {isRequestingDatabase && ( -
+ {isRequestingDatabase ? ( +
{t("common.loading")}
+ ) : ( + currentConnectionCtx && ( + + ) )} {databaseList.length > 0 && ( -
+