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
This commit is contained in:
Shailesh Parmar 2023-04-10 13:08:44 +05:30 committed by GitHub
parent 6568d0df08
commit 751919e6ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,6 +26,7 @@ import {
omit, omit,
round, round,
sortBy, sortBy,
sumBy,
toNumber, toNumber,
} from 'lodash'; } from 'lodash';
import moment from 'moment'; import moment from 'moment';
@ -580,29 +581,32 @@ export const getEntitiesChartSummary = (
export const getWebChartSummary = ( export const getWebChartSummary = (
chartResults: (DataInsightChartResult | undefined)[] chartResults: (DataInsightChartResult | undefined)[]
) => { ) => {
const updatedSummary = WEB_SUMMARY_LIST.map((summary) => { const updatedSummary = [];
for (const summary of WEB_SUMMARY_LIST) {
// grab the current chart type // grab the current chart type
const chartData = chartResults.find( const chartData = chartResults.find(
(chart) => chart?.chartType === summary.id (chart) => chart?.chartType === summary.id
); );
// return default summary if chart data is undefined else calculate the latest count for chartType // return default summary if chart data is undefined else calculate the latest count for chartType
if (isUndefined(chartData)) { if (isUndefined(chartData)) {
return summary; updatedSummary.push(summary);
} else {
if (chartData.chartType === DataInsightChartType.DailyActiveUsers) {
const latestData = last(chartData.data);
return { ...summary, latest: latestData?.activeUsers ?? 0 }; continue;
} else {
const { total } = getGraphDataByEntityType(
chartData.data ?? [],
chartData.chartType
);
return { ...summary, latest: total };
}
} }
});
const { chartType, data } = chartData;
updatedSummary.push({
...summary,
latest: sumBy(
data,
chartType === DataInsightChartType.DailyActiveUsers
? 'activeUsers'
: 'pageViews'
),
});
}
return updatedSummary; return updatedSummary;
}; };