This is an automated email from the ASF dual-hosted git repository.

jihao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new b0fd3a3  [TE] frontend - harleyjj/format-yaml-filter - move 
formatYamlFilter to utils and correct check for Array (#4024)
b0fd3a3 is described below

commit b0fd3a3be05efaa7e7ccba0ae65f2a6b8acc2475
Author: Harley Jackson <[email protected]>
AuthorDate: Wed Mar 27 17:09:16 2019 -0700

    [TE] frontend - harleyjj/format-yaml-filter - move formatYamlFilter to 
utils and correct check for Array (#4024)
---
 .../app/pods/manage/alerts/index/route.js          | 41 ++++++++++--------
 .../app/pods/manage/explore/route.js               | 49 +++++++++++-----------
 .../app/pods/manage/yaml/route.js                  | 39 ++---------------
 thirdeye/thirdeye-frontend/app/utils/utils.js      | 37 +++++++++++++++-
 4 files changed, 87 insertions(+), 79 deletions(-)

diff --git a/thirdeye/thirdeye-frontend/app/pods/manage/alerts/index/route.js 
b/thirdeye/thirdeye-frontend/app/pods/manage/alerts/index/route.js
index e2b67c9..a21c43f 100644
--- a/thirdeye/thirdeye-frontend/app/pods/manage/alerts/index/route.js
+++ b/thirdeye/thirdeye-frontend/app/pods/manage/alerts/index/route.js
@@ -3,7 +3,7 @@ import Route from '@ember/routing/route';
 import fetch from 'fetch';
 import { get, getWithDefault } from '@ember/object';
 import { inject as service } from '@ember/service';
-import { checkStatus } from 'thirdeye-frontend/utils/utils';
+import { checkStatus, formatYamlFilter } from 'thirdeye-frontend/utils/utils';
 import { powerSort } from 'thirdeye-frontend/utils/manage-alert-utils';
 
 // Maps filter name to alert property for filtering
@@ -48,7 +48,7 @@ export default Route.extend({
         collection: yamlAlert.dataset,
         type: this._detectionType(yamlAlert),
         exploreDimensions: dimensions,
-        filters: this._formatYamlFilter(yamlAlert.filters),
+        filters: formatYamlFilter(yamlAlert.filters),
         isNewPipeline: true
       });
     }
@@ -187,22 +187,27 @@ export default Route.extend({
    * @param {Map} filters multimap of filters
    * @return {String} - formatted filters string
    */
-  _formatYamlFilter(filters) {
-    if (filters){
-      const filterStrings = [];
-      Object.keys(filters).forEach(
-        function(filterKey) {
-          filters[filterKey].forEach(
-            function (filterValue) {
-              filterStrings.push(filterKey + "=" + filterValue);
-            }
-          );
-        }
-      );
-      return filterStrings.join(";");
-    }
-    return "";
-  },
+   _formatYamlFilter(filters) {
+     if (filters){
+       const filterStrings = [];
+       Object.keys(filters).forEach(
+         function(filterKey) {
+           const filter = filters[filterKey];
+           if (filter && Array.isArray(filter)) {
+             filter.forEach(
+               function (filterValue) {
+                 filterStrings.push(filterKey + '=' + filterValue);
+               }
+             );
+           } else {
+             filterStrings.push(filterKey + '=' + filter);
+           }
+         }
+       );
+       return filterStrings.join(';');
+     }
+     return '';
+   },
 
   /**
    * A local helper to find "Alerts I subscribe to"
diff --git a/thirdeye/thirdeye-frontend/app/pods/manage/explore/route.js 
b/thirdeye/thirdeye-frontend/app/pods/manage/explore/route.js
index d3cc243..a9e2c64 100644
--- a/thirdeye/thirdeye-frontend/app/pods/manage/explore/route.js
+++ b/thirdeye/thirdeye-frontend/app/pods/manage/explore/route.js
@@ -8,6 +8,7 @@ import RSVP from 'rsvp';
 import { set, get } from '@ember/object';
 import { inject as service } from '@ember/service';
 import { toastOptions } from 'thirdeye-frontend/utils/constants';
+import { formatYamlFilter } from 'thirdeye-frontend/utils/utils';
 import yamljs from 'yamljs';
 import moment from 'moment';
 
@@ -39,8 +40,8 @@ export default Route.extend({
             createdBy: detection_json.createdBy,
             updatedBy: detection_json.updatedBy,
             exploreDimensions: detection_json.dimensions,
-            filters: this._formatYamlFilter(detectionInfo.filters),
-            dimensionExploration: 
this._formatYamlFilter(detectionInfo.dimensionExploration),
+            filters: formatYamlFilter(detectionInfo.filters),
+            dimensionExploration: 
formatYamlFilter(detectionInfo.dimensionExploration),
             lastDetectionTime: lastDetection.toDateString() + ", " +  
lastDetection.toLocaleTimeString() + " (" + 
moment().tz(moment.tz.guess()).format('z') + ")",
             rawYaml: detection_json.yaml
           });
@@ -111,27 +112,25 @@ export default Route.extend({
    * @param {Map} filters multimap of filters
    * @return {String} - formatted filters string
    */
-  _formatYamlFilter(filters) {
-    if (filters){
-      const filterStrings = [];
-
-      Object.keys(filters).forEach(
-        function(filterKey) {
-          const filter = filters[filterKey];
-          if (filter && typeof filter === 'object') {
-
-            filter.forEach(
-              function (filterValue) {
-                filterStrings.push(filterKey + '=' + filterValue);
-              }
-            );
-          } else {
-            filterStrings.push(filterKey + '=' + filter);
-          }
-        }
-      );
-      return filterStrings.join(';');
-    }
-    return '';
-  }
+   _formatYamlFilter(filters) {
+     if (filters){
+       const filterStrings = [];
+       Object.keys(filters).forEach(
+         function(filterKey) {
+           const filter = filters[filterKey];
+           if (filter && Array.isArray(filter)) {
+             filter.forEach(
+               function (filterValue) {
+                 filterStrings.push(filterKey + '=' + filterValue);
+               }
+             );
+           } else {
+             filterStrings.push(filterKey + '=' + filter);
+           }
+         }
+       );
+       return filterStrings.join(';');
+     }
+     return '';
+   }
 });
diff --git a/thirdeye/thirdeye-frontend/app/pods/manage/yaml/route.js 
b/thirdeye/thirdeye-frontend/app/pods/manage/yaml/route.js
index 1779c4a..301f823 100644
--- a/thirdeye/thirdeye-frontend/app/pods/manage/yaml/route.js
+++ b/thirdeye/thirdeye-frontend/app/pods/manage/yaml/route.js
@@ -10,6 +10,7 @@ import { inject as service } from '@ember/service';
 import yamljs from 'yamljs';
 import moment from 'moment';
 import { toastOptions } from 'thirdeye-frontend/utils/constants';
+import { formatYamlFilter } from 'thirdeye-frontend/utils/utils';
 
 export default Route.extend({
   notifications: service('toast'),
@@ -39,8 +40,8 @@ export default Route.extend({
             createdBy: detection_json.createdBy,
             updatedBy: detection_json.updatedBy,
             exploreDimensions: detection_json.dimensions,
-            filters: this._formatYamlFilter(detectionInfo.filters),
-            dimensionExploration: 
this._formatYamlFilter(detectionInfo.dimensionExploration),
+            filters: formatYamlFilter(detectionInfo.filters),
+            dimensionExploration: 
formatYamlFilter(detectionInfo.dimensionExploration),
             lastDetectionTime: lastDetection.toDateString() + ", " +  
lastDetection.toLocaleTimeString() + " (" + 
moment().tz(moment.tz.guess()).format('z') + ")"
           });
 
@@ -94,37 +95,5 @@ export default Route.extend({
     });
   },
 
-  /**
-   * The yaml filters formatter. Convert filters in the yaml file in to a 
legacy filters string
-   * For example, filters = {
-   *   "country": ["us", "cn"],
-   *   "browser": ["chrome"]
-   * }
-   * will be convert into "country=us;country=cn;browser=chrome"
-   *
-   * @method _formatYamlFilter
-   * @param {Map} filters multimap of filters
-   * @return {String} - formatted filters string
-   */
-  _formatYamlFilter(filters) {
-    if (filters){
-      const filterStrings = [];
-      Object.keys(filters).forEach(
-        function(filterKey) {
-          const filter = filters[filterKey];
-          if (filter && typeof filter === 'object') {
-            filter.forEach(
-              function (filterValue) {
-                filterStrings.push(filterKey + '=' + filterValue);
-              }
-            );
-          } else {
-            filterStrings.push(filterKey + '=' + filter);
-          }
-        }
-      );
-      return filterStrings.join(';');
-    }
-    return '';
-  }
+
 });
