@@ -2,6 +2,7 @@ import * as R from 'remeda'
2
2
import React , { ReactElement , Suspense } from 'react'
3
3
import { Metadata } from 'next'
4
4
import { BodyLong , Detail , Heading , Skeleton } from '@navikt/ds-react'
5
+ import { SearchParams } from 'nuqs'
5
6
6
7
import { TeamNotAccesible , TeamNotFound } from '../../../../../components/errors/ErrorMessages'
7
8
import { userHasAdGroup } from '../../../../../auth/authentication'
@@ -12,6 +13,8 @@ import OverallScoreGraph from '../../../../../components/graphs/OverallScoreGrap
12
13
import { getWeekNumber } from '../../../../../utils/date'
13
14
import ScorePerQuestion from '../../../../../components/graphs/ScorePerQuestion'
14
15
import { raise } from '../../../../../utils/ts-utils'
16
+ import OnlyCurrentQuestionsToggle from '../../../../../components/graphs/OnlyCurrentQuestionsToggle'
17
+ import { loadSearchParams } from '../../../../../components/graphs/only-current-search-params'
15
18
16
19
export const metadata : Metadata = {
17
20
title : 'Helsesjekk | Team | Graf' ,
@@ -23,10 +26,13 @@ type Props = {
23
26
groupId : string
24
27
teamId : string
25
28
} >
29
+ searchParams : Promise < SearchParams >
26
30
}
27
31
28
- async function Page ( { params } : Props ) : Promise < ReactElement > {
32
+ async function Page ( { params, searchParams } : Props ) : Promise < ReactElement > {
29
33
const pageParams = await params
34
+ const queryParams = await loadSearchParams ( searchParams )
35
+
30
36
const team = await getTeamByAdGroupAndTeamId ( pageParams . groupId , pageParams . teamId )
31
37
if ( ! team ) {
32
38
return (
@@ -54,7 +60,7 @@ async function Page({ params }: Props): Promise<ReactElement> {
54
60
< OverallGraph teamId = { team . id } />
55
61
</ Suspense >
56
62
< Suspense fallback = { < Skeleton height = { 300 } variant = "rounded" /> } >
57
- < PerQuestionGraph teamId = { team . id } />
63
+ < PerQuestionGraph teamId = { team . id } showOld = { queryParams [ 'show-old' ] ?? false } />
58
64
</ Suspense >
59
65
</ div >
60
66
)
@@ -102,7 +108,7 @@ async function OverallGraph({ teamId }: { teamId: string }): Promise<ReactElemen
102
108
)
103
109
}
104
110
105
- async function PerQuestionGraph ( { teamId } : { teamId : string } ) : Promise < ReactElement > {
111
+ async function PerQuestionGraph ( { teamId, showOld } : { teamId : string ; showOld : boolean } ) : Promise < ReactElement > {
106
112
const teamMetrics = await getTeamScorePerQuestion ( teamId )
107
113
108
114
if ( 'error' in teamMetrics ) {
@@ -128,17 +134,24 @@ async function PerQuestionGraph({ teamId }: { teamId: string }): Promise<ReactEl
128
134
129
135
return (
130
136
< div >
131
- < Heading size = "medium" level = "3" >
132
- Score per spørsmål per uke
133
- </ Heading >
134
- < Detail >
135
- { teamMetrics . length } målinger siden Uke { getWeekNumber ( earliest . timestamp ) } ,{ ' ' }
136
- { earliest . timestamp . getFullYear ( ) }
137
- </ Detail >
137
+ < div className = "flex justify-between" >
138
+ < div >
139
+ < Heading size = "medium" level = "3" >
140
+ Score per spørsmål per uke
141
+ </ Heading >
142
+ < Detail >
143
+ { teamMetrics . length } målinger siden Uke { getWeekNumber ( earliest . timestamp ) } ,{ ' ' }
144
+ { earliest . timestamp . getFullYear ( ) }
145
+ </ Detail >
146
+ </ div >
147
+ < OnlyCurrentQuestionsToggle />
148
+ </ div >
138
149
< div className = "mt-4" >
139
- { teamMetrics . map ( ( it ) => (
140
- < ScorePerQuestion key = { it . question . questionId } question = { it . question } scoring = { it . scoring } />
141
- ) ) }
150
+ { teamMetrics
151
+ . filter ( ( it ) => ( showOld ? true : it . question . isCurrent ) )
152
+ . map ( ( it ) => (
153
+ < ScorePerQuestion key = { it . question . questionId } question = { it . question } scoring = { it . scoring } />
154
+ ) ) }
142
155
</ div >
143
156
</ div >
144
157
)
0 commit comments