Skip to content

Commit

Permalink
fix(notifications): icons causing runtime error
Browse files Browse the repository at this point in the history
Problem: Making the icon red for emergency notifications requires changing the color property. To do it in 1 line we use a ternary statement and unwrap. This causes runtime error similar to: `cannot access property of undefined: 0`.

Solution: Use object.assign instead
  • Loading branch information
hayemaxi committed Nov 14, 2024
1 parent 5efed42 commit ed1b4b1
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/core/src/notifications/panelNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import * as vscode from 'vscode'
import { ResourceTreeDataProvider, TreeNode } from '../shared/treeview/resourceTreeDataProvider'
import { Command, Commands } from '../shared/vscode/commands2'
import { Icon, IconPath, getIcon } from '../shared/icons'
import { Icon, getIcon } from '../shared/icons'
import { contextKey, setContext } from '../shared/vscode/setContext'
import { NotificationType, OnReceiveType, ToolkitNotification, getNotificationTelemetryId } from './types'
import { ToolkitError } from '../shared/errors'
Expand Down Expand Up @@ -81,10 +81,13 @@ export class NotificationsNode implements TreeNode {

public getChildren() {
const buildNode = (n: ToolkitNotification, type: NotificationType) => {
const icon: Icon | IconPath =
type === 'startUp'
? getIcon('vscode-question')
: { ...getIcon('vscode-alert'), color: new vscode.ThemeColor('errorForeground') }
const icon: Icon =
type === 'emergency'
? Object.assign(getIcon('vscode-alert') as Icon, {
color: new vscode.ThemeColor('errorForeground'),
})
: (getIcon('vscode-question') as Icon)

return this.openNotificationCmd.build(n).asTreeNode({
label: n.uiRenderInstructions.content['en-US'].title,
iconPath: icon,
Expand Down

0 comments on commit ed1b4b1

Please sign in to comment.