Skip to content
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

feat(design): expand selected tree items on initial render #2938

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

griest024
Copy link
Member

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Fixes: #2931

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

@griest024 griest024 requested a review from xelaint July 23, 2024 18:45
@griest024 griest024 requested a review from a team as a code owner July 23, 2024 18:45
@griest024
Copy link
Member Author

@xelaint can you review the behavior to make sure that you're happy with it?

@xelaint
Copy link
Member

xelaint commented Jul 23, 2024

I'm not sure if I like the scroll to view behavior. Can we remove that for now?

@griest024 griest024 force-pushed the feat/design/tree/expand-active-items-on-initial-render branch from 971595f to a68a5b1 Compare July 23, 2024 19:09
@griest024
Copy link
Member Author

I'm not sure if I like the scroll to view behavior. Can we remove that for now?

okay removed for now but the user can easily end up in a position where they cannot see the active item on initial render

@griest024
Copy link
Member Author

@xelaint note that the focusing behavior of tree item actually appears to scroll the element into view. This doesn't work for deeply nested items though (docs/packages/search/driver/federated)

* Opens parent and parent of parent all the way to the root of the tree.
*/
openAncestors() {
const openParent = (tree: DaffTreeUi<unknown>) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the recursion and replace with iteration.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what list would be iterated? Recursion is naturally suited to tree structures

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this to use collect (which is itself recursive but has the added protection of a max depth) and iteration.

libs/design/tree/src/tree-item/tree-item.directive.ts Outdated Show resolved Hide resolved
libs/design/tree/src/tree-item/tree-item.directive.ts Outdated Show resolved Hide resolved
this.items.changes.pipe(
takeUntilDestroyed(this.destroyRef),
).subscribe((items: QueryList<DaffTreeItemDirective>) => {
runInInjectionContext(this.injector, () => afterNextRender(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the selected state only available after ngAfterViewInit? Can this be done sooner? Perhaps ngAfterContentInit?

If this needs ngAfterViewInit can we do this without a subscription?

Copy link
Member Author

@griest024 griest024 Jul 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the ContentChildren aren't available in ngAfterContentInit because they're rendered with ngTemplateOutlet. yeah I could do it without the sub

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually no, this doesn't work. The selected value of the tree items isn't updated

const activeTreeItem = items.find((treeItem) => treeItem.selected);
if (activeTreeItem) {
activeTreeItem.openAncestors();
this.cd.markForCheck();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe that a markForCheck is sufficient here. It may be that we have to do a full detectChanges. I would expect Angular to error here with a Expression changed after is has been checked.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't noticed that error in the console. I can still change it if you want though

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the task queue shift created by the observable is likely hiding the error.

@xelaint xelaint added the package: design @daffodil/design label Jul 24, 2024
@xelaint xelaint added this to the Daffodil v1.0 milestone Jul 24, 2024
@xelaint
Copy link
Member

xelaint commented Jul 26, 2024

The UI LGTM.

@damienwebdev
Copy link
Member

I haven't re-reviewed this yet, but please do not merge it until I do.

@griest024 griest024 force-pushed the feat/design/tree/expand-active-items-on-initial-render branch from 58acbec to 8563015 Compare August 8, 2024 13:19
@xelaint xelaint added the status: awaiting review This PR is awaiting review label Aug 12, 2024
@griest024
Copy link
Member Author

bump @damienwebdev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: design @daffodil/design status: awaiting review This PR is awaiting review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT] A parent tree item should be expanded if there is an active/selected tree item within it
3 participants