File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -73,8 +73,42 @@ export function Component(props: TabsProps) {
7373 setActiveKey ( key ) ;
7474 }
7575 }
76+ const inTabs = ( key : string ) : boolean => {
77+ props . tabList . forEach ( tab => {
78+ if ( tab . key === key ) {
79+ return true ;
80+ }
81+ } ) ;
82+ return false ;
83+ }
84+
85+ const addTab = ( key : string ) => {
86+ const newTabs = [ ...props . tabList ] ;
87+ if ( props . project ) {
88+ const module = commonStorage . findModuleInProject ( props . project , key ) ;
89+ if ( module ) {
90+ switch ( module . moduleType ) {
91+ case commonStorage . MODULE_TYPE_MECHANISM :
92+ newTabs . push ( { key : key , title : module . className , type : TabType . MECHANISM } ) ;
93+ break ;
94+ case commonStorage . MODULE_TYPE_OPMODE :
95+ newTabs . push ( { key : key , title : module . className , type : TabType . OPMODE } ) ;
96+ break ;
97+ default :
98+ console . log ( "Unknown module type" , module . moduleType ) ;
99+ break ;
100+ }
101+ }
102+ props . setTabList ( newTabs ) ;
103+ }
104+ } ;
105+
76106 React . useEffect ( ( ) => {
107+ let found = false ;
77108 if ( activeKey != props . activeTab ) {
109+ if ( ! inTabs ( props . activeTab ) ) {
110+ addTab ( props . activeTab ) ;
111+ }
78112 onChange ( props . activeTab ) ;
79113 }
80114 } , [ props . activeTab ] ) ;
You can’t perform that action at this time.
0 commit comments