@@ -130,24 +130,25 @@ export class NotificationsNode implements TreeNode {
130130 /**
131131 * Fired when a notification is clicked on in the panel. It will run any rendering
132132 * instructions included in the notification. See {@link ToolkitNotification.uiRenderInstructions}.
133- *
134- * TODO: implement more rendering possibilites.
135133 */
136134 public async openNotification ( notification : ToolkitNotification ) {
137135 switch ( notification . uiRenderInstructions . onClick . type ) {
138136 case 'modal' :
139- // Handle modal case
137+ // Render blocking modal
138+ getLogger ( 'notifications' ) . verbose ( `rendering modal for notificaiton: ${ notification . id } ...` )
140139 await this . renderModal ( notification )
141140 break
142141 case 'openUrl' :
143142 if ( ! notification . uiRenderInstructions . onClick . url ) {
144143 throw new ToolkitError ( 'No url provided for onclick open url' )
145144 }
146- // Handle openUrl case
145+ // Show open url option
146+ getLogger ( 'notifications' ) . verbose ( `opening url for notification: ${ notification . id } ...` )
147147 await vscode . env . openExternal ( vscode . Uri . parse ( notification . uiRenderInstructions . onClick . url ) )
148148 break
149149 case 'openTextDocument' :
150- // Handle openTextDocument case
150+ // Display read-only txt document
151+ getLogger ( 'notifications' ) . verbose ( `showing txt document for notification: ${ notification . id } ...` )
151152 await this . showReadonlyTextDocument ( notification . uiRenderInstructions . content [ 'en-US' ] . description )
152153 break
153154 }
@@ -158,7 +159,6 @@ export class NotificationsNode implements TreeNode {
158159 * It's read-only so that the "save" option doesn't appear when user closes the notification
159160 */
160161 private async showReadonlyTextDocument ( content : string ) : Promise < void > {
161- getLogger ( 'notifications' ) . info ( 'showing txt document ... ' )
162162 try {
163163 const tempFilePath = path . join ( tempDirPath , 'AWSToolkitNotifications.txt' )
164164
@@ -187,16 +187,19 @@ export class NotificationsNode implements TreeNode {
187187 }
188188 }
189189
190+ /**
191+ * Renders a blocking modal with the notification's content and buttons.
192+ * Handles the button click actions based on the button type.
193+ */
190194 public async renderModal ( notification : ToolkitNotification ) {
191- getLogger ( 'notifications' ) . info ( 'rendering modal ... ' )
192- if ( ! notification . uiRenderInstructions . buttons ) {
195+ if ( ! notification . uiRenderInstructions . actions ) {
193196 throw new ToolkitError ( 'no button defined for modal' )
194197 return
195198 }
196199
197- const buttons = notification . uiRenderInstructions . buttons
200+ const buttons = notification . uiRenderInstructions . actions
198201
199- const buttonLabels = buttons . map ( ( buttons ) => buttons . displayText [ 'en-US' ] )
202+ const buttonLabels = buttons . map ( ( actions ) => actions . displayText [ 'en-US' ] )
200203
201204 const detail = notification . uiRenderInstructions . content [ 'en-US' ] . description
202205
@@ -207,12 +210,17 @@ export class NotificationsNode implements TreeNode {
207210 )
208211
209212 if ( selectedButton ) {
210- const buttons = notification . uiRenderInstructions . buttons . find (
211- ( buttons ) => buttons . displayText [ 'en-US' ] === selectedButton
213+ const buttons = notification . uiRenderInstructions . actions . find (
214+ ( actions ) => actions . displayText [ 'en-US' ] === selectedButton
212215 )
213-
216+ // Different button options
214217 if ( buttons ) {
215218 switch ( buttons . type ) {
219+ case 'openTxt' :
220+ await this . showReadonlyTextDocument (
221+ notification . uiRenderInstructions . content [ 'en-US' ] . description
222+ )
223+ break
216224 case 'updateAndReload' :
217225 await this . updateAndReload ( notification . displayIf . extensionId )
218226 break
@@ -222,14 +230,32 @@ export class NotificationsNode implements TreeNode {
222230 }
223231 break
224232 default :
225- getLogger ( ) . warn ( `Unhandled button type: ${ buttons . type } ` )
233+ throw new ToolkitError ( ' button action not defined' )
226234 }
227235 }
228236 }
229237 }
230238
239+ public async onReceiveNotifications ( notifications : ToolkitNotification [ ] ) {
240+ for ( const notification of notifications ) {
241+ switch ( notification . uiRenderInstructions . onRecieve ) {
242+ case 'modal' :
243+ // Handle modal case
244+ void this . renderModal ( notification )
245+ break
246+ case 'toast' :
247+ // toast case, no user input needed
248+ void vscode . window . showInformationMessage (
249+ notification . uiRenderInstructions . content [ 'en-US' ] . descriptionPreview ??
250+ notification . uiRenderInstructions . content [ 'en-US' ] . title
251+ )
252+ break
253+ }
254+ }
255+ }
256+
231257 private async updateAndReload ( id : string ) {
232- getLogger ( 'notifications' ) . info ( 'Updating and reloading the extension...' )
258+ getLogger ( 'notifications' ) . verbose ( 'Updating and reloading the extension...' )
233259 await vscode . commands . executeCommand ( 'workbench.extensions.installExtension' , id )
234260 await vscode . commands . executeCommand ( 'workbench.action.reloadWindow' )
235261 }
@@ -258,3 +284,5 @@ export class NotificationsNode implements TreeNode {
258284export function registerProvider ( provider : ResourceTreeDataProvider ) {
259285 NotificationsNode . instance . provider = provider
260286}
287+
288+ export const testNotificationsNode = new NotificationsNode ( )
0 commit comments