1818/**
1919 * @author [email protected] (Alan Smith) 2020 */
21- import { TabType , TabTypeUtils } from "./Tabs" ;
21+ import { TabType } from "./Tabs" ;
2222import * as Antd from "antd" ;
2323import * as I18Next from "react-i18next" ;
2424import * as React from "react" ;
2525import * as commonStorage from "../storage/common_storage" ;
26- import { EditOutlined , DeleteOutlined , CopyOutlined } from '@ant-design/icons' ;
26+ import { EditOutlined , DeleteOutlined , CopyOutlined , SelectOutlined } from '@ant-design/icons' ;
2727import ProjectNameComponent from "./ProjectNameComponent" ;
2828
2929type ProjectManageModalProps = {
3030 isOpen : boolean ;
31+ noProjects : boolean ;
3132 onCancel : ( ) => void ;
3233 setProject : ( project : commonStorage . Project | null ) => void ;
3334 setAlertErrorMessage : ( message : string ) => void ;
@@ -50,6 +51,10 @@ export default function ProjectManageModal(props: ProjectManageModalProps) {
5051 // Sort modules alphabetically by title
5152 projects . sort ( ( a , b ) => a . className . localeCompare ( b . className ) ) ;
5253 setModules ( projects ) ;
54+ if ( ( projects . length > 0 ) && props . noProjects ) {
55+ props . setProject ( projects [ 0 ] ) ; // Set the first project as the current project
56+ props . onCancel ( ) ; // Close the modal after selecting
57+ }
5358 } ;
5459
5560 React . useEffect ( ( ) => {
@@ -92,7 +97,7 @@ export default function ProjectManageModal(props: ProjectManageModalProps) {
9297 if ( props . storage ) {
9398 const newProjectName = commonStorage . classNameToModuleName ( trimmedName ) ;
9499 const newProjectPath = commonStorage . makeProjectPath ( newProjectName ) ;
95-
100+
96101 const projectContent = commonStorage . newProjectContent ( newProjectName ) ;
97102 try {
98103 await props . storage . createModule (
@@ -125,15 +130,26 @@ export default function ProjectManageModal(props: ProjectManageModalProps) {
125130 {
126131 title : 'Actions' ,
127132 key : 'actions' ,
128- width : 120 ,
133+ width : 160 ,
129134 render : ( _ , record : commonStorage . Project ) => (
130135 < Antd . Space size = "small" >
136+ < Antd . Tooltip title = { t ( "Select" ) } >
137+ < Antd . Button
138+ type = "text"
139+ size = "small"
140+ icon = { < SelectOutlined /> }
141+ onClick = { ( e ) => {
142+ props . setProject ( record ) ;
143+ props . onCancel ( ) ; // Close the modal after selecting
144+ } }
145+ />
146+ </ Antd . Tooltip >
131147 < Antd . Tooltip title = { t ( "Rename" ) } >
132148 < Antd . Button
133149 type = "text"
134150 size = "small"
135151 icon = { < EditOutlined /> }
136- onClick = { ( ) => {
152+ onClick = { ( e ) => {
137153 setCurrentRecord ( record ) ;
138154 setName ( record . className ) ;
139155 setRenameModalOpen ( true ) ;
@@ -145,7 +161,7 @@ export default function ProjectManageModal(props: ProjectManageModalProps) {
145161 type = "text"
146162 size = "small"
147163 icon = { < CopyOutlined /> }
148- onClick = { ( ) => {
164+ onClick = { ( e ) => {
149165 setCurrentRecord ( record ) ;
150166 setName ( record . className + 'Copy' ) ;
151167 setCopyModalOpen ( true ) ;
@@ -195,10 +211,6 @@ export default function ProjectManageModal(props: ProjectManageModalProps) {
195211 } ,
196212 ] ;
197213
198- const getModalTitle = ( ) => {
199- return 'Project Management' ;
200- } ;
201-
202214 return (
203215 < >
204216 < Antd . Modal
@@ -245,7 +257,7 @@ export default function ProjectManageModal(props: ProjectManageModalProps) {
245257 setNewItemName = { setName }
246258 onAddNewItem = { ( ) => {
247259 if ( currentRecord ) {
248- handleRename ( currentRecord , name ) ;
260+ handleCopy ( currentRecord , name ) ;
249261 }
250262 } }
251263 projects = { modules }
@@ -255,7 +267,7 @@ export default function ProjectManageModal(props: ProjectManageModalProps) {
255267 </ Antd . Modal >
256268
257269 < Antd . Modal
258- title = { getModalTitle ( ) }
270+ title = { t ( "Project Management" ) }
259271 open = { props . isOpen }
260272 onCancel = { props . onCancel }
261273 footer = { [
@@ -265,6 +277,15 @@ export default function ProjectManageModal(props: ProjectManageModalProps) {
265277 ] }
266278 width = { 800 }
267279 >
280+ { props . noProjects && (
281+ < Antd . Alert
282+ message = "No projects found"
283+ description = "Please create a new project to get started."
284+ type = "info"
285+ showIcon
286+ style = { { marginBottom : 16 } }
287+ />
288+ ) }
268289 < div style = { {
269290 marginBottom : 16 ,
270291 border : '1px solid #d9d9d9' ,
@@ -279,29 +300,30 @@ export default function ProjectManageModal(props: ProjectManageModalProps) {
279300 setProjects = { setModules }
280301 />
281302 </ div >
282- < Antd . Table < commonStorage . Project >
283- columns = { columns }
284- dataSource = { modules }
285- rowKey = "modulePath"
286- size = "small"
287- pagination = { modules . length > 5 ? {
288- pageSize : 5 ,
289- showSizeChanger : false ,
290- showQuickJumper : false ,
291- showTotal : ( total , range ) =>
292- `${ range [ 0 ] } -${ range [ 1 ] } of ${ total } items` ,
293- } : false }
294- bordered
295- locale = { {
296- emptyText : 'No projects found'
297- } }
298- onRow = { ( record ) => ( {
299- onDoubleClick : ( ) => {
300- props . setProject ( record ) ;
301- props . onCancel ( ) ; // Close the modal after selecting
302- }
303- } ) }
304- />
303+ { ! props . noProjects && (
304+ < Antd . Table < commonStorage . Project >
305+ columns = { columns }
306+ dataSource = { modules }
307+ rowKey = "modulePath"
308+ size = "small"
309+ pagination = { modules . length > 5 ? {
310+ pageSize : 5 ,
311+ showSizeChanger : false ,
312+ showQuickJumper : false ,
313+ showTotal : ( total , range ) =>
314+ `${ range [ 0 ] } -${ range [ 1 ] } of ${ total } items` ,
315+ } : false }
316+ bordered
317+ locale = { {
318+ emptyText : 'No projects found'
319+ } }
320+ onRow = { ( record ) => ( {
321+ onDoubleClick : ( ) => {
322+ props . setProject ( record ) ;
323+ props . onCancel ( ) ; // Close the modal after selecting
324+ }
325+ } ) }
326+ /> ) }
305327 </ Antd . Modal >
306328 </ >
307329 ) ;
0 commit comments