Skip to content

Commit b3c4b70

Browse files
authored
Merge pull request #4126 from Maxime-J/fix-retention
Fix incomplete retention report
2 parents a4fdd9a + 5f6fc7e commit b3c4b70

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

  • src/app/(main)/websites/[websiteId]/(reports)/retention

src/app/(main)/websites/[websiteId]/(reports)/retention/Retention.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Column, Grid, Icon, Row, Text } from '@umami/react-zen';
22
import type { ReactNode } from 'react';
3+
import { differenceInCalendarDays } from 'date-fns';
34
import { LoadingPanel } from '@/components/common/LoadingPanel';
45
import { Panel } from '@/components/common/Panel';
56
import { useLocale, useMessages, useResultQuery } from '@/components/hooks';
@@ -45,8 +46,6 @@ export function Retention({ websiteId, days = DAYS, startDate, endDate }: Retent
4546
return arr;
4647
}, []) || [];
4748

48-
const totalDays = rows.length;
49-
5049
return (
5150
<LoadingPanel data={data} isLoading={isLoading} error={error}>
5251
{data && (
@@ -84,6 +83,7 @@ export function Retention({ websiteId, days = DAYS, startDate, endDate }: Retent
8483
))}
8584
</Grid>
8685
{rows.map(({ date, visitors, records }: any, rowIndex: number) => {
86+
const maxDay = differenceInCalendarDays(endDate, new Date(date));
8787
return (
8888
<Grid
8989
key={rowIndex}
@@ -103,10 +103,8 @@ export function Retention({ websiteId, days = DAYS, startDate, endDate }: Retent
103103
</Row>
104104
</Column>
105105
{days.map(day => {
106-
if (totalDays - rowIndex < day) {
107-
return null;
108-
}
109-
const percentage = records.filter(a => a.day === day)[0]?.percentage;
106+
if (day > maxDay) return null;
107+
const percentage = records.find(a => a.day === day)?.percentage;
110108
return (
111109
<Cell key={day}>
112110
{percentage ? `${Number(percentage).toFixed(2)}%` : ''}

0 commit comments

Comments
 (0)