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

Replace inheritance attempt with stimulus outlets instead

Kabiru Mwenja587142758832
diff --git a/app/components/work_packages/activities_tab/index_component.rb b/app/components/work_packages/activities_tab/index_component.rb
index 21501794a5d..a5481b29566 100644
--- a/app/components/work_packages/activities_tab/index_component.rb
+++ b/app/components/work_packages/activities_tab/index_component.rb
@@ -52,9 +52,9 @@ module WorkPackages
def wrapper_data_attributes
{
test_selector: "op-wp-activity-tab",
- controller: [base_controller, index_stimulus_controller].join(" "),
+ controller: index_stimulus_controller,
"application-target": "dynamic",
- "#{base_controller}-notification-center-path-name-value": notifications_path,
+ "#{index_stimulus_controller}-notification-center-path-name-value": notifications_path,
"#{index_stimulus_controller}-update-streams-path-value": update_streams_work_package_activities_path(work_package),
"#{index_stimulus_controller}-sorting-value": journal_sorting,
"#{index_stimulus_controller}-filter-value": filter,
@@ -68,16 +68,15 @@ module WorkPackages
end
def add_comment_wrapper_data_attributes
- stimulus_controller = "work-packages--activities-tab--restricted-comment"
-
{
test_selector: "op-work-package-journal--new-comment-component",
- controller: stimulus_controller,
+ controller: restricted_comment_stimulus_controller,
"application-target": "dynamic",
- "#{stimulus_controller}-target": "formContainer",
- action: "#{index_stimulus_controller}:onSubmit-end@window->#{stimulus_controller}#onSubmitEnd",
- "#{stimulus_controller}-highlight-class": "work-packages-activities-tab-journals-new-component--journal-notes-body__restricted-comment", # rubocop:disable Layout/LineLength
- "#{stimulus_controller}-hidden-class": "d-none"
+ "#{restricted_comment_stimulus_controller}-target": "formContainer",
+ action: "#{index_stimulus_controller}:onSubmit-end@window->#{restricted_comment_stimulus_controller}#onSubmitEnd",
+ "#{restricted_comment_stimulus_controller}-highlight-class": "work-packages-activities-tab-journals-new-component--journal-notes-body__restricted-comment", # rubocop:disable Layout/LineLength
+ "#{restricted_comment_stimulus_controller}-hidden-class": "d-none",
+ "#{restricted_comment_stimulus_controller}-#{index_stimulus_controller}-outlet": "##{wrapper_key}"
}
end
@@ -94,8 +93,8 @@ module WorkPackages
User.current.allowed_in_work_package?(:add_work_package_notes, @work_package)
end
- def base_controller = "work-packages--activities-tab--base"
def index_stimulus_controller = "work-packages--activities-tab--index"
+ def restricted_comment_stimulus_controller = "work-packages--activities-tab--restricted-comment"
def unsaved_changes_confirmation_message
I18n.t("activities.work_packages.activity_tab.unsaved_changes_confirmation_message")
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/base.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/base.controller.ts
deleted file mode 100644
index 7463ea48b10..00000000000
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/base.controller.ts
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * -- copyright
- * OpenProject is an open source project management software.
- * Copyright (C) 2023 the OpenProject GmbH
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version 3.
- *
- * OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
- * Copyright (C) 2006-2013 Jean-Philippe Lang
- * Copyright (C) 2010-2013 the ChiliProject Team
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * See COPYRIGHT and LICENSE files for more details.
- * ++
- */
-
-import { Controller } from '@hotwired/stimulus';
-
-export class BaseController extends Controller {
- static values = {
- notificationCenterPathName: { type: String, default: '/notifications' },
- };
-
- declare readonly notificationCenterPathNameValue:string;
-
- private readonly MOBILE_BREAKPOINT = 1279;
- private readonly MOBILE_BREAKPOINT_WITHIN_SPLIT_SCREENS = 1013;
-
- public isMobile():boolean {
- if (this.isWithinNotificationCenter() || this.isWithinSplitScreen()) {
- return window.innerWidth < this.MOBILE_BREAKPOINT_WITHIN_SPLIT_SCREENS;
- }
- return window.innerWidth < this.MOBILE_BREAKPOINT;
- }
-
- public isWithinNotificationCenter():boolean {
- return window.location.pathname.includes(this.notificationCenterPathNameValue);
- }
-
- public isWithinSplitScreen():boolean {
- return window.location.pathname.includes('work_packages/details');
- }
-}
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 4e8d3079979..6df93831971 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
@@ -28,7 +28,7 @@
* ++
*/
-import { BaseController } from './base.controller';
+import { Controller } from '@hotwired/stimulus';
import {
ICKEditorInstance,
} from 'core-app/shared/components/editor/components/ckeditor/ckeditor.types';
@@ -47,21 +47,19 @@ interface CustomEventWithIdParam extends Event {
};
}
-export default class IndexController extends BaseController {
- static get values() {
- return {
- ...super.values,
- updateStreamsPath: String,
- sorting: String,
- pollingIntervalInMs: Number,
- filter: String,
- userId: Number,
- workPackageId: Number,
- lastServerTimestamp: String,
- showConflictFlashMessageUrl: String,
- unsavedChangesConfirmationMessage: String,
- };
- }
+export default class IndexController extends Controller {
+ static values = {
+ updateStreamsPath: String,
+ sorting: String,
+ pollingIntervalInMs: Number,
+ filter: String,
+ userId: Number,
+ workPackageId: Number,
+ notificationCenterPathName: String,
+ lastServerTimestamp: String,
+ showConflictFlashMessageUrl: String,
+ unsavedChangesConfirmationMessage: String,
+ };
static targets = ['journalsContainer', 'buttonRow', 'formRow', 'form', 'formSubmitButton', 'reactionButton'];
@@ -79,6 +77,7 @@ export default class IndexController extends BaseController {
declare lastServerTimestampValue:string;
declare intervallId:number;
declare pollingIntervalInMsValue:number;
+ declare notificationCenterPathNameValue:string;
declare filterValue:string;
declare userIdValue:number;
declare workPackageIdValue:number;
@@ -522,6 +521,22 @@ export default class IndexController extends BaseController {
return document.querySelector(`[data-anchor-${activityAnchorName}-id="${activityId}"]`);
}
+ // Code Maintenance: Get rid of this JS based view port checks when activities are rendered in fully primierized activity tab in all contexts
+ isMobile():boolean {
+ if (this.isWithinNotificationCenter() || this.isWithinSplitScreen()) {
+ return window.innerWidth < 1013;
+ }
+ return window.innerWidth < 1279;
+ }
+
+ private isWithinNotificationCenter():boolean {
+ return window.location.pathname.includes(this.notificationCenterPathNameValue);
+ }
+
+ private isWithinSplitScreen():boolean {
+ return window.location.pathname.includes('work_packages/details');
+ }
+
private setCssClasses() {
if (this.isWithinNotificationCenter()) {
this.element.classList.add('work-packages-activities-tab-index-component--within-notification-center');
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/restricted-comment.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/restricted-comment.controller.ts
index 303a1eeccc3..fc79466e670 100644
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/restricted-comment.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/restricted-comment.controller.ts
@@ -28,15 +28,18 @@
* ++
*/
-import { BaseController } from './base.controller';
+import { Controller } from '@hotwired/stimulus';
+import type IndexController from './index.controller';
-export default class RestrictedCommentController extends BaseController {
+export default class RestrictedCommentController extends Controller {
static targets = ['restrictedCheckbox', 'formContainer', 'learnMoreLink'];
+ static outlets = ['work-packages--activities-tab--index'];
static classes = ['highlight', 'hidden'];
declare readonly restrictedCheckboxTarget:HTMLInputElement;
declare readonly formContainerTarget:HTMLElement;
declare readonly learnMoreLinkTarget:HTMLAnchorElement;
+ declare readonly workPackagesActivitiesTabIndexOutlet:IndexController;
declare readonly highlightClass:string;
declare readonly hiddenClass:string;
@@ -53,7 +56,7 @@ export default class RestrictedCommentController extends BaseController {
}
private toggleLearnMoreLink(isChecked:boolean):void {
- if (this.isMobile()) return; // hidden on mobile
+ if (this.workPackagesActivitiesTabIndexOutlet.isMobile()) return; // hidden on mobile
this.learnMoreLinkTarget.classList.toggle(this.hiddenClass, !isChecked);
}