@@ -13,18 +13,27 @@ import { LabelledPieChart } from '@/components/charts/labelled-pie-chart'
1313import { humanizeDuration } from '@/lib/utils'
1414import { Metric } from '@/lib/definitions'
1515
16- import { getReport } from '@/server/actions/report'
17- import type { ReportModiefied } from '@/server/types'
16+ import { getReport } from '@/server/actions'
17+ import type { ReportWithTimestamps } from '@/server/types/extended'
18+ import type { ReportModiefied } from '@/server/databases/types'
1819
1920const Page = ( { params } : { params : { reportSlug : string } } ) => {
2021 const { userId } = useAuth ( )
21- const [ metrics , setMetrics ] = useState < Metric > ( )
22+ const [ metrics , setMetrics ] = useState < Metric | undefined > ( )
2223
2324 useEffect ( ( ) => {
2425 getReport ( { userId : userId as string , reportSlug : params . reportSlug } )
25- . then ( ( data ) => {
26- const parsedData = data as ReportModiefied [ ]
27- setMetrics ( parsedData [ 0 ] ?. metadata ?. drowser ?. metrics as Metric )
26+ . then ( ( response ) => {
27+ if ( response . success && response . data ) {
28+ // Get metrics from the response data
29+ const report = response . data as ReportWithTimestamps & ReportModiefied
30+ // Fixed type assertion by ensuring proper type matching
31+ if ( report ?. metadata ?. drowser ?. metrics ) {
32+ setMetrics ( report . metadata . drowser . metrics as unknown as Metric )
33+ }
34+ } else {
35+ console . error ( 'Error fetching report:' , response . error )
36+ }
2837 } )
2938 . catch ( ( err ) => console . log ( err ) )
3039 } , [ userId , params . reportSlug ] )
@@ -37,70 +46,70 @@ const Page = ({ params }: { params: { reportSlug: string } }) => {
3746 < CardHeader >
3847 < CardTitle > Total Tests</ CardTitle >
3948 < CardDescription >
40- < span className = 'text-4xl font-bold' > { metrics . total_tests ?? 0 } </ span >
49+ < span className = 'text-4xl font-bold' > { metrics ? .total_tests ?? 0 } </ span >
4150 </ CardDescription >
4251 </ CardHeader >
4352 < CardContent >
44- < LineChart className = 'aspect-[4/3]' data = { metrics . graphs . total_tests } />
53+ < LineChart className = 'aspect-[4/3]' data = { metrics ? .graphs ? .total_tests } />
4554 </ CardContent >
4655 </ Card >
4756 < Card >
4857 < CardHeader >
4958 < CardTitle > Passing Tests</ CardTitle >
5059 < CardDescription >
51- < span className = 'text-4xl font-bold' > { metrics . passing_tests ?? 0 } </ span >
60+ < span className = 'text-4xl font-bold' > { metrics ? .passing_tests ?? 0 } </ span >
5261 </ CardDescription >
5362 </ CardHeader >
5463 < CardContent >
55- < BarChart className = 'aspect-[4/3]' data = { metrics . graphs . passing_tests } />
64+ < BarChart className = 'aspect-[4/3]' data = { metrics ? .graphs ? .passing_tests } />
5665 </ CardContent >
5766 </ Card >
5867 < Card >
5968 < CardHeader >
6069 < CardTitle > Failed Tests</ CardTitle >
6170 < CardDescription >
62- < span className = 'text-4xl font-bold' > { metrics . failed_tests ?? 0 } </ span >
71+ < span className = 'text-4xl font-bold' > { metrics ? .failed_tests ?? 0 } </ span >
6372 </ CardDescription >
6473 </ CardHeader >
6574 < CardContent >
66- < BarChart className = 'aspect-[4/3]' data = { metrics . graphs . failed_tests } />
75+ < BarChart className = 'aspect-[4/3]' data = { metrics ? .graphs ? .failed_tests } />
6776 </ CardContent >
6877 </ Card >
6978 < Card >
7079 < CardHeader >
7180 < CardTitle > Test Coverage</ CardTitle >
7281 < CardDescription >
7382 < span className = 'text-4xl font-bold' > { `${ (
74- metrics . test_coverage ?? 0
83+ metrics ? .test_coverage ?? 0
7584 ) . toFixed ( ) } %`} </ span >
7685 </ CardDescription >
7786 </ CardHeader >
7887 < CardContent >
79- < BarChart className = 'aspect-[4/3]' data = { metrics . graphs . test_coverage } />
88+ < BarChart className = 'aspect-[4/3]' data = { metrics ? .graphs ? .test_coverage } />
8089 </ CardContent >
8190 </ Card >
8291 < Card >
8392 < CardHeader >
8493 < CardTitle > Avg. Test Duration</ CardTitle >
8594 < CardDescription >
8695 < span className = 'text-4xl font-bold' >
87- { humanizeDuration ( metrics . avg_test_duration ?? 0 ) }
96+ { humanizeDuration ( metrics ? .avg_test_duration ?? 0 ) }
8897 </ span >
8998 </ CardDescription >
9099 </ CardHeader >
91100 < CardContent >
92- < BarChart className = 'aspect-[4/3]' data = { metrics . graphs . avg_test_duration } />
101+ < BarChart className = 'aspect-[4/3]' data = { metrics ? .graphs ? .avg_test_duration } />
93102 </ CardContent >
94103 </ Card >
95104 < Card >
96105 < CardHeader >
97106 < CardTitle > Flaky Tests</ CardTitle >
98107 < CardDescription >
99- < span className = 'text-4xl font-bold' > { metrics . flaky_tests ?? 0 } </ span >
108+ < span className = 'text-4xl font-bold' > { metrics ? .flaky_tests ?? 0 } </ span >
100109 </ CardDescription >
101110 </ CardHeader >
102111 < CardContent >
103- < LabelledPieChart className = 'aspect-[4/3]' data = { metrics . graphs . flaky_tests } />
112+ < LabelledPieChart className = 'aspect-[4/3]' data = { metrics ? .graphs ? .flaky_tests } />
104113 </ CardContent >
105114 </ Card >
106115 </ div >
@@ -111,7 +120,7 @@ const Page = ({ params }: { params: { reportSlug: string } }) => {
111120 < h2 className = 'text-2xl font-bold' > No Metrics Available</ h2 >
112121 < p className = 'text-gray-500' >
113122 It looks like there are no metrics to display at the moment. Please provide a verified
114- or conform json configuration form the < strong > Drowser</ strong > package
123+ or conform json configuration from the < strong > Drowser</ strong > package
115124 </ p >
116125 </ div >
117126 </ div >
0 commit comments