fix: tables cannot be selected when there is no conversation (#98)

This commit is contained in:
CorrectRoadH
2023-05-19 11:08:31 +08:00
committed by GitHub
parent 8c5ddc37e1
commit 374824e281

View File

@ -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 (