A platform for community discussion. Free, open, simple.
FIX: Prevent false unsaved changes warning (#36059)
Krzysztof Kotlarek610c1f435600
diff --git a/frontend/discourse/app/components/reviewable-refresh/note-form.gjs b/frontend/discourse/app/components/reviewable-refresh/note-form.gjsindex 3f96070a6b9..f68ea5139fe 100644--- a/frontend/discourse/app/components/reviewable-refresh/note-form.gjs+++ b/frontend/discourse/app/components/reviewable-refresh/note-form.gjs@@ -2,12 +2,14 @@ import Component from "@glimmer/component";import { fn, hash } from "@ember/helper";import { action } from "@ember/object";import { service } from "@ember/service";+import { isEmpty } from "@ember/utils";import ExpandingTextArea from "discourse/components/expanding-text-area";import Form from "discourse/components/form";import PluginOutlet from "discourse/components/plugin-outlet";import lazyHash from "discourse/helpers/lazy-hash";import { ajax } from "discourse/lib/ajax";import { popupAjaxError } from "discourse/lib/ajax-error";+import { bind } from "discourse/lib/decorators";import { i18n } from "discourse-i18n";/**@@ -36,6 +38,11 @@ export default class ReviewableNoteForm extends Component {setFn(event.target.value);}+ @bind+ onDirtyCheck() {+ return !isEmpty(this.formApi.get("content"));+ }+/*** Handles form submission from Form component.*@@ -83,6 +90,7 @@ export default class ReviewableNoteForm extends Component {@data={{hash content=""}}@onSubmit={{this.onSubmit}}@onRegisterApi={{this.registerApi}}+ @onDirtyCheck={{this.onDirtyCheck}}class="reviewable-note-form__form"as |form|>diff --git a/spec/system/viewing_reviewable_spec.rb b/spec/system/viewing_reviewable_spec.rbindex 804edf8a3ad..a06067630fd 100644--- a/spec/system/viewing_reviewable_spec.rb+++ b/spec/system/viewing_reviewable_spec.rb@@ -117,6 +117,31 @@ describe "Viewing reviewable item", type: :system dorefreshed_review_page.click_timeline_tabexpect(page).to have_text("This is a review note.")end++ it "shows confirmation dialog when navigating away with unsaved note, but not after clearing the note" do+ dialog = PageObjects::Components::Dialog.new++ refreshed_review_page.visit_reviewable(reviewable_flagged_post)+ refreshed_review_page.click_timeline_tab++ review_note_form.form.fill_in("content", with: "This is a draft note")++ click_logo++ expect(dialog).to be_open+ expect(dialog).to have_content(I18n.t("js.form_kit.dirty_form"))++ dialog.click_no++ expect(page).to have_current_path("/review/#{reviewable_flagged_post.id}")++ review_note_form.form.fill_in("content", with: "")++ click_logo++ expect(dialog).to be_closed+ expect(page).to have_current_path("/")+ endenddescribe "when the reviewable item is a queued post" do