mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	settings: Extract sort helpers for various lists.
Giving these functions a name and moving them to
the top-level scope has a couple tactical advantages:
    - names show in tracebacks
    - code is less indented
    - setup code is less cluttered
    - will be easier to add unit tests
    - will make some upcoming diffs nicer
These are technically more `compare_foo` than `sort_foo`,
but we already had a naming convention that was sort of
in place.
			
			
This commit is contained in:
		@@ -14,6 +14,23 @@ exports.maybe_disable_widgets = function () {
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
function compare_by_index(a, b, i) {
 | 
			
		||||
    if (a[i] > b[i]) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    } else if (a[i] === b[i]) {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function sort_pattern(a, b) {
 | 
			
		||||
    return compare_by_index(a, b, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function sort_url(a, b) {
 | 
			
		||||
    return compare_by_index(a, b, 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.populate_filters = function (filters_data) {
 | 
			
		||||
    if (!meta.loaded) {
 | 
			
		||||
        return;
 | 
			
		||||
@@ -45,22 +62,8 @@ exports.populate_filters = function (filters_data) {
 | 
			
		||||
        parent_container: $("#filter-settings").expectOne(),
 | 
			
		||||
    }).init();
 | 
			
		||||
 | 
			
		||||
    function compare_by_index(a, b, i) {
 | 
			
		||||
        if (a[i] > b[i]) {
 | 
			
		||||
            return 1;
 | 
			
		||||
        } else if (a[i] === b[i]) {
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    filters_list.add_sort_function("pattern", function (a, b) {
 | 
			
		||||
        return compare_by_index(a, b, 0);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    filters_list.add_sort_function("url", function (a, b) {
 | 
			
		||||
        return compare_by_index(a, b, 1);
 | 
			
		||||
    });
 | 
			
		||||
    filters_list.add_sort_function("pattern", sort_pattern);
 | 
			
		||||
    filters_list.add_sort_function("url", sort_url);
 | 
			
		||||
 | 
			
		||||
    const active_col = $('.admin_filters_table th.active').expectOne();
 | 
			
		||||
    filters_list.sort(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user