Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix auto-scrolling after activities tab refactoring

Kabiru Mwenjaa285cdcd151d
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/auto-scrolling.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/auto-scrolling.controller.ts
index ab7d9d5beb2..b69f98c7ccf 100644
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/auto-scrolling.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/auto-scrolling.controller.ts
@@ -70,8 +70,8 @@ export default class AutoScrollingController extends withIndexOutletMixin(Contro
window.location.hash = `#${anchorName}-${activityId}`;
}
- performAutoScrollingOnStreamsUpdate() {
- if (this.indexOutlet.sortingValue === 'asc' && this.isJournalsContainerScrolledToBottom()) {
+ performAutoScrollingOnStreamsUpdate(journalsContainerAtBottom:boolean = false) {
+ if (this.indexOutlet.sortingValue === 'asc' && journalsContainerAtBottom) {
// scroll to (new) bottom if sorting is ascending and journals container was already at bottom before a new activity was added
if (this.isMobile()) {
this.scrollInputContainerIntoView(300);
@@ -198,4 +198,16 @@ export default class AutoScrollingController extends withIndexOutletMixin(Contro
private get inputContainer():HTMLElement | null {
return this.element.querySelector('.work-packages-activities-tab-journals-new-component');
}
+
+ isJournalsContainerScrolledToBottom():boolean {
+ let atBottom = false;
+ // we have to handle different scrollable containers for different viewports/pages in order to identify if the user is at the bottom of the journals
+ // DOM structure different for notification center and workpackage detail view as well
+ const scrollableContainer = this.scrollableContainer;
+ if (scrollableContainer) {
+ atBottom = (scrollableContainer.scrollTop + scrollableContainer.clientHeight + 10) >= scrollableContainer.scrollHeight;
+ }
+
+ return atBottom;
+ }
}
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/polling.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/polling.controller.ts
index 636825d8b7f..7e683bfc48c 100644
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/polling.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/polling.controller.ts
@@ -90,9 +90,12 @@ export default class PollingController extends withIndexOutletMixin(Controller)
// otherwise the browser will perform an auto scroll to the before focused button after the stream update was applied
this.unfocusReactionButtons();
+ // Capture scroll position before the update
+ const journalsContainerAtBottom = this.autoScrollingOutlet.isJournalsContainerScrolledToBottom();
+
void this.performUpdateStreamsRequest(this.prepareUpdateStreamsUrl(editingJournals))
.then(({ html, headers }) => {
- this.handleUpdateStreamsResponse(html, headers);
+ this.handleUpdateStreamsResponse(html, headers, journalsContainerAtBottom);
}).catch((error) => {
console.error('Error updating activities list:', error);
}).finally(() => {
@@ -182,8 +185,8 @@ export default class PollingController extends withIndexOutletMixin(Controller)
return url.toString();
}
- private handleUpdateStreamsResponse(html:string, headers:Headers) {
- // the timeout is require in order to give the Turb.renderStream method enough time to render the new journals
+ private handleUpdateStreamsResponse(html:string, headers:Headers, journalsContainerAtBottom:boolean) {
+ // the timeout is required in order to give the Turbo.renderStream method enough time to render the new journals
// the methods below partially rely on the DOM to be updated
// a specific signal would be way better than a static timeout, but I couldn't find a suitable one
setTimeout(() => {
@@ -191,7 +194,7 @@ export default class PollingController extends withIndexOutletMixin(Controller)
this.indexOutlet.setLastServerTimestampViaHeaders(headers);
this.checkForAndHandleWorkPackageUpdate(html);
this.checkForNewNotifications(html);
- this.performAutoScrolling(html);
+ this.performAutoScrolling(html, journalsContainerAtBottom);
this.setLatestKnownChangesetUpdatedAt();
}, 100);
}
@@ -307,12 +310,12 @@ export default class PollingController extends withIndexOutletMixin(Controller)
return editingJournals;
}
- private performAutoScrolling(html:string) {
+ private performAutoScrolling(html:string, journalsContainerAtBottom:boolean) {
// only process append, prepend and update actions
if (!(html.includes('action="append"') || html.includes('action="prepend"') || html.includes('action="update"'))) {
return;
}
- this.autoScrollingOutlet.performAutoScrollingOnStreamsUpdate();
+ this.autoScrollingOutlet.performAutoScrollingOnStreamsUpdate(journalsContainerAtBottom);
}
}
diff --git a/spec/features/activities/work_package/activities_spec.rb b/spec/features/activities/work_package/activities_spec.rb
index 8b3536542be..4e31ea3f652 100644
--- a/spec/features/activities/work_package/activities_spec.rb
+++ b/spec/features/activities/work_package/activities_spec.rb
@@ -1005,7 +1005,7 @@ RSpec.describe "Work package activity", :js, :with_cuprite do
logout
login_as(admin)
- # navigate to the same workpackage, but as a different user
+ # navigate to the same workpackage, as the same user
wp_page.visit!
wp_page.wait_for_activity_tab
# expect the editor to be opened and content to be rescued for the correct user