From 374824e2817c9a1004f497be0bbedb6a1cbf155b Mon Sep 17 00:00:00 2001 From: CorrectRoadH Date: Fri, 19 May 2023 11:08:31 +0800 Subject: [PATCH] fix: tables cannot be selected when there is no conversation (#98) --- src/components/ConnectionSidebar.tsx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/components/ConnectionSidebar.tsx b/src/components/ConnectionSidebar.tsx index 3bb5918..967a592 100644 --- a/src/components/ConnectionSidebar.tsx +++ b/src/components/ConnectionSidebar.tsx @@ -40,6 +40,9 @@ const ConnectionSidebar = () => { conversationStore.currentConversationId )?.selectedTablesName || []; const tableSchemaLoadingState = useLoading(); + const currentConversation = conversationStore.getConversationById( + conversationStore.currentConversationId + ); useEffect(() => { const handleWindowResize = () => { @@ -118,17 +121,36 @@ const ConnectionSidebar = () => { } }; + // only create conversation when currentConversation is null. + // Note: This function is used to solve issue #95 + // https://github.com/sqlchat/sqlchat/issues/95 + const createConversation = () => { + if (!currentConversation) { + if (!currentConnectionCtx) { + conversationStore.createConversation(); + } else { + conversationStore.createConversation( + currentConnectionCtx.connection.id, + currentConnectionCtx.database?.name + ); + } + } + }; + const handleTableNameSelect = async (selectedTablesName: string[]) => { + createConversation(); conversationStore.updateSelectedTablesName(selectedTablesName); }; const handleAllSelect = async () => { + createConversation(); conversationStore.updateSelectedTablesName( tableList.map((table) => table.name) ); }; const handleEmptySelect = async () => { + createConversation(); conversationStore.updateSelectedTablesName([]); }; return (