From 0d52ced27a7ddd20f70099129ecfc3ffed1b4d0d Mon Sep 17 00:00:00 2001 From: evykassirer Date: Mon, 29 Jul 2024 15:47:47 -0700 Subject: [PATCH] input_pill: Move group and stream logic to add_subscribers module. This is part of a larger effort to refactor input_pill to remove custom logic and move it into relevant modules. This commit completely removes group_id from all modules, but there's another module that uses stream that must be refactored before that can be removed from input_pill. --- web/src/add_subscribers_pill.ts | 23 +++++++++++++++++++++++ web/src/input_pill.ts | 6 ------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/web/src/add_subscribers_pill.ts b/web/src/add_subscribers_pill.ts index b409b3688d..f4bae6cdb8 100644 --- a/web/src/add_subscribers_pill.ts +++ b/web/src/add_subscribers_pill.ts @@ -1,5 +1,10 @@ +import assert from "minimalistic-assert"; + +import render_input_pill from "../templates/input_pill.hbs"; + import * as blueslip from "./blueslip"; import * as input_pill from "./input_pill"; +import type {InputPillItem} from "./input_pill"; import * as keydown_util from "./keydown_util"; import type {User} from "./people"; import * as pill_typeahead from "./pill_typeahead"; @@ -61,6 +66,22 @@ function set_up_pill_typeahead({ pill_typeahead.set_up_combined($pill_container.find(".input"), pill_widget, opts); } +function generate_pill_html(item: InputPillItem): string { + if (item.type === "user_group") { + return render_input_pill({ + display_value: item.display_value, + group_id: item.group_id, + }); + } else if (item.type === "user") { + return user_pill.generate_pill_html(item); + } + assert(item.type === "stream"); + return render_input_pill({ + ...item, + has_stream: true, + }); +} + export function create({ $pill_container, get_potential_subscribers, @@ -72,6 +93,7 @@ export function create({ $container: $pill_container, create_item_from_text, get_text_from_item, + generate_pill_html, }); function get_users(): User[] { const potential_subscribers = get_potential_subscribers(); @@ -116,6 +138,7 @@ export function create_without_add_button({ $container: $pill_container, create_item_from_text, get_text_from_item, + generate_pill_html, }); function get_users(): User[] { const potential_subscribers = get_potential_subscribers(); diff --git a/web/src/input_pill.ts b/web/src/input_pill.ts index fa5ec6c277..160449fce9 100644 --- a/web/src/input_pill.ts +++ b/web/src/input_pill.ts @@ -16,7 +16,6 @@ import * as ui_util from "./ui_util"; export type InputPillItem = { display_value: string; type: string; - group_id?: number; // Used for search pills operator?: string; stream?: StreamSubscription; @@ -63,7 +62,6 @@ type InputPillStore = { type InputPillRenderingDetails = { display_value: string; - group_id?: number | undefined; has_stream?: boolean; stream?: StreamSubscription; }; @@ -168,10 +166,6 @@ export function create( display_value: item.display_value, }; - if (item.group_id) { - opts.group_id = item.group_id; - } - if (item.type === "stream" && item.stream) { opts.has_stream = true; opts.stream = item.stream;