A platform for community discussion. Free, open, simple.
FIX: stop sorting options in date-pickers on the bookmark modal and the topic-timers modal (#15750)
Andrei Prigorshneve30f13d85079
diff --git a/app/assets/javascripts/discourse/app/components/bookmark.js b/app/assets/javascripts/discourse/app/components/bookmark.jsindex 354b015b4af..df1409a793e 100644--- a/app/assets/javascripts/discourse/app/components/bookmark.js+++ b/app/assets/javascripts/discourse/app/components/bookmark.js@@ -5,7 +5,10 @@ import I18n from "I18n";import KeyboardShortcuts from "discourse/lib/keyboard-shortcuts";import ItsATrap from "@discourse/itsatrap";import { Promise } from "rsvp";-import { TIME_SHORTCUT_TYPES } from "discourse/lib/time-shortcut";+import {+ TIME_SHORTCUT_TYPES,+ defaultTimeShortcuts,+} from "discourse/lib/time-shortcut";import { action } from "@ember/object";import { ajax } from "discourse/lib/ajax";import bootbox from "bootbox";@@ -291,12 +294,12 @@ export default Component.extend({});},- @discourseComputed()- customTimeShortcutOptions() {- let customOptions = [];+ @discourseComputed("userTimezone")+ timeOptions(userTimezone) {+ const options = defaultTimeShortcuts(userTimezone);if (this.showPostLocalDate) {- customOptions.push({+ options.push({icon: "globe-americas",id: TIME_SHORTCUT_TYPES.POST_LOCAL_DATE,label: "time_shortcut.post_local_date",@@ -306,7 +309,7 @@ export default Component.extend({});}- return customOptions;+ return options;},@discourseComputed("existingBookmarkHasReminder")diff --git a/app/assets/javascripts/discourse/app/components/edit-topic-timer-form.js b/app/assets/javascripts/discourse/app/components/edit-topic-timer-form.jsindex f3d984bcd56..4489a1353ba 100644--- a/app/assets/javascripts/discourse/app/components/edit-topic-timer-form.js+++ b/app/assets/javascripts/discourse/app/components/edit-topic-timer-form.js@@ -14,9 +14,11 @@ import I18n from "I18n";import { action } from "@ember/object";import Component from "@ember/component";import { isEmpty } from "@ember/utils";-import { MOMENT_MONDAY, now, startOfDay } from "discourse/lib/time-utils";import KeyboardShortcuts from "discourse/lib/keyboard-shortcuts";-import { TIME_SHORTCUT_TYPES } from "discourse/lib/time-shortcut";+import {+ TIME_SHORTCUT_TYPES,+ timeShortcuts,+} from "discourse/lib/time-shortcut";import ItsATrap from "@discourse/itsatrap";export default Component.extend({@@ -81,23 +83,19 @@ export default Component.extend({},@discourseComputed()- customTimeShortcutOptions() {+ timeOptions() {const timezone = this.currentUser.resolvedTimezone(this.currentUser);+ const shortcuts = timeShortcuts(timezone);+return [- {- icon: "far-clock",- id: "two_weeks",- label: "time_shortcut.two_weeks",- time: startOfDay(now(timezone).add(2, "weeks").day(MOMENT_MONDAY)),- timeFormatKey: "dates.long_no_year",- },- {- icon: "far-calendar-plus",- id: "six_months",- label: "time_shortcut.six_months",- time: startOfDay(now(timezone).add(6, "months").startOf("month")),- timeFormatKey: "dates.long_no_year",- },+ shortcuts.laterToday(),+ shortcuts.tomorrow(),+ shortcuts.laterThisWeek(),+ shortcuts.thisWeekend(),+ shortcuts.monday(),+ shortcuts.twoWeeks(),+ shortcuts.nextMonth(),+ shortcuts.sixMonths(),];},diff --git a/app/assets/javascripts/discourse/app/components/time-shortcut-picker.js b/app/assets/javascripts/discourse/app/components/time-shortcut-picker.jsindex 5839191f48f..46890b6afe0 100644--- a/app/assets/javascripts/discourse/app/components/time-shortcut-picker.js+++ b/app/assets/javascripts/discourse/app/components/time-shortcut-picker.js@@ -9,7 +9,7 @@ import {} from "discourse/lib/time-utils";import {TIME_SHORTCUT_TYPES,- defaultShortcutOptions,+ defaultTimeShortcuts,specialShortcutOptions,} from "discourse/lib/time-shortcut";import discourseComputed, {@@ -169,30 +169,23 @@ export default Component.extend({},@discourseComputed(+ "timeShortcuts","hiddenOptions",- "customOptions","customLabels","userTimezone")- options(hiddenOptions, customOptions, customLabels, userTimezone) {+ options(timeShortcuts, hiddenOptions, customLabels, userTimezone) {this._loadLastUsedCustomDatetime();- let options = defaultShortcutOptions(userTimezone);+ let options;+ if (timeShortcuts && timeShortcuts.length) {+ options = timeShortcuts;+ } else {+ options = defaultTimeShortcuts(userTimezone);+ }this._hideDynamicOptions(options);- options = options.concat(customOptions);-- options.sort((a, b) => {- if (a.time < b.time) {- return -1;- }- if (a.time > b.time) {- return 1;- }- return 0;- });let specialOptions = specialShortcutOptions();-if (this.lastCustomDate && this.lastCustomTime) {let lastCustom = specialOptions.findBy("id",@@ -202,7 +195,6 @@ export default Component.extend({lastCustom.timeFormatKey = "dates.long_no_year";lastCustom.hidden = false;}-options = options.concat(specialOptions);if (hiddenOptions.length > 0) {diff --git a/app/assets/javascripts/discourse/app/lib/time-shortcut.js b/app/assets/javascripts/discourse/app/lib/time-shortcut.jsindex 37d6585cdf9..5d59365443a 100644--- a/app/assets/javascripts/discourse/app/lib/time-shortcut.js+++ b/app/assets/javascripts/discourse/app/lib/time-shortcut.js@@ -6,8 +6,10 @@ import {nextBusinessWeekStart,nextMonth,now,+ sixMonths,thisWeekend,tomorrow,+ twoWeeks,} from "discourse/lib/time-utils";export const TIME_SHORTCUT_TYPES = {@@ -24,54 +26,15 @@ export const TIME_SHORTCUT_TYPES = {POST_LOCAL_DATE: "post_local_date",};-export function defaultShortcutOptions(timezone) {+export function defaultTimeShortcuts(timezone) {+ const shortcuts = timeShortcuts(timezone);return [- {- icon: "angle-right",- id: TIME_SHORTCUT_TYPES.LATER_TODAY,- label: "time_shortcut.later_today",- time: laterToday(timezone),- timeFormatKey: "dates.time",- },- {- icon: "far-sun",- id: TIME_SHORTCUT_TYPES.TOMORROW,- label: "time_shortcut.tomorrow",- time: tomorrow(timezone),- timeFormatKey: "dates.time_short_day",- },- {- icon: "angle-double-right",- id: TIME_SHORTCUT_TYPES.LATER_THIS_WEEK,- label: "time_shortcut.later_this_week",- time: laterThisWeek(timezone),- timeFormatKey: "dates.time_short_day",- },- {- icon: "bed",- id: TIME_SHORTCUT_TYPES.THIS_WEEKEND,- label: "time_shortcut.this_weekend",- time: thisWeekend(timezone),- timeFormatKey: "dates.time_short_day",- },- {- icon: "briefcase",- id: TIME_SHORTCUT_TYPES.START_OF_NEXT_BUSINESS_WEEK,- label:- now(timezone).day() === MOMENT_MONDAY ||- now(timezone).day() === MOMENT_SUNDAY- ? "time_shortcut.start_of_next_business_week_alt"- : "time_shortcut.start_of_next_business_week",- time: nextBusinessWeekStart(timezone),- timeFormatKey: "dates.long_no_year",- },- {- icon: "far-calendar-plus",- id: TIME_SHORTCUT_TYPES.NEXT_MONTH,- label: "time_shortcut.next_month",- time: nextMonth(timezone),- timeFormatKey: "dates.long_no_year",- },+ shortcuts.laterToday(),+ shortcuts.tomorrow(),+ shortcuts.laterThisWeek(),+ shortcuts.thisWeekend(),+ shortcuts.monday(),+ shortcuts.nextMonth(),];}@@ -99,3 +62,84 @@ export function specialShortcutOptions() {},];}++export function timeShortcuts(timezone) {+ return {+ laterToday() {+ return {+ icon: "angle-right",+ id: TIME_SHORTCUT_TYPES.LATER_TODAY,+ label: "time_shortcut.later_today",+ time: laterToday(timezone),+ timeFormatKey: "dates.time",+ };+ },+ tomorrow() {+ return {+ icon: "far-sun",+ id: TIME_SHORTCUT_TYPES.TOMORROW,+ label: "time_shortcut.tomorrow",+ time: tomorrow(timezone),+ timeFormatKey: "dates.time_short_day",+ };+ },+ laterThisWeek() {+ return {+ icon: "angle-double-right",+ id: TIME_SHORTCUT_TYPES.LATER_THIS_WEEK,+ label: "time_shortcut.later_this_week",+ time: laterThisWeek(timezone),+ timeFormatKey: "dates.time_short_day",+ };+ },+ thisWeekend() {+ return {+ icon: "bed",+ id: TIME_SHORTCUT_TYPES.THIS_WEEKEND,+ label: "time_shortcut.this_weekend",+ time: thisWeekend(timezone),+ timeFormatKey: "dates.time_short_day",+ };+ },+ monday() {+ return {+ icon: "briefcase",+ id: TIME_SHORTCUT_TYPES.START_OF_NEXT_BUSINESS_WEEK,+ label:+ now(timezone).day() === MOMENT_MONDAY ||+ now(timezone).day() === MOMENT_SUNDAY+ ? "time_shortcut.start_of_next_business_week_alt"+ : "time_shortcut.start_of_next_business_week",+ time: nextBusinessWeekStart(timezone),+ timeFormatKey: "dates.long_no_year",+ };+ },+ nextMonth() {+ return {+ icon: "far-calendar-plus",+ id: TIME_SHORTCUT_TYPES.NEXT_MONTH,+ label: "time_shortcut.next_month",+ time: nextMonth(timezone),+ timeFormatKey: "dates.long_no_year",+ };+ },+ twoWeeks() {+ return {+ icon: "far-clock",+ id: "two_weeks",+ label: "time_shortcut.two_weeks",+ time: twoWeeks(timezone),+ timeFormatKey: "dates.long_no_year",+ };+ },+ sixMonths() {+ return {+ icon: "far-calendar-plus",+ id: "six_months",+ label: "time_shortcut.six_months",+ time: sixMonths(timezone),+ timeFormatKey: "dates.long_no_year",+ };+ },+ };+}diff --git a/app/assets/javascripts/discourse/app/lib/time-utils.js b/app/assets/javascripts/discourse/app/lib/time-utils.jsindex 5266362e5b4..2a8e1e43429 100644--- a/app/assets/javascripts/discourse/app/lib/time-utils.js+++ b/app/assets/javascripts/discourse/app/lib/time-utils.js@@ -43,6 +43,14 @@ export function nextMonth(timezone) {return startOfDay(now(timezone).add(1, "month").startOf("month"));}+export function twoWeeks(timezone) {+ return startOfDay(now(timezone).add(2, "weeks").day(MOMENT_MONDAY));+}++export function sixMonths(timezone) {+ return startOfDay(now(timezone).add(6, "months").startOf("month"));+}+export function nextBusinessWeekStart(timezone) {return startOfDay(now(timezone).add(7, "days")).day(MOMENT_MONDAY);}diff --git a/app/assets/javascripts/discourse/app/templates/components/bookmark.hbs b/app/assets/javascripts/discourse/app/templates/components/bookmark.hbsindex e7b76e8bb9d..44d14a340a6 100644--- a/app/assets/javascripts/discourse/app/templates/components/bookmark.hbs+++ b/app/assets/javascripts/discourse/app/templates/components/bookmark.hbs@@ -38,9 +38,9 @@{{#if userHasTimezoneSet}}{{time-shortcut-picker+ timeShortcuts=timeOptionsprefilledDatetime=prefilledDatetimeonTimeSelected=(action "onTimeSelected")- customOptions=customTimeShortcutOptionshiddenOptions=hiddenTimeShortcutOptionscustomLabels=customTimeShortcutLabels_itsatrap=_itsatrapdiff --git a/app/assets/javascripts/discourse/app/templates/components/edit-topic-timer-form.hbs b/app/assets/javascripts/discourse/app/templates/components/edit-topic-timer-form.hbsindex 6655b533f72..5f5bdb8dad3 100644--- a/app/assets/javascripts/discourse/app/templates/components/edit-topic-timer-form.hbs+++ b/app/assets/javascripts/discourse/app/templates/components/edit-topic-timer-form.hbs@@ -20,9 +20,9 @@{{#if showFutureDateInput}}<label class="control-label">{{i18n "topic.topic_status_update.when"}}</label>{{time-shortcut-picker+ timeShortcuts=timeOptionsprefilledDatetime=topicTimer.execute_atonTimeSelected=onTimeSelected- customOptions=customTimeShortcutOptionshiddenOptions=hiddenTimeShortcutOptions_itsatrap=_itsatrap}}