recent_view: Remove `All` filter.

Fixes #27588

Co-authored-by: cherish2003 <saicherissh90@gmail.com>
This commit is contained in:
Aman Agrawal 2023-11-19 06:43:24 +00:00 committed by Tim Abbott
parent b1d5cd6bf6
commit 26f7f9d3d8
3 changed files with 5 additions and 30 deletions

View File

@ -769,11 +769,7 @@ export function set_filter(filter) {
`[data-filter="${CSS.escape(filter)}"]`,
);
// If user clicks `All`, we clear all filters.
if (filter === "all" && filters.size !== 0) {
filters = new Set();
// If the button was already selected, remove the filter.
} else if ($filter_elem.hasClass("btn-recent-selected")) {
if ($filter_elem.hasClass("btn-recent-selected")) {
filters.delete(filter);
// If the button was not selected, we add the filter.
} else {
@ -786,18 +782,11 @@ export function set_filter(filter) {
function show_selected_filters() {
// Add `btn-selected-filter` to the buttons to show
// which filters are applied.
if (filters.size === 0) {
for (const filter of filters) {
$("#recent_view_filter_buttons")
.find('[data-filter="all"]')
.find(`[data-filter="${CSS.escape(filter)}"]`)
.addClass("btn-recent-selected")
.attr("aria-checked", "true");
} else {
for (const filter of filters) {
$("#recent_view_filter_buttons")
.find(`[data-filter="${CSS.escape(filter)}"]`)
.addClass("btn-recent-selected")
.attr("aria-checked", "true");
}
}
}

View File

@ -1,4 +1,3 @@
<button data-filter="all" type="button" class="btn btn-default btn-recent-filters">{{t 'All' }}</button>
<button data-filter="include_private" type="button" class="btn btn-default btn-recent-filters {{#if is_spectator}}fake_disabled_button{{/if}}" role="checkbox" aria-checked="true">
{{#if filter_pm}}
<i class="fa fa-check-square-o"></i>

View File

@ -420,7 +420,7 @@ function stub_out_filter_buttons() {
//
// See show_selected_filters() and set_filter() in the
// implementation.
for (const filter of ["all", "unread", "muted", "participated", "include_private"]) {
for (const filter of ["unread", "muted", "participated", "include_private"]) {
const $stub = $.create(`filter-${filter}-stub`);
const selector = `[data-filter="${filter}"]`;
$("#recent_view_filter_buttons").set_find_results(selector, $stub);
@ -499,11 +499,10 @@ test("test_filter_is_spectator", ({mock_template}) => {
rt.clear_for_tests();
stub_out_filter_buttons();
recent_view_util.set_visible(true);
rt.set_filter("all");
rt.process_messages([messages[0]]);
});
test("test_filter_all", ({mock_template}) => {
test("test_no_filter", ({mock_template}) => {
// Just tests inplace rerender of a message
// in All topics filter.
page_params.is_spectator = false;
@ -534,7 +533,6 @@ test("test_filter_all", ({mock_template}) => {
rt.clear_for_tests();
stub_out_filter_buttons();
recent_view_util.set_visible(true);
rt.set_filter("all");
rt.process_messages([messages[0]]);
assert.equal(
rt.filters_should_hide_topic({last_msg_id: 1, participated: true, type: "stream"}),
@ -794,9 +792,6 @@ test("test_filter_unread", ({mock_template}) => {
$("#recent_view_filter_buttons").removeClass("btn-recent-selected");
// reselect "unread" filter
rt.set_filter("unread");
// Now clicking "all" filter should have no change to expected data.
rt.set_filter("all");
});
test("test_filter_participated", ({mock_template}) => {
@ -921,16 +916,12 @@ test("test_filter_participated", ({mock_template}) => {
];
rt.process_messages([messages[4]]);
expected_filter_participated = false;
rt.set_filter("all");
});
test("test_update_unread_count", () => {
recent_view_util.set_visible(false);
rt.clear_for_tests();
stub_out_filter_buttons();
rt.set_filter("all");
rt.process_messages(messages);
// update a message
@ -950,7 +941,6 @@ test("basic assertions", ({mock_template, override_rewire}) => {
stub_out_filter_buttons();
recent_view_util.set_visible(true);
rt.set_default_focus();
rt.set_filter("all");
rt.process_messages(messages);
let all_topics = rt_data.get_conversations();
@ -1078,7 +1068,6 @@ test("test_reify_local_echo_message", ({mock_template}) => {
rt.clear_for_tests();
stub_out_filter_buttons();
recent_view_util.set_visible(true);
rt.set_filter("all");
rt.process_messages(messages);
rt_data.process_message({
@ -1127,7 +1116,6 @@ test("test_delete_messages", ({override}) => {
recent_view_util.set_visible(false);
rt.clear_for_tests();
stub_out_filter_buttons();
rt.set_filter("all");
rt.process_messages(messages);
// messages[0] was removed.
@ -1169,7 +1157,6 @@ test("test_topic_edit", ({override}) => {
// NOTE: This test should always run in the end as it modified the messages data.
rt.clear_for_tests();
stub_out_filter_buttons();
rt.set_filter("all");
rt.process_messages(messages);
let all_topics = rt_data.get_conversations();