types: Migrated add_stream_options_popover to TypeScript.

The migration requires some new assert statements as well as a change
in how the `return undefined` case is spelled to match the types declared by 
Tippy upstream.
This commit is contained in:
Roshan Jagadish 2024-03-16 01:32:20 +05:30 committed by GitHub
parent 45cfa42469
commit 20e44997e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 9 deletions

View File

@ -46,7 +46,7 @@ EXEMPT_FILES = make_set(
[ [
"web/shared/src/poll_data.ts", "web/shared/src/poll_data.ts",
"web/src/about_zulip.ts", "web/src/about_zulip.ts",
"web/src/add_stream_options_popover.js", "web/src/add_stream_options_popover.ts",
"web/src/add_subscribers_pill.js", "web/src/add_subscribers_pill.js",
"web/src/admin.js", "web/src/admin.js",
"web/src/alert_popup.ts", "web/src/alert_popup.ts",

View File

@ -1,4 +1,6 @@
import $ from "jquery"; import $ from "jquery";
import assert from "minimalistic-assert";
import type {ReferenceElement} from "tippy.js";
import render_left_sidebar_stream_setting_popover from "../templates/popovers/left_sidebar_stream_setting_popover.hbs"; import render_left_sidebar_stream_setting_popover from "../templates/popovers/left_sidebar_stream_setting_popover.hbs";
@ -6,7 +8,7 @@ import * as popover_menus from "./popover_menus";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import {parse_html} from "./ui_util"; import {parse_html} from "./ui_util";
export function initialize() { export function initialize(): void {
popover_menus.register_popover_menu("#streams_inline_icon", { popover_menus.register_popover_menu("#streams_inline_icon", {
onShow(instance) { onShow(instance) {
const can_create_streams = const can_create_streams =
@ -31,32 +33,41 @@ export function initialize() {
// When showing the popover menu, we want the // When showing the popover menu, we want the
// "Add streams" and the "Filter streams" tooltip // "Add streams" and the "Filter streams" tooltip
// to appear below the "Add streams" icon. // to appear below the "Add streams" icon.
const add_streams_tooltip = $("#add_streams_tooltip").get(0); const add_streams_tooltip: ReferenceElement | undefined =
$("#add_streams_tooltip").get(0);
assert(add_streams_tooltip !== undefined);
add_streams_tooltip._tippy?.setProps({ add_streams_tooltip._tippy?.setProps({
placement: "bottom", placement: "bottom",
}); });
const filter_streams_tooltip = $("#filter_streams_tooltip").get(0);
const filter_streams_tooltip: (ReferenceElement & HTMLElement) | undefined =
$("#filter_streams_tooltip").get(0);
// If `filter_streams_tooltip` is not triggered yet, this will set its initial placement. // If `filter_streams_tooltip` is not triggered yet, this will set its initial placement.
assert(filter_streams_tooltip !== undefined);
filter_streams_tooltip.dataset.tippyPlacement = "bottom"; filter_streams_tooltip.dataset.tippyPlacement = "bottom";
filter_streams_tooltip._tippy?.setProps({ filter_streams_tooltip._tippy?.setProps({
placement: "bottom", placement: "bottom",
}); });
// The linter complains about unbalanced returns return undefined;
return true;
}, },
onHidden(instance) { onHidden(instance) {
instance.destroy(); instance.destroy();
popover_menus.popover_instances.stream_settings = undefined; popover_menus.popover_instances.stream_settings = null;
// After the popover menu is closed, we want the // After the popover menu is closed, we want the
// "Add streams" and the "Filter streams" tooltip // "Add streams" and the "Filter streams" tooltip
// to appear at it's original position that is // to appear at it's original position that is
// above the "Add streams" icon. // above the "Add streams" icon.
const add_streams_tooltip = $("#add_streams_tooltip").get(0); const add_streams_tooltip: ReferenceElement | undefined =
$("#add_streams_tooltip").get(0);
assert(add_streams_tooltip !== undefined);
add_streams_tooltip._tippy?.setProps({ add_streams_tooltip._tippy?.setProps({
placement: "top", placement: "top",
}); });
const filter_streams_tooltip = $("#filter_streams_tooltip").get(0);
const filter_streams_tooltip: (ReferenceElement & HTMLElement) | undefined =
$("#filter_streams_tooltip").get(0);
assert(filter_streams_tooltip !== undefined);
filter_streams_tooltip.dataset.tippyPlacement = "top"; filter_streams_tooltip.dataset.tippyPlacement = "top";
filter_streams_tooltip._tippy?.setProps({ filter_streams_tooltip._tippy?.setProps({
placement: "top", placement: "top",