@@ -49,7 +49,7 @@ export const InstructionGroups = React.memo(({ instructions, aliases, search }:
49
49
return acc ;
50
50
} , { } ) ;
51
51
return aliases . map ( ( alias ) => ( { ...alias , instruction : instructionsByMnemonic [ alias . alias_of ] } ) ) ;
52
- } , [ instructions ] ) ;
52
+ } , [ instructions , aliases ] ) ;
53
53
54
54
const searchValue = search . toLowerCase ( ) ;
55
55
@@ -58,43 +58,61 @@ export const InstructionGroups = React.memo(({ instructions, aliases, search }:
58
58
item . doc ?. opcode ?. toLowerCase ( ) ?. includes ( searchValue ) ||
59
59
item . doc ?. fift ?. toLowerCase ( ) ?. includes ( searchValue ) ||
60
60
item ?. doc ?. description ?. toLowerCase ( ) ?. includes ( searchValue ) ,
61
- ) , [ searchValue ] ) ;
61
+ ) , [ instructions , searchValue ] ) ;
62
62
63
63
const filteredAliases = useMemo ( ( ) => aliasesWithInstructions . filter (
64
64
( item ) =>
65
65
item . mnemonic ?. toLowerCase ( ) ?. includes ( searchValue ) ||
66
66
item . description ?. toLowerCase ( ) ?. includes ( searchValue ) ||
67
67
item . doc_fift ?. toLowerCase ( ) ?. includes ( searchValue ) ,
68
- ) , [ searchValue ] ) ;
68
+ ) , [ aliasesWithInstructions , searchValue ] ) ;
69
69
70
- return < Tabs >
71
- {
72
- sections . map ( ( { label, types, value } ) => {
70
+ const activeTab = useMemo ( ( ) => {
71
+ if ( filteredAliases . length > 0 && filteredInstructions . length === 0 ) {
72
+ return 'alias' ;
73
+ }
74
+ return 'all' ;
75
+ } , [ filteredAliases , filteredInstructions ] ) ;
76
+
77
+ return (
78
+ < Tabs key = { activeTab } defaultValue = { activeTab } >
79
+ { sections . map ( ( { label, types, value } ) => {
73
80
if ( value === 'alias' ) {
74
- return filteredAliases ?. length ? < TabItem label = { label } value = { value } key = { value } >
75
- < InstructionTable instructions = { filteredAliases . map ( ( alias ) => ( {
76
- opcode : alias . instruction ?. doc ?. opcode ,
77
- fift : alias . doc_fift ,
78
- gas : alias . instruction ?. doc ?. gas ,
79
- description : alias . description ,
80
- stack : alias . doc_stack ,
81
- } ) ) } />
82
- </ TabItem > : null ;
81
+ if ( ! filteredAliases . length ) return null ;
82
+ return (
83
+ < TabItem label = { label } value = { value } key = { value } >
84
+ < InstructionTable
85
+ instructions = { filteredAliases . map ( ( alias ) => ( {
86
+ opcode : alias . instruction ?. doc . opcode ,
87
+ fift : alias . doc_fift ,
88
+ gas : alias . instruction ?. doc . gas ,
89
+ description : alias . description ,
90
+ stack : alias . doc_stack ,
91
+ } ) ) }
92
+ />
93
+ </ TabItem >
94
+ ) ;
83
95
}
84
96
85
- const tabInstructions = types ? filteredInstructions . filter ( instruction => types . includes ( instruction . doc . category ) ) : filteredInstructions ;
86
- return ( tabInstructions ?. length ?
97
+ const tabInstructions = types
98
+ ? filteredInstructions . filter ( ( inst ) => types . includes ( inst . doc . category ) )
99
+ : filteredInstructions ;
100
+
101
+ if ( ! tabInstructions . length ) return null ;
102
+ return (
87
103
< TabItem label = { label } value = { value } key = { value } >
88
104
< InstructionTable
89
- instructions = { tabInstructions . map ( instruction => ( {
90
- opcode : instruction . doc ?. opcode ,
91
- fift : instruction . doc ?. fift ,
92
- gas : instruction . doc ?. gas ,
93
- description : instruction ?. doc . description ,
94
- stack : instruction . doc ?. stack ,
95
- } ) ) } />
96
- </ TabItem > : null ) ;
97
- } )
98
- }
99
- </ Tabs > ;
105
+ instructions = { tabInstructions . map ( ( inst ) => ( {
106
+ opcode : inst . doc . opcode ,
107
+ fift : inst . doc . fift ,
108
+ gas : inst . doc . gas ,
109
+ description : inst . doc . description ,
110
+ stack : inst . doc . stack ,
111
+ } ) ) }
112
+ />
113
+ </ TabItem >
114
+ ) ;
115
+ } ) }
116
+ </ Tabs >
117
+ ) ;
100
118
} ) ;
0 commit comments