Skip to content

Commit

Permalink
refactor,fix(desktop-notifications-poc): incident_history.type gets r…
Browse files Browse the repository at this point in the history
…espected when sorting, fixed wrong icons and icon families, reverted icon name method refactoring, fixed positioning of fa-paper-plane icon
  • Loading branch information
ncosta-ic committed Apr 25, 2024
1 parent 733ac58 commit 4db47c4
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 57 deletions.
2 changes: 1 addition & 1 deletion library/Notifications/Common/Icons.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private function __construct()

public const USER_MANAGER = 'user-tie';

public const CLOSED = 'circle-check';
public const CLOSED = 'check';

public const OPENED = 'sun';

Expand Down
2 changes: 1 addition & 1 deletion library/Notifications/Model/IncidentHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function createBehaviors(Behaviors $behaviors): void

public function getDefaultSort(): array
{
return ['incident_history.time desc'];
return ['incident_history.time desc, incident_history.type desc'];
}

public function createRelations(Relations $relations): void
Expand Down
115 changes: 60 additions & 55 deletions library/Notifications/Widget/ItemList/IncidentHistoryListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,30 @@ class IncidentHistoryListItem extends BaseListItem

protected function assembleVisual(BaseHtmlElement $visual): void
{
$iconName = $this->getIconName();
$incidentIcon = $this->getIncidentEventIcon();
if ($incidentIcon === '') {
$content = new IconBall('ellipsis', 'fa-solid');
} else {
switch ($this->item->type) {
case 'incident_severity_changed':
$content = new Icon($incidentIcon, ['class' => 'severity-' . $this->item->new_severity]);

switch ($this->item->type) {
case 'opened':
case 'incident_severity_changed':
$content = new Icon($iconName, ['class' => 'severity-' . $this->item->new_severity]);

break;
case 'rule_matched':
case 'closed':
$content = new IconBall($iconName);

break;
case 'notified':
case 'recipient_role_changed':
$style = 'fa-regular';
if ($iconName === Icons::UNSUBSCRIBED || $iconName === Icons::UNMANAGE) {
$style = 'fa-solid';
}

$content = new IconBall($iconName, $style);
break;
case 'rule_matched':
case 'opened':
case 'closed':
$content = new IconBall($incidentIcon);

break;
case 'escalation_triggered':
$content = new IconBall($iconName, 'fa-solid');
break;
case 'notified':
case 'escalation_triggered':
case 'recipient_role_changed':
$content = new IconBall($incidentIcon, 'fa-solid');

break;
default:
$content = new IconBall('ellipsis');
break;
default:
$content = new IconBall('ellipsis', 'fa-solid');
}
}

$visual->addHtml($content);
Expand Down Expand Up @@ -83,46 +78,56 @@ protected function assembleHeader(BaseHtmlElement $header): void
$header->add(new TimeAgo($this->item->time->getTimestamp()));
}

protected function getIconName(): string
protected function getIncidentEventIcon(): string
{
switch ($this->item->type) {
case 'opened':
return Icons::OPENED;
case 'incident_severity_changed':
switch ($this->item->new_severity) {
case 'ok':
return Icons::OK;
case 'err':
return Icons::ERROR;
case 'crit':
return Icons::CRITICAL;
default:
return Icons::WARNING;
}
return $this->getSeverityIcon();
case 'recipient_role_changed':
return $this->getRoleIcon();
case 'closed':
return Icons::CLOSED;
case 'recipient_role_changed':
switch ($this->item->new_recipient_role) {
case 'manager':
return Icons::MANAGE;
case 'subscriber':
return Icons::SUBSCRIBED;
default:
if ($this->item->old_recipient_role !== null) {
if ($this->item->old_recipient_role === 'manager') {
return Icons::UNMANAGE;
} else {
return Icons::UNSUBSCRIBED;
}
}
return '';
}
case 'rule_matched':
return Icons::RULE_MATCHED;
case 'notified':
return Icons::NOTIFIED;
case 'escalation_triggered':
return Icons::TRIGGERED;
default:
return Icons::NOTIFIED;
}
}

protected function getSeverityIcon(): string
{
switch ($this->item->new_severity) {
case 'ok':
return Icons::OK;
case 'err':
return Icons::ERROR;
case 'crit':
return Icons::CRITICAL;
default:
return Icons::WARNING;
}
}

protected function getRoleIcon(): string
{
switch ($this->item->new_recipient_role) {
case 'manager':
return Icons::MANAGE;
case 'subscriber':
return Icons::SUBSCRIBED;
default:
if ($this->item->old_recipient_role !== null) {
if ($this->item->old_recipient_role === 'manager') {
return Icons::UNMANAGE;
} else {
return Icons::UNSUBSCRIBED;
}
}

return '';
}
}
Expand Down
4 changes: 4 additions & 0 deletions public/css/common.less
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
i.icon:before {
font-size: 0.6em;
}

i.icon.fa-paper-plane:before {
margin-right: .2em;
}
}

.contact-ball {
Expand Down

0 comments on commit 4db47c4

Please sign in to comment.