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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Require confirmation on Kbd Esc with editor content
Kabiru Mwenjac0cb078e8f38
diff --git a/app/components/work_packages/activities_tab/index_component.rb b/app/components/work_packages/activities_tab/index_component.rbindex 1454db30a84..2cee3709ece 100644--- a/app/components/work_packages/activities_tab/index_component.rb+++ b/app/components/work_packages/activities_tab/index_component.rb@@ -64,7 +64,8 @@ module WorkPackages"#{stimulus_controller}-polling-interval-in-ms-value": polling_interval,"#{stimulus_controller}-notification-center-path-name-value": notifications_path,"#{stimulus_controller}-show-conflict-flash-message-url-value": show_conflict_flash_message_work_packages_path,- "#{stimulus_controller}-last-server-timestamp-value": last_server_timestamp+ "#{stimulus_controller}-last-server-timestamp-value": last_server_timestamp,+ "#{stimulus_controller}-unsaved-changes-confirmation-message-value": unsaved_changes_confirmation_message}end@@ -95,6 +96,10 @@ module WorkPackagesenddef activities_tab_index_stimulus_controller = "work-packages--activities-tab--index"++ def unsaved_changes_confirmation_message+ I18n.t("activities.work_packages.activity_tab.unsaved_changes_confirmation_message")+ endendendenddiff --git a/config/locales/en.yml b/config/locales/en.ymlindex fc80bcb7c48..1ebd4310ea5 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -52,6 +52,7 @@ en:restricted_visibility: Restricted visibilityrestricted_visibility_explainer: Only visible to a limited group of members. %{who_link_text}restricted_journal: Restricted comments are visible to a limited group of members.+ unsaved_changes_confirmation_message: You have unsaved changes. Are you sure you want to close the editor?admin:plugins:@@ -3674,7 +3675,7 @@ en:<br/>Example: <code>/my/page</code>setting_after_login_default_redirect_url: "After login redirect"- setting_after_login_default_redirect_url_text_html: >+ setting_after_login_default_redirect_url_text_html: >Set a default path to redirect users after login, if no back link was provided. Redirects to home page if not set.<br/>Example: <code>/my/page</code>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.tsindex a0250c4a579..08e36601da1 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@@ -58,6 +58,7 @@ export default class IndexController extends Controller {notificationCenterPathName: String,lastServerTimestamp: String,showConflictFlashMessageUrl: String,+ unsavedChangesConfirmationMessage: String,};static targets = ['journalsContainer', 'buttonRow', 'formRow', 'form', 'formSubmitButton', 'reactionButton'];@@ -83,6 +84,8 @@ export default class IndexController extends Controller {declare rescuedEditorDataKey:string;declare latestKnownChangesetUpdatedAtKey:string;declare showConflictFlashMessageUrlValue:string;+ declare unsavedChangesConfirmationMessageValue:string;+private handleWorkPackageUpdateBound:EventListener;private handleVisibilityChangeBound:EventListener;private rescueEditorContentBound:EventListener;@@ -719,7 +722,11 @@ export default class IndexController extends Controller {if (this.isEditorEmpty()) {this.hideEditor();} else {- this.adjustJournalContainerMargin();+ const shouldClose = window.confirm(this.unsavedChangesConfirmationMessageValue);++ if (shouldClose) {+ this.hideEditor();+ }}}diff --git a/spec/features/activities/work_package/activity_tab_comment_editor_spec.rb b/spec/features/activities/work_package/activity_tab_comment_editor_spec.rbindex 6e09de34ace..3000155832b 100644--- a/spec/features/activities/work_package/activity_tab_comment_editor_spec.rb+++ b/spec/features/activities/work_package/activity_tab_comment_editor_spec.rb@@ -61,15 +61,38 @@ RSpec.describe "Work package activity tab comment editor",endend- context "when editor content is not empty" do- it "is not dismissable via keyboard Esc" do- activity_tab.add_comment(text: "Sample text", save: false)+ context "when editor has content" do+ context "and the user confirms the dismissal" do+ it "requires confirmation to dismiss via keyboard Esc" do+ activity_tab.add_comment(text: "Sample text", save: false)- activity_tab.expect_focus_on_editor- activity_tab.dismiss_comment_editor_with_esc+ activity_tab.expect_focus_on_editor- activity_tab.expect_focus_on_editor- expect(page).to have_test_selector("op-work-package-journal-form-element")+ accept_alert do+ activity_tab.dismiss_comment_editor_with_esc+ end++ expect(page).not_to have_test_selector("op-work-package-journal-form-element")+ end+ end++ context "and the user cancels the dismissal" do+ it "does not dismiss the editor" do+ activity_tab.add_comment(text: "Sample text", save: false)++ activity_tab.expect_focus_on_editor++ dismiss_confirm do+ activity_tab.dismiss_comment_editor_with_esc+ end++ activity_tab.expect_focus_on_editor++ page.within_test_selector("op-work-package-journal-form-element") do+ editor = activity_tab.get_editor_form_field_element+ expect(editor.input_element.text).to eq("Sample text")+ end+ endendendend