-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Feature: Tree expansion state #18227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
8165dc3
implement tree expansion logic
madsrasmussen 677d2ae
wip test example
madsrasmussen 94105ac
Merge branch 'v15/dev' into v15/feature/tree-expansion
madsrasmussen 78b53cd
Merge branch 'v15/dev' into v15/feature/tree-expansion
madsrasmussen 3ef8f21
support complex expansion
madsrasmussen 52479c1
extend entity
madsrasmussen c7813e0
extend with model
madsrasmussen 7500a03
Merge branch 'v15/dev' into v15/feature/tree-expansion
madsrasmussen bdd65c0
Update tree-item-context.interface.ts
madsrasmussen a88cdce
use expansion model to observe open state
madsrasmussen 1ac8c3b
clean up
madsrasmussen 1e42ae2
fall back to tree context
madsrasmussen 4591b51
Update default-tree.context.ts
madsrasmussen d2f3698
Update default-tree.context.ts
madsrasmussen e697740
Update default-tree.context.ts
madsrasmussen 25fb01e
clean up
madsrasmussen 626a186
Merge branch 'v15/dev' into v15/feature/tree-expansion
madsrasmussen 3d8a3e9
simplify model and state
madsrasmussen e4a08d1
refactor to manager
madsrasmussen 0e1254e
remove test data
madsrasmussen 9900456
Update default-tree.context.ts
madsrasmussen 7482248
rename
madsrasmussen 06fe2f5
add get method
madsrasmussen 15f39cc
rename to collapse
madsrasmussen bae0ff7
all collapse all method
madsrasmussen a623766
Merge branch 'v15/dev' into v15/feature/tree-expansion
madsrasmussen 67dc5de
fix collapse logic
madsrasmussen c6c1644
Merge branch 'v15/dev' into v15/feature/tree-expansion
madsrasmussen f55ec82
add js docs
madsrasmussen 7aec694
add tests for expansion manager
madsrasmussen 4f091ae
do not load children if the item is already open
madsrasmussen a878186
Update tree-item-element-base.ts
madsrasmussen fab707c
config to expand tree root in pickers
madsrasmussen 5d20dfb
expand tree root for duplicate to
madsrasmussen 400670b
Update tree-expansion-manager.test.ts
madsrasmussen a5626a1
make methods async
madsrasmussen 42be261
Merge branch 'v15/dev' into v15/feature/tree-expansion
nielslyngsoe b6aa63b
use array state
madsrasmussen 8eabec2
add isExpanded helper
madsrasmussen 5265769
refactor to use isExpanded helper
madsrasmussen 9cc302f
fix type issues
madsrasmussen f966260
Merge branch 'v15/dev' into v15/feature/tree-expansion
nielslyngsoe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
1 change: 1 addition & 0 deletions
1
src/Umbraco.Web.UI.Client/src/packages/core/tree/expansion-manager/index.ts
This file contains hidden or 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 @@ | ||
| export * from './tree-expansion-manager.js'; |
107 changes: 107 additions & 0 deletions
107
...aco.Web.UI.Client/src/packages/core/tree/expansion-manager/tree-expansion-manager.test.ts
This file contains hidden or 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,107 @@ | ||
| import { UmbTreeExpansionManager } from './tree-expansion-manager.js'; | ||
| import { expect } from '@open-wc/testing'; | ||
| import { Observable } from '@umbraco-cms/backoffice/external/rxjs'; | ||
| import { customElement } from '@umbraco-cms/backoffice/external/lit'; | ||
| import { UmbControllerHostElementMixin } from '@umbraco-cms/backoffice/controller-api'; | ||
|
|
||
| @customElement('test-my-controller-host') | ||
| class UmbTestControllerHostElement extends UmbControllerHostElementMixin(HTMLElement) {} | ||
|
|
||
| describe('UmbTreeExpansionManager', () => { | ||
| let manager: UmbTreeExpansionManager; | ||
| const item = { entityType: 'test', unique: '123' }; | ||
| const item2 = { entityType: 'test', unique: '456' }; | ||
|
|
||
| beforeEach(() => { | ||
| const hostElement = new UmbTestControllerHostElement(); | ||
| manager = new UmbTreeExpansionManager(hostElement); | ||
| }); | ||
|
|
||
| describe('Public API', () => { | ||
| describe('properties', () => { | ||
| it('has an expansion property', () => { | ||
| expect(manager).to.have.property('expansion').to.be.an.instanceOf(Observable); | ||
| }); | ||
| }); | ||
|
|
||
| describe('methods', () => { | ||
| it('has an isExpanded method', () => { | ||
| expect(manager).to.have.property('isExpanded').that.is.a('function'); | ||
| }); | ||
|
|
||
| it('has a setExpansion method', () => { | ||
| expect(manager).to.have.property('setExpansion').that.is.a('function'); | ||
| }); | ||
|
|
||
| it('has a getExpansion method', () => { | ||
| expect(manager).to.have.property('getExpansion').that.is.a('function'); | ||
| }); | ||
|
|
||
| it('has a expandItem method', () => { | ||
| expect(manager).to.have.property('expandItem').that.is.a('function'); | ||
| }); | ||
|
|
||
| it('has a collapseItem method', () => { | ||
| expect(manager).to.have.property('collapseItem').that.is.a('function'); | ||
| }); | ||
|
|
||
| it('has a collapseAll method', () => { | ||
| expect(manager).to.have.property('collapseAll').that.is.a('function'); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('isExpanded', () => { | ||
| it('checks if an item is expanded', (done) => { | ||
| manager.setExpansion([item]); | ||
| const isExpanded = manager.isExpanded(item); | ||
| expect(isExpanded).to.be.an.instanceOf(Observable); | ||
| manager.isExpanded(item).subscribe((value) => { | ||
| console.log('VALUE', value); | ||
| expect(value).to.be.true; | ||
| done(); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('setExpansion', () => { | ||
| it('sets the expansion state', () => { | ||
| const expansion = [item]; | ||
| manager.setExpansion(expansion); | ||
| expect(manager.getExpansion()).to.deep.equal(expansion); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getExpansion', () => { | ||
| it('gets the expansion state', () => { | ||
| const expansion = [item]; | ||
| manager.setExpansion(expansion); | ||
| expect(manager.getExpansion()).to.deep.equal(expansion); | ||
| }); | ||
| }); | ||
|
|
||
| describe('expandItem', () => { | ||
| it('expands an item', async () => { | ||
| await manager.expandItem(item); | ||
| expect(manager.getExpansion()).to.deep.equal([item]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('collapseItem', () => { | ||
| it('collapses an item', async () => { | ||
| await manager.expandItem(item); | ||
| expect(manager.getExpansion()).to.deep.equal([item]); | ||
| manager.collapseItem(item); | ||
| expect(manager.getExpansion()).to.deep.equal([]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('collapseAll', () => { | ||
| it('collapses all items', () => { | ||
| manager.setExpansion([item, item2]); | ||
| expect(manager.getExpansion()).to.deep.equal([item, item2]); | ||
| manager.collapseAll(); | ||
| expect(manager.getExpansion()).to.deep.equal([]); | ||
| }); | ||
| }); | ||
| }); |
81 changes: 81 additions & 0 deletions
81
src/Umbraco.Web.UI.Client/src/packages/core/tree/expansion-manager/tree-expansion-manager.ts
This file contains hidden or 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,81 @@ | ||
| import type { UmbTreeExpansionModel } from './types.js'; | ||
| import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api'; | ||
| import type { UmbEntityModel } from '@umbraco-cms/backoffice/entity'; | ||
| import { UmbArrayState, type Observable } from '@umbraco-cms/backoffice/observable-api'; | ||
|
|
||
| /** | ||
| * Manages the expansion state of a tree | ||
| * @exports | ||
| * @class UmbTreeExpansionManager | ||
| * @augments {UmbControllerBase} | ||
| */ | ||
| export class UmbTreeExpansionManager extends UmbControllerBase { | ||
| #expansion = new UmbArrayState<UmbEntityModel>([], (x) => x.unique); | ||
| expansion = this.#expansion.asObservable(); | ||
|
|
||
| /** | ||
| * Checks if an entity is expanded | ||
| * @param {UmbEntityModel} entity The entity to check | ||
| * @param {string} entity.entityType The entity type | ||
| * @param {string} entity.unique The unique key | ||
| * @returns {Observable<boolean>} True if the entity is expanded | ||
| * @memberof UmbTreeExpansionManager | ||
| */ | ||
| isExpanded(entity: UmbEntityModel): Observable<boolean> { | ||
| return this.#expansion.asObservablePart((entries) => | ||
| entries?.some((entry) => entry.entityType === entity.entityType && entry.unique === entity.unique), | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Sets the expansion state | ||
| * @param {UmbTreeExpansionModel | undefined} expansion The expansion state | ||
| * @memberof UmbTreeExpansionManager | ||
| * @returns {void} | ||
| */ | ||
| setExpansion(expansion: UmbTreeExpansionModel): void { | ||
| this.#expansion.setValue(expansion); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the expansion state | ||
| * @memberof UmbTreeExpansionManager | ||
| * @returns {UmbTreeExpansionModel} The expansion state | ||
| */ | ||
| getExpansion(): UmbTreeExpansionModel { | ||
| return this.#expansion.getValue(); | ||
| } | ||
|
|
||
| /** | ||
| * Opens a child tree item | ||
| * @param {UmbEntityModel} entity The entity to open | ||
| * @param {string} entity.entityType The entity type | ||
| * @param {string} entity.unique The unique key | ||
| * @memberof UmbTreeExpansionManager | ||
| * @returns {Promise<void>} | ||
| */ | ||
| public async expandItem(entity: UmbEntityModel): Promise<void> { | ||
| this.#expansion.appendOne(entity); | ||
| } | ||
|
|
||
| /** | ||
| * Closes a child tree item | ||
| * @param {UmbEntityModel} entity The entity to close | ||
| * @param {string} entity.entityType The entity type | ||
| * @param {string} entity.unique The unique key | ||
| * @memberof UmbTreeExpansionManager | ||
| * @returns {Promise<void>} | ||
| */ | ||
| public async collapseItem(entity: UmbEntityModel): Promise<void> { | ||
| this.#expansion.filter((x) => x.entityType !== entity.entityType || x.unique !== entity.unique); | ||
| } | ||
|
|
||
| /** | ||
| * Closes all child tree items | ||
| * @memberof UmbTreeExpansionManager | ||
| * @returns {Promise<void>} | ||
| */ | ||
| public async collapseAll(): Promise<void> { | ||
| this.#expansion.setValue([]); | ||
| } | ||
| } |
3 changes: 3 additions & 0 deletions
3
src/Umbraco.Web.UI.Client/src/packages/core/tree/expansion-manager/types.ts
This file contains hidden or 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,3 @@ | ||
| import type { UmbEntityModel } from '@umbraco-cms/backoffice/entity'; | ||
|
|
||
| export type UmbTreeExpansionModel = Array<UmbEntityModel>; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.