refactor: rename selectedTablesName to selectedTableNameList

This commit is contained in:
Tianzhou Chen
2023-06-08 01:06:22 +08:00
parent 7edf20a82a
commit e774078613
6 changed files with 17 additions and 17 deletions

View File

@ -27,8 +27,8 @@ const ConnectionSidebar = () => {
const databaseList = connectionStore.databaseList.filter((database) => database.connectionId === currentConnectionCtx?.connection.id);
const [tableList, updateTableList] = useState<Table[]>([]);
const [schemaList, updateSchemaList] = useState<Schema[]>([]);
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 (
<div key={table.name}>
<Checkbox
value={selectedTablesName.includes(table.name)}
value={selectedTableNameList.includes(table.name)}
label={table.name}
onValueChange={handleTableCheckboxChange}
>

View File

@ -157,7 +157,7 @@ const ConversationView = () => {
connectionStore.currentConnectionCtx.connection.engineType,
schemaList,
currentConversation.selectedSchemaName || "",
currentConversation.selectedTablesName || [],
currentConversation.selectedTableNameList || [],
maxToken,
userPrompt
);

View File

@ -31,7 +31,7 @@ const SchemaDrawer = (props: Props) => {
connectionStore.currentConnectionCtx.connection.engineType,
schemaList,
currentConversation.selectedSchemaName || "",
currentConversation.selectedTablesName || [],
currentConversation.selectedTableNameList || [],
maxToken
);
}

View File

@ -23,7 +23,7 @@ interface ConversationState {
getConversationById: (conversationId: Id | undefined) => Conversation | undefined;
updateConversation: (conversationId: Id, conversation: Partial<Conversation>) => 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<ConversationState>()(
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,
});
}
},

View File

@ -4,7 +4,7 @@ export interface Conversation {
id: string;
connectionId?: Id;
databaseName?: string;
selectedTablesName?: string[];
selectedTableNameList?: string[];
selectedSchemaName?: string;
assistantId: Id;
title: string;

View File

@ -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);
});