RC Filters: group.allSelected consider subsets
authorStephane Bisson <sbisson@wikimedia.org>
Tue, 2 May 2017 13:25:33 +0000 (09:25 -0400)
committerStephane Bisson <sbisson@wikimedia.org>
Tue, 2 May 2017 13:25:33 +0000 (09:25 -0400)
Consider a group to be all selected if its unselected
items are subsets of selected items.

This allows the watchlist group to show as no-effect
when 'watched' and 'notwatched' are selected but
'watchednow' is not selected.

Bug: T163964
Change-Id: I40d2a02ab074bc87f8a6f2498834b89fbbe55771

resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FilterGroup.js

index 3ec544c..ca7c4e6 100644 (file)
         * @return {boolean} All items are selected
         */
        mw.rcfilters.dm.FilterGroup.prototype.areAllSelected = function () {
-               return this.getItems().every( function ( filterItem ) {
-                       return filterItem.isSelected();
+               var selected = [],
+                       unselected = [];
+
+               this.getItems().forEach( function ( filterItem ) {
+                       if ( filterItem.isSelected() ) {
+                               selected.push( filterItem );
+                       } else {
+                               unselected.push( filterItem );
+                       }
+               } );
+
+               if ( unselected.length === 0 ) {
+                       return true;
+               }
+
+               // check if every unselected is a subset of a selected
+               return unselected.every( function ( unselectedFilterItem ) {
+                       return selected.some( function ( selectedFilterItem ) {
+                               return selectedFilterItem.existsInSubset( unselectedFilterItem.getName() );
+                       } );
                } );
        };