FEATURE: show default custom date on time-shortcut-pickers (#17867)

This commit is contained in:
Andrei Prigorshnev 2022-08-18 14:55:54 +04:00 committed by GitHub
parent 5990842dd9
commit be1b202fd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 21 deletions

View File

@ -1,9 +1,4 @@
import { import { laterToday, now, parseCustomDatetime } from "discourse/lib/time-utils";
START_OF_DAY_HOUR,
laterToday,
now,
parseCustomDatetime,
} from "discourse/lib/time-utils";
import { import {
TIME_SHORTCUT_TYPES, TIME_SHORTCUT_TYPES,
defaultTimeShortcuts, defaultTimeShortcuts,
@ -70,12 +65,9 @@ export default Component.extend({
_itsatrap: null, _itsatrap: null,
defaultCustomReminderTime: `0${START_OF_DAY_HOUR}:00`,
@on("init") @on("init")
_setupPicker() { _setupPicker() {
this.setProperties({ this.setProperties({
customTime: this.defaultCustomReminderTime,
userTimezone: this.currentUser.timezone, userTimezone: this.currentUser.timezone,
hiddenOptions: this.hiddenOptions || [], hiddenOptions: this.hiddenOptions || [],
customOptions: this.customOptions || [], customOptions: this.customOptions || [],
@ -232,7 +224,16 @@ export default Component.extend({
let dateTime = null; let dateTime = null;
if (type === TIME_SHORTCUT_TYPES.CUSTOM) { if (type === TIME_SHORTCUT_TYPES.CUSTOM) {
this.set("customTime", this.customTime || this.defaultCustomReminderTime); const defaultCustomDateTime = this._defaultCustomDateTime();
this.set(
"customDate",
this.customDate || defaultCustomDateTime.format("YYYY-MM-DD")
);
this.set(
"customTime",
this.customTime || defaultCustomDateTime.format("HH:mm")
);
const customDatetime = parseCustomDatetime( const customDatetime = parseCustomDatetime(
this.customDate, this.customDate,
this.customTime, this.customTime,
@ -274,4 +275,8 @@ export default Component.extend({
} }
}); });
}, },
_defaultCustomDateTime() {
return moment.tz(this.userTimezone).add(1, "hour");
},
}); });

View File

@ -12,7 +12,7 @@
<div class="control-group custom-date-time-wrap custom-input-wrap"> <div class="control-group custom-date-time-wrap custom-input-wrap">
<div class="tap-tile-date-input"> <div class="tap-tile-date-input">
{{d-icon "calendar-alt"}} {{d-icon "calendar-alt"}}
<DatePickerFuture @value={{this.customDate}} @onSelect={{action (mut this.customDate)}} @id="custom-date" /> <DatePickerFuture @value={{this.customDate}} @defaultDate={{this.defaultCustomDate}} @onSelect={{action (mut this.customDate)}} @id="custom-date" />
</div> </div>
<div class="tap-tile-time-input"> <div class="tap-tile-time-input">
{{d-icon "far-clock"}} {{d-icon "far-clock"}}

View File

@ -247,22 +247,18 @@ acceptance("Topic - Edit timer", function (needs) {
test("schedule publish to category - last custom date and time", async function (assert) { test("schedule publish to category - last custom date and time", async function (assert) {
updateCurrentUser({ moderator: true }); updateCurrentUser({ moderator: true });
await visit("/t/internationalization-localization"); 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(".toggle-admin-menu");
await click(".admin-topic-timer-update button"); await click(".admin-topic-timer-update button");
assert.notOk( assert.notOk(
exists("#tap_tile_last_custom"), exists("#tap_tile_last_custom"),
"it does not show last custom if the custom date and time was not filled and valid" "it does not show last custom if the custom date and time was not filled before"
); );
await click(".modal-close");
await click(".toggle-admin-menu");
await click(".admin-topic-timer-update button");
await click("#tap_tile_custom"); await click("#tap_tile_custom");
await fillIn(".tap-tile-date-input .date-picker", "2100-11-24"); await fillIn(".tap-tile-date-input .date-picker", "2100-11-24");
await fillIn("#custom-time", "10:30"); await fillIn("#custom-time", "10:30");

View File

@ -116,11 +116,18 @@ module("Integration | Component | time-shortcut-picker", function (hooks) {
); );
}); });
test("defaults to 08:00 for custom time", async function (assert) { test("default custom date time is in one hour from now", async function (assert) {
this.clock = fakeTime(
"2100-12-11T17:00:00",
this.currentUser.timezone,
true
);
await render(hbs`<TimeShortcutPicker @_itsatrap={{this.itsatrap}} />`); await render(hbs`<TimeShortcutPicker @_itsatrap={{this.itsatrap}} />`);
await click("#tap_tile_custom"); await click("#tap_tile_custom");
assert.strictEqual(query("#custom-time").value, "08:00"); assert.strictEqual(query("#custom-date > input").value, "2100-12-11");
assert.strictEqual(query("#custom-time").value, "18:00");
}); });
test("shows 'Next Monday' instead of 'Monday' on Sundays", async function (assert) { test("shows 'Next Monday' instead of 'Monday' on Sundays", async function (assert) {