Update stats API - date and source filters apply to stats

This commit is contained in:
Ilango
2024-03-11 21:54:42 +05:30
parent 131eccef45
commit ed6b3b2a6d
3 changed files with 65 additions and 27 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
import client from './client'
const getStatsFromChatflow = (id) => client.get(`/stats/${id}`)
const getStatsFromChatflow = (id, params) => client.get(`/stats/${id}`, { params: { ...params } })
export default {
getStatsFromChatflow
@@ -115,6 +115,11 @@ const ViewMessagesDialog = ({ show, dialogProps, onCancel }) => {
endDate: endDate,
chatType: chatTypeFilter.length ? chatTypeFilter : undefined
})
getStatsApi.request(dialogProps.chatflow.id, {
startDate: date,
endDate: endDate,
chatType: chatTypeFilter.length ? chatTypeFilter : undefined
})
}
const onEndDateSelected = (date) => {
@@ -124,6 +129,11 @@ const ViewMessagesDialog = ({ show, dialogProps, onCancel }) => {
startDate: startDate,
chatType: chatTypeFilter.length ? chatTypeFilter : undefined
})
getStatsApi.request(dialogProps.chatflow.id, {
endDate: date,
startDate: startDate,
chatType: chatTypeFilter.length ? chatTypeFilter : undefined
})
}
const onChatTypeSelected = (chatTypes) => {
@@ -133,6 +143,11 @@ const ViewMessagesDialog = ({ show, dialogProps, onCancel }) => {
startDate: startDate,
endDate: endDate
})
getStatsApi.request(dialogProps.chatflow.id, {
chatType: chatTypes.length ? chatTypes : undefined,
startDate: startDate,
endDate: endDate
})
}
const exportMessages = async () => {
@@ -432,6 +447,7 @@ const ViewMessagesDialog = ({ show, dialogProps, onCancel }) => {
setSelectedMessageIndex(0)
setStartDate(new Date().setMonth(new Date().getMonth() - 1))
setEndDate(new Date())
setStats([])
}
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -463,23 +479,6 @@ const ViewMessagesDialog = ({ show, dialogProps, onCancel }) => {
</DialogTitle>
<DialogContent>
<>
<div
style={{
display: 'grid',
gridTemplateColumns: 'repeat(3, minmax(0, 1fr))',
gap: 10,
marginBottom: 16,
marginLeft: 8,
marginRight: 8
}}
>
<StatsCard title='Total Messages (API/Embed)' stat={`${stats.totalMessages}`} />
<StatsCard title='Total Feedback Received' stat={`${stats.totalFeedback}`} />
<StatsCard
title='Positive Feedback'
stat={`${((stats.positiveFeedback / stats.totalFeedback) * 100 || 0).toFixed(2)}%`}
/>
</div>
<div
style={{
display: 'flex',
@@ -536,6 +535,23 @@ const ViewMessagesDialog = ({ show, dialogProps, onCancel }) => {
</div>
<div style={{ flex: 1 }}></div>
</div>
<div
style={{
display: 'grid',
gridTemplateColumns: 'repeat(3, minmax(0, 1fr))',
gap: 10,
marginBottom: 16,
marginLeft: 8,
marginRight: 8
}}
>
<StatsCard title='Total Messages' stat={`${stats.totalMessages}`} />
<StatsCard title='Total Feedback Received' stat={`${stats.totalFeedback}`} />
<StatsCard
title='Positive Feedback'
stat={`${((stats.positiveFeedback / stats.totalFeedback) * 100 || 0).toFixed(2)}%`}
/>
</div>
<div style={{ display: 'flex', flexDirection: 'row' }}>
{chatlogs && chatlogs.length == 0 && (
<Stack sx={{ alignItems: 'center', justifyContent: 'center', width: '100%' }} flexDirection='column'>