diff --git a/frontend/app/components/Kai/KaiStore.ts b/frontend/app/components/Kai/KaiStore.ts index fb8a1736a..7369b25b9 100644 --- a/frontend/app/components/Kai/KaiStore.ts +++ b/frontend/app/components/Kai/KaiStore.ts @@ -334,6 +334,7 @@ class KaiStore { } }; + charts = new Map>(); getMessageChart = async (msgId: string, projectId: string) => { this.setProcessingStage({ content: 'Generating visualization...', @@ -353,7 +354,7 @@ class KaiStore { ...filters, }; const metric = new Widget().fromJson(data); - kaiService.saveChartData(msgId, projectId, data); + this.charts.set(msgId, data); return metric; } catch (e) { console.error(e); @@ -363,19 +364,31 @@ class KaiStore { } }; + saveLatestChart = async (msgId: string, projectId: string) => { + const data = this.charts.get(msgId); + if (data) { + try { + await kaiService.saveChartData(msgId, projectId, data); + this.charts.delete(msgId); + } catch (e) { + console.error(e); + } + } + }; + getParsedChart = (data: string) => { const parsedData = JSON.parse(data); return new Widget().fromJson(parsedData); }; + setUsage = (usage: { total: number; used: number; percent: number }) => { + this.usage = usage; + }; + checkUsage = async () => { try { const { total, used } = await kaiService.checkUsage(); - this.usage = { - total, - used, - percent: Math.round((used / total) * 100), - }; + this.setUsage({ total, used, percent: Math.round((used / total) * 100) }); } catch (e) { console.error(e); } diff --git a/frontend/app/components/Kai/components/ChatMsg.tsx b/frontend/app/components/Kai/components/ChatMsg.tsx index a1fbd7522..d335952ae 100644 --- a/frontend/app/components/Kai/components/ChatMsg.tsx +++ b/frontend/app/components/Kai/components/ChatMsg.tsx @@ -159,6 +159,13 @@ function ChatMsg({ setLoadingChart(false); } }; + + const metricData = metric?.data; + React.useEffect(() => { + if (!chart_data && metricData && metricData.values.length > 0) { + kaiStore.saveLatestChart(messageId, siteId); + } + }, [metricData, chart_data]); return (
{isUser ? ( diff --git a/frontend/app/components/Kai/components/ChatsModal.tsx b/frontend/app/components/Kai/components/ChatsModal.tsx index a39d358f0..16f374d15 100644 --- a/frontend/app/components/Kai/components/ChatsModal.tsx +++ b/frontend/app/components/Kai/components/ChatsModal.tsx @@ -58,16 +58,20 @@ function ChatsModal({
) : null} {isPending ? ( -
{t('Loading chats')}...
+
+ {t('Loading chats')}... +
) : (
- {datedCollections.map((col) => ( - + {datedCollections.map((col, i) => ( + + + ))}
)}