From e774078613a5e379d81092b8fcc45776752a92df Mon Sep 17 00:00:00 2001 From: Tianzhou Chen Date: Thu, 8 Jun 2023 01:06:22 +0800 Subject: [PATCH] refactor: rename selectedTablesName to selectedTableNameList --- src/components/ConnectionSidebar.tsx | 16 ++++++++-------- src/components/ConversationView/index.tsx | 2 +- src/components/SchemaDrawer.tsx | 2 +- src/store/conversation.ts | 6 +++--- src/types/conversation.ts | 2 +- src/utils/openai.ts | 6 +++--- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/components/ConnectionSidebar.tsx b/src/components/ConnectionSidebar.tsx index 79e1cbb..fbeff56 100644 --- a/src/components/ConnectionSidebar.tsx +++ b/src/components/ConnectionSidebar.tsx @@ -27,8 +27,8 @@ const ConnectionSidebar = () => { const databaseList = connectionStore.databaseList.filter((database) => database.connectionId === currentConnectionCtx?.connection.id); const [tableList, updateTableList] = useState([]); const [schemaList, updateSchemaList] = useState([]); - const selectedTablesName: string[] = - conversationStore.getConversationById(conversationStore.currentConversationId)?.selectedTablesName || []; + const selectedTableNameList: string[] = + conversationStore.getConversationById(conversationStore.currentConversationId)?.selectedTableNameList || []; const selectedSchemaName: string = conversationStore.getConversationById(conversationStore.currentConversationId)?.selectedSchemaName || ""; const tableSchemaLoadingState = useLoading(); @@ -59,13 +59,13 @@ const ConnectionSidebar = () => { useEffect(() => { // update total token - const totalToken = selectedTablesName.reduce((totalToken, tableName) => { + const totalToken = selectedTableNameList.reduce((totalToken, tableName) => { const table = tableList.find((table) => table.name === tableName); // because old cache didn't have token, So the value may is undefined. return totalToken + (table?.token || countTextTokens(table?.structure || "")); }, 0); setTotalToken(totalToken); - }, [selectedTablesName, tableList]); + }, [selectedTableNameList, tableList]); useEffect(() => { if (currentConnectionCtx?.connection) { @@ -144,14 +144,14 @@ const ConnectionSidebar = () => { const handleTableCheckboxChange = async (tableName: string, value: boolean) => { if (value) { - conversationStore.updateSelectedTablesName([...selectedTablesName, tableName]); + conversationStore.updateSelectedTablesName([...selectedTableNameList, tableName]); } else { - conversationStore.updateSelectedTablesName(selectedTablesName.filter((name) => name !== tableName)); + conversationStore.updateSelectedTablesName(selectedTableNameList.filter((name) => name !== tableName)); } }; const handleSchemaNameSelect = async (schemaName: string) => { - // need to empty selectedTablesName when schemaName changed. because selectedTablesName may not exist in new schema. + // need to empty selectedTableNameList when schemaName changed. because selectedTableNameList may not exist in new schema. conversationStore.updateSelectedTablesName([]); conversationStore.updateSelectedSchemaName(schemaName); }; @@ -234,7 +234,7 @@ const ConnectionSidebar = () => { return (
diff --git a/src/components/ConversationView/index.tsx b/src/components/ConversationView/index.tsx index ebc2c91..45b4397 100644 --- a/src/components/ConversationView/index.tsx +++ b/src/components/ConversationView/index.tsx @@ -157,7 +157,7 @@ const ConversationView = () => { connectionStore.currentConnectionCtx.connection.engineType, schemaList, currentConversation.selectedSchemaName || "", - currentConversation.selectedTablesName || [], + currentConversation.selectedTableNameList || [], maxToken, userPrompt ); diff --git a/src/components/SchemaDrawer.tsx b/src/components/SchemaDrawer.tsx index 26fb403..95b3821 100644 --- a/src/components/SchemaDrawer.tsx +++ b/src/components/SchemaDrawer.tsx @@ -31,7 +31,7 @@ const SchemaDrawer = (props: Props) => { connectionStore.currentConnectionCtx.connection.engineType, schemaList, currentConversation.selectedSchemaName || "", - currentConversation.selectedTablesName || [], + currentConversation.selectedTableNameList || [], maxToken ); } diff --git a/src/store/conversation.ts b/src/store/conversation.ts index 62b970c..415a6e3 100644 --- a/src/store/conversation.ts +++ b/src/store/conversation.ts @@ -23,7 +23,7 @@ interface ConversationState { getConversationById: (conversationId: Id | undefined) => Conversation | undefined; updateConversation: (conversationId: Id, conversation: Partial) => void; clearConversation: (filter: (conversation: Conversation) => boolean) => void; - updateSelectedTablesName: (selectedTablesName: string[]) => void; + updateSelectedTablesName: (selectedTableNameList: string[]) => void; updateSelectedSchemaName: (selectedSchemaName: string) => void; } @@ -65,11 +65,11 @@ export const useConversationStore = create()( conversationList: state.conversationList.filter(filter), })); }, - updateSelectedTablesName: (selectedTablesName: string[]) => { + updateSelectedTablesName: (selectedTableNameList: string[]) => { const currentConversation = get().getConversationById(get().currentConversationId); if (currentConversation) { get().updateConversation(currentConversation.id, { - selectedTablesName, + selectedTableNameList, }); } }, diff --git a/src/types/conversation.ts b/src/types/conversation.ts index f2877c6..b629c92 100644 --- a/src/types/conversation.ts +++ b/src/types/conversation.ts @@ -4,7 +4,7 @@ export interface Conversation { id: string; connectionId?: Id; databaseName?: string; - selectedTablesName?: string[]; + selectedTableNameList?: string[]; selectedSchemaName?: string; assistantId: Id; title: string; diff --git a/src/utils/openai.ts b/src/utils/openai.ts index 3d26b03..375a8d8 100644 --- a/src/utils/openai.ts +++ b/src/utils/openai.ts @@ -16,7 +16,7 @@ export function generateDbPromptFromContext( engine: Engine, schemaList: Schema[], selectedSchemaName: string, - selectedTablesName: string[], + selectedTableNameList: string[], maxToken: number, userPrompt?: string ): string { @@ -28,8 +28,8 @@ export function generateDbPromptFromContext( // Because in have Token custom number in connectionSidebar. If [] denote all table. the Token will be inconsistent. const tableList: string[] = []; const selectedSchema = schemaList.find((schema: Schema) => schema.name == (selectedSchemaName || "")); - if (selectedTablesName) { - selectedTablesName.forEach((tableName: string) => { + if (selectedTableNameList) { + selectedTableNameList.forEach((tableName: string) => { const table = selectedSchema?.tables.find((table: Table) => table.name == tableName); tableList.push(table!.structure); });