Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

components: Add key() accessor to toggle, and fix misuse of value().

Evy Kassirer290dc6b00b0f
diff --git a/web/src/components.ts b/web/src/components.ts
index 9294d484ed2..5edd7cb066c 100644
--- a/web/src/components.ts
+++ b/web/src/components.ts
@@ -23,6 +23,7 @@ export type Toggle = {
disable_tab: (name: string) => void;
enable_tab: (name: string) => void;
value: () => string | undefined;
+ key: () => string | undefined;
get: () => JQuery;
goto: (name: string) => void;
register_event_handlers: () => void;
@@ -186,6 +187,14 @@ export function toggle(opts: {
return undefined;
},
+ key() {
+ if (meta.idx >= 0) {
+ return opts.values[meta.idx]!.key;
+ }
+ /* istanbul ignore next */
+ return undefined;
+ },
+
get() {
return $component;
},
diff --git a/web/src/stream_settings_ui.ts b/web/src/stream_settings_ui.ts
index cc19768bd4a..f5ef18e41fa 100644
--- a/web/src/stream_settings_ui.ts
+++ b/web/src/stream_settings_ui.ts
@@ -1166,7 +1166,7 @@ export function change_state(
// Callback to .goto() will update browser_history unless a
// stream is being edited. We are always editing a stream here
// so its safe to call
- if (left_side_tab !== toggler.value()) {
+ if (left_side_tab !== toggler.key()) {
toggler.goto(left_side_tab);
}
switch_to_stream_row(stream_id);
diff --git a/web/src/user_group_edit.ts b/web/src/user_group_edit.ts
index 82a87ec2ecb..0c9fe4f1f43 100644
--- a/web/src/user_group_edit.ts
+++ b/web/src/user_group_edit.ts
@@ -1658,7 +1658,7 @@ export function change_state(
// Callback to .goto() will update browser_history unless a
// group is being edited. We are always editing a group here
// so its safe to call
- if (left_side_tab !== group_list_toggler.value()) {
+ if (left_side_tab !== group_list_toggler.key()) {
user_group_components.set_active_group_id(group.id);
group_list_toggler.goto(left_side_tab);
}
diff --git a/web/tests/components.test.cjs b/web/tests/components.test.cjs
index d4372b83b80..59d6fa91a8b 100644
--- a/web/tests/components.test.cjs
+++ b/web/tests/components.test.cjs
@@ -231,6 +231,7 @@ run_test("basics", () => {
assert.equal(env.tabs[2].class, "last");
assert.deepEqual(callback_args, ["translated: Keyboard shortcuts", "keyboard-shortcuts"]);
assert.equal(widget.value(), "translated: Keyboard shortcuts");
+ assert.equal(widget.key(), "keyboard-shortcuts");
callback_args = undefined;
@@ -241,6 +242,7 @@ run_test("basics", () => {
assert.equal(env.tabs[2].class, "last");
assert.deepEqual(callback_args, ["translated: Message formatting", "message-formatting"]);
assert.equal(widget.value(), "translated: Message formatting");
+ assert.equal(widget.key(), "message-formatting");
// Go to same tab twice and make sure we get callback.
callback_args = undefined;