From 1b132dad0d5aeaa0ba183b65418e8090f5f0c63d Mon Sep 17 00:00:00 2001 From: Ted Johansson Date: Thu, 6 Apr 2023 14:58:40 +0800 Subject: [PATCH] FIX: Correctly pre-select first option in bookmark notification drop-down (#20976) When selecting the "Keep bookmark" in the user preference for what to do after a bookmark reminder is sent, it does not propagate to the drop-down in the "Create bookmark" modal. Instead it defaults to "Keep bookmark and clear reminder". All other options work fine. We set a default ("Keep bookmark and clear reminder") if no user preference is found, However, this uses the index of the option, and the index of the first option ("Keep bookmark") is 0, which is treated as falsey in JavaScript, thus causing the default to be selected. This change switches from logical "or" conditional `||` operator to nullish coalescing `??` operator. --- .../javascripts/discourse/app/components/bookmark.js | 2 +- .../tests/integration/components/bookmark-test.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/bookmark.js b/app/assets/javascripts/discourse/app/components/bookmark.js index 51cce43e7ce..7132f03a5cc 100644 --- a/app/assets/javascripts/discourse/app/components/bookmark.js +++ b/app/assets/javascripts/discourse/app/components/bookmark.js @@ -61,7 +61,7 @@ export default Component.extend({ showOptions: false, _itsatrap: new ItsATrap(), autoDeletePreference: - this.model.autoDeletePreference || + this.model.autoDeletePreference ?? AUTO_DELETE_PREFERENCES.CLEAR_REMINDER, }); diff --git a/app/assets/javascripts/discourse/tests/integration/components/bookmark-test.js b/app/assets/javascripts/discourse/tests/integration/components/bookmark-test.js index f5243652b93..2d254feba00 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/bookmark-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/bookmark-test.js @@ -3,6 +3,7 @@ import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { render } from "@ember/test-helpers"; import { query } from "discourse/tests/helpers/qunit-helpers"; import { hbs } from "ember-cli-htmlbars"; +import I18n from "I18n"; module("Integration | Component | bookmark", function (hooks) { setupRenderingTest(hooks); @@ -21,7 +22,7 @@ module("Integration | Component | bookmark", function (hooks) { test("prefills the custom reminder type date and time", async function (assert) { let name = "test"; let reminderAt = "2020-05-15T09:45:00"; - this.model = { id: 1, name, reminderAt }; + this.model = { id: 1, autoDeletePreference: 0, name, reminderAt }; await render(hbs` .name").innerHTML.trim(), + I18n.t("bookmarks.auto_delete_preference.never") + ); }); });