@@ -25,13 +25,13 @@ import * as React from 'react';
25
25
import * as commonStorage from '../storage/common_storage' ;
26
26
import * as storageModule from '../storage/module' ;
27
27
import * as storageProject from '../storage/project' ;
28
- import { EditOutlined , DeleteOutlined , CopyOutlined , SelectOutlined } from '@ant-design/icons' ;
29
28
import ClassNameComponent from './ClassNameComponent' ;
29
+ import ManageTable from './ManageTable' ;
30
30
31
31
/** Represents a module in the file management system. */
32
32
interface Module {
33
33
path : string ;
34
- title : string ;
34
+ name : string ;
35
35
type : TabType ;
36
36
}
37
37
@@ -47,15 +47,9 @@ interface FileManageModalProps {
47
47
tabType : TabType ;
48
48
}
49
49
50
- /** Default page size for table pagination. */
51
- const DEFAULT_PAGE_SIZE = 5 ;
52
-
53
50
/** Modal width in pixels. */
54
51
const MODAL_WIDTH = 800 ;
55
52
56
- /** Actions column width in pixels. */
57
- const ACTIONS_COLUMN_WIDTH = 160 ;
58
-
59
53
/**
60
54
* Modal component for managing files (mechanisms and opmodes) within a project.
61
55
* Provides functionality to create, rename, copy, and delete modules.
@@ -86,19 +80,19 @@ export default function FileManageModal(props: FileManageModalProps) {
86
80
if ( props . tabType === TabType . MECHANISM ) {
87
81
moduleList = props . project . mechanisms . map ( ( m ) => ( {
88
82
path : m . modulePath ,
89
- title : m . className ,
83
+ name : m . className ,
90
84
type : TabType . MECHANISM ,
91
85
} ) ) ;
92
86
} else if ( props . tabType === TabType . OPMODE ) {
93
87
moduleList = props . project . opModes . map ( ( o ) => ( {
94
88
path : o . modulePath ,
95
- title : o . className ,
89
+ name : o . className ,
96
90
type : TabType . OPMODE ,
97
91
} ) ) ;
98
92
}
99
93
100
- // Sort modules alphabetically by title
101
- moduleList . sort ( ( a , b ) => a . title . localeCompare ( b . title ) ) ;
94
+ // Sort modules alphabetically by name
95
+ moduleList . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
102
96
setModules ( moduleList ) ;
103
97
} , [ props . project , props . tabType ] ) ;
104
98
@@ -163,7 +157,7 @@ export default function FileManageModal(props: FileManageModalProps) {
163
157
164
158
const newModule = {
165
159
path : newModulePath ,
166
- title : newClassName ,
160
+ name : newClassName ,
167
161
type : originalModule . type ,
168
162
} ;
169
163
@@ -208,7 +202,7 @@ export default function FileManageModal(props: FileManageModalProps) {
208
202
if ( newModule ) {
209
203
const module : Module = {
210
204
path : newModule . modulePath ,
211
- title : newModule . className ,
205
+ name : newModule . className ,
212
206
type : props . tabType ,
213
207
} ;
214
208
setModules ( [ ...modules , module ] ) ;
@@ -237,105 +231,26 @@ export default function FileManageModal(props: FileManageModalProps) {
237
231
}
238
232
} ;
239
233
240
- /** Handles button click events to prevent row selection. */
241
- const handleButtonClick = ( e : React . MouseEvent ) : void => {
242
- e . stopPropagation ( ) ;
243
- } ;
244
-
245
- /** Handles row double-click to open module in tab. */
246
- const handleRowDoubleClick = ( record : Module ) : void => {
234
+ /** Handles selection to open module in tab. */
235
+ const handleSelect = ( record : Module ) : void => {
247
236
props . gotoTab ( record . path ) ;
248
237
props . onClose ( ) ;
249
238
} ;
250
239
251
240
/** Opens the rename modal for a specific module. */
252
241
const openRenameModal = ( record : Module ) : void => {
253
242
setCurrentRecord ( record ) ;
254
- setName ( record . title ) ;
243
+ setName ( record . name ) ;
255
244
setRenameModalOpen ( true ) ;
256
245
} ;
257
246
258
247
/** Opens the copy modal for a specific module. */
259
248
const openCopyModal = ( record : Module ) : void => {
260
249
setCurrentRecord ( record ) ;
261
- setName ( t ( 'COPY_SUFFIX' , { name : record . title } ) ) ;
250
+ setName ( t ( 'COPY_SUFFIX' , { name : record . name } ) ) ;
262
251
setCopyModalOpen ( true ) ;
263
252
} ;
264
253
265
- /** Table column configuration. */
266
- const columns : Antd . TableProps < Module > [ 'columns' ] = [
267
- {
268
- title : t ( 'NAME' ) ,
269
- dataIndex : 'title' ,
270
- key : 'title' ,
271
- ellipsis : {
272
- showTitle : false ,
273
- } ,
274
- render : ( title : string ) => (
275
- < Antd . Tooltip title = { title } >
276
- { title }
277
- </ Antd . Tooltip >
278
- ) ,
279
- } ,
280
- {
281
- title : t ( 'ACTIONS' ) ,
282
- key : 'actions' ,
283
- width : ACTIONS_COLUMN_WIDTH ,
284
- render : ( _ , record : Module ) => (
285
- < Antd . Space size = "small" >
286
- < Antd . Tooltip title = { t ( 'Select' ) } >
287
- < Antd . Button
288
- type = "text"
289
- size = "small"
290
- icon = { < SelectOutlined /> }
291
- onClick = { ( ) => handleRowDoubleClick ( record ) }
292
- />
293
- </ Antd . Tooltip >
294
- < Antd . Tooltip title = { t ( 'RENAME' ) } >
295
- < Antd . Button
296
- type = "text"
297
- size = "small"
298
- icon = { < EditOutlined /> }
299
- onClick = { ( e ) => {
300
- handleButtonClick ( e ) ;
301
- openRenameModal ( record ) ;
302
- } }
303
- />
304
- </ Antd . Tooltip >
305
- < Antd . Tooltip title = { t ( 'COPY' ) } >
306
- < Antd . Button
307
- type = "text"
308
- size = "small"
309
- icon = { < CopyOutlined /> }
310
- onClick = { ( e ) => {
311
- handleButtonClick ( e ) ;
312
- openCopyModal ( record ) ;
313
- } }
314
- />
315
- </ Antd . Tooltip >
316
- < Antd . Tooltip title = { t ( 'Delete' ) } >
317
- < Antd . Popconfirm
318
- title = { t ( 'DELETE_MODULE_CONFIRM' , { title : record . title } ) }
319
- description = { t ( 'DELETE_CANNOT_BE_UNDONE' ) }
320
- onConfirm = { ( ) => handleDeleteConfirm ( record ) }
321
- okText = { t ( 'Delete' ) }
322
- cancelText = { t ( 'Cancel' ) }
323
- okType = "danger"
324
- >
325
- < Antd . Button
326
- type = "text"
327
- size = "small"
328
- icon = { < DeleteOutlined /> }
329
- danger
330
- onClick = { handleButtonClick }
331
- />
332
- </ Antd . Popconfirm >
333
- </ Antd . Tooltip >
334
- </ Antd . Space >
335
- ) ,
336
- } ,
337
- ] ;
338
-
339
254
/** Gets the modal title based on module type. */
340
255
const getModalTitle = ( ) : string => {
341
256
return t ( 'TYPE_MANAGEMENT' , { type : TabTypeUtils . toString ( props . tabType ) } ) ;
@@ -348,7 +263,7 @@ export default function FileManageModal(props: FileManageModalProps) {
348
263
}
349
264
return t ( 'RENAME_TYPE_TITLE' , {
350
265
type : TabTypeUtils . toString ( currentRecord . type ) ,
351
- title : currentRecord . title
266
+ title : currentRecord . name
352
267
} ) ;
353
268
} ;
354
269
@@ -359,7 +274,7 @@ export default function FileManageModal(props: FileManageModalProps) {
359
274
}
360
275
return t ( 'COPY_TYPE_TITLE' , {
361
276
type : TabTypeUtils . toString ( currentRecord . type ) ,
362
- title : currentRecord . title
277
+ title : currentRecord . name
363
278
} ) ;
364
279
} ;
365
280
@@ -369,6 +284,14 @@ export default function FileManageModal(props: FileManageModalProps) {
369
284
return t ( 'NO_FILES_FOUND' , { type : tabTypeString . toLowerCase ( ) } ) ;
370
285
} ;
371
286
287
+ const getModuleFromName = ( name : string ) : Module => {
288
+ const module = modules . find ( ( m ) => m . name === name ) ;
289
+ if ( ! module ) {
290
+ throw new Error ( 'Module not found for name: ' + name ) ;
291
+ }
292
+ return module ;
293
+ }
294
+
372
295
return (
373
296
< >
374
297
< Antd . Modal
@@ -436,27 +359,17 @@ export default function FileManageModal(props: FileManageModalProps) {
436
359
footer = { null }
437
360
width = { MODAL_WIDTH }
438
361
>
439
- < Antd . Table < Module >
440
- columns = { columns }
441
- dataSource = { modules }
442
- rowKey = "path"
443
- size = "small"
444
- pagination = { modules . length > DEFAULT_PAGE_SIZE ? {
445
- pageSize : DEFAULT_PAGE_SIZE ,
446
- showSizeChanger : false ,
447
- showQuickJumper : false ,
448
- showTotal : ( total , range ) =>
449
- t ( 'PAGINATION_TOTAL' , { start : range [ 0 ] , end : range [ 1 ] , total } ) ,
450
- } : false }
451
- bordered
452
- locale = { {
453
- emptyText : getEmptyText ( ) ,
454
- } }
455
- onRow = { ( record ) => ( {
456
- onDoubleClick : ( ) => handleRowDoubleClick ( record ) ,
457
- } ) }
458
- />
459
- < br />
362
+ < ManageTable
363
+ textOnEmpty = { getEmptyText ( ) }
364
+ records = { modules }
365
+ showDelete = { true }
366
+ deleteDialogTitle = "DELETE_PROJECT_CONFIRM"
367
+ onSelect = { ( record ) => handleSelect ( getModuleFromName ( record . name ) ) }
368
+ onRename = { ( record ) => openRenameModal ( getModuleFromName ( record . name ) ) }
369
+ onCopy = { ( record ) => openCopyModal ( getModuleFromName ( record . name ) ) }
370
+ onDelete = { ( record ) => handleDeleteConfirm ( getModuleFromName ( record . name ) ) }
371
+ />
372
+ < br />
460
373
< h4 style = { { margin : '0 0 8px 0' } } >
461
374
{ t ( 'CREATE_NEW' , { type : TabTypeUtils . toString ( props . tabType ) } ) }
462
375
</ h4 >
0 commit comments