import { KubernetesObject } from '@kubernetes/client-node' ; import { Command , MarkdownString , ThemeColor , ThemeIcon , TreeItem , TreeItemCollapsibleState , Uri } from 'vscode' ; import { CommandId } from '../../commands' ; import { asAbsolutePath } from '../../extensionContext' ; import { FileTypes } from '../../fileTypes' ; import { KubernetesContextWithCluster } from '../../kubernetes/kubernetesConfig' ; import { kubernetesTools } from '../../kubernetes/kubernetesTools' ; import { createMarkdownTable , KnownTreeNodeResources } from '../../utils/markdownUtils' ; export const enum TreeNodeIcon { Error = 'error' , Warning = 'warning' , Success = 'success' , Unknown = 'unknown' } /**
 * Defines tree view item base class used by all GitOps tree views.
 */ export class TreeNode extends TreeItem { /**
     * Kubernetes resource.
     */ resource ? : Exclude < KnownTreeNodeResources , KubernetesContextWithCluster > | KubernetesObject ; /**
     * Reference to the parent node (if exists).
     */ parent : TreeNode | undefined ; /**
     * Reference to all the child nodes.
     */ children : TreeNode [ ] = [ ] ; param label constructor ( label ) { super ( label , TreeItemCollapsibleState . None ) ; } /**
     * Collapses tree node and hides its children.
     */ makeCollapsible ( ) { this . collapsibleState = TreeItemCollapsibleState . Collapsed ; } /**
     * Expands a tree node and shows its children.
     */ expand ( ) { this . collapsibleState = TreeItemCollapsibleState . Expanded ; } param icon setIcon ( icon ) { if ( icon === TreeNodeIcon . Error ) { this . iconPath = new ThemeIcon ( 'error' , new ThemeColor ( 'editorError.foreground' ) ) ; } else if ( icon === TreeNodeIcon . Warning ) { this . iconPath = new ThemeIcon ( 'warning' , new ThemeColor ( 'editorWarning.foreground' ) ) ; } else if ( icon === TreeNodeIcon . Success ) { this . iconPath = new ThemeIcon ( 'pass' , new ThemeColor ( 'terminal.ansiGreen' ) ) ; } else if ( icon === TreeNodeIcon . Unknown ) { this . iconPath = new ThemeIcon ( 'circle-large-outline' ) ; } else if ( typeof icon === 'string' ) { this . iconPath = { light : asAbsolutePath ( `resources/icons/light/${ icon }.svg` ) , dark : asAbsolutePath ( `resources/icons/dark/${ icon }.svg` ) , } ; } else { this . iconPath = icon ; } } param child returns addChild ( child ) { this . children . push ( child ) ; child . parent = this ; if ( this . children . length ) { if ( this . collapsibleState !== TreeItemCollapsibleState . Expanded ) { this . makeCollapsible ( ) ; } } return this ; } param contexts joinContexts ( contexts ) { return contexts . filter ( context => context . length ) . map ( context => `${ context };` ) . join ( '' ) ; } get tooltip ( ) : string | MarkdownString { if ( this . resource ) { return createMarkdownTable ( this . resource as KnownTreeNodeResources ) ; } } get command ( ) : Command { if ( this . resource ) { const resourceUri = kubernetesTools . getResourceUri ( this . resource . metadata ?. namespace , `${ this . resource . kind }/${ this . resource . metadata ?. name }` , FileTypes . Yaml ) ; return { command : CommandId . EditorOpenResource , arguments : [ resourceUri ] , title : 'View Resource' , } ; } } /**
     * VSCode contexts to use for setting  contextValue * of this tree node. Used for context/inline menus.
      get contexts ( ) : string [ ] { return [ ] ; } get contextValue ( ) { if ( this . contexts . length ) { return this . joinContexts ( this . contexts ) ; } } }