Skip to content

Commit bbb90c9

Browse files
committed
feat: add a manual refresh schema button
1 parent 4c3e4f5 commit bbb90c9

4 files changed

Lines changed: 37 additions & 4 deletions

File tree

src/components/ConnectionSidebar.tsx

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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}

src/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"self": "Connection",
2929
"new": "Create Connection",
3030
"edit": "Edit Connection",
31+
"refresh-schema": "Refresh Schema",
3132
"select-database": "Select your database",
3233
"select-table": "Select your table",
3334
"select-schema": "Select your Schema",

src/locales/zh.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"self": "连接",
2929
"new": "创建连接",
3030
"edit": "编辑连接",
31+
"refresh-schema": "刷新 Schema",
3132
"select-database": "选择数据库",
3233
"select-table": "选择数据表",
3334
"select-schema": "选择 Schema",

src/store/connection.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { create } from "zustand";
44
import { persist } from "zustand/middleware";
55
import { Connection, Database, Engine, ResponseObject, Schema } from "@/types";
66
import { countTextTokens, generateUUID } from "@/utils";
7-
import { count } from "console";
87

98
interface ConnectionContext {
109
connection: Connection;

0 commit comments

Comments
 (0)