From aaae3c47968e209973053305668fda67c79e69db Mon Sep 17 00:00:00 2001 From: Sumit Arora Date: Tue, 4 Feb 2020 18:26:16 -0500 Subject: [PATCH] feat(devtools): Adding parent nodes for selected component (rangle/angular-devtools#34) --- .../directive-forest.component.css | 19 +++++++++- .../directive-forest.component.html | 35 +++++++------------ .../directive-forest.component.ts | 23 +++++++++--- 3 files changed, 50 insertions(+), 27 deletions(-) diff --git a/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.css b/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.css index ea4f289bf04c6..2208b5f95dc60 100644 --- a/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.css +++ b/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.css @@ -3,6 +3,7 @@ height: 100%; overflow: auto; } + :host /deep/ .mat-tree-node .mat-icon { font-size: 12px; width: 16px; @@ -22,7 +23,7 @@ font-size: 11px; } -:host /deep/ mat-tree-node > button { +:host /deep/ mat-tree-node>button { outline: none; border: 0; background: transparent; @@ -92,3 +93,19 @@ width: 20%; display: flex; } + +.parent-nodes { + background-color: #ddd; + padding: 2px; + bottom: 0px; + position: fixed; + width: 100%; +} + +.btn-node { + font-size: 11px; + margin: 0px; + padding-left: 5px; + padding-right: 5px; + line-height: 20px; +} diff --git a/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.html b/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.html index 6b6b2cc38dd32..59f56de9edc66 100644 --- a/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.html +++ b/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.html @@ -1,31 +1,16 @@ - + - + {{ node.name }} [{{ node.directives }}] - + + + diff --git a/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.ts b/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.ts index d5b309a21e395..b3a704f6af32f 100644 --- a/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.ts +++ b/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.ts @@ -8,7 +8,7 @@ import { Output, ViewChild, } from '@angular/core'; -import { Node } from 'protocol'; +import { Node, ElementID } from 'protocol'; import { CdkTree, FlatTreeControl } from '@angular/cdk/tree'; import { ComponentDataSource, FlatNode } from './component-data-source'; @@ -51,6 +51,8 @@ export class DirectiveForestComponent { currentlyMatchedIndex = -1; selectedNode: FlatNode | null = null; + parents: FlatNode[]; + treeControl = new FlatTreeControl( node => node.level, node => node.expandable @@ -61,15 +63,16 @@ export class DirectiveForestComponent { hasChild = (_: number, node: FlatNode) => node.expandable; - constructor(private _host: ElementRef) {} + constructor(private _host: ElementRef) { } handleSelect(node: FlatNode): void { const matchedTree: FlatNode[] = this._findMatchedNodes(); - this.currentlyMatchedIndex = matchedTree.findIndex(matchedNode => matchedNode.id === node.id); + this.currentlyMatchedIndex = matchedTree.findIndex(matchedNode => matchedNode.id === node.id); this.select(node); } select(node: FlatNode): void { + this.populateParents(node.id); this.selectNode.emit(node.original); this.selectedNode = node; @@ -87,6 +90,18 @@ export class DirectiveForestComponent { }, 0); } + populateParents(id: ElementID): void { + this.parents = id.reduce((nodes: FlatNode[], index: number) => { + let nodeId = [index]; + if (nodes.length > 0) { + nodeId = nodes[nodes.length - 1].id.concat(index); + } + const selectedNode = this.dataSource.data.find((item) => item.id.toString() === nodeId.toString()); + nodes.push(selectedNode); + return nodes; + }, []); + } + @HostListener('document:keydown.ArrowUp', ['$event']) navigateUp(evnt: KeyboardEvent): void { if (this.invalidArrowEvent(evnt)) { @@ -188,7 +203,7 @@ export class DirectiveForestComponent { } hasMatched(): boolean { - return this._findMatchedNodes().length > 0; + return this._findMatchedNodes().length > 0; } nextMatched(): void {