44 */
55
66import * as vscode from 'vscode'
7+ import * as nls from 'vscode-nls'
78import { ResourceTreeDataProvider , TreeNode } from '../shared/treeview/resourceTreeDataProvider'
89import { Command , Commands } from '../shared/vscode/commands2'
910import { Icon , getIcon } from '../shared/icons'
@@ -18,13 +19,16 @@ import { openUrl } from '../shared/utilities/vsCodeUtils'
1819import { telemetry } from '../shared/telemetry/telemetry'
1920import { globals } from '../shared'
2021
22+ const localize = nls . loadMessageBundle ( )
2123const logger = getLogger ( 'notifications' )
2224
2325/**
2426 * Controls the "Notifications" side panel/tree in each extension. It takes purely UX actions
2527 * and does not determine what notifications to dispaly or how to fetch and store them.
2628 */
2729export class NotificationsNode implements TreeNode {
30+ public static readonly title = localize ( 'AWS.notifications.title' , 'Notifications' )
31+
2832 public readonly id = 'notifications'
2933 public readonly resource = this
3034 public provider ?: ResourceTreeDataProvider
@@ -37,6 +41,7 @@ export class NotificationsNode implements TreeNode {
3741 private readonly showContextStr : contextKey
3842 private readonly startUpNodeContext : string
3943 private readonly emergencyNodeContext : string
44+ private view : vscode . TreeView < TreeNode > | undefined
4045
4146 static #instance: NotificationsNode
4247
@@ -65,16 +70,31 @@ export class NotificationsNode implements TreeNode {
6570 }
6671
6772 public getTreeItem ( ) {
68- const item = new vscode . TreeItem ( 'Notifications' )
73+ const item = new vscode . TreeItem ( NotificationsNode . title )
6974 item . collapsibleState = vscode . TreeItemCollapsibleState . Collapsed
7075 item . contextValue = 'notifications'
7176
7277 return item
7378 }
7479
7580 public refresh ( ) : void {
76- const hasNotifications = this . startUpNotifications . length > 0 || this . emergencyNotifications . length > 0
77- void setContext ( this . showContextStr , hasNotifications )
81+ if ( ! this . view ) {
82+ throw new ToolkitError ( 'NotificationsNode: TreeView accessed without being registered.' )
83+ }
84+
85+ const totalNotifications = this . notificationCount ( )
86+ if ( totalNotifications > 0 ) {
87+ this . view . badge = {
88+ tooltip : `${ totalNotifications } notification${ totalNotifications > 1 ? 's' : '' } ` ,
89+ value : totalNotifications ,
90+ }
91+ this . view . title = `${ NotificationsNode . title } (${ totalNotifications } )`
92+ void setContext ( this . showContextStr , true )
93+ } else {
94+ this . view . badge = undefined
95+ this . view . title = NotificationsNode . title
96+ void setContext ( this . showContextStr , false )
97+ }
7898
7999 this . provider ?. refresh ( )
80100 }
@@ -88,11 +108,12 @@ export class NotificationsNode implements TreeNode {
88108 } )
89109 : ( getIcon ( 'vscode-question' ) as Icon )
90110
111+ const title = n . uiRenderInstructions . content [ 'en-US' ] . title
91112 return this . openNotificationCmd . build ( n ) . asTreeNode ( {
92- label : n . uiRenderInstructions . content [ 'en-US' ] . title ,
113+ label : title ,
114+ tooltip : title ,
93115 iconPath : icon ,
94116 contextValue : type === 'startUp' ? this . startUpNodeContext : this . emergencyNodeContext ,
95- tooltip : 'Click to open' ,
96117 } )
97118 }
98119
@@ -130,6 +151,10 @@ export class NotificationsNode implements TreeNode {
130151 return vscode . commands . executeCommand ( this . focusCmdStr )
131152 }
132153
154+ private notificationCount ( ) {
155+ return this . startUpNotifications . length + this . emergencyNotifications . length
156+ }
157+
133158 /**
134159 * Fired when a notification is clicked on in the panel. It will run any rendering
135160 * instructions included in the notification. See {@link ToolkitNotification.uiRenderInstructions}.
@@ -271,14 +296,13 @@ export class NotificationsNode implements TreeNode {
271296 }
272297
273298 registerView ( context : vscode . ExtensionContext ) {
274- const view = registerToolView (
299+ this . view = registerToolView (
275300 {
276301 nodes : [ this ] ,
277302 view : isAmazonQ ( ) ? 'aws.amazonq.notifications' : 'aws.toolkit.notifications' ,
278303 refreshCommands : [ ( provider : ResourceTreeDataProvider ) => this . registerProvider ( provider ) ] ,
279304 } ,
280305 context
281306 )
282- view . message = `New feature announcements and emergency notifications for ${ isAmazonQ ( ) ? 'Amazon Q' : 'AWS Toolkit' } will appear here.`
283307 }
284308}
0 commit comments