Skip to content

Commit 2a9d996

Browse files
committed
[Dashboard] Fix: If only one time period has analytics events (#5886)
## 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 <!-- start pr-codex --> --- ## 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}` <!-- end pr-codex -->
1 parent 1e8ddcb commit 2a9d996

File tree

2 files changed

+8
-2
lines changed
  • apps/dashboard/src/app/team/[team_slug]

2 files changed

+8
-2
lines changed

apps/dashboard/src/app/team/[team_slug]/(team)/~/analytics/page.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,10 @@ function UsersChartCard({
257257
}
258258
data={timeSeriesData}
259259
aggregateFn={(_data, key) =>
260-
timeSeriesData[timeSeriesData.length - 2]?.[key]
260+
// If there is only one data point, use that one, otherwise use the previous
261+
timeSeriesData.filter((d) => (d[key] as number) > 0).length >= 2
262+
? timeSeriesData[timeSeriesData.length - 2]?.[key]
263+
: timeSeriesData[timeSeriesData.length - 1]?.[key]
261264
}
262265
// Get the trend from the last two COMPLETE periods
263266
trendFn={(data, key) =>

apps/dashboard/src/app/team/[team_slug]/[project_slug]/page.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,10 @@ function UsersChartCard({
279279
queryKey="usersChart"
280280
data={timeSeriesData}
281281
aggregateFn={(_data, key) =>
282-
timeSeriesData[timeSeriesData.length - 2]?.[key]
282+
// If there is only one data point, use that one, otherwise use the previous
283+
timeSeriesData.filter((d) => (d[key] as number) > 0).length >= 2
284+
? timeSeriesData[timeSeriesData.length - 2]?.[key]
285+
: timeSeriesData[timeSeriesData.length - 1]?.[key]
283286
}
284287
// Get the trend from the last two COMPLETE periods
285288
trendFn={(data, key) =>

0 commit comments

Comments
 (0)