refac
This commit is contained in:
1 parent
9df25b6932
commit
00924fbf79
2 files changed
+33
-5
No files matched your search
@@ -246,7 +246,9 @@ export const getModelChats = async (
|
|||||||
startDate: number | null = null,
|
startDate: number | null = null,
|
||||||
endDate: number | null = null,
|
endDate: number | null = null,
|
||||||
skip: number = 0,
|
skip: number = 0,
|
||||||
limit: number = 50
|
limit: number = 50,
|
||||||
|
orderBy: string | null = null,
|
||||||
|
direction: string | null = null
|
||||||
) => {
|
) => {
|
||||||
let error = null;
|
let error = null;
|
||||||
|
|
||||||
@@ -255,6 +257,8 @@ export const getModelChats = async (
|
|||||||
if (endDate) searchParams.append('end_date', endDate.toString());
|
if (endDate) searchParams.append('end_date', endDate.toString());
|
||||||
if (skip) searchParams.append('skip', skip.toString());
|
if (skip) searchParams.append('skip', skip.toString());
|
||||||
if (limit) searchParams.append('limit', limit.toString());
|
if (limit) searchParams.append('limit', limit.toString());
|
||||||
|
if (orderBy) searchParams.append('order_by', orderBy);
|
||||||
|
if (direction) searchParams.append('direction', direction);
|
||||||
|
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`${WEBUI_API_BASE_URL}/analytics/models/${encodeURIComponent(modelId)}/chats?${searchParams.toString()}`,
|
`${WEBUI_API_BASE_URL}/analytics/models/${encodeURIComponent(modelId)}/chats?${searchParams.toString()}`,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
type Tab = 'overview' | 'chats';
|
type Tab = 'overview' | 'chats';
|
||||||
|
type ChatSortKey = 'title' | 'updated_at' | 'user_name';
|
||||||
let selectedTab: Tab = 'overview';
|
let selectedTab: Tab = 'overview';
|
||||||
|
|
||||||
// Overview tab state
|
// Overview tab state
|
||||||
@@ -41,6 +42,8 @@
|
|||||||
}> = [];
|
}> = [];
|
||||||
let chatListLoading = false;
|
let chatListLoading = false;
|
||||||
let allChatsLoaded = false;
|
let allChatsLoaded = false;
|
||||||
|
let chatOrderBy: ChatSortKey = 'updated_at';
|
||||||
|
let chatDirection: 'asc' | 'desc' = 'desc';
|
||||||
const PAGE_SIZE = 50;
|
const PAGE_SIZE = 50;
|
||||||
|
|
||||||
const close = () => {
|
const close = () => {
|
||||||
@@ -48,6 +51,8 @@
|
|||||||
selectedTab = 'overview';
|
selectedTab = 'overview';
|
||||||
chatList = [];
|
chatList = [];
|
||||||
allChatsLoaded = false;
|
allChatsLoaded = false;
|
||||||
|
chatOrderBy = 'updated_at';
|
||||||
|
chatDirection = 'desc';
|
||||||
history = [];
|
history = [];
|
||||||
tags = [];
|
tags = [];
|
||||||
onClose();
|
onClose();
|
||||||
@@ -88,7 +93,9 @@
|
|||||||
startDate,
|
startDate,
|
||||||
endDate,
|
endDate,
|
||||||
0,
|
0,
|
||||||
PAGE_SIZE
|
PAGE_SIZE,
|
||||||
|
chatOrderBy,
|
||||||
|
chatDirection
|
||||||
);
|
);
|
||||||
const chats = res?.chats ?? [];
|
const chats = res?.chats ?? [];
|
||||||
chatList = chats.map((c: any) => ({
|
chatList = chats.map((c: any) => ({
|
||||||
@@ -98,7 +105,7 @@
|
|||||||
user_id: c.user_id,
|
user_id: c.user_id,
|
||||||
user_name: c.user_name
|
user_name: c.user_name
|
||||||
}));
|
}));
|
||||||
allChatsLoaded = chats.length < PAGE_SIZE;
|
allChatsLoaded = chatList.length >= (res?.total ?? chats.length);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to load chats:', err);
|
console.error('Failed to load chats:', err);
|
||||||
chatList = [];
|
chatList = [];
|
||||||
@@ -118,7 +125,9 @@
|
|||||||
startDate,
|
startDate,
|
||||||
endDate,
|
endDate,
|
||||||
skip,
|
skip,
|
||||||
PAGE_SIZE
|
PAGE_SIZE,
|
||||||
|
chatOrderBy,
|
||||||
|
chatDirection
|
||||||
);
|
);
|
||||||
const chats = res?.chats ?? [];
|
const chats = res?.chats ?? [];
|
||||||
const newChats = chats.map((c: any) => ({
|
const newChats = chats.map((c: any) => ({
|
||||||
@@ -131,13 +140,23 @@
|
|||||||
const existingIds = new Set(chatList.map((c) => c.id));
|
const existingIds = new Set(chatList.map((c) => c.id));
|
||||||
const uniqueNewChats = newChats.filter((c) => !existingIds.has(c.id));
|
const uniqueNewChats = newChats.filter((c) => !existingIds.has(c.id));
|
||||||
chatList = [...chatList, ...uniqueNewChats];
|
chatList = [...chatList, ...uniqueNewChats];
|
||||||
allChatsLoaded = chats.length < PAGE_SIZE;
|
allChatsLoaded = chatList.length >= (res?.total ?? chatList.length);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to load more chats:', err);
|
console.error('Failed to load more chats:', err);
|
||||||
}
|
}
|
||||||
chatListLoading = false;
|
chatListLoading = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const setChatSort = (key: ChatSortKey) => {
|
||||||
|
if (chatOrderBy === key) {
|
||||||
|
chatDirection = chatDirection === 'asc' ? 'desc' : 'asc';
|
||||||
|
} else {
|
||||||
|
chatOrderBy = key;
|
||||||
|
chatDirection = key === 'updated_at' ? 'desc' : 'asc';
|
||||||
|
}
|
||||||
|
loadChats();
|
||||||
|
};
|
||||||
|
|
||||||
const selectTab = (tab: Tab) => {
|
const selectTab = (tab: Tab) => {
|
||||||
selectedTab = tab;
|
selectedTab = tab;
|
||||||
if (tab === 'chats' && chatList.length === 0) {
|
if (tab === 'chats' && chatList.length === 0) {
|
||||||
@@ -150,6 +169,8 @@
|
|||||||
selectedTab = 'overview';
|
selectedTab = 'overview';
|
||||||
chatList = [];
|
chatList = [];
|
||||||
allChatsLoaded = false;
|
allChatsLoaded = false;
|
||||||
|
chatOrderBy = 'updated_at';
|
||||||
|
chatDirection = 'desc';
|
||||||
selectedRange = '30d';
|
selectedRange = '30d';
|
||||||
loadOverview(30);
|
loadOverview(30);
|
||||||
}
|
}
|
||||||
@@ -251,6 +272,9 @@
|
|||||||
allLoaded={allChatsLoaded}
|
allLoaded={allChatsLoaded}
|
||||||
showUserInfo={true}
|
showUserInfo={true}
|
||||||
shareUrl={true}
|
shareUrl={true}
|
||||||
|
orderBy={chatOrderBy}
|
||||||
|
direction={chatDirection}
|
||||||
|
onSort={setChatSort}
|
||||||
onLoadMore={loadMoreChats}
|
onLoadMore={loadMoreChats}
|
||||||
onChatClick={() => (show = false)}
|
onChatClick={() => (show = false)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in new issue
Block a user