From c99505dab9b2d966057b727117ea016bde62a739 Mon Sep 17 00:00:00 2001 From: Janani Neelamekam Date: Mon, 2 Oct 2023 15:53:20 -0700 Subject: [PATCH] Timeline export & Slack command changes --- src/dispatch/plugins/dispatch_slack/fields.py | 19 ++++++++++++++++--- .../dispatch_slack/incident/interactive.py | 14 ++++++++++++-- .../dispatch/src/incident/TimelineTab.vue | 15 ++++++++++++++- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/dispatch/plugins/dispatch_slack/fields.py b/src/dispatch/plugins/dispatch_slack/fields.py index 169c1ec6aa8e..edaf51145917 100644 --- a/src/dispatch/plugins/dispatch_slack/fields.py +++ b/src/dispatch/plugins/dispatch_slack/fields.py @@ -1,3 +1,4 @@ +import datetime from datetime import timedelta from typing import List @@ -222,10 +223,22 @@ def datetime_picker_block( **kwargs, ): """Builds a datetime picker block""" + hour = None + minute = None + date = initial_option.split("|")[0] if initial_option.split("|")[0]!="" else None + + if initial_option.split("|")[1]!="": + #appends zero if time is not entered in hh format + if len(initial_option.split("|")[1].split(":")[0]) == 1: + h= "0"+initial_option.split("|")[1].split(":")[0] + else: + h=initial_option.split("|")[1].split(":")[0] + hour = {"text":h,"value":h} + minute = {"text":initial_option.split("|")[1].split(":")[1],"value":initial_option.split("|")[1].split(":")[1]} return [ - date_picker_input(), - hour_picker_input(), - minute_picker_input(), + date_picker_input(initial_date=date), + hour_picker_input(initial_option=hour), + minute_picker_input(initial_option=minute), timezone_picker_input(), ] diff --git a/src/dispatch/plugins/dispatch_slack/incident/interactive.py b/src/dispatch/plugins/dispatch_slack/incident/interactive.py index 28374bbfeead..fde4497475d0 100644 --- a/src/dispatch/plugins/dispatch_slack/incident/interactive.py +++ b/src/dispatch/plugins/dispatch_slack/incident/interactive.py @@ -1,4 +1,5 @@ import logging +import re import uuid from datetime import datetime, timedelta from typing import Any @@ -975,6 +976,15 @@ def handle_add_timeline_event_command( ) -> None: """Handles the add timeline event command.""" ack() + description= None + date= "" + time= "" + if re.match('.*DESC\s*(.+?)(?: DATE|$|TIME)',body['text'], re.IGNORECASE): + description= (re.match('DESC\s*(.+?)(?: DATE|$|TIME)',body['text'], re.IGNORECASE).group(1)).strip() + if re.match('.*DATE\s*(\d{4}\-\d{2}\-\d{2})(?: TIME|$|DESC)',body['text'], re.IGNORECASE): + date= (re.match('.*DATE\s*(\d{4}\-\d{2}\-\d{2})(?: TIME|$|DESC)',body['text'], re.IGNORECASE).group(1)).strip() + if re.match('.*TIME\s*(([01]?[0-9]|2[0-3]):[0-5][0-9])(?: |DATE|$|DESC)',body['text'], re.IGNORECASE): + time= (re.match('.*TIME\s*(([01]?[0-9]|2[0-3]):[0-5][0-9])(?: |DATE|$|DESC)',body['text'], re.IGNORECASE).group(1)).strip() blocks = [ Context( @@ -982,10 +992,10 @@ def handle_add_timeline_event_command( MarkdownText(text="Use this form to add an event to the incident's timeline.") ] ), - description_input(), + description_input(initial_value=description), ] - blocks.extend(datetime_picker_block()) + blocks.extend(datetime_picker_block(initial_option=date+"|"+time)) modal = Modal( title="Add Timeline Event", diff --git a/src/dispatch/static/dispatch/src/incident/TimelineTab.vue b/src/dispatch/static/dispatch/src/incident/TimelineTab.vue index 0158c6fea5e2..517e630a7769 100644 --- a/src/dispatch/static/dispatch/src/incident/TimelineTab.vue +++ b/src/dispatch/static/dispatch/src/incident/TimelineTab.vue @@ -172,8 +172,16 @@ export default { ]), exportToCSV() { this.exportLoading = true + const selected_items=[] let items = this.sortedEvents - Util.exportCSV(items, this.name + "-timeline-export.csv") + items.forEach(item=> { + if(this.showItem(item)){ + selected_items.push(item) + } + } + ) + + Util.exportCSV(selected_items.map(item=> ({'Time (in UTC)': item.started_at,'Description': item.description,'Owner': this.extractOwner(item)})), this.name + "-timeline-export.csv") this.exportLoading = false }, showItem(item) { @@ -184,6 +192,11 @@ export default { if (item.description == "Incident created") return "mdi-flare" return eventTypeToIcon[item.type] }, + extractOwner(item){ + if (item.owner!=null && item.owner!="") return item.owner + return 'Dispatch' + + }, countHidden() { if (!this.events) return 0 return sum(