Skip to content

Commit

Permalink
Timeline export & Slack command changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Janani Neelamekam committed Oct 2, 2023
1 parent 58de4b4 commit c99505d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
19 changes: 16 additions & 3 deletions src/dispatch/plugins/dispatch_slack/fields.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
from datetime import timedelta
from typing import List

Expand Down Expand Up @@ -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(),
]

Expand Down
14 changes: 12 additions & 2 deletions src/dispatch/plugins/dispatch_slack/incident/interactive.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import re
import uuid
from datetime import datetime, timedelta
from typing import Any
Expand Down Expand Up @@ -975,17 +976,26 @@ 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(
elements=[
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",
Expand Down
15 changes: 14 additions & 1 deletion src/dispatch/static/dispatch/src/incident/TimelineTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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(
Expand Down

0 comments on commit c99505d

Please sign in to comment.