-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(design)!: add tree renderMode (#2777)
BREAKING CHANGE: Previously, the now-named renderMode "not-in-dom" was the default. This is no longer the case. If one was rendering immensely large trees and you now notice a significant slow-down, you can change the renderMode like: ```ts <ul daff-tree ... renderMode="not-in-dom"> ... </ul> ``` Which will restore the original behavior.
- Loading branch information
1 parent
53b0d65
commit 2d8ec58
Showing
11 changed files
with
206 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* Represents the mode of rendering for nodes in a tree UI. | ||
* - 'in-dom': Closed nodes are present in the Document Object Model (DOM). | ||
* - 'not-in-dom': Closed nodes are not present in the Document Object Model (DOM). | ||
*/ | ||
export type DaffTreeRenderMode = 'in-dom' | 'not-in-dom'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { | ||
Component, | ||
Input, | ||
} from '@angular/core'; | ||
import { | ||
ComponentFixture, | ||
TestBed, | ||
} from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
|
||
import { DaffTreeData } from '../../interfaces/tree-data'; | ||
import { DaffTreeRenderMode } from '../../interfaces/tree-render-mode'; | ||
import { DaffTreeModule } from '../../tree.module'; | ||
import { DaffTreeComponent } from '../tree.component'; | ||
|
||
@Component({ | ||
template: ` | ||
<ul daff-tree [tree]="data" [renderMode]="renderMode"> | ||
<ng-template #daffTreeItemWithChildrenTpl let-node> | ||
<button daffTreeItem [node]="node">{{ node.title }} </button> | ||
</ng-template> | ||
<ng-template #daffTreeItemTpl let-node> | ||
<a daffTreeItem [node]="node" href="node.url">{{ node.title }}</a> | ||
</ng-template> | ||
</ul> | ||
`, | ||
}) | ||
class WrapperComponent { | ||
@Input() data: DaffTreeData<any>; | ||
@Input() renderMode: DaffTreeRenderMode; | ||
} | ||
|
||
|
||
describe('@daffodil/design/tree - DaffTreeComponent | renderModes', () => { | ||
let wrapper: WrapperComponent; | ||
let component: DaffTreeComponent; | ||
let fixture: ComponentFixture<WrapperComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [DaffTreeModule, CommonModule], | ||
declarations: [WrapperComponent], | ||
}) | ||
.compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(WrapperComponent); | ||
wrapper = fixture.componentInstance; | ||
component = fixture.debugElement.query(By.css('ul[daff-tree]')).componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(wrapper).toBeTruthy(); | ||
}); | ||
|
||
it('should render two nodes when renderMode is `not-in-dom`', () => { | ||
wrapper.data = { title: 'Root', url: '', id: '', items: [ | ||
{ title: 'Child A', url: '', id: '', items: [ | ||
{ title: 'Child Aa', url: '', id: '', items: [], data: {}}, | ||
], data: {}}, | ||
{ title: 'Child B', url: '', id: '', items: [], data: {}}, | ||
], data: {}}; | ||
wrapper.renderMode = 'not-in-dom'; | ||
fixture.detectChanges(); | ||
expect(fixture.debugElement.queryAll(By.css('li')).length).toEqual(2); | ||
}); | ||
|
||
it('should render three nodes when renderMode is `in-dom`', () => { | ||
wrapper.data = { title: 'Root', url: '', id: '', items: [ | ||
{ title: 'Child A', url: '', id: '', items: [ | ||
{ title: 'Child Aa', url: '', id: '', items: [], data: {}}, | ||
], data: {}}, | ||
{ title: 'Child B', url: '', id: '', items: [], data: {}}, | ||
], data: {}}; | ||
wrapper.renderMode = 'in-dom'; | ||
fixture.detectChanges(); | ||
expect(fixture.debugElement.queryAll(By.css('li')).length).toEqual(3); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
<ng-container *ngFor="let node of flatTree; trackBy: trackByTreeElement"> | ||
<li [attr.aria-level]="node.level"> | ||
<ng-container | ||
*ngTemplateOutlet="node.hasChildren ? withChildrenTemplate : treeItemTemplate; context: { $implicit: node }"> | ||
</ng-container> | ||
</li> | ||
<ng-container> | ||
<li [attr.aria-level]="node.level" [class.hidden]="!node.visible"> | ||
<ng-container | ||
*ngTemplateOutlet="node.hasChildren ? withChildrenTemplate : treeItemTemplate; context: { $implicit: node }"> | ||
</ng-container> | ||
</li> | ||
</ng-container> | ||
</ng-container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.