From 206d8db433d17ef4cb9e7c6f76cc405fc6f3b7c0 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Thu, 22 Apr 2021 09:26:31 +1000 Subject: [PATCH] FIX: Invalid Date on "last" shortcut for timer + bookmarks (#12783) The "last custom date and time" shortcut for the topic timer and bookmarks could get into a state where it had an Invalid Date if the user opened the topic timer modal, clicked Custom Date and then closed the modal without making changes. This has been fixed, the last custom date + time will no longer be set in this case and if somehow the last custom date + time is invalid that option will not show. Also improve the wording from just "Last" to "Last custom datetime" --- .../app/components/time-shortcut-picker.js | 7 ++-- .../tests/acceptance/topic-edit-timer-test.js | 35 +++++++++++++++++++ config/locales/client.en.yml | 14 +------- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/time-shortcut-picker.js b/app/assets/javascripts/discourse/app/components/time-shortcut-picker.js index e35e3a33a37..69d4a436d5b 100644 --- a/app/assets/javascripts/discourse/app/components/time-shortcut-picker.js +++ b/app/assets/javascripts/discourse/app/components/time-shortcut-picker.js @@ -88,7 +88,6 @@ export default Component.extend({ } this._bindKeyboardShortcuts(); - this._loadLastUsedCustomDatetime(); }, @observes("prefilledDatetime") @@ -134,7 +133,7 @@ export default Component.extend({ if (lastTime && lastDate) { let parsed = parseCustomDatetime(lastDate, lastTime, this.userTimezone); - if (parsed < now(this.userTimezone)) { + if (!parsed.isValid() || parsed < now(this.userTimezone)) { return; } @@ -175,6 +174,8 @@ export default Component.extend({ "userTimezone" ) options(additionalOptionsToShow, hiddenOptions, customOptions, userTimezone) { + this._loadLastUsedCustomDatetime(); + let options = defaultShortcutOptions(userTimezone); if (additionalOptionsToShow.length > 0) { @@ -255,7 +256,7 @@ export default Component.extend({ this.userTimezone ); - if (customDatetime.isValid()) { + if (customDatetime.isValid() && this.customDate) { dateTime = customDatetime; localStorage.lastCustomTime = this.customTime; diff --git a/app/assets/javascripts/discourse/tests/acceptance/topic-edit-timer-test.js b/app/assets/javascripts/discourse/tests/acceptance/topic-edit-timer-test.js index 82a72b87c1e..070ee1aaced 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/topic-edit-timer-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/topic-edit-timer-test.js @@ -133,6 +133,41 @@ acceptance("Topic - Edit timer", function (needs) { assert.ok(regex.test(text)); }); + test("schedule - last custom date and time", async function (assert) { + updateCurrentUser({ moderator: true }); + + await visit("/t/internationalization-localization"); + await click(".toggle-admin-menu"); + await click(".admin-topic-timer-update button"); + + await click("#tap_tile_custom"); + await click(".modal-close"); + + await click(".toggle-admin-menu"); + await click(".admin-topic-timer-update button"); + + assert.notOk( + exists("#tap_tile_last_custom"), + "it does not show last custom if the custom date and time was not filled and valid" + ); + + await click("#tap_tile_custom"); + await fillIn(".tap-tile-date-input .date-picker", "2099-11-24"); + await fillIn("#custom-time", "10:30"); + await click(".edit-topic-timer-buttons button.btn-primary"); + + await click(".toggle-admin-menu"); + await click(".admin-topic-timer-update button"); + + assert.ok( + exists("#tap_tile_last_custom"), + "it show last custom because the custom date and time was valid" + ); + let text = queryAll("#tap_tile_last_custom").text().trim(); + const regex = /Nov 24, 10:30 am/g; + assert.ok(regex.test(text)); + }); + test("TL4 can't auto-delete", async function (assert) { updateCurrentUser({ moderator: false, admin: false, trust_level: 4 }); diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index efaadae43cd..b91131b93c7 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -324,18 +324,6 @@ en: search_placeholder: "Search bookmarks by name, topic title, or post content" search: "Search" reminders: - later_today: "Later today" - next_business_day: "Next business day" - tomorrow: "Tomorrow" - next_week: "Next week" - post_local_date: "Date in post" - later_this_week: "Later this week" - start_of_next_business_week: "Monday" - start_of_next_business_week_alt: "Next Monday" - next_month: "Next month" - custom: "Custom date and time" - last_custom: "Last" - none: "No reminder needed" today_with_time: "today at %{time}" tomorrow_with_time: "tomorrow at %{time}" at_time: "at %{date_time}" @@ -614,7 +602,7 @@ en: custom: "Custom date and time" relative: "Relative time" none: "None needed" - last_custom: "Last" + last_custom: "Last custom datetime" user_action: user_posted_topic: "%{user} posted the topic"