mirror of https://github.com/zulip/zulip.git
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.
This commit is contained in:
parent
443e24390b
commit
0d52ced27a
|
@ -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 blueslip from "./blueslip";
|
||||||
import * as input_pill from "./input_pill";
|
import * as input_pill from "./input_pill";
|
||||||
|
import type {InputPillItem} from "./input_pill";
|
||||||
import * as keydown_util from "./keydown_util";
|
import * as keydown_util from "./keydown_util";
|
||||||
import type {User} from "./people";
|
import type {User} from "./people";
|
||||||
import * as pill_typeahead from "./pill_typeahead";
|
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);
|
pill_typeahead.set_up_combined($pill_container.find(".input"), pill_widget, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function generate_pill_html(item: InputPillItem<CombinedPill>): 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({
|
export function create({
|
||||||
$pill_container,
|
$pill_container,
|
||||||
get_potential_subscribers,
|
get_potential_subscribers,
|
||||||
|
@ -72,6 +93,7 @@ export function create({
|
||||||
$container: $pill_container,
|
$container: $pill_container,
|
||||||
create_item_from_text,
|
create_item_from_text,
|
||||||
get_text_from_item,
|
get_text_from_item,
|
||||||
|
generate_pill_html,
|
||||||
});
|
});
|
||||||
function get_users(): User[] {
|
function get_users(): User[] {
|
||||||
const potential_subscribers = get_potential_subscribers();
|
const potential_subscribers = get_potential_subscribers();
|
||||||
|
@ -116,6 +138,7 @@ export function create_without_add_button({
|
||||||
$container: $pill_container,
|
$container: $pill_container,
|
||||||
create_item_from_text,
|
create_item_from_text,
|
||||||
get_text_from_item,
|
get_text_from_item,
|
||||||
|
generate_pill_html,
|
||||||
});
|
});
|
||||||
function get_users(): User[] {
|
function get_users(): User[] {
|
||||||
const potential_subscribers = get_potential_subscribers();
|
const potential_subscribers = get_potential_subscribers();
|
||||||
|
|
|
@ -16,7 +16,6 @@ import * as ui_util from "./ui_util";
|
||||||
export type InputPillItem<ItemType> = {
|
export type InputPillItem<ItemType> = {
|
||||||
display_value: string;
|
display_value: string;
|
||||||
type: string;
|
type: string;
|
||||||
group_id?: number;
|
|
||||||
// Used for search pills
|
// Used for search pills
|
||||||
operator?: string;
|
operator?: string;
|
||||||
stream?: StreamSubscription;
|
stream?: StreamSubscription;
|
||||||
|
@ -63,7 +62,6 @@ type InputPillStore<ItemType> = {
|
||||||
|
|
||||||
type InputPillRenderingDetails = {
|
type InputPillRenderingDetails = {
|
||||||
display_value: string;
|
display_value: string;
|
||||||
group_id?: number | undefined;
|
|
||||||
has_stream?: boolean;
|
has_stream?: boolean;
|
||||||
stream?: StreamSubscription;
|
stream?: StreamSubscription;
|
||||||
};
|
};
|
||||||
|
@ -168,10 +166,6 @@ export function create<ItemType>(
|
||||||
display_value: item.display_value,
|
display_value: item.display_value,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (item.group_id) {
|
|
||||||
opts.group_id = item.group_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.type === "stream" && item.stream) {
|
if (item.type === "stream" && item.stream) {
|
||||||
opts.has_stream = true;
|
opts.has_stream = true;
|
||||||
opts.stream = item.stream;
|
opts.stream = item.stream;
|
||||||
|
|
Loading…
Reference in New Issue