2
2
3
3
import { Card } from "@pythnetwork/component-library/Card" ;
4
4
import { Paginator } from "@pythnetwork/component-library/Paginator" ;
5
+ import { Switch } from "@pythnetwork/component-library/Switch" ;
5
6
import {
6
7
type RowConfig ,
7
8
type SortDescriptor ,
8
9
Table ,
9
10
} from "@pythnetwork/component-library/Table" ;
10
- import { type ReactNode , Suspense , useMemo } from "react" ;
11
+ import { type ReactNode , Suspense , useMemo , useState } from "react" ;
11
12
import { useFilter , useCollator } from "react-aria" ;
12
13
13
14
import { useQueryParamFilterPagination } from "../../use-query-param-filter-pagination" ;
@@ -33,6 +34,7 @@ type PriceComponent = {
33
34
deviationScore : number ;
34
35
stalledPenalty : number ;
35
36
stalledScore : number ;
37
+ isTest : boolean ;
36
38
} ;
37
39
38
40
export const PriceComponentsCard = ( {
@@ -56,6 +58,16 @@ const ResolvedPriceComponentsCard = ({
56
58
} : Props ) => {
57
59
const collator = useCollator ( ) ;
58
60
const filter = useFilter ( { sensitivity : "base" , usage : "search" } ) ;
61
+ const [ includeTestComponents , setIncludeTestComponents ] = useState ( false ) ;
62
+
63
+ const filteredPriceComponents = useMemo (
64
+ ( ) =>
65
+ includeTestComponents
66
+ ? priceComponents
67
+ : priceComponents . filter ( ( component ) => ! component . isTest ) ,
68
+ [ includeTestComponents , priceComponents ] ,
69
+ ) ;
70
+
59
71
const {
60
72
search,
61
73
sortDescriptor,
@@ -70,7 +82,7 @@ const ResolvedPriceComponentsCard = ({
70
82
numPages,
71
83
mkPageLink,
72
84
} = useQueryParamFilterPagination (
73
- priceComponents ,
85
+ filteredPriceComponents ,
74
86
( priceComponent , search ) =>
75
87
filter . contains ( priceComponent . id , search ) ||
76
88
( priceComponent . publisherNameAsString !== undefined &&
@@ -181,6 +193,8 @@ const ResolvedPriceComponentsCard = ({
181
193
182
194
return (
183
195
< PriceComponentsCardContents
196
+ includeTestComponents = { includeTestComponents }
197
+ setIncludeTestComponents = { setIncludeTestComponents }
184
198
numResults = { numResults }
185
199
search = { search }
186
200
sortDescriptor = { sortDescriptor }
@@ -206,6 +220,8 @@ type PriceComponentsCardProps = Pick<
206
220
| { isLoading : true }
207
221
| {
208
222
isLoading ?: false ;
223
+ includeTestComponents : boolean ;
224
+ setIncludeTestComponents : ( newValue : boolean ) => void ;
209
225
numResults : number ;
210
226
search : string ;
211
227
sortDescriptor : SortDescriptor ;
@@ -237,6 +253,18 @@ const PriceComponentsCardContents = ({
237
253
< Card
238
254
className = { className }
239
255
title = "Price components"
256
+ toolbar = {
257
+ < Switch
258
+ { ...( props . isLoading
259
+ ? { isPending : true }
260
+ : {
261
+ isSelected : props . includeTestComponents ,
262
+ onChange : props . setIncludeTestComponents ,
263
+ } ) }
264
+ >
265
+ Show test components
266
+ </ Switch >
267
+ }
240
268
{ ...( ! props . isLoading && {
241
269
footer : (
242
270
< Paginator
0 commit comments