From 1140ca7a787fee7052e183c97453fd1e4a84c078 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Tue, 15 Apr 2025 20:18:06 +0530 Subject: [PATCH] fix: stale report value shown if summary fetch breaks (#11270) This pull request includes several changes to better show the report metrics fetching status on the dashboard. This also prevents showing stale data in case fetching summary fails due to timeout or other issue The most important changes include adding a new fetching status state to the store called `summaryFetchingStatus`, updating the `useReportMetrics` composable, and modifying the `ChartStats` component to handle different fetching statuses. #### Loading ![CleanShot 2025-04-09 at 13 49 35@2x](https://github.com/user-attachments/assets/575c9905-0bf7-4a6e-8709-026896dd95f8) #### Finished ![CleanShot 2025-04-09 at 13 49 43@2x](https://github.com/user-attachments/assets/ef7f8cb3-ca34-4627-a954-ba23f156d2ff) #### Failed image --------- Co-authored-by: Muhsin Keloth --- .../dashboard/composables/useReportMetrics.js | 7 +- .../dashboard/settings/reports/BotReports.vue | 1 + .../settings/reports/ReportContainer.vue | 10 +- .../components/ChartElements/ChartStats.vue | 33 ++++- app/javascript/dashboard/store/constants.js | 5 + .../dashboard/store/modules/reports.js | 23 +++- .../modules/specs/reports/actions.spec.js | 124 +++++++++++++++++- .../dashboard/store/mutation-types.js | 2 + 8 files changed, 192 insertions(+), 13 deletions(-) create mode 100644 app/javascript/dashboard/store/constants.js diff --git a/app/javascript/dashboard/composables/useReportMetrics.js b/app/javascript/dashboard/composables/useReportMetrics.js index 37168e256..50cc0b350 100644 --- a/app/javascript/dashboard/composables/useReportMetrics.js +++ b/app/javascript/dashboard/composables/useReportMetrics.js @@ -7,8 +7,12 @@ import { formatTime } from '@chatwoot/utils'; * @param {string} [accountSummaryKey='getAccountSummary'] - The key for accessing account summary data. * @returns {Object} An object containing utility functions for report metrics. */ -export function useReportMetrics(accountSummaryKey = 'getAccountSummary') { +export function useReportMetrics( + accountSummaryKey = 'getAccountSummary', + summarFetchingKey = 'getAccountSummaryFetchingStatus' +) { const accountSummary = useMapGetter(accountSummaryKey); + const fetchingStatus = useMapGetter(summarFetchingKey); /** * Calculates the trend percentage for a given metric. @@ -53,5 +57,6 @@ export function useReportMetrics(accountSummaryKey = 'getAccountSummary') { calculateTrend, isAverageMetricType, displayMetric, + fetchingStatus, }; } diff --git a/app/javascript/dashboard/routes/dashboard/settings/reports/BotReports.vue b/app/javascript/dashboard/routes/dashboard/settings/reports/BotReports.vue index 772a6810a..11800a029 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/reports/BotReports.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/reports/BotReports.vue @@ -98,6 +98,7 @@ export default { diff --git a/app/javascript/dashboard/routes/dashboard/settings/reports/ReportContainer.vue b/app/javascript/dashboard/routes/dashboard/settings/reports/ReportContainer.vue index da4cc0167..01ee625fe 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/reports/ReportContainer.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/reports/ReportContainer.vue @@ -19,6 +19,10 @@ export default { type: String, default: 'getAccountSummary', }, + summaryFetchingKey: { + type: String, + default: 'getAccountSummaryFetchingStatus', + }, reportKeys: { type: Object, default: () => ({ @@ -148,7 +152,11 @@ export default { :key="metric.KEY" class="p-4 mb-3 rounded-md" > - +
import { useReportMetrics } from 'dashboard/composables/useReportMetrics'; +import Spinner from 'dashboard/components-next/spinner/Spinner.vue'; +import { STATUS } from 'dashboard/store/constants'; +import { useI18n } from 'vue-i18n'; const props = defineProps({ metric: { @@ -10,11 +13,16 @@ const props = defineProps({ type: String, default: 'getAccountSummary', }, + summaryFetchingKey: { + type: String, + default: 'getAccountSummaryFetchingStatus', + }, }); -const { calculateTrend, displayMetric, isAverageMetricType } = useReportMetrics( - props.accountSummaryKey -); +const { t } = useI18n(); + +const { calculateTrend, displayMetric, isAverageMetricType, fetchingStatus } = + useReportMetrics(props.accountSummaryKey, props.summaryFetchingKey); const trendColor = (value, key) => { if (isAverageMetricType(key)) { @@ -34,10 +42,25 @@ const trendColor = (value, key) => { {{ metric.NAME }}
-
+
+ +
+
+ {{ t('REPORT.SUMMARY_FETCHING_FAILED') }} +
+
{{ displayMetric(metric.KEY) }}
-
+