From 2a9d9963b7f84a1de27ebceb940c617e0e98c99b Mon Sep 17 00:00:00 2001 From: gregfromstl Date: Sun, 5 Jan 2025 07:40:16 +0000 Subject: [PATCH] [Dashboard] Fix: If only one time period has analytics events (#5886) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Notes for the reviewer Adds an edge case if a user only has events for a single time period. Previously, this would show 0 in the analytics summary since it normally takes the most recent *complete* time period. Now, it falls back to show the incomplete period if there is no complete period with data. ## How to test Run the dashboard and view the project client ID listed in the linear ticket --- ## PR-Codex overview This PR focuses on improving the handling of time series data in the `aggregateFn` function by ensuring that if there is only one data point, it uses that point instead of the previous one. This change is applied in two files. ### Detailed summary - Updated `aggregateFn` in `apps/dashboard/src/app/team/[team_slug]/[project_slug]/page.tsx`: - Added logic to check if there is only one valid data point. - If only one point exists, it uses the last data point; otherwise, it uses the previous one. - Updated `aggregateFn` in `apps/dashboard/src/app/team/[team_slug]/(team)/~/analytics/page.tsx`: - Similar logic added as in the previous file to handle time series data appropriately. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` --- .../src/app/team/[team_slug]/(team)/~/analytics/page.tsx | 5 ++++- .../src/app/team/[team_slug]/[project_slug]/page.tsx | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/dashboard/src/app/team/[team_slug]/(team)/~/analytics/page.tsx b/apps/dashboard/src/app/team/[team_slug]/(team)/~/analytics/page.tsx index 1ba33619388..217dace6e70 100644 --- a/apps/dashboard/src/app/team/[team_slug]/(team)/~/analytics/page.tsx +++ b/apps/dashboard/src/app/team/[team_slug]/(team)/~/analytics/page.tsx @@ -257,7 +257,10 @@ function UsersChartCard({ } data={timeSeriesData} aggregateFn={(_data, key) => - timeSeriesData[timeSeriesData.length - 2]?.[key] + // If there is only one data point, use that one, otherwise use the previous + timeSeriesData.filter((d) => (d[key] as number) > 0).length >= 2 + ? timeSeriesData[timeSeriesData.length - 2]?.[key] + : timeSeriesData[timeSeriesData.length - 1]?.[key] } // Get the trend from the last two COMPLETE periods trendFn={(data, key) => diff --git a/apps/dashboard/src/app/team/[team_slug]/[project_slug]/page.tsx b/apps/dashboard/src/app/team/[team_slug]/[project_slug]/page.tsx index fee25daf6cf..44ce7556077 100644 --- a/apps/dashboard/src/app/team/[team_slug]/[project_slug]/page.tsx +++ b/apps/dashboard/src/app/team/[team_slug]/[project_slug]/page.tsx @@ -279,7 +279,10 @@ function UsersChartCard({ queryKey="usersChart" data={timeSeriesData} aggregateFn={(_data, key) => - timeSeriesData[timeSeriesData.length - 2]?.[key] + // If there is only one data point, use that one, otherwise use the previous + timeSeriesData.filter((d) => (d[key] as number) > 0).length >= 2 + ? timeSeriesData[timeSeriesData.length - 2]?.[key] + : timeSeriesData[timeSeriesData.length - 1]?.[key] } // Get the trend from the last two COMPLETE periods trendFn={(data, key) =>