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)}"]`, `[data-filter="${CSS.escape(filter)}"]`,
); );
// If user clicks `All`, we clear all filters. if ($filter_elem.hasClass("btn-recent-selected")) {
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")) {
filters.delete(filter); filters.delete(filter);
// If the button was not selected, we add the filter. // If the button was not selected, we add the filter.
} else { } else {
@@ -786,12 +782,6 @@ export function set_filter(filter) {
function show_selected_filters() { function show_selected_filters() {
// Add `btn-selected-filter` to the buttons to show // Add `btn-selected-filter` to the buttons to show
// which filters are applied. // which filters are applied.
if (filters.size === 0) {
$("#recent_view_filter_buttons")
.find('[data-filter="all"]')
.addClass("btn-recent-selected")
.attr("aria-checked", "true");
} else {
for (const filter of filters) { for (const filter of filters) {
$("#recent_view_filter_buttons") $("#recent_view_filter_buttons")
.find(`[data-filter="${CSS.escape(filter)}"]`) .find(`[data-filter="${CSS.escape(filter)}"]`)
@@ -799,7 +789,6 @@ function show_selected_filters() {
.attr("aria-checked", "true"); .attr("aria-checked", "true");
} }
} }
}
export function update_filters_view() { export function update_filters_view() {
const rendered_filters = render_recent_view_filters({ const rendered_filters = render_recent_view_filters({

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"> <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}} {{#if filter_pm}}
<i class="fa fa-check-square-o"></i> <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 // See show_selected_filters() and set_filter() in the
// implementation. // 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 $stub = $.create(`filter-${filter}-stub`);
const selector = `[data-filter="${filter}"]`; const selector = `[data-filter="${filter}"]`;
$("#recent_view_filter_buttons").set_find_results(selector, $stub); $("#recent_view_filter_buttons").set_find_results(selector, $stub);
@@ -499,11 +499,10 @@ test("test_filter_is_spectator", ({mock_template}) => {
rt.clear_for_tests(); rt.clear_for_tests();
stub_out_filter_buttons(); stub_out_filter_buttons();
recent_view_util.set_visible(true); recent_view_util.set_visible(true);
rt.set_filter("all");
rt.process_messages([messages[0]]); rt.process_messages([messages[0]]);
}); });
test("test_filter_all", ({mock_template}) => { test("test_no_filter", ({mock_template}) => {
// Just tests inplace rerender of a message // Just tests inplace rerender of a message
// in All topics filter. // in All topics filter.
page_params.is_spectator = false; page_params.is_spectator = false;
@@ -534,7 +533,6 @@ test("test_filter_all", ({mock_template}) => {
rt.clear_for_tests(); rt.clear_for_tests();
stub_out_filter_buttons(); stub_out_filter_buttons();
recent_view_util.set_visible(true); recent_view_util.set_visible(true);
rt.set_filter("all");
rt.process_messages([messages[0]]); rt.process_messages([messages[0]]);
assert.equal( assert.equal(
rt.filters_should_hide_topic({last_msg_id: 1, participated: true, type: "stream"}), 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"); $("#recent_view_filter_buttons").removeClass("btn-recent-selected");
// reselect "unread" filter // reselect "unread" filter
rt.set_filter("unread"); 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}) => { test("test_filter_participated", ({mock_template}) => {
@@ -921,16 +916,12 @@ test("test_filter_participated", ({mock_template}) => {
]; ];
rt.process_messages([messages[4]]); rt.process_messages([messages[4]]);
expected_filter_participated = false;
rt.set_filter("all");
}); });
test("test_update_unread_count", () => { test("test_update_unread_count", () => {
recent_view_util.set_visible(false); recent_view_util.set_visible(false);
rt.clear_for_tests(); rt.clear_for_tests();
stub_out_filter_buttons(); stub_out_filter_buttons();
rt.set_filter("all");
rt.process_messages(messages); rt.process_messages(messages);
// update a message // update a message
@@ -950,7 +941,6 @@ test("basic assertions", ({mock_template, override_rewire}) => {
stub_out_filter_buttons(); stub_out_filter_buttons();
recent_view_util.set_visible(true); recent_view_util.set_visible(true);
rt.set_default_focus(); rt.set_default_focus();
rt.set_filter("all");
rt.process_messages(messages); rt.process_messages(messages);
let all_topics = rt_data.get_conversations(); let all_topics = rt_data.get_conversations();
@@ -1078,7 +1068,6 @@ test("test_reify_local_echo_message", ({mock_template}) => {
rt.clear_for_tests(); rt.clear_for_tests();
stub_out_filter_buttons(); stub_out_filter_buttons();
recent_view_util.set_visible(true); recent_view_util.set_visible(true);
rt.set_filter("all");
rt.process_messages(messages); rt.process_messages(messages);
rt_data.process_message({ rt_data.process_message({
@@ -1127,7 +1116,6 @@ test("test_delete_messages", ({override}) => {
recent_view_util.set_visible(false); recent_view_util.set_visible(false);
rt.clear_for_tests(); rt.clear_for_tests();
stub_out_filter_buttons(); stub_out_filter_buttons();
rt.set_filter("all");
rt.process_messages(messages); rt.process_messages(messages);
// messages[0] was removed. // 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. // NOTE: This test should always run in the end as it modified the messages data.
rt.clear_for_tests(); rt.clear_for_tests();
stub_out_filter_buttons(); stub_out_filter_buttons();
rt.set_filter("all");
rt.process_messages(messages); rt.process_messages(messages);
let all_topics = rt_data.get_conversations(); let all_topics = rt_data.get_conversations();