jihaozh commented on a change in pull request #5593:
URL: https://github.com/apache/incubator-pinot/pull/5593#discussion_r445136244



##########
File path: thirdeye/thirdeye-frontend/app/pods/manage/alerts/index/controller.js
##########
@@ -281,190 +275,144 @@ export default Controller.extend({
   ),
 
   /**
-   * We are recalculating the options of each selection field. The values come 
from the aggregated
-   * properties across all filtered alerts. For example, it returns all 
possible values for 'application'
-   * @method _recalculateFilterKeys
-   * @param {Array} alertsCollection - array of alerts we are extracting 
values from
-   * @param {Object} blockItem - the current search filter object
-   * @returns {Array} - a deduped array of values to use as select options
-   * @private
+   * flag meaning alerts are loading for current page
+   * @type {Boolean}
    */
-  _recalculateFilterKeys(alertsCollection, blockItem) {
-    const filterToPropertyMap = get(this, 'filterToPropertyMap');
-    // Aggregate all existing values for our target properties in the current 
array collection
-    let alertPropsAsKeys = [];
-    // Make sure subscription groups are not bundled for filter parameters
-    if (blockItem.name === 'subscription') {
-      alertsCollection.forEach(alert => {
-        let groups = alert[filterToPropertyMap[blockItem.name]];
-        if (groups) {
-          groups.split(", ").forEach(g => {
-            alertPropsAsKeys.push(g);
-          });
-        }
-      });
-    } else if (blockItem.name === 'application') {
-      // Make sure applications are not bundled for filter parameters
-      alertsCollection.forEach(alert => {
-        let applications = alert[filterToPropertyMap[blockItem.name]];
-        if (applications) {
-          applications.split(", ").forEach(a => {
-            alertPropsAsKeys.push(a);
-          });
-        }
-      });
-    } else {
-      alertPropsAsKeys = alertsCollection.map(alert => 
alert[filterToPropertyMap[blockItem.name]]);
+  isLoading: computed(
+    '_getAlerts.isIdle',
+    function() {
+      return !get(this, '_getAnomalies.isIdle');
     }
-    // Add 'none' select option if allowed
-    const canInsertNullOption = alertPropsAsKeys.includes(undefined) && 
blockItem.hasNullOption;
-    if (canInsertNullOption) { alertPropsAsKeys.push('none'); }
-    // Return a deduped array containing all of the values for this property 
in the current set of alerts
-    return [ ...new Set(powerSort(alertPropsAsKeys.filter(val => 
isPresent(val)), null)) ];
-  },
+  ),
 
   /**
-   * This is the core filtering method which acts upon a set of initial alerts 
to return a subset
-   * @method _filterAlerts
-   * @param {Array} initialAlerts - array of all alerts to start with
-   * @param {Object} filters - filter key/values to process
-   * @example
-   * {
-   *   application: ['app name a', 'app name b'],
-   *   status: ['active'],
-   *   owner: ['[email protected], [email protected]'],
-   *   type: null
-   * }
+   * When user chooses to either find an alert by name, or use a global filter,
+   * we should re-set all local filters.
+   * @method _resetFilters
+   * @param {Boolean} isSelectDisabled
    * @returns {undefined}
    * @private
    */
-  _filterAlerts(initialAlerts, filters) {
-    const filterToPropertyMap = get(this, 'filterToPropertyMap');
-    // A click on a primary alert filter will reset 'filteredAlerts'
-    if (filters.primary) {
-      this._processPrimaryFilters(initialAlerts, filters.primary);
-    }
-    // Pick up cached alert array for the secondary filters
-    let filteredAlerts = get(this, 'filteredAlerts');
-    // If there is a secondary filter present, filter by it, using the keys 
we've set up in our filter map
-    Object.keys(filterToPropertyMap).forEach((filterKey) => {
-      let filterValueArray = filters[filterKey];
-      if (filterValueArray && filterValueArray.length) {
-        let newAlerts = filteredAlerts.filter(alert => {
-          // See 'filterToPropertyMap' in route. For filterKey = 'owner' this 
would map alerts by alert['createdBy'] = x
-          const targetAlertPropertyValue = 
alert[filterToPropertyMap[filterKey]];
-          let alertMeetsCriteria = false;
-          // In the cases for subscription and application, there can be 
multiple values.  We just need to match on one
-          if (filterKey === "subscription") {
-            if (targetAlertPropertyValue) {
-              filterValueArray.forEach(val => {
-                if (targetAlertPropertyValue.includes(val)) {
-                  alertMeetsCriteria = true;
-                }
-              });
-            }
-          } else if (filterKey === "application") {
-            if (targetAlertPropertyValue) {
-              filterValueArray.forEach(val => {
-                if (targetAlertPropertyValue.includes(val)) {
-                  alertMeetsCriteria = true;
-                }
-              });
-            }
-          } else {
-            alertMeetsCriteria = targetAlertPropertyValue && 
filterValueArray.includes(targetAlertPropertyValue);
-          }
-          const isMatchForNone = 
!alert.hasOwnProperty(filterToPropertyMap[filterKey]) && 
filterValueArray.includes('none');
-          return alertMeetsCriteria || isMatchForNone;
-        });
-        filteredAlerts = newAlerts;
-      }
-    });
+  _resetLocalFilters() {
+    let alertFilters = {};
+    const newFilterBlocksLocal = _.cloneDeep(get(this, 'initialFiltersLocal'));
 
-    // If status filter is present, we re-build the results array to contain 
only active alerts, inactive alerts, or both.
-    if (filters.status) {
-      const concatStatus = filters.status.length ? 
filters.status.join().toLowerCase() : 'active';
-      const requireAll = filters.status.includes('Active') && 
filters.status.includes('Inactive');
-      const alertsByState = {
-        active: filteredAlerts.filter(alert => alert.active),
-        inactive: filteredAlerts.filter(alert => !alert.active)
-      };
-      filteredAlerts = requireAll ? [ ...alertsByState.active, 
...alertsByState.inactive ] : alertsByState[concatStatus];
-    }
+    // Do not highlight any of the primary filters
+    Object.assign(alertFilters, { primary: 'none' });
 
-    return filteredAlerts;
+    // Reset local (secondary) filters, and set select fields to 'disabled'
+    setProperties(this, {
+      filterBlocksLocal: newFilterBlocksLocal,
+      resetFiltersLocal: moment().valueOf(),
+      allowFilterSummary: false,
+      alertFilters
+    });
   },
 
+  _getAlerts: task (function * (params) {
+    const subscriptionGroups = this.get('subscriptionGroupConfig');
+    const alerts = yield 
fetch(yamlAPI.getPaginatedAlertsUrl(params)).then(checkStatus);
+    const enrichedAlerts = enrichAlertResponseObject((alerts || {}).elements, 
subscriptionGroups);
+    set(this, 'originalAlerts', enrichedAlerts);
+    set(this, 'totalNumberOfAlerts', (alerts || {}).count);
+    // Reset secondary filters
+    setProperties(this, {
+      filterBlocksLocal: _.cloneDeep(get(this, 'initialFiltersLocal')),
+      resetFiltersLocal: moment().valueOf()
+    });
+  }).keepLatest(),
+
   /**
-   * Simply select the appropriate set of alerts called for by primary filter
-   * @method _processPrimaryFilters
-   * @param {Array} originalAlerts - array of all alerts from model
-   * @param {Object} primaryFilter - filter key/value for primary filter 
selections
-   * @returns {undefined}
-   * @private
+   * Ember concurrency task that triggers alert names autocomplete
    */
-  _processPrimaryFilters (originalAlerts, primaryFilter) {
-    const { ownedAlerts, subscribedAlerts } = getProperties(this, 
'ownedAlerts', 'subscribedAlerts');
+  _searchAlertNames: task(function* (text) {
+    yield timeout(1000);
+    return fetch(autocompleteAPI.alertByName(text))
+      .then(checkStatus);
+  }),
+
+  _fetchAlerts() {
+    const paramsForAlerts = get(this, 'paramsForAlerts');
+    return this.get('_getAlerts').perform(paramsForAlerts);
+  },
 
-    let newAlerts = [];
+  _handlePrimaryFilter(primaryFilter, paramsForAlerts) {
     switch(primaryFilter) {
       case 'Alerts I subscribe to': {
-        newAlerts = subscribedAlerts;
+        const user = this.get('user');
+        paramsForAlerts['subscribedBy'] = user;

Review comment:
       One little catch here. The user string is in the format of 
'[email protected]', but the email written in the subscription group is 
stored as '[email protected]'. So directly searching the user as a string 
won't get any result. Maybe change it to send '[email protected]' or 
'userName' directly? 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to