mirror of https://github.com/zulip/zulip.git
set_up_stream: Update sorter function.
Make sure that typeahead results are alphabetized. Fixes #30577.
This commit is contained in:
parent
1a8997589d
commit
77c614e072
|
@ -115,7 +115,7 @@ export function set_up_stream(
|
||||||
if (query.startsWith("#")) {
|
if (query.startsWith("#")) {
|
||||||
query = query.slice(1);
|
query = query.slice(1);
|
||||||
}
|
}
|
||||||
return typeahead_helper.sort_streams(stream_matches, query);
|
return typeahead_helper.sort_streams_by_name(stream_matches, query);
|
||||||
},
|
},
|
||||||
updater(item: StreamPillData, _query: string): undefined {
|
updater(item: StreamPillData, _query: string): undefined {
|
||||||
stream_pill.append_stream(item, pills, false);
|
stream_pill.append_stream(item, pills, false);
|
||||||
|
|
|
@ -628,6 +628,10 @@ export function compare_by_activity(
|
||||||
return util.strcmp(stream_a.name, stream_b.name);
|
return util.strcmp(stream_a.name, stream_b.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function compare_by_name(stream_a: StreamSubscription, stream_b: StreamSubscription): number {
|
||||||
|
return util.strcmp(stream_a.name, stream_b.name);
|
||||||
|
}
|
||||||
|
|
||||||
export function sort_streams(matches: StreamPillData[], query: string): StreamPillData[] {
|
export function sort_streams(matches: StreamPillData[], query: string): StreamPillData[] {
|
||||||
const name_results = typeahead.triage(query, matches, (x) => x.name, compare_by_activity);
|
const name_results = typeahead.triage(query, matches, (x) => x.name, compare_by_activity);
|
||||||
const desc_results = typeahead.triage(
|
const desc_results = typeahead.triage(
|
||||||
|
@ -640,6 +644,11 @@ export function sort_streams(matches: StreamPillData[], query: string): StreamPi
|
||||||
return [...name_results.matches, ...desc_results.matches, ...desc_results.rest];
|
return [...name_results.matches, ...desc_results.matches, ...desc_results.rest];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function sort_streams_by_name(matches: StreamPillData[], query: string): StreamPillData[] {
|
||||||
|
const results = typeahead.triage(query, matches, (x) => x.name, compare_by_name);
|
||||||
|
return [...results.matches, ...results.rest];
|
||||||
|
}
|
||||||
|
|
||||||
export function query_matches_person(
|
export function query_matches_person(
|
||||||
query: string,
|
query: string,
|
||||||
person: UserPillData | UserOrMentionPillData,
|
person: UserPillData | UserOrMentionPillData,
|
||||||
|
|
|
@ -226,7 +226,7 @@ run_test("set_up_user", ({mock_template, override, override_rewire}) => {
|
||||||
|
|
||||||
run_test("set_up_stream", ({mock_template, override, override_rewire}) => {
|
run_test("set_up_stream", ({mock_template, override, override_rewire}) => {
|
||||||
override_rewire(typeahead_helper, "render_stream", () => $fake_rendered_stream);
|
override_rewire(typeahead_helper, "render_stream", () => $fake_rendered_stream);
|
||||||
override_rewire(typeahead_helper, "sort_streams", ({streams}) => {
|
override_rewire(typeahead_helper, "sort_streams_by_name", ({streams}) => {
|
||||||
sort_streams_called = true;
|
sort_streams_called = true;
|
||||||
return streams;
|
return streams;
|
||||||
});
|
});
|
||||||
|
|
|
@ -211,6 +211,15 @@ test("sort_streams", ({override, override_rewire}) => {
|
||||||
assert.deepEqual(test_streams[4].name, "dead"); // Completely inactive stream
|
assert.deepEqual(test_streams[4].name, "dead"); // Completely inactive stream
|
||||||
assert.deepEqual(test_streams[5].name, "Derp"); // Muted stream last
|
assert.deepEqual(test_streams[5].name, "Derp"); // Muted stream last
|
||||||
|
|
||||||
|
// Sort streams by name
|
||||||
|
test_streams = th.sort_streams_by_name(test_streams, "d");
|
||||||
|
assert.deepEqual(test_streams[0].name, "dead");
|
||||||
|
assert.deepEqual(test_streams[1].name, "dead (almost)");
|
||||||
|
assert.deepEqual(test_streams[2].name, "Denmark");
|
||||||
|
assert.deepEqual(test_streams[3].name, "Derp");
|
||||||
|
assert.deepEqual(test_streams[4].name, "Dev");
|
||||||
|
assert.deepEqual(test_streams[5].name, "Docs");
|
||||||
|
|
||||||
override_rewire(compose_state, "stream_name", () => "Different");
|
override_rewire(compose_state, "stream_name", () => "Different");
|
||||||
// Test sort streams with description
|
// Test sort streams with description
|
||||||
test_streams = [
|
test_streams = [
|
||||||
|
|
Loading…
Reference in New Issue