mirror of https://github.com/zulip/zulip.git
deprecated_feature_notice: Move code to a separate module.
This commit is contained in:
parent
1d4b6c1320
commit
e3a099d732
|
@ -9,12 +9,12 @@ set_global("navigator", {
|
|||
userAgent: "",
|
||||
});
|
||||
|
||||
const ui = zrequire("ui");
|
||||
const deprecated_feature_notice = zrequire("deprecated_feature_notice");
|
||||
|
||||
run_test("get_hotkey_deprecation_notice", () => {
|
||||
const expected =
|
||||
'translated: We\'ve replaced the "*" hotkey with "Ctrl + s" to make this common shortcut easier to trigger.';
|
||||
const actual = ui.get_hotkey_deprecation_notice("*", "Ctrl + s");
|
||||
const actual = deprecated_feature_notice.get_hotkey_deprecation_notice("*", "Ctrl + s");
|
||||
assert.equal(actual, expected);
|
||||
});
|
||||
|
||||
|
@ -23,7 +23,7 @@ run_test("get_hotkey_deprecation_notice_mac", () => {
|
|||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36";
|
||||
const expected =
|
||||
'translated: We\'ve replaced the "*" hotkey with "Cmd + s" to make this common shortcut easier to trigger.';
|
||||
const actual = ui.get_hotkey_deprecation_notice("*", "Cmd + s");
|
||||
const actual = deprecated_feature_notice.get_hotkey_deprecation_notice("*", "Cmd + s");
|
||||
assert.equal(actual, expected);
|
||||
// Reset userAgent
|
||||
navigator.userAgent = "";
|
|
@ -0,0 +1,56 @@
|
|||
import $ from "jquery";
|
||||
|
||||
import * as blueslip from "./blueslip";
|
||||
import * as common from "./common";
|
||||
import {$t} from "./i18n";
|
||||
import {localstorage} from "./localstorage";
|
||||
import * as overlays from "./overlays";
|
||||
|
||||
export function get_hotkey_deprecation_notice(originalHotkey, replacementHotkey) {
|
||||
return $t(
|
||||
{
|
||||
defaultMessage:
|
||||
'We\'ve replaced the "{originalHotkey}" hotkey with "{replacementHotkey}" to make this common shortcut easier to trigger.',
|
||||
},
|
||||
{originalHotkey, replacementHotkey},
|
||||
);
|
||||
}
|
||||
|
||||
let shown_deprecation_notices = [];
|
||||
|
||||
export function maybe_show_deprecation_notice(key) {
|
||||
let message;
|
||||
const isCmdOrCtrl = common.has_mac_keyboard() ? "Cmd" : "Ctrl";
|
||||
if (key === "C") {
|
||||
message = get_hotkey_deprecation_notice("C", "x");
|
||||
} else if (key === "*") {
|
||||
message = get_hotkey_deprecation_notice("*", isCmdOrCtrl + " + s");
|
||||
} else {
|
||||
blueslip.error("Unexpected deprecation notice for hotkey:", key);
|
||||
return;
|
||||
}
|
||||
|
||||
// Here we handle the tracking for showing deprecation notices,
|
||||
// whether or not local storage is available.
|
||||
if (localstorage.supported()) {
|
||||
const notices_from_storage = JSON.parse(localStorage.getItem("shown_deprecation_notices"));
|
||||
if (notices_from_storage !== null) {
|
||||
shown_deprecation_notices = notices_from_storage;
|
||||
} else {
|
||||
shown_deprecation_notices = [];
|
||||
}
|
||||
}
|
||||
|
||||
if (!shown_deprecation_notices.includes(key)) {
|
||||
overlays.open_modal("#deprecation-notice-modal");
|
||||
$("#deprecation-notice-message").text(message);
|
||||
$("#close-deprecation-notice").trigger("focus");
|
||||
shown_deprecation_notices.push(key);
|
||||
if (localstorage.supported()) {
|
||||
localStorage.setItem(
|
||||
"shown_deprecation_notices",
|
||||
JSON.stringify(shown_deprecation_notices),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ import * as compose_actions from "./compose_actions";
|
|||
import * as compose_state from "./compose_state";
|
||||
import * as condense from "./condense";
|
||||
import * as copy_and_paste from "./copy_and_paste";
|
||||
import * as deprecated_feature_notice from "./deprecated_feature_notice";
|
||||
import * as drafts from "./drafts";
|
||||
import * as emoji_picker from "./emoji_picker";
|
||||
import * as feedback_widget from "./feedback_widget";
|
||||
|
@ -808,10 +809,10 @@ export function process_hotkey(e, hotkey) {
|
|||
browser_history.go_to_location("drafts");
|
||||
return true;
|
||||
case "C_deprecated":
|
||||
ui.maybe_show_deprecation_notice("C");
|
||||
deprecated_feature_notice.maybe_show_deprecation_notice("C");
|
||||
return true;
|
||||
case "star_deprecated":
|
||||
ui.maybe_show_deprecation_notice("*");
|
||||
deprecated_feature_notice.maybe_show_deprecation_notice("*");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
import $ from "jquery";
|
||||
import SimpleBar from "simplebar";
|
||||
|
||||
import * as blueslip from "./blueslip";
|
||||
import * as common from "./common";
|
||||
import {$t} from "./i18n";
|
||||
import {localstorage} from "./localstorage";
|
||||
import * as message_list from "./message_list";
|
||||
import * as message_lists from "./message_lists";
|
||||
import * as overlays from "./overlays";
|
||||
|
||||
// What, if anything, obscures the home tab?
|
||||
|
||||
|
@ -109,55 +105,6 @@ export function show_failed_message_success(message_id) {
|
|||
});
|
||||
}
|
||||
|
||||
export function get_hotkey_deprecation_notice(originalHotkey, replacementHotkey) {
|
||||
return $t(
|
||||
{
|
||||
defaultMessage:
|
||||
'We\'ve replaced the "{originalHotkey}" hotkey with "{replacementHotkey}" to make this common shortcut easier to trigger.',
|
||||
},
|
||||
{originalHotkey, replacementHotkey},
|
||||
);
|
||||
}
|
||||
|
||||
let shown_deprecation_notices = [];
|
||||
|
||||
export function maybe_show_deprecation_notice(key) {
|
||||
let message;
|
||||
const isCmdOrCtrl = common.has_mac_keyboard() ? "Cmd" : "Ctrl";
|
||||
if (key === "C") {
|
||||
message = get_hotkey_deprecation_notice("C", "x");
|
||||
} else if (key === "*") {
|
||||
message = get_hotkey_deprecation_notice("*", isCmdOrCtrl + " + s");
|
||||
} else {
|
||||
blueslip.error("Unexpected deprecation notice for hotkey:", key);
|
||||
return;
|
||||
}
|
||||
|
||||
// Here we handle the tracking for showing deprecation notices,
|
||||
// whether or not local storage is available.
|
||||
if (localstorage.supported()) {
|
||||
const notices_from_storage = JSON.parse(localStorage.getItem("shown_deprecation_notices"));
|
||||
if (notices_from_storage !== null) {
|
||||
shown_deprecation_notices = notices_from_storage;
|
||||
} else {
|
||||
shown_deprecation_notices = [];
|
||||
}
|
||||
}
|
||||
|
||||
if (!shown_deprecation_notices.includes(key)) {
|
||||
overlays.open_modal("#deprecation-notice-modal");
|
||||
$("#deprecation-notice-message").text(message);
|
||||
$("#close-deprecation-notice").trigger("focus");
|
||||
shown_deprecation_notices.push(key);
|
||||
if (localstorage.supported()) {
|
||||
localStorage.setItem(
|
||||
"shown_deprecation_notices",
|
||||
JSON.stringify(shown_deprecation_notices),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save the compose content cursor position and restore when we
|
||||
// shift-tab back in (see hotkey.js).
|
||||
let saved_compose_cursor = 0;
|
||||
|
|
Loading…
Reference in New Issue