diff --git a/src/components/ConnectionSidebar.tsx b/src/components/ConnectionSidebar.tsx
index 15cd3c9..f47d0e5 100644
--- a/src/components/ConnectionSidebar.tsx
+++ b/src/components/ConnectionSidebar.tsx
@@ -12,6 +12,7 @@ import QuotaView from "./QuotaView";
import { countTextTokens, getModel, hasFeature } from "../utils";
import SettingAvatarIcon from "./SettingAvatarIcon";
import Checkbox from "./kit/Checkbox";
+import { head } from "lodash-es";
interface State {}
@@ -26,7 +27,6 @@ const ConnectionSidebar = () => {
const databaseList = connectionStore.databaseList.filter((database) => database.connectionId === currentConnectionCtx?.connection.id);
const [tableList, updateTableList] = useState
([]);
const [schemaList, updateSchemaList] = useState([]);
- const [hasSchemaProperty, updateHasSchemaProperty] = useState(false);
const selectedTablesName: string[] =
conversationStore.getConversationById(conversationStore.currentConversationId)?.selectedTablesName || [];
const selectedSchemaName: string =
@@ -35,17 +35,8 @@ const ConnectionSidebar = () => {
const currentConversation = conversationStore.getConversationById(conversationStore.currentConversationId);
const maxToken = getModel(settingStore.setting.openAIApiConfig?.model || "").max_token;
const [totalToken, setTotalToken] = useState(0);
- useEffect(() => {
- updateHasSchemaProperty(
- currentConnectionCtx?.connection.engineType === Engine.PostgreSQL || currentConnectionCtx?.connection.engineType === Engine.MSSQL
- );
- }, [currentConnectionCtx?.connection]);
-
- useEffect(() => {
- updateHasSchemaProperty(
- currentConnectionCtx?.connection.engineType === Engine.PostgreSQL || currentConnectionCtx?.connection.engineType === Engine.MSSQL
- );
- }, [currentConnectionCtx?.connection]);
+ const hasSchemaProperty: boolean =
+ currentConnectionCtx?.connection.engineType === Engine.PostgreSQL || currentConnectionCtx?.connection.engineType === Engine.MSSQL;
useEffect(() => {
const handleWindowResize = () => {
@@ -106,11 +97,6 @@ const ConnectionSidebar = () => {
updateSchemaList(schemaList);
// need to create a conversation. otherwise updateSelectedSchemaName will failed.
createConversation();
- if (hasSchemaProperty) {
- conversationStore.updateSelectedSchemaName(schemaList[0]?.name || "");
- } else {
- conversationStore.updateSelectedSchemaName("");
- }
}, [connectionStore, hasSchemaProperty, currentConnectionCtx]);
useEffect(() => {
@@ -118,6 +104,12 @@ const ConnectionSidebar = () => {
updateTableList(tableList);
}, [selectedSchemaName, schemaList]);
+ useEffect(() => {
+ if (hasSchemaProperty && selectedSchemaName === "") {
+ conversationStore.updateSelectedSchemaName(head(schemaList)?.name || "");
+ }
+ }, [schemaList, currentConversation]);
+
const handleDatabaseNameSelect = async (databaseName: string) => {
if (!currentConnectionCtx?.connection) {
return;