mirror of
https://github.com/sqlchat/sqlchat.git
synced 2025-08-02 14:01:59 +08:00
refactor: rename selectedTablesName to selectedTableNameList
This commit is contained in:
@ -27,8 +27,8 @@ 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 selectedTablesName: string[] =
|
const selectedTableNameList: string[] =
|
||||||
conversationStore.getConversationById(conversationStore.currentConversationId)?.selectedTablesName || [];
|
conversationStore.getConversationById(conversationStore.currentConversationId)?.selectedTableNameList || [];
|
||||||
const selectedSchemaName: string =
|
const selectedSchemaName: string =
|
||||||
conversationStore.getConversationById(conversationStore.currentConversationId)?.selectedSchemaName || "";
|
conversationStore.getConversationById(conversationStore.currentConversationId)?.selectedSchemaName || "";
|
||||||
const tableSchemaLoadingState = useLoading();
|
const tableSchemaLoadingState = useLoading();
|
||||||
@ -59,13 +59,13 @@ const ConnectionSidebar = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// update total token
|
// update total token
|
||||||
const totalToken = selectedTablesName.reduce((totalToken, tableName) => {
|
const totalToken = selectedTableNameList.reduce((totalToken, tableName) => {
|
||||||
const table = tableList.find((table) => table.name === tableName);
|
const table = tableList.find((table) => table.name === tableName);
|
||||||
// because old cache didn't have token, So the value may is undefined.
|
// because old cache didn't have token, So the value may is undefined.
|
||||||
return totalToken + (table?.token || countTextTokens(table?.structure || ""));
|
return totalToken + (table?.token || countTextTokens(table?.structure || ""));
|
||||||
}, 0);
|
}, 0);
|
||||||
setTotalToken(totalToken);
|
setTotalToken(totalToken);
|
||||||
}, [selectedTablesName, tableList]);
|
}, [selectedTableNameList, tableList]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (currentConnectionCtx?.connection) {
|
if (currentConnectionCtx?.connection) {
|
||||||
@ -144,14 +144,14 @@ const ConnectionSidebar = () => {
|
|||||||
|
|
||||||
const handleTableCheckboxChange = async (tableName: string, value: boolean) => {
|
const handleTableCheckboxChange = async (tableName: string, value: boolean) => {
|
||||||
if (value) {
|
if (value) {
|
||||||
conversationStore.updateSelectedTablesName([...selectedTablesName, tableName]);
|
conversationStore.updateSelectedTablesName([...selectedTableNameList, tableName]);
|
||||||
} else {
|
} else {
|
||||||
conversationStore.updateSelectedTablesName(selectedTablesName.filter((name) => name !== tableName));
|
conversationStore.updateSelectedTablesName(selectedTableNameList.filter((name) => name !== tableName));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSchemaNameSelect = async (schemaName: string) => {
|
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.updateSelectedTablesName([]);
|
||||||
conversationStore.updateSelectedSchemaName(schemaName);
|
conversationStore.updateSelectedSchemaName(schemaName);
|
||||||
};
|
};
|
||||||
@ -234,7 +234,7 @@ const ConnectionSidebar = () => {
|
|||||||
return (
|
return (
|
||||||
<div key={table.name}>
|
<div key={table.name}>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
value={selectedTablesName.includes(table.name)}
|
value={selectedTableNameList.includes(table.name)}
|
||||||
label={table.name}
|
label={table.name}
|
||||||
onValueChange={handleTableCheckboxChange}
|
onValueChange={handleTableCheckboxChange}
|
||||||
>
|
>
|
||||||
|
@ -157,7 +157,7 @@ const ConversationView = () => {
|
|||||||
connectionStore.currentConnectionCtx.connection.engineType,
|
connectionStore.currentConnectionCtx.connection.engineType,
|
||||||
schemaList,
|
schemaList,
|
||||||
currentConversation.selectedSchemaName || "",
|
currentConversation.selectedSchemaName || "",
|
||||||
currentConversation.selectedTablesName || [],
|
currentConversation.selectedTableNameList || [],
|
||||||
maxToken,
|
maxToken,
|
||||||
userPrompt
|
userPrompt
|
||||||
);
|
);
|
||||||
|
@ -31,7 +31,7 @@ const SchemaDrawer = (props: Props) => {
|
|||||||
connectionStore.currentConnectionCtx.connection.engineType,
|
connectionStore.currentConnectionCtx.connection.engineType,
|
||||||
schemaList,
|
schemaList,
|
||||||
currentConversation.selectedSchemaName || "",
|
currentConversation.selectedSchemaName || "",
|
||||||
currentConversation.selectedTablesName || [],
|
currentConversation.selectedTableNameList || [],
|
||||||
maxToken
|
maxToken
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ interface ConversationState {
|
|||||||
getConversationById: (conversationId: Id | undefined) => Conversation | undefined;
|
getConversationById: (conversationId: Id | undefined) => Conversation | undefined;
|
||||||
updateConversation: (conversationId: Id, conversation: Partial<Conversation>) => void;
|
updateConversation: (conversationId: Id, conversation: Partial<Conversation>) => void;
|
||||||
clearConversation: (filter: (conversation: Conversation) => boolean) => void;
|
clearConversation: (filter: (conversation: Conversation) => boolean) => void;
|
||||||
updateSelectedTablesName: (selectedTablesName: string[]) => void;
|
updateSelectedTablesName: (selectedTableNameList: string[]) => void;
|
||||||
updateSelectedSchemaName: (selectedSchemaName: string) => void;
|
updateSelectedSchemaName: (selectedSchemaName: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,11 +65,11 @@ export const useConversationStore = create<ConversationState>()(
|
|||||||
conversationList: state.conversationList.filter(filter),
|
conversationList: state.conversationList.filter(filter),
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
updateSelectedTablesName: (selectedTablesName: string[]) => {
|
updateSelectedTablesName: (selectedTableNameList: string[]) => {
|
||||||
const currentConversation = get().getConversationById(get().currentConversationId);
|
const currentConversation = get().getConversationById(get().currentConversationId);
|
||||||
if (currentConversation) {
|
if (currentConversation) {
|
||||||
get().updateConversation(currentConversation.id, {
|
get().updateConversation(currentConversation.id, {
|
||||||
selectedTablesName,
|
selectedTableNameList,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -4,7 +4,7 @@ export interface Conversation {
|
|||||||
id: string;
|
id: string;
|
||||||
connectionId?: Id;
|
connectionId?: Id;
|
||||||
databaseName?: string;
|
databaseName?: string;
|
||||||
selectedTablesName?: string[];
|
selectedTableNameList?: string[];
|
||||||
selectedSchemaName?: string;
|
selectedSchemaName?: string;
|
||||||
assistantId: Id;
|
assistantId: Id;
|
||||||
title: string;
|
title: string;
|
||||||
|
@ -16,7 +16,7 @@ export function generateDbPromptFromContext(
|
|||||||
engine: Engine,
|
engine: Engine,
|
||||||
schemaList: Schema[],
|
schemaList: Schema[],
|
||||||
selectedSchemaName: string,
|
selectedSchemaName: string,
|
||||||
selectedTablesName: string[],
|
selectedTableNameList: string[],
|
||||||
maxToken: number,
|
maxToken: number,
|
||||||
userPrompt?: string
|
userPrompt?: string
|
||||||
): 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.
|
// Because in have Token custom number in connectionSidebar. If [] denote all table. the Token will be inconsistent.
|
||||||
const tableList: string[] = [];
|
const tableList: string[] = [];
|
||||||
const selectedSchema = schemaList.find((schema: Schema) => schema.name == (selectedSchemaName || ""));
|
const selectedSchema = schemaList.find((schema: Schema) => schema.name == (selectedSchemaName || ""));
|
||||||
if (selectedTablesName) {
|
if (selectedTableNameList) {
|
||||||
selectedTablesName.forEach((tableName: string) => {
|
selectedTableNameList.forEach((tableName: string) => {
|
||||||
const table = selectedSchema?.tables.find((table: Table) => table.name == tableName);
|
const table = selectedSchema?.tables.find((table: Table) => table.name == tableName);
|
||||||
tableList.push(table!.structure);
|
tableList.push(table!.structure);
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user