Skip to content

Commit 5661ec0

Browse files
committed
feat(notifications): adjust wording and add activity bar badge
- Remove description from the notifications panel - unneeded. It is obvious the panel is for notifications. - Make hover text the full title of the notification in case user side bar width isn't enough to display the full title. - Add a badge to the Q activity bar icon indicating how many notifications you have. Also adds this as (#) to the panel title.
1 parent ed1b4b1 commit 5661ec0

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

packages/core/src/notifications/panelNode.ts

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import * as vscode from 'vscode'
7+
import * as nls from 'vscode-nls'
78
import { ResourceTreeDataProvider, TreeNode } from '../shared/treeview/resourceTreeDataProvider'
89
import { Command, Commands } from '../shared/vscode/commands2'
910
import { Icon, getIcon } from '../shared/icons'
@@ -18,13 +19,16 @@ import { openUrl } from '../shared/utilities/vsCodeUtils'
1819
import { telemetry } from '../shared/telemetry/telemetry'
1920
import { globals } from '../shared'
2021

22+
const localize = nls.loadMessageBundle()
2123
const 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
*/
2729
export 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}.
@@ -275,14 +300,13 @@ export class NotificationsNode implements TreeNode {
275300
}
276301

277302
registerView(context: vscode.ExtensionContext) {
278-
const view = registerToolView(
303+
this.view = registerToolView(
279304
{
280305
nodes: [this],
281306
view: isAmazonQ() ? 'aws.amazonq.notifications' : 'aws.toolkit.notifications',
282307
refreshCommands: [(provider: ResourceTreeDataProvider) => this.registerProvider(provider)],
283308
},
284309
context
285310
)
286-
view.message = `New feature announcements and emergency notifications for ${isAmazonQ() ? 'Amazon Q' : 'AWS Toolkit'} will appear here.`
287311
}
288312
}

0 commit comments

Comments
 (0)