1
1
import { Table } from 'antd' ;
2
- import { ColumnsType } from 'antd/es/table' ;
3
- import { TableRowSelection } from 'antd/es/table/interface' ;
4
2
import { usePathname } from 'next/navigation' ;
5
- import { Key , ReactNode , useCallback , useMemo , useState } from 'react' ;
6
- import { ResizeCallbackData } from 'react-resizable' ;
3
+ import { Key , ReactNode , useCallback , useState } from 'react' ;
7
4
import { CircuitSchemaProps } from '../type' ;
8
5
import calculateSubcircuitsForParent from '../utils/calculate-subcircuits-for-parent' ;
9
6
import columns from './Columns' ;
10
- import CustomRow from './CustomRow' ;
11
- import DownloadCircuitButton from './DownloadCircuitButton' ;
12
- import ResizableTitle from './ResizableTitle' ;
13
7
import SubcircuitTable from './SubcircuitsTable' ;
8
+ import DownloadContainer from './download/DownloadContainer' ;
14
9
10
+ import { classNames } from '@/util/utils' ;
15
11
import styles from './exploreCircuitTable.module.scss' ;
16
12
17
13
export type CustomRowProps = {
@@ -25,45 +21,6 @@ export type CustomRowProps = {
25
21
'data-row-key' ?: string ;
26
22
} ;
27
23
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
-
46
- function RowWrapper ( {
47
- handleExpandRow,
48
- expandedRowKeys,
49
- mergedColumns,
50
- ...props
51
- } : CustomRowProps & {
52
- handleExpandRow : ( expanded : boolean , record : CircuitSchemaProps ) => void ;
53
- expandedRowKeys : Key [ ] ;
54
- mergedColumns : ColumnsType < CircuitSchemaProps > ;
55
- } ) {
56
- return (
57
- < CustomRow
58
- // eslint-disable-next-line react/jsx-props-no-spreading
59
- { ...props }
60
- handleExpandRow = { handleExpandRow }
61
- expandedRowKeys = { expandedRowKeys }
62
- columnCount = { mergedColumns . length }
63
- />
64
- ) ;
65
- }
66
-
67
24
export default function CircuitTable ( {
68
25
data,
69
26
downloadable = true ,
@@ -73,19 +30,10 @@ export default function CircuitTable({
73
30
downloadable ?: boolean ;
74
31
// hasSearch?: boolean;
75
32
} ) {
76
- // ROWS
33
+ const [ circuitToDownload , setCircuitToDownload ] = useState < CircuitSchemaProps | null > ( null ) ;
34
+ const [ downloadModalOpen , SetDownloadModalOpen ] = useState < boolean > ( false ) ;
35
+
77
36
const [ expandedRowKeys , setExpandedRowKeys ] = useState < Key [ ] > ( [ ] ) ;
78
- const [ selectedRowKeys , setSelectedRowKeys ] = useState < string [ ] > ( [ ] ) ;
79
- const [ columnWidths , setColumnWidths ] = useState < Record < string , number > > ( {
80
- name : 150 ,
81
- description : 300 ,
82
- brainRegion : 150 ,
83
- numberOfNeurons : 100 ,
84
- specie : 120 ,
85
- contributorSimple : 150 ,
86
- registrationDate : 150 ,
87
- hasSubcircuits : 120 ,
88
- } ) ;
89
37
90
38
// FILTERING
91
39
// const [searchQuery, setSearchQuery] = useState<string>('');
@@ -102,100 +50,57 @@ export default function CircuitTable({
102
50
) ;
103
51
} , [ ] ) ;
104
52
105
- const handleResize = useCallback (
106
- ( key : string ) =>
107
- ( e : React . SyntheticEvent , { size } : ResizeCallbackData ) => {
108
- setColumnWidths ( ( prev ) => {
109
- const newWidths = { ...prev , [ key ] : size . width } ;
110
- return newWidths ;
111
- } ) ;
112
- } ,
113
- [ ]
114
- ) ;
115
-
116
53
const pathname = usePathname ( ) ;
117
54
const isCircuitDetailPage = pathname . includes ( '/circuit/' ) ;
118
55
119
- const mergedColumns : ColumnsType < CircuitSchemaProps > = useMemo ( ( ) => {
120
- return columns (
121
- expandedRowKeys ,
122
- calculateSubcircuitsForParent ,
123
- handleRowExpandClick ,
124
- handleResize ,
125
- isCircuitDetailPage
126
- ) . map ( ( col ) => ( {
127
- ...col ,
128
- width : columnWidths [ col . key as string ] || col . width ,
129
- } ) ) ;
130
- } , [ expandedRowKeys , handleRowExpandClick , handleResize , columnWidths , isCircuitDetailPage ] ) ;
56
+ // DOWNLOAD MODAL
57
+ const handleOpenDownloadModal = useCallback ( ( record : CircuitSchemaProps ) => {
58
+ setCircuitToDownload ( record ) ;
59
+ SetDownloadModalOpen ( true ) ;
60
+ } , [ ] ) ;
131
61
132
- const rowSelection = useMemo (
133
- ( ) : TableRowSelection < CircuitSchemaProps > | undefined =>
134
- downloadable
135
- ? {
136
- type : 'checkbox' ,
137
- selectedRowKeys,
138
- onChange : ( newSelectedRowKeys : Key [ ] , _selectedRows : CircuitSchemaProps [ ] ) => {
139
- const key = newSelectedRowKeys [ 0 ] as string ;
140
- const updatedKeys = selectedRowKeys [ 0 ] === key ? [ ] : [ key ] ;
141
- setSelectedRowKeys ( updatedKeys ) ;
142
- } ,
143
- }
144
- : undefined ,
145
- [ selectedRowKeys , downloadable ]
146
- ) ;
62
+ const handleCloseDownloadModal = useCallback ( ( ) => {
63
+ setCircuitToDownload ( null ) ;
64
+ SetDownloadModalOpen ( false ) ;
65
+ } , [ ] ) ;
147
66
67
+ // ROW EXPANSION & SUBCIRCUITS
148
68
const handleExpandRow = useCallback ( ( expanded : boolean , row : CircuitSchemaProps ) => {
149
69
const rowKey = row . key ;
150
70
setExpandedRowKeys ( ( prev ) =>
151
71
expanded ? [ ...prev , rowKey ] : prev . filter ( ( key ) => key !== rowKey )
152
72
) ;
153
73
} , [ ] ) ;
154
74
155
- const selectedRows = useMemo ( ( ) => {
156
- if ( ! selectedRowKeys [ 0 ] ) return [ ] ;
157
- const selectedCircuit = findSelectedCircuit ( data , selectedRowKeys [ 0 ] ) ;
158
- return selectedCircuit ? [ selectedCircuit ] : [ ] ;
159
- } , [ data , selectedRowKeys ] ) ;
160
-
161
75
const renderSubcircuits = useCallback (
162
76
( circuit : CircuitSchemaProps ) =>
163
77
circuit . subcircuits && circuit . subcircuits . length > 0 ? (
164
78
< SubcircuitTable
79
+ columns = { columns (
80
+ expandedRowKeys ,
81
+ calculateSubcircuitsForParent ,
82
+ handleRowExpandClick ,
83
+ isCircuitDetailPage ,
84
+ handleOpenDownloadModal
85
+ ) }
165
86
circuit = { circuit }
166
- mergedColumns = { mergedColumns }
167
- rowSelection = { rowSelection || ( { } as TableRowSelection < CircuitSchemaProps > ) }
168
87
expandedRowKeys = { expandedRowKeys }
169
88
onExpand = { handleExpandRow }
170
89
downloadable = { downloadable }
171
- selectedRows = { selectedRows }
172
- selectedRowKeys = { selectedRowKeys }
173
90
/>
174
91
) : null ,
175
92
[
176
- mergedColumns ,
177
- rowSelection ,
178
93
expandedRowKeys ,
179
94
handleExpandRow ,
180
95
downloadable ,
181
- selectedRowKeys ,
182
- selectedRows ,
96
+ handleOpenDownloadModal ,
97
+ handleRowExpandClick ,
98
+ isCircuitDetailPage ,
183
99
]
184
100
) ;
185
101
186
- const rowWrapperWithColumns = ( props : CustomRowProps ) => (
187
- // eslint-disable-next-line react/jsx-props-no-spreading
188
- < RowWrapper
189
- // eslint-disable-next-line react/jsx-props-no-spreading
190
- { ...props }
191
- handleExpandRow = { handleExpandRow }
192
- expandedRowKeys = { expandedRowKeys }
193
- mergedColumns = { mergedColumns }
194
- />
195
- ) ;
196
-
197
- const lastRow = selectedRows . at ( - 1 ) ;
198
- const fileUrl = lastRow ?. files ?. [ 0 ] ?. url ;
102
+ // const lastRow: CircuitSchemaProps | undefined = selectedRows.at(-1);
103
+ // const fileUrl = lastRow?.files?.[0]?.url;
199
104
200
105
return (
201
106
< div className = "relative flex w-full flex-col" >
@@ -221,19 +126,15 @@ export default function CircuitTable({
221
126
'--ant-table-expand-icon-col-width' : '0px' ,
222
127
} as React . CSSProperties
223
128
}
224
- data-row-selection = { downloadable && downloadable . toString ( ) }
225
- components = { {
226
- header : {
227
- cell : ResizableTitle ,
228
- } ,
229
- body : {
230
- row : rowWrapperWithColumns ,
231
- } ,
232
- } }
233
129
dataSource = { data }
234
- columns = { mergedColumns }
130
+ columns = { columns (
131
+ expandedRowKeys ,
132
+ calculateSubcircuitsForParent ,
133
+ handleRowExpandClick ,
134
+ isCircuitDetailPage ,
135
+ handleOpenDownloadModal
136
+ ) }
235
137
pagination = { false }
236
- rowSelection = { downloadable ? rowSelection : undefined }
237
138
expandable = { {
238
139
expandedRowRender : renderSubcircuits ,
239
140
expandedRowKeys,
@@ -242,8 +143,29 @@ export default function CircuitTable({
242
143
rowExpandable : ( record ) => ! ! record . subcircuits && record . subcircuits . length > 0 ,
243
144
} }
244
145
/>
245
- { fileUrl && < DownloadCircuitButton fileUrl = { fileUrl } selectedRowKeys = { selectedRowKeys } /> }
146
+ { /* { fileUrl && <DownloadCircuitButton fileUrl={fileUrl} selectedRowKeys={selectedRowKeys} /> } */ }
246
147
</ div >
148
+ < >
149
+ < div
150
+ className = { classNames (
151
+ 'out-expo fixed bottom-3 z-[999999] h-screen w-[44vw] overflow-y-scroll bg-primary-9 p-8 transition-right duration-500' ,
152
+ downloadModalOpen ? 'right-0' : '-right-full'
153
+ ) }
154
+ >
155
+ { circuitToDownload !== null && (
156
+ < DownloadContainer
157
+ content = { circuitToDownload }
158
+ handleCloseDownloadModal = { handleCloseDownloadModal }
159
+ />
160
+ ) }
161
+ </ div >
162
+ < div
163
+ className = { classNames (
164
+ 'fixed left-0 top-0 z-[999998] h-screen w-screen bg-black transition-opacity duration-500 ease-out-back' ,
165
+ downloadModalOpen ? 'opacity-50' : 'pointer-events-none opacity-0'
166
+ ) }
167
+ />
168
+ </ >
247
169
</ div >
248
170
</ div >
249
171
) ;
0 commit comments