@@ -108,7 +108,7 @@ const MIN_TABS_FOR_CLOSE_OTHERS = 2;
108108 * Provides context menus for tab operations and modal dialogs for user input.
109109 */
110110export function Component ( props : TabsProps ) : React . JSX . Element {
111- const { t } = I18Next . useTranslation ( ) ;
111+ const { t } = I18Next . useTranslation ( ) ;
112112 const [ modal , contextHolder ] = Antd . Modal . useModal ( ) ;
113113
114114 const [ activeKey , setActiveKey ] = React . useState ( props . activeTab ) ;
@@ -118,6 +118,10 @@ export function Component(props: TabsProps): React.JSX.Element {
118118 const [ copyModalOpen , setCopyModalOpen ] = React . useState ( false ) ;
119119 const [ currentTab , setCurrentTab ] = React . useState < TabItem | null > ( null ) ;
120120
121+ const triggerProjectUpdate = ( ) : void => {
122+ props . setProject ( structuredClone ( props . project ) ) ;
123+ }
124+
121125 /** Handles tab change and updates current module. */
122126 const handleTabChange = ( key : string ) : void => {
123127 if ( props . project ) {
@@ -145,10 +149,10 @@ export function Component(props: TabsProps): React.JSX.Element {
145149
146150 switch ( module . moduleType ) {
147151 case commonStorage . MODULE_TYPE_MECHANISM :
148- newTabs . push ( { key, title : module . className , type : TabType . MECHANISM } ) ;
152+ newTabs . push ( { key, title : module . className , type : TabType . MECHANISM } ) ;
149153 break ;
150154 case commonStorage . MODULE_TYPE_OPMODE :
151- newTabs . push ( { key, title : module . className , type : TabType . OPMODE } ) ;
155+ newTabs . push ( { key, title : module . className , type : TabType . OPMODE } ) ;
152156 break ;
153157 default :
154158 console . warn ( 'Unknown module type:' , module . moduleType ) ;
@@ -160,8 +164,8 @@ export function Component(props: TabsProps): React.JSX.Element {
160164
161165 /** Handles tab edit actions (add/remove). */
162166 const handleTabEdit = (
163- targetKey : React . MouseEvent | React . KeyboardEvent | string ,
164- action : 'add' | 'remove'
167+ targetKey : React . MouseEvent | React . KeyboardEvent | string ,
168+ action : 'add' | 'remove'
165169 ) : void => {
166170 const items = props . tabList ;
167171 if ( action === 'add' ) {
@@ -187,6 +191,7 @@ export function Component(props: TabsProps): React.JSX.Element {
187191 /** Handles successful addition of new tabs. */
188192 const handleAddTabOk = ( newTabs : TabItem [ ] ) : void => {
189193 props . setTabList ( [ props . tabList [ 0 ] , ...newTabs ] ) ;
194+
190195 setActiveKey ( props . tabList [ 0 ] . key ) ;
191196 setAddTabDialogOpen ( false ) ;
192197 } ;
@@ -199,22 +204,22 @@ export function Component(props: TabsProps): React.JSX.Element {
199204
200205 try {
201206 const newPath = await commonStorage . renameModuleInProject (
202- props . storage ,
203- props . project ,
204- newName ,
205- key
207+ props . storage ,
208+ props . project ,
209+ newName ,
210+ key
206211 ) ;
207212
208213 const newTabs = props . tabList . map ( ( tab ) => {
209214 if ( tab . key === key ) {
210- return { ...tab , title : newName , key : newPath } ;
215+ return { ...tab , title : newName , key : newPath } ;
211216 }
212217 return tab ;
213218 } ) ;
214219
215220 props . setTabList ( newTabs ) ;
216221 setActiveKey ( newPath ) ;
217- props . setProject ( { ... props . project } ) ;
222+ triggerProjectUpdate ( ) ;
218223 } catch ( error ) {
219224 console . error ( 'Error renaming module:' , error ) ;
220225 props . setAlertErrorMessage ( 'Failed to rename module' ) ;
@@ -231,10 +236,10 @@ export function Component(props: TabsProps): React.JSX.Element {
231236
232237 try {
233238 const newPath = await commonStorage . copyModuleInProject (
234- props . storage ,
235- props . project ,
236- newName ,
237- key
239+ props . storage ,
240+ props . project ,
241+ newName ,
242+ key
238243 ) ;
239244
240245 const newTabs = [ ...props . tabList ] ;
@@ -246,10 +251,10 @@ export function Component(props: TabsProps): React.JSX.Element {
246251 return ;
247252 }
248253
249- newTabs . push ( { key : newPath , title : newName , type : originalTab . type } ) ;
254+ newTabs . push ( { key : newPath , title : newName , type : originalTab . type } ) ;
250255 props . setTabList ( newTabs ) ;
251256 setActiveKey ( newPath ) ;
252- props . setProject ( { ... props . project } ) ;
257+ triggerProjectUpdate ( ) ;
253258 } catch ( error ) {
254259 console . error ( 'Error copying module:' , error ) ;
255260 props . setAlertErrorMessage ( 'Failed to copy module' ) ;
@@ -261,7 +266,7 @@ export function Component(props: TabsProps): React.JSX.Element {
261266 /** Handles closing other tabs except the current one. */
262267 const handleCloseOtherTabs = ( currentTabKey : string ) : void => {
263268 const newTabs = props . tabList . filter (
264- ( tab ) => tab . key === currentTabKey || tab . type === TabType . ROBOT
269+ ( tab ) => tab . key === currentTabKey || tab . type === TabType . ROBOT
265270 ) ;
266271 props . setTabList ( newTabs ) ;
267272 setActiveKey ( currentTabKey ) ;
@@ -300,7 +305,7 @@ export function Component(props: TabsProps): React.JSX.Element {
300305
301306 if ( props . storage && props . project ) {
302307 await commonStorage . removeModuleFromProject ( props . storage , props . project , tab . key ) ;
303- props . setProject ( { ... props . project } ) ;
308+ triggerProjectUpdate ( ) ;
304309 }
305310
306311 if ( newTabs . length > 0 ) {
@@ -360,7 +365,7 @@ export function Component(props: TabsProps): React.JSX.Element {
360365 key : tab . key ,
361366 label : (
362367 < Antd . Dropdown
363- menu = { { items : createTabContextMenuItems ( tab ) } }
368+ menu = { { items : createTabContextMenuItems ( tab ) } }
364369 trigger = { [ 'contextMenu' ] }
365370 >
366371 < span > { tab . title } </ span >
@@ -389,14 +394,14 @@ export function Component(props: TabsProps): React.JSX.Element {
389394 onCancel = { ( ) => setAddTabDialogOpen ( false ) }
390395 onOk = { handleAddTabOk }
391396 project = { props . project }
397+ setProject = { props . setProject }
392398 currentTabs = { props . tabList }
393399 storage = { props . storage }
394400 />
395401
396402 < Antd . Modal
397- title = { `Rename ${ currentTab ? TabTypeUtils . toString ( currentTab . type ) : '' } : ${
398- currentTab ? currentTab . title : ''
399- } `}
403+ title = { `Rename ${ currentTab ? TabTypeUtils . toString ( currentTab . type ) : '' } : ${ currentTab ? currentTab . title : ''
404+ } `}
400405 open = { renameModalOpen }
401406 onCancel = { ( ) => setRenameModalOpen ( false ) }
402407 onOk = { ( ) => {
@@ -425,9 +430,8 @@ export function Component(props: TabsProps): React.JSX.Element {
425430 </ Antd . Modal >
426431
427432 < Antd . Modal
428- title = { `Copy ${ currentTab ? TabTypeUtils . toString ( currentTab . type ) : '' } : ${
429- currentTab ? currentTab . title : ''
430- } `}
433+ title = { `Copy ${ currentTab ? TabTypeUtils . toString ( currentTab . type ) : '' } : ${ currentTab ? currentTab . title : ''
434+ } `}
431435 open = { copyModalOpen }
432436 onCancel = { ( ) => setCopyModalOpen ( false ) }
433437 onOk = { ( ) => {
@@ -460,7 +464,7 @@ export function Component(props: TabsProps): React.JSX.Element {
460464 onChange = { handleTabChange }
461465 onEdit = { handleTabEdit }
462466 activeKey = { activeKey }
463- tabBarStyle = { { padding : 0 , margin : 0 } }
467+ tabBarStyle = { { padding : 0 , margin : 0 } }
464468 hideAdd = { false }
465469 items = { createTabItems ( ) }
466470 />
0 commit comments