11import { Column , Grid , Icon , Row , Text } from '@umami/react-zen' ;
22import type { ReactNode } from 'react' ;
3+ import { differenceInCalendarDays } from 'date-fns' ;
34import { LoadingPanel } from '@/components/common/LoadingPanel' ;
45import { Panel } from '@/components/common/Panel' ;
56import { 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