mirror of
https://github.com/sqlchat/sqlchat.git
synced 2025-09-28 18:43:53 +08:00
feat: add a manual refresh schema button
This commit is contained in:
@ -124,6 +124,28 @@ const ConnectionSidebar = () => {
|
|||||||
}
|
}
|
||||||
}, [schemaList, currentConversation]);
|
}, [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) => {
|
const handleDatabaseNameSelect = async (databaseName: string) => {
|
||||||
if (!currentConnectionCtx?.connection) {
|
if (!currentConnectionCtx?.connection) {
|
||||||
return;
|
return;
|
||||||
@ -192,13 +214,23 @@ const ConnectionSidebar = () => {
|
|||||||
<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">
|
<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">
|
||||||
<img className="px-4 shrink-0" src="/chat-logo.webp" alt="" />
|
<img className="px-4 shrink-0" src="/chat-logo.webp" alt="" />
|
||||||
<div className="w-full grow">
|
<div className="w-full grow">
|
||||||
{isRequestingDatabase && (
|
{isRequestingDatabase ? (
|
||||||
<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">
|
<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">
|
||||||
<Icon.BiLoaderAlt className="w-4 h-auto animate-spin mr-1" /> {t("common.loading")}
|
<Icon.BiLoaderAlt className="w-4 h-auto animate-spin mr-1" /> {t("common.loading")}
|
||||||
</div>
|
</div>
|
||||||
|
) : (
|
||||||
|
currentConnectionCtx && (
|
||||||
|
<button
|
||||||
|
onClick={() => syncDatabaseList()}
|
||||||
|
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"
|
||||||
|
>
|
||||||
|
<Icon.BiRefresh className="h-6 w-auto" />
|
||||||
|
<span>{t("connection.refresh-schema")}</span>
|
||||||
|
</button>
|
||||||
|
)
|
||||||
)}
|
)}
|
||||||
{databaseList.length > 0 && (
|
{databaseList.length > 0 && (
|
||||||
<div className="w-full sticky top-0 z-1 mt-4">
|
<div className="w-full sticky top-0 z-1">
|
||||||
<Select
|
<Select
|
||||||
className="w-full px-4 py-3 !text-base"
|
className="w-full px-4 py-3 !text-base"
|
||||||
value={currentConnectionCtx?.database?.name}
|
value={currentConnectionCtx?.database?.name}
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
"self": "Connection",
|
"self": "Connection",
|
||||||
"new": "Create Connection",
|
"new": "Create Connection",
|
||||||
"edit": "Edit Connection",
|
"edit": "Edit Connection",
|
||||||
|
"refresh-schema": "Refresh Schema",
|
||||||
"select-database": "Select your database",
|
"select-database": "Select your database",
|
||||||
"select-table": "Select your table",
|
"select-table": "Select your table",
|
||||||
"select-schema": "Select your Schema",
|
"select-schema": "Select your Schema",
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
"self": "连接",
|
"self": "连接",
|
||||||
"new": "创建连接",
|
"new": "创建连接",
|
||||||
"edit": "编辑连接",
|
"edit": "编辑连接",
|
||||||
|
"refresh-schema": "刷新 Schema",
|
||||||
"select-database": "选择数据库",
|
"select-database": "选择数据库",
|
||||||
"select-table": "选择数据表",
|
"select-table": "选择数据表",
|
||||||
"select-schema": "选择 Schema",
|
"select-schema": "选择 Schema",
|
||||||
|
@ -4,7 +4,6 @@ import { create } from "zustand";
|
|||||||
import { persist } from "zustand/middleware";
|
import { persist } from "zustand/middleware";
|
||||||
import { Connection, Database, Engine, ResponseObject, Schema } from "@/types";
|
import { Connection, Database, Engine, ResponseObject, Schema } from "@/types";
|
||||||
import { countTextTokens, generateUUID } from "@/utils";
|
import { countTextTokens, generateUUID } from "@/utils";
|
||||||
import { count } from "console";
|
|
||||||
|
|
||||||
interface ConnectionContext {
|
interface ConnectionContext {
|
||||||
connection: Connection;
|
connection: Connection;
|
||||||
|
Reference in New Issue
Block a user