mirror of https://github.com/zulip/zulip.git
default streams: Remove complicated remove logic.
Now if a default stream gets deleted, we just redraw the table. We always have a small number of default streams, and the way that we were removing rows without the actual consent of `list_render` was really janky (and just a vestige of pre-list-render code that never got fully ported). This also makes us consistent with how we handle added streams (i.e. just call `update_default_streams_table`). ASIDE: Ideally we will update `list_render` at some point to have an API for adding and removing elements. It does allow you now to call `data()` to reset its data, but for now we just build a new `list_render` object every time.
This commit is contained in:
parent
fd5ee9a831
commit
f8913dc321
|
@ -1181,7 +1181,7 @@ with_overrides(function (override) {
|
||||||
global.with_stub(function (stub) {
|
global.with_stub(function (stub) {
|
||||||
override('subs.remove_stream', noop);
|
override('subs.remove_stream', noop);
|
||||||
override('stream_data.delete_sub', noop);
|
override('stream_data.delete_sub', noop);
|
||||||
override('settings_streams.remove_default_stream', noop);
|
override('settings_streams.update_default_streams_table', noop);
|
||||||
override('stream_data.remove_default_stream', noop);
|
override('stream_data.remove_default_stream', noop);
|
||||||
|
|
||||||
override('stream_data.get_sub_by_id', function (id) {
|
override('stream_data.get_sub_by_id', function (id) {
|
||||||
|
|
|
@ -289,7 +289,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
|
||||||
if (was_subscribed) {
|
if (was_subscribed) {
|
||||||
stream_list.remove_sidebar_row(stream.stream_id);
|
stream_list.remove_sidebar_row(stream.stream_id);
|
||||||
}
|
}
|
||||||
settings_streams.remove_default_stream(stream.stream_id);
|
settings_streams.update_default_streams_table();
|
||||||
stream_data.remove_default_stream(stream.stream_id);
|
stream_data.remove_default_stream(stream.stream_id);
|
||||||
if (page_params.realm_notifications_stream_id === stream.stream_id) {
|
if (page_params.realm_notifications_stream_id === stream.stream_id) {
|
||||||
page_params.realm_notifications_stream_id = -1;
|
page_params.realm_notifications_stream_id = -1;
|
||||||
|
|
|
@ -18,10 +18,6 @@ exports.maybe_disable_widgets = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.build_default_stream_table = function (streams_data) {
|
exports.build_default_stream_table = function (streams_data) {
|
||||||
const self = {};
|
|
||||||
|
|
||||||
self.row_dict = new Map();
|
|
||||||
|
|
||||||
const table = $("#admin_default_streams_table").expectOne();
|
const table = $("#admin_default_streams_table").expectOne();
|
||||||
|
|
||||||
const streams_list = list_render.create(table, streams_data, {
|
const streams_list = list_render.create(table, streams_data, {
|
||||||
|
@ -31,7 +27,6 @@ exports.build_default_stream_table = function (streams_data) {
|
||||||
stream: item,
|
stream: item,
|
||||||
can_modify: page_params.is_admin,
|
can_modify: page_params.is_admin,
|
||||||
}));
|
}));
|
||||||
self.row_dict.set(item.stream_id, row);
|
|
||||||
return row;
|
return row;
|
||||||
},
|
},
|
||||||
filter: {
|
filter: {
|
||||||
|
@ -49,30 +44,13 @@ exports.build_default_stream_table = function (streams_data) {
|
||||||
streams_list.sort("alphabetic", "name");
|
streams_list.sort("alphabetic", "name");
|
||||||
|
|
||||||
loading.destroy_indicator($('#admin_page_default_streams_loading_indicator'));
|
loading.destroy_indicator($('#admin_page_default_streams_loading_indicator'));
|
||||||
|
|
||||||
self.remove = function (stream_id) {
|
|
||||||
if (self.row_dict.has(stream_id)) {
|
|
||||||
const row = self.row_dict.get(stream_id);
|
|
||||||
row.remove();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return self;
|
|
||||||
};
|
|
||||||
|
|
||||||
let default_stream_table;
|
|
||||||
|
|
||||||
exports.remove_default_stream = function (stream_id) {
|
|
||||||
if (default_stream_table) {
|
|
||||||
default_stream_table.remove(stream_id);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.update_default_streams_table = function () {
|
exports.update_default_streams_table = function () {
|
||||||
if (/#*organization/.test(window.location.hash) ||
|
if (/#*organization/.test(window.location.hash) ||
|
||||||
/#*settings/.test(window.location.hash)) {
|
/#*settings/.test(window.location.hash)) {
|
||||||
$("#admin_default_streams_table").expectOne().find("tr.default_stream_row").remove();
|
$("#admin_default_streams_table").expectOne().find("tr.default_stream_row").remove();
|
||||||
default_stream_table = exports.build_default_stream_table(
|
exports.build_default_stream_table(
|
||||||
page_params.realm_default_streams);
|
page_params.realm_default_streams);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue