You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metron.apache.org by mm...@apache.org on 2018/07/11 01:32:49 UTC

[33/50] [abbrv] metron git commit: METRON-1634 Alerts UI add comment doesn' t immediately show up. (merrimanr) closes apache/metron#1077

METRON-1634 Alerts UI add comment doesn't immediately show up. (merrimanr) closes apache/metron#1077


Project: http://git-wip-us.apache.org/repos/asf/metron/repo
Commit: http://git-wip-us.apache.org/repos/asf/metron/commit/622d50a1
Tree: http://git-wip-us.apache.org/repos/asf/metron/tree/622d50a1
Diff: http://git-wip-us.apache.org/repos/asf/metron/diff/622d50a1

Branch: refs/heads/feature/METRON-1554-pcap-query-panel
Commit: 622d50a168ef7056377d3a3143bc47d2d57ad67f
Parents: 436cec4
Author: merrimanr <me...@gmail.com>
Authored: Tue Jun 26 10:42:06 2018 -0500
Committer: rmerriman <me...@gmail.com>
Committed: Tue Jun 26 10:42:06 2018 -0500

----------------------------------------------------------------------
 .../alert-details/alert-details.component.ts    | 32 ++++++++++++--------
 1 file changed, 19 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/metron/blob/622d50a1/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.ts
----------------------------------------------------------------------
diff --git a/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.ts b/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.ts
index c939f04..efc7e84 100644
--- a/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.ts
+++ b/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.ts
@@ -99,7 +99,7 @@ export class AlertDetailsComponent implements OnInit {
       this.alertSource = alertSource;
       this.selectedAlertState = this.getAlertState(alertSource['alert_status']);
       this.alertSources = (alertSource.metron_alert && alertSource.metron_alert.length > 0) ? alertSource.metron_alert : [alertSource];
-      this.setComments(alertSource);
+      this.setComments(alertSource['comments'] || []);
 
       if (fireToggleEditor) {
         this.toggleNameEditor();
@@ -107,8 +107,7 @@ export class AlertDetailsComponent implements OnInit {
     });
   }
 
-  setComments(alert) {
-    let alertComments = alert['comments'] ? alert['comments'] : [];
+  setComments(alertComments) {
     this.alertCommentsWrapper = alertComments.map(alertComment =>
         new AlertCommentWrapper(alertComment, moment(new Date(alertComment.timestamp)).fromNow()));
   }
@@ -222,22 +221,25 @@ export class AlertDetailsComponent implements OnInit {
   }
 
   onAddComment() {
-    let alertComment = new AlertComment(this.alertCommentStr, this.authenticationService.getCurrentUserName(), new Date().getTime());
-    let tAlertComments = this.alertCommentsWrapper.map(alertsWrapper => alertsWrapper.alertComment);
-    tAlertComments.unshift(alertComment);
-    this.patchAlert(new Patch('add', '/comments', tAlertComments));
+    let newComment = new AlertComment(this.alertCommentStr, this.authenticationService.getCurrentUserName(), new Date().getTime());
+    let alertComments = this.alertCommentsWrapper.map(alertsWrapper => alertsWrapper.alertComment);
+    alertComments.unshift(newComment);
+    this.setComments(alertComments);
+    this.patchAlert(new Patch('add', '/comments', alertComments), () => {
+      let previousComments = this.alertCommentsWrapper.map(alertsWrapper => alertsWrapper.alertComment)
+              .filter(alertComment => alertComment !== newComment);
+      this.setComments(previousComments);
+    });
   }
 
-  patchAlert(patch: Patch) {
+  patchAlert(patch: Patch, onPatchError) {
     let patchRequest = new PatchRequest();
     patchRequest.guid = this.alertSource.guid;
     patchRequest.index = this.alertIndex;
     patchRequest.patch = [patch];
     patchRequest.sensorType = this.alertSourceType;
 
-    this.updateService.patch(patchRequest).subscribe(() => {
-      this.getData();
-    });
+    this.updateService.patch(patchRequest).subscribe(() => {}, onPatchError);
   }
 
   onDeleteComment(index: number) {
@@ -250,8 +252,12 @@ export class AlertDetailsComponent implements OnInit {
 
     this.metronDialogBox.showConfirmationMessage(commentText).subscribe(response => {
       if (response) {
-        this.alertCommentsWrapper.splice(index, 1);
-        this.patchAlert(new Patch('add', '/comments', this.alertCommentsWrapper.map(alertsWrapper => alertsWrapper.alertComment)));
+        let deletedCommentWrapper = this.alertCommentsWrapper.splice(index, 1)[0];
+        this.patchAlert(new Patch('add', '/comments', this.alertCommentsWrapper.map(alertsWrapper => alertsWrapper.alertComment)), () => {
+          // add the deleted comment back
+          this.alertCommentsWrapper.unshift(deletedCommentWrapper);
+          this.alertCommentsWrapper.sort((a, b) => b.alertComment.timestamp - a.alertComment.timestamp);
+        });
       }
     });
   }