Skip to content

Commit eb2b355

Browse files
Fix download for 3rd depth level subcircuits (#333)
* Removed the component of search bar and filter options * Removed the file filtering-circuits * Created a function to find circuits everywhere it is in the tree * Ran prettier --------- Co-authored-by: Loris Olivier <53363974+loris-maru@users.noreply.github.com>
1 parent 3ca87aa commit eb2b355

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

src/components/explore-section/Circuit/global/CircuitTable.tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@ export type CustomRowProps = {
2525
'data-row-key'?: string;
2626
};
2727

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+
2846
function RowWrapper({
2947
handleExpandRow,
3048
expandedRowKeys,
@@ -134,11 +152,11 @@ export default function CircuitTable({
134152
);
135153
}, []);
136154

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]);
142160

143161
const renderSubcircuits = useCallback(
144162
(circuit: CircuitSchemaProps) =>

src/components/explore-section/Circuit/global/SubcircuitsTable.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ export type SubcircuitsTableProps = {
1414
mergedColumns: ColumnsType<CircuitSchemaProps>;
1515
rowSelection: TableRowSelection<CircuitSchemaProps>;
1616
expandedRowKeys: Key[];
17-
onExpand: (expanded: boolean, row: CircuitSchemaProps) => void;
1817
downloadable: boolean;
19-
handleExpandRow?: (expanded: boolean, row: CircuitSchemaProps) => void;
18+
onExpand?: (expanded: boolean, row: CircuitSchemaProps) => void;
2019
selectedRows: CircuitSchemaProps[];
2120
selectedRowKeys: string[];
2221
};
@@ -26,9 +25,8 @@ export default function SubcircuitTable({
2625
mergedColumns,
2726
rowSelection,
2827
expandedRowKeys,
29-
onExpand,
3028
downloadable = true,
31-
handleExpandRow,
29+
onExpand,
3230
selectedRows,
3331
selectedRowKeys,
3432
}: SubcircuitsTableProps) {
@@ -76,7 +74,7 @@ export default function SubcircuitTable({
7674
expandable={{
7775
expandedRowRender: renderSubcircuits,
7876
expandedRowKeys,
79-
onExpand: handleExpandRow,
77+
onExpand,
8078
expandIcon: () => null,
8179
rowExpandable: (record) => !!record.subcircuits && record.subcircuits.length > 0,
8280
}}

0 commit comments

Comments
 (0)