Skip to content

Commit 2d90700

Browse files
committed
types(notifications): add types to onClick, onReceive, actions
1 parent 2e83fe0 commit 2d90700

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

packages/core/src/notifications/panelNode.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ResourceTreeDataProvider, TreeNode } from '../shared/treeview/resourceT
88
import { Command, Commands } from '../shared/vscode/commands2'
99
import { Icon, IconPath, getIcon } from '../shared/icons'
1010
import { contextKey, setContext } from '../shared/vscode/setContext'
11-
import { NotificationType, ToolkitNotification, getNotificationTelemetryId } from './types'
11+
import { NotificationType, OnReceiveType, ToolkitNotification, getNotificationTelemetryId } from './types'
1212
import { ToolkitError } from '../shared/errors'
1313
import { isAmazonQ } from '../shared/extensionUtilities'
1414
import { getLogger } from '../shared/logger/logger'
@@ -165,7 +165,11 @@ export class NotificationsNode implements TreeNode {
165165
* Can be either a blocking modal or a bottom-right corner toast
166166
* Handles the button click actions based on the button type.
167167
*/
168-
private showInformationWindow(notification: ToolkitNotification, type: string = 'toast', passive: boolean = false) {
168+
private showInformationWindow(
169+
notification: ToolkitNotification,
170+
type: OnReceiveType = 'toast',
171+
passive: boolean = false
172+
) {
169173
const isModal = type === 'modal'
170174

171175
// modal has to have defined actions (buttons)

packages/core/src/notifications/types.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export interface ExactMatch {
3838

3939
export type ConditionalClause = Range | ExactMatch | OR
4040

41+
export type OnReceiveType = 'toast' | 'modal'
42+
export type OnClickType = 'modal' | 'openTextDocument' | 'openUrl'
43+
export type ActionType = 'openUrl' | 'updateAndReload' | 'openTxt'
44+
4145
/** How to display the notification. */
4246
export interface UIRenderInstructions {
4347
content: {
@@ -47,13 +51,13 @@ export interface UIRenderInstructions {
4751
toastPreview?: string // optional property for toast
4852
}
4953
}
50-
onRecieve: string
54+
onRecieve: OnReceiveType // TODO: typo
5155
onClick: {
52-
type: string
56+
type: OnClickType
5357
url?: string // optional property for 'openUrl'
5458
}
5559
actions?: Array<{
56-
type: string
60+
type: ActionType
5761
displayText: {
5862
[`en-US`]: string
5963
}

packages/core/src/test/notifications/controller.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ describe('RemoteFetcher', function () {
534534
})
535535
})
536536

537-
function getValidTestNotification(id: string) {
537+
function getValidTestNotification(id: string): ToolkitNotification {
538538
return {
539539
id,
540540
displayIf: {
@@ -556,7 +556,7 @@ function getValidTestNotification(id: string) {
556556
}
557557
}
558558

559-
function getInvalidTestNotification(id: string) {
559+
function getInvalidTestNotification(id: string): ToolkitNotification {
560560
return {
561561
id,
562562
displayIf: {
@@ -570,6 +570,8 @@ function getInvalidTestNotification(id: string) {
570570
description: 'test',
571571
},
572572
},
573+
onRecieve: 'toast',
574+
onClick: { type: 'modal' },
573575
},
574576
}
575577
}

0 commit comments

Comments
 (0)