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

update workpackage attributes on main workpackage section when changeset was polled

Jonas Jabarica0e80f0a4c3
diff --git a/app/components/work_packages/activities_tab/journals/item_component/details.rb b/app/components/work_packages/activities_tab/journals/item_component/details.rb
index 6cb3546250f..b83e58eeeb5 100644
--- a/app/components/work_packages/activities_tab/journals/item_component/details.rb
+++ b/app/components/work_packages/activities_tab/journals/item_component/details.rb
@@ -184,7 +184,12 @@ module WorkPackages
end
def render_single_detail(container, detail)
- container.with_row(flex_layout: true, my: 1, align_items: :flex_start) do |detail_container|
+ container.with_row(
+ flex_layout: true,
+ my: 1,
+ align_items: :flex_start,
+ classes: "work-packages-activities-tab-journals-item-component-details--journal-detail-container"
+ ) do |detail_container|
render_stem_line(detail_container)
render_detail_description(detail_container, detail)
end
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts
index ca82eafa607..09a826e09bd 100644
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts
@@ -3,6 +3,8 @@ import {
ICKEditorInstance,
} from 'core-app/shared/components/editor/components/ckeditor/ckeditor.types';
import { TurboRequestsService } from 'core-app/core/turbo/turbo-requests.service';
+import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
+import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
interface CustomEventWithIdParam extends Event {
params:{
@@ -51,7 +53,13 @@ export default class IndexController extends Controller {
private updateInProgress:boolean;
private turboRequests:TurboRequestsService;
+ private apiV3Service:ApiV3Service;
+
async connect() {
+ const context = await window.OpenProject.getPluginContext();
+ this.turboRequests = context.services.turboRequests;
+ this.apiV3Service = context.services.apiV3Service;
+
this.setLocalStorageKey();
this.setLastUpdateTimestamp();
this.setupEventListeners();
@@ -60,8 +68,24 @@ export default class IndexController extends Controller {
this.populateRescuedEditorContent();
this.markAsConnected();
- const context = await window.OpenProject.getPluginContext();
- this.turboRequests = context.services.turboRequests;
+ // Towards using updateDisplayedWorkPackageAttributes here:
+ //
+ // this ideally only is triggered when switched back to the activities tab from e.g. the "Files" tab
+ // in order to make sure that the state of the displayed work package attributes is aligned with the state of the refreshed journal entries
+ //
+ // this is necessary because the polling for updates (and related work package attribute updates) only happens when the activity tab is connected
+ //
+ // without any further checks, this update is currently triggered even after the very first rendering of the activity tab
+ //
+ // this is not ideal but I don't want to introduce another hacky "ui-state-check" for now
+ this.updateDisplayedWorkPackageAttributes();
+
+ // something like below could be used to check for the ui state in the disconnect method
+ // in order to identify if the activity tab was connected at least once
+ // and then call updateDisplayedWorkPackageAttributes accordingly after an "implicit" tab change:
+ //
+ // const workPackageContainer = document.getElementsByTagName('wp-full-view-entry')[0] as HTMLElement;
+ // workPackageContainer.dataset.activityTabWasConnected = 'true';
}
disconnect() {
@@ -72,10 +96,12 @@ export default class IndexController extends Controller {
}
private markAsConnected() {
+ // used in specs for timing
(this.element as HTMLElement).dataset.stimulusControllerConnected = 'true';
}
private markAsDisconnected() {
+ // used in specs for timing
(this.element as HTMLElement).dataset.stimulusControllerConnected = 'false';
}
@@ -129,6 +155,7 @@ export default class IndexController extends Controller {
async updateActivitiesList() {
if (this.updateInProgress) return;
+
this.updateInProgress = true;
const journalsContainerAtBottom = this.isJournalsContainerScrolledToBottom(this.journalsContainerTarget);
@@ -161,8 +188,24 @@ export default class IndexController extends Controller {
private handleUpdateStreamsResponse(html:string, journalsContainerAtBottom:boolean) {
this.setLastUpdateTimestamp();
- // only process append and prepend actions
- if (!(html.includes('action="append"') || html.includes('action="prepend"'))) {
+ this.checkForAndHandleWorkPackageUpdate(html);
+ this.performAutoScrolling(html, journalsContainerAtBottom);
+ }
+
+ private checkForAndHandleWorkPackageUpdate(html:string) {
+ if (html.includes('work-packages-activities-tab-journals-item-component-details--journal-detail-container')) {
+ this.updateDisplayedWorkPackageAttributes();
+ }
+ }
+
+ private updateDisplayedWorkPackageAttributes() {
+ const wp = this.apiV3Service.work_packages.id(this.workPackageIdValue);
+ void wp.refresh();
+ }
+
+ 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;
}
// the timeout is require in order to give the Turb.renderStream method enough time to render the new journals
diff --git a/spec/features/activities/work_package/activities_spec.rb b/spec/features/activities/work_package/activities_spec.rb
index 51022d5a90e..6f697d627ed 100644
--- a/spec/features/activities/work_package/activities_spec.rb
+++ b/spec/features/activities/work_package/activities_spec.rb
@@ -923,4 +923,49 @@ RSpec.describe "Work package activity", :js, :with_cuprite, with_flag: { primeri
end
end
end
+
+ describe "work package attribute updates" do
+ let(:work_package) { create(:work_package, project:, author: admin) }
+
+ let!(:first_comment_by_member) do
+ create(:work_package_journal, user: member, notes: "First comment by member", journable: work_package, version: 2)
+ end
+
+ current_user { admin }
+
+ before do
+ # set WORK_PACKAGES_ACTIVITIES_TAB_POLLING_INTERVAL_IN_MS to 1000
+ # to speed up the polling interval for test duration
+ ENV["WORK_PACKAGES_ACTIVITIES_TAB_POLLING_INTERVAL_IN_MS"] = "1000"
+
+ wp_page.visit!
+ wp_page.wait_for_activity_tab
+ end
+
+ after do
+ ENV.delete("WORK_PACKAGES_ACTIVITIES_TAB_POLLING_INTERVAL_IN_MS")
+ end
+
+ it "shows the updated work package attribute without reload", :aggregate_failures do
+ # wait for the latest comments to be loaded before proceeding!
+ activity_tab.expect_journal_notes(text: "First comment by member")
+ wp_page.expect_attributes(subject: work_package.subject)
+
+ # we need to wait a bit before triggering the update below
+ # otherwise the update is already picked up by the initial (async) workpackage attributes update called in the connect hook
+ # and we wouldn't test the polling based update below
+ sleep 2
+ wp_page.expect_attributes(subject: work_package.subject) # check if the initial update picked up the original subject
+
+ # simulate another user is updating the work package subject
+ # this btw does behave very strangely in test env and will not assign the change to the specified user
+ WorkPackages::UpdateService.new(user: admin, model: work_package).call(subject: "Subject updated")
+
+ # activity tab should show the updated attribute
+ activity_tab.expect_journal_changed_attribute(text: "Subject updated")
+
+ # work package page should also show the updated attribute
+ wp_page.expect_attributes(subject: "Subject updated")
+ end
+ end
end