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

akshayrai09 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 a102ee0  [TE] frontend - harleyjj/yaml-editor - if there is no 
existing subscription group, the user can create one on edit-alert (#4071)
a102ee0 is described below

commit a102ee0501385a8a851f245e61f9921dc0bbfa09
Author: Harley Jackson <[email protected]>
AuthorDate: Thu Apr 4 10:36:29 2019 -0700

    [TE] frontend - harleyjj/yaml-editor - if there is no existing subscription 
group, the user can create one on edit-alert (#4071)
---
 .../app/pods/components/yaml-editor/component.js   | 86 +++++++++++++++++-----
 .../app/pods/components/yaml-editor/template.hbs   | 12 ++-
 2 files changed, 77 insertions(+), 21 deletions(-)

diff --git 
a/thirdeye/thirdeye-frontend/app/pods/components/yaml-editor/component.js 
b/thirdeye/thirdeye-frontend/app/pods/components/yaml-editor/component.js
index c1ebf9e..e3d968c 100644
--- a/thirdeye/thirdeye-frontend/app/pods/components/yaml-editor/component.js
+++ b/thirdeye/thirdeye-frontend/app/pods/components/yaml-editor/component.js
@@ -99,6 +99,22 @@ export default Component.extend({
   ),
 
   /**
+   * Flag to trigger special case of no existing subscription groups for an 
alert
+   * @method noExistingSubscriptionGroup
+   * @return {Boolean}
+   */
+  noExistingSubscriptionGroup: computed(
+    'subscriptionGroupNames',
+    function() {
+      const subscriptionGroupNames = get(this, 'subscriptionGroupNames');
+      if (subscriptionGroupNames && Array.isArray(subscriptionGroupNames) && 
subscriptionGroupNames.length > 0) {
+        return false;
+      }
+      return true;
+    }
+  ),
+
+  /**
    * sets Yaml value displayed to contents of detectionYaml or yamlAlertProps
    * @method currentYamlAlert
    * @return {String}
@@ -274,6 +290,54 @@ export default Component.extend({
     return defaultReturn;
   },
 
+  // Method for handling subscription group, whether there are any or not
+  async _handleSubscriptionGroup(subscriptionYaml, notifications, 
subscriptionGroupId) {
+    const noExistingSubscriptionGroup = get(this, 
'noExistingSubscriptionGroup');
+    if (noExistingSubscriptionGroup) {
+      //PUT settings
+      const setting_url = '/yaml/subscription';
+      const settingsPostProps = {
+        method: 'POST',
+        body: subscriptionYaml,
+        headers: { 'content-type': 'text/plain' }
+      };
+      try {
+        const settings_result = await fetch(setting_url, settingsPostProps);
+        const settings_status  = get(settings_result, 'status');
+        const settings_json = await settings_result.json();
+        if (settings_status !== 200) {
+          set(this, 'errorMsg', get(settings_json, 'message'));
+          notifications.error(`Failed to save the subscription configuration 
due to: ${settings_json.message}.`, 'Error', toastOptions);
+        } else {
+          notifications.success('Subscription configuration saved 
successfully', 'Done', toastOptions);
+        }
+      } catch (error) {
+        notifications.error('Error while saving subscription config.', error, 
toastOptions);
+      }
+    } else {
+      //PUT settings
+      const setting_url = `/yaml/subscription/${subscriptionGroupId}`;
+      const settingsPostProps = {
+        method: 'PUT',
+        body: subscriptionYaml,
+        headers: { 'content-type': 'text/plain' }
+      };
+      try {
+        const settings_result = await fetch(setting_url, settingsPostProps);
+        const settings_status  = get(settings_result, 'status');
+        const settings_json = await settings_result.json();
+        if (settings_status !== 200) {
+          set(this, 'errorMsg', get(settings_json, 'message'));
+          notifications.error(`Failed to save the subscription configuration 
due to: ${settings_json.message}.`, 'Error', toastOptions);
+        } else {
+          notifications.success('Subscription configuration saved 
successfully', 'Done', toastOptions);
+        }
+      } catch (error) {
+        notifications.error('Error while saving subscription config.', error, 
toastOptions);
+      }
+    }
+  },
+
   actions: {
     changeAccordion() {
       set(this, 'toggleCollapsed', !get(this, 'toggleCollapsed'));
@@ -460,26 +524,8 @@ export default Component.extend({
       } catch (error) {
         notifications.error('Error while saving detection config.', error, 
toastOptions);
       }
-      //PUT settings
-      const setting_url = `/yaml/subscription/${subscriptionGroupId}`;
-      const settingsPostProps = {
-        method: 'PUT',
-        body: subscriptionYaml,
-        headers: { 'content-type': 'text/plain' }
-      };
-      try {
-        const settings_result = await fetch(setting_url, settingsPostProps);
-        const settings_status  = get(settings_result, 'status');
-        const settings_json = await settings_result.json();
-        if (settings_status !== 200) {
-          set(this, 'errorMsg', get(settings_json, 'message'));
-          notifications.error(`Failed to save the subscription configuration 
due to: ${settings_json.message}.`, 'Error', toastOptions);
-        } else {
-          notifications.success('Subscription configuration saved 
successfully', 'Done', toastOptions);
-        }
-      } catch (error) {
-        notifications.error('Error while saving subscription config.', error, 
toastOptions);
-      }
+      // If there is no existing subscription group, this method will handle it
+      this._handleSubscriptionGroup(subscriptionYaml, notifications, 
subscriptionGroupId);
     }
   }
 });
diff --git 
a/thirdeye/thirdeye-frontend/app/pods/components/yaml-editor/template.hbs 
b/thirdeye/thirdeye-frontend/app/pods/components/yaml-editor/template.hbs
index be978f7..2adf0de 100644
--- a/thirdeye/thirdeye-frontend/app/pods/components/yaml-editor/template.hbs
+++ b/thirdeye/thirdeye-frontend/app/pods/components/yaml-editor/template.hbs
@@ -75,7 +75,17 @@
       <legend class="te-form__section-title">{{alertSettingsTitle}}</legend>
     </div>
     <div class="col-xs-4">
-      <label class="te-label te-label--small">Add this alert to a subscription 
group</label>
+      {{#if isEditMode}}
+        <label class="te-label te-label--small">
+          {{#if noExistingSubscriptionGroup}}
+            Create a subscription group for this alert
+          {{else}}
+            Edit a subscription group already subscribed to this alert
+          {{/if}}</label>
+      {{else}}
+        <label class="te-label te-label--small">Add this alert to a 
subscription group</label>
+      {{/if}}
+
       {{!--  subscription group --}}
       {{#power-select
         placeholder="Create a new subscription group"


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

Reply via email to