components: Let toggle label be optional.

`stream_settings_ui` has only `label_html` and no `label`,
so we need fix this type to be able to convert that module
to typescript.
This commit is contained in:
evykassirer 2024-11-18 16:51:11 -08:00 committed by Tim Abbott
parent dc0e82deef
commit 919cebe0f9
3 changed files with 7 additions and 5 deletions

View File

@ -28,8 +28,10 @@ export type Toggle = {
export function toggle(opts: {
html_class?: string;
values: {label: string; label_html?: string; key: string}[];
callback?: (label: string, value: string) => void;
values: (({label: string; label_html?: never} | {label_html: string; label?: never}) & {
key: string;
})[];
callback?: (label: string | undefined, value: string) => void;
child_wants_focus?: boolean;
selected?: number;
}): Toggle {
@ -50,7 +52,7 @@ export function toggle(opts: {
if (value.label_html !== undefined) {
const html = value.label_html;
$tab.html(html);
} else {
} else if (value.label !== undefined) {
$tab.text(value.label);
}

View File

@ -298,7 +298,7 @@ export function set_up_toggler(): void {
{label: $t({defaultMessage: "Message formatting"}), key: "message-formatting"},
{label: $t({defaultMessage: "Search filters"}), key: "search-operators"},
],
callback(_name: string, key: string) {
callback(_name: string | undefined, key: string) {
$(".overlay-modal").hide();
$(`#${CSS.escape(key)}`).show();
scroll_util

View File

@ -580,7 +580,7 @@ export function show_user_profile(user: User, default_tab_key = "profile-tab"):
{label: $t({defaultMessage: "Channels"}), key: "user-profile-streams-tab"},
{label: $t({defaultMessage: "User groups"}), key: "user-profile-groups-tab"},
],
callback(_name: string, key: string) {
callback(_name: string | undefined, key: string) {
$(".tabcontent").hide();
$(`#${CSS.escape(key)}`).show();
$("#user-profile-modal .modal__footer").hide();