All files / views/trees/definition-tree/nodes/collections collections-node.ts

100% Statements 20/20
100% Branches 0/0
100% Functions 9/9
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56              1x       1x       1x       1x 1x   1x       10x   10x 3x     7x       4x 4x 4x   4x 4x     4x       1x       2x 2x    
import * as vscode from "vscode";
import { TreeNode, sortByLabel } from "@src/views/trees/tree-node";
import { DefinitionTreeNode } from "../../definition-tree-node";
import { CollectionClassNode } from "./collection-class-node";
 
export class CollectionsNode extends CollectionClassNode {
	override getContextValue(): string {
		return 'collections';
	}
 
	override getIcon(): vscode.ThemeIcon | undefined {
		return undefined;
	}
 
	override getLabel(): vscode.TreeItemLabel {
		return { label: 'Collections' };
	}
 
	override getDescription(): string {
		const graphs = this.getDocumentGraphs();
		const collections = [...this.vocabulary.getCollections(graphs)];
 
		return collections.length.toString();
	}
 
	override hasChildren(): boolean {
		const graphs = this.getDocumentGraphs();
 
		for(const _ of this.vocabulary.getCollections(graphs)) {
			return true;
		}
 
		return false;
	}
 
	override getChildren(): TreeNode[] {
		const result = [];
		const graphs = this.getDocumentGraphs();
		const collections = [...this.vocabulary.getCollections(graphs)];
 
		for (const c of collections) {
			result.push(this.createChildNode(CollectionClassNode, c));
		}
 
		return sortByLabel(result);
	}
 
	override getTooltip(): vscode.MarkdownString | undefined {
		return undefined;
	}
 
	override resolveNodeForUri(iri: string): DefinitionTreeNode | undefined {
		const children = this.getChildren() as DefinitionTreeNode[];
		return children.find(n => n.uri === iri);
	}
}