import * as kuberesources from '../../kuberesources' ; import { ExplorerExtender } from './explorer.extension' ; import { ClusterExplorerNode } from './node' ; import { ContributedGroupingFolderNode } from './node.folder.grouping.custom' ; import { ResourceFolderNode } from './node.folder.resource' ; import { NODE_TYPES } from './explorer' ; export abstract class NodeSourceImpl { at ( parent ) { return new ContributedNodeSourceExtender ( parent , this ) ; } if ( condition ) { return new ConditionalNodeSource ( this , condition ) ; } abstract nodes ( ) ; } export class CustomResourceFolderNodeSource extends NodeSourceImpl { constructor ( private readonly resourceKind ) { super ( ) ; } async nodes ( ) { return [ ResourceFolderNode . create ( this . resourceKind ) ] ; } } export class CustomGroupingFolderNodeSource extends NodeSourceImpl { constructor ( private readonly displayName , private readonly contextValue , private readonly children ) { super ( ) ; } async nodes ( ) { return [ new ContributedGroupingFolderNode ( this . displayName , this . contextValue , this . children ) ] ; } } class ConditionalNodeSource extends NodeSourceImpl { constructor ( private readonly impl , private readonly condition ) { super ( ) ; } async nodes ( ) { if ( await this . condition ( ) ) { return this . impl . nodes ( ) ; } return [ ] ; } } export class ContributedNodeSourceExtender implements ExplorerExtender < ClusterExplorerNode > { constructor ( private readonly under , private readonly nodeSource ) { } contributesChildren ( parent ? ) { if ( ! parent ) { return false ; } if ( this . under ) { return parent . nodeType === NODE_TYPES . folder . grouping && parent . displayName === this . under ; } return parent . nodeType === NODE_TYPES . context && parent . kubectlContext . active ; } getChildren ( _parent ? ) { return this . nodeSource . nodes ( ) ; } }