33 * SPDX-License-Identifier: Apache-2.0
44 */
55
6- import { ChatItem , ChatItemType , MynahUI } from '@aws/mynah-ui'
6+ import { ChatItem , ChatItemType , MynahUI , NotificationType } from '@aws/mynah-ui'
77import { Connector } from '../connector'
88import { TabType , TabsStorage } from '../storages/tabsStorage'
99import { TabDataGenerator } from '../tabs/generator'
10+ import { uiComponentsTexts } from '../texts/constants'
1011import { MynahUIRef } from '../../../commons/types'
11- import { TabCreationUtils } from './tabCreationUtils'
1212
1313export interface MessageControllerProps {
1414 mynahUIRef : MynahUIRef
@@ -48,8 +48,15 @@ export class MessageController {
4848 [ 'featuredev' , 'gumby' , 'review' , 'testgen' , 'doc' ] . includes ( selectedTab . type )
4949 ) {
5050 // Create a new tab if there's none
51- const newTabID = TabCreationUtils . createNewTab ( this . mynahUI , this . tabDataGenerator , 'cwc' )
51+ const newTabID : string | undefined = this . mynahUI . updateStore (
52+ '' ,
53+ this . tabDataGenerator . getTabData ( 'cwc' , false )
54+ )
5255 if ( newTabID === undefined ) {
56+ this . mynahUI . notify ( {
57+ content : uiComponentsTexts . noMoreTabsTooltip ,
58+ type : NotificationType . WARNING ,
59+ } )
5360 return undefined
5461 }
5562 this . tabsStorage . addTab ( {
@@ -72,8 +79,6 @@ export class MessageController {
7279 return
7380 }
7481
75- let targetTabId : string
76-
7782 if (
7883 selectedTab !== undefined &&
7984 [ tabType , 'unknown' ] . includes ( selectedTab . type ) &&
@@ -94,13 +99,20 @@ export class MessageController {
9499 body : '' ,
95100 } )
96101
97- targetTabId = selectedTab . id
98- } else {
99- const newTabID = TabCreationUtils . createNewTab ( this . mynahUI , this . tabDataGenerator , 'cwc' )
100- if ( newTabID === undefined ) {
101- return undefined
102- }
102+ return selectedTab . id
103+ }
103104
105+ const newTabID : string | undefined = this . mynahUI . updateStore (
106+ '' ,
107+ this . tabDataGenerator . getTabData ( 'cwc' , false )
108+ )
109+ if ( newTabID === undefined ) {
110+ this . mynahUI . notify ( {
111+ content : uiComponentsTexts . noMoreTabsTooltip ,
112+ type : NotificationType . WARNING ,
113+ } )
114+ return undefined
115+ } else {
104116 this . tabsStorage . updateTabLastCommand ( newTabID , command )
105117 this . mynahUI . addChatItem ( newTabID , message )
106118 this . mynahUI . addChatItem ( newTabID , {
@@ -128,10 +140,8 @@ export class MessageController {
128140 this . connector . onUpdateTabType ( newTabID )
129141 this . tabsStorage . updateTabStatus ( newTabID , 'busy' )
130142
131- targetTabId = newTabID
143+ return newTabID
132144 }
133-
134- return targetTabId
135145 }
136146
137147 private get mynahUI ( ) : MynahUI | undefined {
0 commit comments