@@ -25,13 +25,13 @@ import * as React from 'react';
2525import * as commonStorage from '../storage/common_storage' ;
2626import * as storageModule from '../storage/module' ;
2727import * as storageProject from '../storage/project' ;
28- import { EditOutlined , DeleteOutlined , CopyOutlined , SelectOutlined } from '@ant-design/icons' ;
2928import ClassNameComponent from './ClassNameComponent' ;
29+ import ManageTable from './ManageTable' ;
3030
3131/** Represents a module in the file management system. */
3232interface Module {
3333 path : string ;
34- title : string ;
34+ name : string ;
3535 type : TabType ;
3636}
3737
@@ -47,15 +47,9 @@ interface FileManageModalProps {
4747 tabType : TabType ;
4848}
4949
50- /** Default page size for table pagination. */
51- const DEFAULT_PAGE_SIZE = 5 ;
52-
5350/** Modal width in pixels. */
5451const MODAL_WIDTH = 800 ;
5552
56- /** Actions column width in pixels. */
57- const ACTIONS_COLUMN_WIDTH = 160 ;
58-
5953/**
6054 * Modal component for managing files (mechanisms and opmodes) within a project.
6155 * Provides functionality to create, rename, copy, and delete modules.
@@ -86,19 +80,19 @@ export default function FileManageModal(props: FileManageModalProps) {
8680 if ( props . tabType === TabType . MECHANISM ) {
8781 moduleList = props . project . mechanisms . map ( ( m ) => ( {
8882 path : m . modulePath ,
89- title : m . className ,
83+ name : m . className ,
9084 type : TabType . MECHANISM ,
9185 } ) ) ;
9286 } else if ( props . tabType === TabType . OPMODE ) {
9387 moduleList = props . project . opModes . map ( ( o ) => ( {
9488 path : o . modulePath ,
95- title : o . className ,
89+ name : o . className ,
9690 type : TabType . OPMODE ,
9791 } ) ) ;
9892 }
9993
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 ) ) ;
10296 setModules ( moduleList ) ;
10397 } , [ props . project , props . tabType ] ) ;
10498
@@ -163,7 +157,7 @@ export default function FileManageModal(props: FileManageModalProps) {
163157
164158 const newModule = {
165159 path : newModulePath ,
166- title : newClassName ,
160+ name : newClassName ,
167161 type : originalModule . type ,
168162 } ;
169163
@@ -208,7 +202,7 @@ export default function FileManageModal(props: FileManageModalProps) {
208202 if ( newModule ) {
209203 const module : Module = {
210204 path : newModule . modulePath ,
211- title : newModule . className ,
205+ name : newModule . className ,
212206 type : props . tabType ,
213207 } ;
214208 setModules ( [ ...modules , module ] ) ;
@@ -237,105 +231,26 @@ export default function FileManageModal(props: FileManageModalProps) {
237231 }
238232 } ;
239233
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 => {
247236 props . gotoTab ( record . path ) ;
248237 props . onClose ( ) ;
249238 } ;
250239
251240 /** Opens the rename modal for a specific module. */
252241 const openRenameModal = ( record : Module ) : void => {
253242 setCurrentRecord ( record ) ;
254- setName ( record . title ) ;
243+ setName ( record . name ) ;
255244 setRenameModalOpen ( true ) ;
256245 } ;
257246
258247 /** Opens the copy modal for a specific module. */
259248 const openCopyModal = ( record : Module ) : void => {
260249 setCurrentRecord ( record ) ;
261- setName ( t ( 'COPY_SUFFIX' , { name : record . title } ) ) ;
250+ setName ( t ( 'COPY_SUFFIX' , { name : record . name } ) ) ;
262251 setCopyModalOpen ( true ) ;
263252 } ;
264253
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-
339254 /** Gets the modal title based on module type. */
340255 const getModalTitle = ( ) : string => {
341256 return t ( 'TYPE_MANAGEMENT' , { type : TabTypeUtils . toString ( props . tabType ) } ) ;
@@ -348,7 +263,7 @@ export default function FileManageModal(props: FileManageModalProps) {
348263 }
349264 return t ( 'RENAME_TYPE_TITLE' , {
350265 type : TabTypeUtils . toString ( currentRecord . type ) ,
351- title : currentRecord . title
266+ title : currentRecord . name
352267 } ) ;
353268 } ;
354269
@@ -359,7 +274,7 @@ export default function FileManageModal(props: FileManageModalProps) {
359274 }
360275 return t ( 'COPY_TYPE_TITLE' , {
361276 type : TabTypeUtils . toString ( currentRecord . type ) ,
362- title : currentRecord . title
277+ title : currentRecord . name
363278 } ) ;
364279 } ;
365280
@@ -369,6 +284,14 @@ export default function FileManageModal(props: FileManageModalProps) {
369284 return t ( 'NO_FILES_FOUND' , { type : tabTypeString . toLowerCase ( ) } ) ;
370285 } ;
371286
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+
372295 return (
373296 < >
374297 < Antd . Modal
@@ -436,27 +359,17 @@ export default function FileManageModal(props: FileManageModalProps) {
436359 footer = { null }
437360 width = { MODAL_WIDTH }
438361 >
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 />
460373 < h4 style = { { margin : '0 0 8px 0' } } >
461374 { t ( 'CREATE_NEW' , { type : TabTypeUtils . toString ( props . tabType ) } ) }
462375 </ h4 >
0 commit comments