Skip to content

Commit

Permalink
incidents: Support notification suppression
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed Jul 4, 2024
1 parent fbfae6e commit 95b9b73
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 4 deletions.
2 changes: 2 additions & 0 deletions library/Notifications/Model/IncidentHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ public static function translateNotificationState(string $state): string
return t('failed', 'notifications.transmission.state');
case 'pending':
return t('pending', 'notifications.transmission.state');
case 'suppressed':
return t('suppressed', 'notifications.transmission.state');
default:
return t('unknown', 'notifications.transmission.state');
}
Expand Down
4 changes: 3 additions & 1 deletion library/Notifications/Model/Objects.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @property string $host
* @property ?string $service
* @property ?string $url
* @property ?string $mute_reason
*
* @property Query | Event $event
* @property Query | Incident $incident
Expand All @@ -48,7 +49,8 @@ public function getColumns()
return [
'source_id',
'name',
'url'
'url',
'mute_reason'
];
}

Expand Down
16 changes: 16 additions & 0 deletions library/Notifications/Widget/ItemList/IncidentHistoryListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ protected function getIncidentEventIcon(): string
switch ($this->item->type) {
case 'opened':
return Icons::OPENED;
case 'muted':
return Icons::MUTE;
case 'unmuted':
return Icons::UNMUTE;
case 'incident_severity_changed':
return $this->getSeverityIcon();
case 'recipient_role_changed':
Expand Down Expand Up @@ -180,6 +184,10 @@ protected function buildMessage(): string
);
}

if ($this->item->notification_state === 'suppressed') {
$this->getAttributes()->add('class', 'notification-suppressed');
}

break;
case 'incident_severity_changed':
$message = sprintf(
Expand Down Expand Up @@ -251,6 +259,14 @@ protected function buildMessage(): string
$this->item->rule_escalation->name
);

break;
case 'muted':
$message = t('Notifications for this incident have been muted');

break;
case 'unmuted':
$message = t('Notifications for this incident have been unmuted');

break;
default:
$message = '';
Expand Down
4 changes: 4 additions & 0 deletions library/Notifications/Widget/ItemList/IncidentListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ protected function assembleHeader(BaseHtmlElement $header): void
$header->add($this->createTitle());
$meta = new HtmlElement('span', Attributes::create(['class' => 'meta']));

if ($this->item->severity !== 'ok' && $this->item->object->mute_reason !== null) {
$meta->addHtml(new Icon(Icons::MUTE, ['title' => $this->item->object->mute_reason]));
}

/** @var Source $source */
$source = $this->item->object->source;
$meta->addHtml((new SourceIcon(SourceIcon::SIZE_BIG))->addHtml($source->getIcon()));
Expand Down
5 changes: 2 additions & 3 deletions public/css/common.less
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@

.event-list .list-item,
.incident-list .list-item {
.meta .source-icon {
margin-left: auto;
.meta > :not(:last-child) {
margin-right: 0.5em;
}
}
}
4 changes: 4 additions & 0 deletions public/css/detail/incident-detail.less
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@
}
}
}

.list-item.notification-suppressed {
opacity: .75;
}
}

0 comments on commit 95b9b73

Please sign in to comment.