File tree Expand file tree Collapse file tree 2 files changed +26
-10
lines changed
src/components/explore-section/Circuit/global Expand file tree Collapse file tree 2 files changed +26
-10
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,24 @@ export type CustomRowProps = {
25
25
'data-row-key' ?: string ;
26
26
} ;
27
27
28
+ function findSelectedCircuit (
29
+ circuits : CircuitSchemaProps [ ] ,
30
+ key : string
31
+ ) : CircuitSchemaProps | null {
32
+ for ( const circuit of circuits ) {
33
+ if ( circuit . key === key ) {
34
+ return circuit ;
35
+ }
36
+ if ( circuit . subcircuits ) {
37
+ const found = findSelectedCircuit ( circuit . subcircuits , key ) ;
38
+ if ( found ) {
39
+ return found ;
40
+ }
41
+ }
42
+ }
43
+ return null ;
44
+ }
45
+
28
46
function RowWrapper ( {
29
47
handleExpandRow,
30
48
expandedRowKeys,
@@ -134,11 +152,11 @@ export default function CircuitTable({
134
152
) ;
135
153
} , [ ] ) ;
136
154
137
- const selectedRows = data . flatMap ( ( circuit ) =>
138
- circuit . key === selectedRowKeys [ 0 ]
139
- ? [ circuit ]
140
- : ( circuit . subcircuits || [ ] ) . filter ( ( sub ) => sub . key === selectedRowKeys [ 0 ] )
141
- ) ;
155
+ const selectedRows = useMemo ( ( ) => {
156
+ if ( ! selectedRowKeys [ 0 ] ) return [ ] ;
157
+ const selectedCircuit = findSelectedCircuit ( data , selectedRowKeys [ 0 ] ) ;
158
+ return selectedCircuit ? [ selectedCircuit ] : [ ] ;
159
+ } , [ data , selectedRowKeys ] ) ;
142
160
143
161
const renderSubcircuits = useCallback (
144
162
( circuit : CircuitSchemaProps ) =>
Original file line number Diff line number Diff line change @@ -14,9 +14,8 @@ export type SubcircuitsTableProps = {
14
14
mergedColumns : ColumnsType < CircuitSchemaProps > ;
15
15
rowSelection : TableRowSelection < CircuitSchemaProps > ;
16
16
expandedRowKeys : Key [ ] ;
17
- onExpand : ( expanded : boolean , row : CircuitSchemaProps ) => void ;
18
17
downloadable : boolean ;
19
- handleExpandRow ?: ( expanded : boolean , row : CircuitSchemaProps ) => void ;
18
+ onExpand ?: ( expanded : boolean , row : CircuitSchemaProps ) => void ;
20
19
selectedRows : CircuitSchemaProps [ ] ;
21
20
selectedRowKeys : string [ ] ;
22
21
} ;
@@ -26,9 +25,8 @@ export default function SubcircuitTable({
26
25
mergedColumns,
27
26
rowSelection,
28
27
expandedRowKeys,
29
- onExpand,
30
28
downloadable = true ,
31
- handleExpandRow ,
29
+ onExpand ,
32
30
selectedRows,
33
31
selectedRowKeys,
34
32
} : SubcircuitsTableProps ) {
@@ -76,7 +74,7 @@ export default function SubcircuitTable({
76
74
expandable = { {
77
75
expandedRowRender : renderSubcircuits ,
78
76
expandedRowKeys,
79
- onExpand : handleExpandRow ,
77
+ onExpand,
80
78
expandIcon : ( ) => null ,
81
79
rowExpandable : ( record ) => ! ! record . subcircuits && record . subcircuits . length > 0 ,
82
80
} }
You can’t perform that action at this time.
0 commit comments