-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[59769] When adding new relations, auto-scroll to show the newly added relation #17355
base: dev
Are you sure you want to change the base?
[59769] When adding new relations, auto-scroll to show the newly added relation #17355
Conversation
8f2522a
to
6c71aed
Compare
34e143b
to
8775574
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please have a look at my remarks.
frontend/src/stimulus/controllers/dynamic/work-packages/relations-tab/scroll.controller.ts
Outdated
Show resolved
Hide resolved
app/components/work_package_relations_tab/index_component.html.erb
Outdated
Show resolved
Hide resolved
|
||
connect() { | ||
// Wait to ensure DOM is fully loaded | ||
setTimeout(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setTimeout
does not automatically ensure you that the DOM is fully loaded afaik, there might still be some delays that could prevent that could from being executed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have left some comments below
} | ||
|
||
waitForRenderAndAct() { | ||
const element = document.querySelector('[data-scroll-to="true"]'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend to use a stimulus target instead of a normal data attribute. The value is crutial for this controller to work, so it should be an explicit target imho.
if (element) { | ||
element.scrollIntoView({ behavior: 'smooth', block: 'center' }); | ||
} else { | ||
requestAnimationFrame(this.waitForRenderAndAct.bind(this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates like an infinte loop when there is no scroll target (e.g. on a fresh page reload). The code is just executed endlessly.
Further, requestAnimationFrame
is just meant for animations and will execute the code 60 times per second (assuming 60hertz screen), because that makes sense for animations. But you don't have an animation here.
Ticket
https://community.openproject.org/projects/stream-planning-and-reporting/work_packages/59769/activity
Screen recording
Screen.Recording.2024-12-04.at.16.44.53.mov
What are you trying to accomplish?
Scroll to the currently created relation in relations tab.
What approach did you choose and why?
After creating a relation, pass the relation-wp-id to the component for initializing it.
Merge checklist