Merge "RCFilters: Don't emit wikipage.content on first load"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 18 Jul 2017 23:18:51 +0000 (23:18 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 18 Jul 2017 23:18:51 +0000 (23:18 +0000)
1  2 
resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js

@@@ -15,8 -15,6 +15,8 @@@
                this.baseFilterState = {};
                this.uriProcessor = null;
                this.initializing = false;
 +
 +              this.prevLoggedItems = [];
        };
  
        /* Initialization */
                        // so it gets processed
                        this.changesListModel.update(
                                $changesList.length ? $changesList : 'NO_RESULTS',
-                               $( 'fieldset.rcoptions' ).first()
+                               $( 'fieldset.rcoptions' ).first(),
+                               true // We're using existing DOM elements
                        );
                }
  
                        this.filtersModel.toggleFilterSelected( filterName, false );
                        this.updateChangesList();
                        this.filtersModel.reassessFilterInteractions( filterItem );
 +
 +                      // Log filter grouping
 +                      this.trackFilterGroupings( 'removefilter' );
                }
  
                if ( isHighlighted ) {
                        this.filtersModel.reassessFilterInteractions();
  
                        this.updateChangesList();
 +
 +                      // Log filter grouping
 +                      this.trackFilterGroupings( 'savedfilters' );
                }
        };
  
                );
        };
  
 +      /**
 +       * Track filter grouping usage
 +       *
 +       * @param {string} action Action taken
 +       */
 +      mw.rcfilters.Controller.prototype.trackFilterGroupings = function ( action ) {
 +              var controller = this,
 +                      rightNow = new Date().getTime(),
 +                      randomIdentifier = String( mw.user.sessionId() ) + String( rightNow ) + String( Math.random() ),
 +                      // Get all current filters
 +                      filters = this.filtersModel.getSelectedItems().map( function ( item ) {
 +                              return item.getName();
 +                      } );
 +
 +              action = action || 'filtermenu';
 +
 +              // Check if these filters were the ones we just logged previously
 +              // (Don't log the same grouping twice, in case the user opens/closes)
 +              // the menu without action, or with the same result
 +              if (
 +                      // Only log if the two arrays are different in size
 +                      filters.length !== this.prevLoggedItems.length ||
 +                      // Or if any filters are not the same as the cached filters
 +                      filters.some( function ( filterName ) {
 +                              return controller.prevLoggedItems.indexOf( filterName ) === -1;
 +                      } ) ||
 +                      // Or if any cached filters are not the same as given filters
 +                      this.prevLoggedItems.some( function ( filterName ) {
 +                              return filters.indexOf( filterName ) === -1;
 +                      } )
 +              ) {
 +                      filters.forEach( function ( filterName ) {
 +                              mw.track(
 +                                      'event.ChangesListFilterGrouping',
 +                                      {
 +                                              action: action,
 +                                              groupIdentifier: randomIdentifier,
 +                                              filter: filterName,
 +                                              userId: mw.user.getId()
 +                                      }
 +                              );
 +                      } );
 +
 +                      // Cache the filter names
 +                      this.prevLoggedItems = filters;
 +              }
 +      };
  }( mediaWiki, jQuery ) );