22
33import { Card } from "@pythnetwork/component-library/Card" ;
44import { Paginator } from "@pythnetwork/component-library/Paginator" ;
5+ import { Switch } from "@pythnetwork/component-library/Switch" ;
56import {
67 type RowConfig ,
78 type SortDescriptor ,
89 Table ,
910} from "@pythnetwork/component-library/Table" ;
10- import { type ReactNode , Suspense , useMemo } from "react" ;
11+ import { type ReactNode , Suspense , useMemo , useState } from "react" ;
1112import { useFilter , useCollator } from "react-aria" ;
1213
1314import { useQueryParamFilterPagination } from "../../use-query-param-filter-pagination" ;
@@ -33,6 +34,7 @@ type PriceComponent = {
3334 deviationScore : number ;
3435 stalledPenalty : number ;
3536 stalledScore : number ;
37+ isTest : boolean ;
3638} ;
3739
3840export const PriceComponentsCard = ( {
@@ -56,6 +58,16 @@ const ResolvedPriceComponentsCard = ({
5658} : Props ) => {
5759 const collator = useCollator ( ) ;
5860 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+
5971 const {
6072 search,
6173 sortDescriptor,
@@ -70,7 +82,7 @@ const ResolvedPriceComponentsCard = ({
7082 numPages,
7183 mkPageLink,
7284 } = useQueryParamFilterPagination (
73- priceComponents ,
85+ filteredPriceComponents ,
7486 ( priceComponent , search ) =>
7587 filter . contains ( priceComponent . id , search ) ||
7688 ( priceComponent . publisherNameAsString !== undefined &&
@@ -181,6 +193,8 @@ const ResolvedPriceComponentsCard = ({
181193
182194 return (
183195 < PriceComponentsCardContents
196+ includeTestComponents = { includeTestComponents }
197+ setIncludeTestComponents = { setIncludeTestComponents }
184198 numResults = { numResults }
185199 search = { search }
186200 sortDescriptor = { sortDescriptor }
@@ -206,6 +220,8 @@ type PriceComponentsCardProps = Pick<
206220 | { isLoading : true }
207221 | {
208222 isLoading ?: false ;
223+ includeTestComponents : boolean ;
224+ setIncludeTestComponents : ( newValue : boolean ) => void ;
209225 numResults : number ;
210226 search : string ;
211227 sortDescriptor : SortDescriptor ;
@@ -237,6 +253,18 @@ const PriceComponentsCardContents = ({
237253 < Card
238254 className = { className }
239255 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+ }
240268 { ...( ! props . isLoading && {
241269 footer : (
242270 < Paginator
0 commit comments