@@ -115,11 +115,18 @@ const TIER_SVG_COLORS: Record<string, { filled: string; outline: string }> = {
115115 sandbox : { filled : '#f0ab00' , outline : '#f0ab00' } ,
116116} ;
117117
118- function TierIcon ( { tier } : { tier : string } ) {
119- const colors = TIER_SVG_COLORS [ tier ] || TIER_SVG_COLORS . sandbox ;
120- // 3 horizontal bars: bottom=bar1, middle=bar2, top=bar3
121- // maintained: all 3 filled; tested: 2 filled + 1 outline; sandbox: 1 filled + 2 outline
122- const filledCount = tier === 'maintained' ? 3 : tier === 'tested' ? 2 : 1 ;
118+ const KNOWN_TIER_ORDER = [ 'maintained' , 'tested' , 'sandbox' ] ;
119+
120+ const TIER_FILLED_BARS : Record < string , number > = {
121+ maintained : 3 ,
122+ tested : 2 ,
123+ sandbox : 1 ,
124+ } ;
125+
126+ function TierIcon ( { tier } : { tier : string } ) : React . ReactElement | null {
127+ const colors = TIER_SVG_COLORS [ tier ] ;
128+ if ( ! colors ) return null ;
129+ const filledCount = TIER_FILLED_BARS [ tier ] ?? 1 ;
123130 return (
124131 < svg
125132 width = "16"
@@ -167,7 +174,7 @@ export default function PatternCatalogPage() {
167174 const [ catalogImage , setCatalogImage ] = React . useState < string | null > ( null ) ;
168175 const [ catalogDescription , setCatalogDescription ] = React . useState < string | undefined > ( ) ;
169176 const [ catalogLogo , setCatalogLogo ] = React . useState < string | undefined > ( ) ;
170- const [ selectedTiers , setSelectedTiers ] = React . useState < Set < string > > ( new Set ( [ 'maintained' ] ) ) ;
177+ const [ selectedTiers , setSelectedTiers ] = React . useState < Set < string > > ( new Set ( ) ) ;
171178 const [ tierSelectOpen , setTierSelectOpen ] = React . useState ( false ) ;
172179
173180 const loadData = React . useCallback ( ( ) => {
@@ -191,6 +198,29 @@ export default function PatternCatalogPage() {
191198 loadData ( ) ;
192199 } , [ loadData ] ) ;
193200
201+ const availableTiers = React . useMemo ( ( ) => {
202+ const tierSet = new Set ( patterns . map ( ( p ) => p . tier ) ) ;
203+ return Array . from ( tierSet ) . sort ( ( a , b ) => {
204+ const ai = KNOWN_TIER_ORDER . indexOf ( a ) ;
205+ const bi = KNOWN_TIER_ORDER . indexOf ( b ) ;
206+ if ( ai !== - 1 && bi !== - 1 ) return ai - bi ;
207+ if ( ai !== - 1 ) return - 1 ;
208+ if ( bi !== - 1 ) return 1 ;
209+ return a . localeCompare ( b , undefined , { sensitivity : 'base' } ) ;
210+ } ) ;
211+ } , [ patterns ] ) ;
212+
213+ const defaultsApplied = React . useRef ( false ) ;
214+ React . useEffect ( ( ) => {
215+ if ( defaultsApplied . current || availableTiers . length === 0 ) return ;
216+ defaultsApplied . current = true ;
217+ if ( availableTiers . includes ( 'maintained' ) ) {
218+ setSelectedTiers ( new Set ( [ 'maintained' ] ) ) ;
219+ } else {
220+ setSelectedTiers ( new Set ( availableTiers ) ) ;
221+ }
222+ } , [ availableTiers ] ) ;
223+
194224 const filteredPatterns = React . useMemo (
195225 ( ) => ( selectedTiers . size === 0 ? patterns : patterns . filter ( ( p ) => selectedTiers . has ( p . tier ) ) ) ,
196226 [ patterns , selectedTiers ] ,
@@ -284,7 +314,7 @@ export default function PatternCatalogPage() {
284314 ) }
285315 >
286316 < SelectList >
287- { [ 'maintained' , 'tested' , 'sandbox' ] . map ( ( tier ) => (
317+ { availableTiers . map ( ( tier ) => (
288318 < SelectOption
289319 key = { tier }
290320 value = { tier }
@@ -315,7 +345,11 @@ export default function PatternCatalogPage() {
315345 < Tooltip content = { TIER_DESCRIPTIONS [ pattern . tier ] || pattern . tier } >
316346 < Label
317347 color = { TIER_COLORS [ pattern . tier ] || 'grey' }
318- icon = { < TierIcon tier = { pattern . tier } /> }
348+ icon = {
349+ TIER_SVG_COLORS [ pattern . tier ] ? (
350+ < TierIcon tier = { pattern . tier } />
351+ ) : undefined
352+ }
319353 >
320354 { pattern . tier }
321355 </ Label >
0 commit comments