diff --git a/thirdeye/thirdeye-frontend/app/utils/utils.js 
b/thirdeye/thirdeye-frontend/app/utils/utils.js
index d655d98..00f0313 100644
--- a/thirdeye/thirdeye-frontend/app/utils/utils.js
+++ b/thirdeye/thirdeye-frontend/app/utils/utils.js
@@ -176,6 +176,40 @@ export function toIso(dateStr) {
   return moment(Number(dateStr)).toISOString();
 }
 
+/**
+ * The yaml filters formatter. Convert filters in the yaml file in to a legacy 
filters string
+ * For example, filters = {
+ *   "country": ["us", "cn"],
+ *   "browser": ["chrome"]
+ * }
+ * will be convert into "country=us;country=cn;browser=chrome"
+ *
+ * @method _formatYamlFilter
+ * @param {Map} filters multimap of filters
+ * @return {String} - formatted filters string
+ */
+export function formatYamlFilter(filters) {
+  if (filters){
+    const filterStrings = [];
+    Object.keys(filters).forEach(
+      function(filterKey) {
+        const filter = filters[filterKey];
+        if (filter && Array.isArray(filter)) {
+          filter.forEach(
+            function (filterValue) {
+              filterStrings.push(filterKey + '=' + filterValue);
+            }
+          );
+        } else {
+          filterStrings.push(filterKey + '=' + filter);
+        }
+      }
+    );
+    return filterStrings.join(';');
+  }
+  return '';
+}
+
 export default {
   checkStatus,
   humanizeFloat,
@@ -185,5 +219,6 @@ export default {
   parseProps,
   postProps,
   toIso,
-  postYamlProps
+  postYamlProps,
+  formatYamlFilter
 };


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

Reply via email to