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.
This commit is contained in:
Ted Johansson 2023-04-06 14:58:40 +08:00 committed by GitHub
parent b2a951e4a5
commit 1b132dad0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -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,
});

View File

@ -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`
<Bookmark
@ -40,5 +41,9 @@ module("Integration | Component | bookmark", function (hooks) {
"2020-05-15"
);
assert.strictEqual(query("#custom-time").value, "09:45");
assert.strictEqual(
query(".selected-name > .name").innerHTML.trim(),
I18n.t("bookmarks.auto_delete_preference.never")
);
});
});