mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
hash_util: Remove dependency on narrow_state module.
We directly pass operators to remove dependency on narrow_state module. This avoids a circular dependency of `filter` module which is evident on the `/devtools/integrations/` page.
This commit is contained in:
@@ -16,8 +16,6 @@ const ui_report = mock_esm("../../static/js/ui_report", {
|
|||||||
const hash_util = zrequire("hash_util");
|
const hash_util = zrequire("hash_util");
|
||||||
const stream_data = zrequire("stream_data");
|
const stream_data = zrequire("stream_data");
|
||||||
const people = zrequire("people");
|
const people = zrequire("people");
|
||||||
const {Filter} = zrequire("../js/filter");
|
|
||||||
const narrow_state = zrequire("narrow_state");
|
|
||||||
|
|
||||||
const hamlet = {
|
const hamlet = {
|
||||||
user_id: 15,
|
user_id: 15,
|
||||||
@@ -185,23 +183,24 @@ run_test("test_by_conversation_and_time_uri", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
run_test("test_search_public_streams_notice_url", () => {
|
run_test("test_search_public_streams_notice_url", () => {
|
||||||
function set_uri(uri) {
|
function get_operators(uri) {
|
||||||
const operators = hash_util.parse_narrow(uri.split("/"));
|
return hash_util.parse_narrow(uri.split("/"));
|
||||||
narrow_state.set_current_filter(new Filter(operators));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set_uri("#narrow/search/abc");
|
|
||||||
assert.equal(hash_util.search_public_streams_notice_url(), "#narrow/streams/public/search/abc");
|
|
||||||
|
|
||||||
set_uri("#narrow/has/link/has/image/has/attachment");
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
hash_util.search_public_streams_notice_url(),
|
hash_util.search_public_streams_notice_url(get_operators("#narrow/search/abc")),
|
||||||
|
"#narrow/streams/public/search/abc",
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
hash_util.search_public_streams_notice_url(
|
||||||
|
get_operators("#narrow/has/link/has/image/has/attachment"),
|
||||||
|
),
|
||||||
"#narrow/streams/public/has/link/has/image/has/attachment",
|
"#narrow/streams/public/has/link/has/image/has/attachment",
|
||||||
);
|
);
|
||||||
|
|
||||||
set_uri("#narrow/sender/15");
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
hash_util.search_public_streams_notice_url(),
|
hash_util.search_public_streams_notice_url(get_operators("#narrow/sender/15")),
|
||||||
"#narrow/streams/public/sender/15-hamlet",
|
"#narrow/streams/public/sender/15-hamlet",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import $ from "jquery";
|
import $ from "jquery";
|
||||||
|
|
||||||
import {$t_html} from "./i18n";
|
import {$t_html} from "./i18n";
|
||||||
import * as narrow_state from "./narrow_state";
|
|
||||||
import * as people from "./people";
|
import * as people from "./people";
|
||||||
import * as stream_data from "./stream_data";
|
import * as stream_data from "./stream_data";
|
||||||
import * as ui_report from "./ui_report";
|
import * as ui_report from "./ui_report";
|
||||||
@@ -195,9 +194,7 @@ export function stream_edit_uri(sub) {
|
|||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function search_public_streams_notice_url() {
|
export function search_public_streams_notice_url(operators) {
|
||||||
// Computes the URL of the current narrow if streams:public were added.
|
|
||||||
const operators = narrow_state.filter().operators();
|
|
||||||
const public_operator = {operator: "streams", operand: "public"};
|
const public_operator = {operator: "streams", operand: "public"};
|
||||||
return operators_to_hash([public_operator].concat(operators));
|
return operators_to_hash([public_operator].concat(operators));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,7 +84,9 @@ export function show_end_of_results_notice() {
|
|||||||
// It's a bit hacky to use the href, but
|
// It's a bit hacky to use the href, but
|
||||||
// !filter.includes_full_stream_history() implies streams:public
|
// !filter.includes_full_stream_history() implies streams:public
|
||||||
// wasn't already present.
|
// wasn't already present.
|
||||||
const update_hash = hash_util.search_public_streams_notice_url();
|
// Computes the URL of the current narrow if streams:public were added.
|
||||||
|
const operators = narrow_state.filter().operators();
|
||||||
|
const update_hash = hash_util.search_public_streams_notice_url(operators);
|
||||||
$(".all-messages-search-caution a.search-shared-history").attr("href", update_hash);
|
$(".all-messages-search-caution a.search-shared-history").attr("href", update_hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user