From 751919e6ca74f91a436dfbf38fd271b0d4522c51 Mon Sep 17 00:00:00 2001 From: Shailesh Parmar Date: Mon, 10 Apr 2023 13:08:44 +0530 Subject: [PATCH] fixes App Analytics summary not adjusting to the datetime [UI] #10571 (#10961) * fixes App Analytics summary not adjusting to the datetime [UI] #10571 * added comments to the code * updated sum logic, used sumBy method from lodash * addressing comment --- .../ui/src/utils/DataInsightUtils.tsx | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/DataInsightUtils.tsx b/openmetadata-ui/src/main/resources/ui/src/utils/DataInsightUtils.tsx index 86de8447718..42e96ee1653 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/DataInsightUtils.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/utils/DataInsightUtils.tsx @@ -26,6 +26,7 @@ import { omit, round, sortBy, + sumBy, toNumber, } from 'lodash'; import moment from 'moment'; @@ -580,29 +581,32 @@ export const getEntitiesChartSummary = ( export const getWebChartSummary = ( chartResults: (DataInsightChartResult | undefined)[] ) => { - const updatedSummary = WEB_SUMMARY_LIST.map((summary) => { + const updatedSummary = []; + + for (const summary of WEB_SUMMARY_LIST) { // grab the current chart type const chartData = chartResults.find( (chart) => chart?.chartType === summary.id ); // return default summary if chart data is undefined else calculate the latest count for chartType if (isUndefined(chartData)) { - return summary; - } else { - if (chartData.chartType === DataInsightChartType.DailyActiveUsers) { - const latestData = last(chartData.data); + updatedSummary.push(summary); - return { ...summary, latest: latestData?.activeUsers ?? 0 }; - } else { - const { total } = getGraphDataByEntityType( - chartData.data ?? [], - chartData.chartType - ); - - return { ...summary, latest: total }; - } + continue; } - }); + + const { chartType, data } = chartData; + + updatedSummary.push({ + ...summary, + latest: sumBy( + data, + chartType === DataInsightChartType.DailyActiveUsers + ? 'activeUsers' + : 'pageViews' + ), + }); + } return updatedSummary; };