mirror of
https://github.com/sqlchat/sqlchat.git
synced 2025-09-25 00:55:05 +08:00
fix: no select first schema when create a new conversation (#123)
This commit is contained in:
@ -12,6 +12,7 @@ import QuotaView from "./QuotaView";
|
|||||||
import { countTextTokens, getModel, hasFeature } from "../utils";
|
import { countTextTokens, getModel, hasFeature } from "../utils";
|
||||||
import SettingAvatarIcon from "./SettingAvatarIcon";
|
import SettingAvatarIcon from "./SettingAvatarIcon";
|
||||||
import Checkbox from "./kit/Checkbox";
|
import Checkbox from "./kit/Checkbox";
|
||||||
|
import { head } from "lodash-es";
|
||||||
|
|
||||||
interface State {}
|
interface State {}
|
||||||
|
|
||||||
@ -26,7 +27,6 @@ const ConnectionSidebar = () => {
|
|||||||
const databaseList = connectionStore.databaseList.filter((database) => database.connectionId === currentConnectionCtx?.connection.id);
|
const databaseList = connectionStore.databaseList.filter((database) => database.connectionId === currentConnectionCtx?.connection.id);
|
||||||
const [tableList, updateTableList] = useState<Table[]>([]);
|
const [tableList, updateTableList] = useState<Table[]>([]);
|
||||||
const [schemaList, updateSchemaList] = useState<Schema[]>([]);
|
const [schemaList, updateSchemaList] = useState<Schema[]>([]);
|
||||||
const [hasSchemaProperty, updateHasSchemaProperty] = useState<boolean>(false);
|
|
||||||
const selectedTablesName: string[] =
|
const selectedTablesName: string[] =
|
||||||
conversationStore.getConversationById(conversationStore.currentConversationId)?.selectedTablesName || [];
|
conversationStore.getConversationById(conversationStore.currentConversationId)?.selectedTablesName || [];
|
||||||
const selectedSchemaName: string =
|
const selectedSchemaName: string =
|
||||||
@ -35,17 +35,8 @@ const ConnectionSidebar = () => {
|
|||||||
const currentConversation = conversationStore.getConversationById(conversationStore.currentConversationId);
|
const currentConversation = conversationStore.getConversationById(conversationStore.currentConversationId);
|
||||||
const maxToken = getModel(settingStore.setting.openAIApiConfig?.model || "").max_token;
|
const maxToken = getModel(settingStore.setting.openAIApiConfig?.model || "").max_token;
|
||||||
const [totalToken, setTotalToken] = useState<number>(0);
|
const [totalToken, setTotalToken] = useState<number>(0);
|
||||||
useEffect(() => {
|
const hasSchemaProperty: boolean =
|
||||||
updateHasSchemaProperty(
|
currentConnectionCtx?.connection.engineType === Engine.PostgreSQL || currentConnectionCtx?.connection.engineType === Engine.MSSQL;
|
||||||
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]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleWindowResize = () => {
|
const handleWindowResize = () => {
|
||||||
@ -106,11 +97,6 @@ const ConnectionSidebar = () => {
|
|||||||
updateSchemaList(schemaList);
|
updateSchemaList(schemaList);
|
||||||
// need to create a conversation. otherwise updateSelectedSchemaName will failed.
|
// need to create a conversation. otherwise updateSelectedSchemaName will failed.
|
||||||
createConversation();
|
createConversation();
|
||||||
if (hasSchemaProperty) {
|
|
||||||
conversationStore.updateSelectedSchemaName(schemaList[0]?.name || "");
|
|
||||||
} else {
|
|
||||||
conversationStore.updateSelectedSchemaName("");
|
|
||||||
}
|
|
||||||
}, [connectionStore, hasSchemaProperty, currentConnectionCtx]);
|
}, [connectionStore, hasSchemaProperty, currentConnectionCtx]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -118,6 +104,12 @@ const ConnectionSidebar = () => {
|
|||||||
updateTableList(tableList);
|
updateTableList(tableList);
|
||||||
}, [selectedSchemaName, schemaList]);
|
}, [selectedSchemaName, schemaList]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (hasSchemaProperty && selectedSchemaName === "") {
|
||||||
|
conversationStore.updateSelectedSchemaName(head(schemaList)?.name || "");
|
||||||
|
}
|
||||||
|
}, [schemaList, currentConversation]);
|
||||||
|
|
||||||
const handleDatabaseNameSelect = async (databaseName: string) => {
|
const handleDatabaseNameSelect = async (databaseName: string) => {
|
||||||
if (!currentConnectionCtx?.connection) {
|
if (!currentConnectionCtx?.connection) {
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user