Skip to content

Commit

Permalink
fix(desktop-notifications): fixed wrong injection order, fixed icons …
Browse files Browse the repository at this point in the history
…not displaying properly
  • Loading branch information
ncosta-ic committed Apr 16, 2024
1 parent 610b1a8 commit 18a82ba
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion application/controllers/IncidentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function historyAction(): void
$url->setQueryString(QueryString::render($filter) . '&' . $url->getParams()->toString());

// create and render history list
$list = (new ExtendedIncidentHistoryListInfinite($history->execute()))
$list = (new ExtendedIncidentHistoryListInfinite($history))
->setPageSize($limitControl->getLimit())
->setLoadMoreUrl($url->setParam('time', $time));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ExtendedIncidentHistoryList extends BaseItemList
private $eventTracker;

/** @var string Order in which the list gets constructed */
private $order = 'desc';
protected $order = 'desc';

/**
* @param Query | ResultSet | iterable<object> $data
Expand All @@ -51,7 +51,7 @@ protected function init(): void
if ($this->eventTracker === null) {
$this->eventTracker = $event;

if ($this->order === 'asc') {
if ($this->order === 'asc' && $event->id !== null) {
/** @var ExtendedIncidentHistoryListItem $pseudoItem */
$pseudoItem = new $itemClass($this->createPseudoData($event), $this);
$this->addHtml($pseudoItem);
Expand All @@ -66,9 +66,11 @@ protected function init(): void
$sourceEvent = $event;
}

/** @var ExtendedIncidentHistoryListItem $pseudoItem */
$pseudoItem = new $itemClass($this->createPseudoData($sourceEvent), $this);
$this->addHtml($pseudoItem);
if ($sourceEvent->id !== null) {
/** @var ExtendedIncidentHistoryListItem $pseudoItem */
$pseudoItem = new $itemClass($this->createPseudoData($sourceEvent), $this);
$this->addHtml($pseudoItem);
}

// update tracker to use the newest source event
$this->eventTracker = $event;
Expand All @@ -77,7 +79,7 @@ protected function init(): void

if ($this->order === 'desc') {
$this->on(HtmlDocument::ON_ASSEMBLED, function () {
if ($this->order === 'desc' && $this->eventTracker !== null) {
if ($this->order === 'desc' && $this->eventTracker !== null && $this->eventTracker->id !== null) {
$itemClass = $this->getItemClass();
/*
* TODO(nc): Find a better way to handle the show more element position when building in
Expand Down Expand Up @@ -139,7 +141,7 @@ protected function getItemClass(): string
return ExtendedIncidentHistoryListItem::class;
}

private function createPseudoData(Event $event): IncidentHistory
protected function createPseudoData(Event $event): IncidentHistory
{
$obj = new class extends IncidentHistory {
/** @var bool */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected function assembleVisual(BaseHtmlElement $visual): void
$icon = (new Icon(Icons::CLOSED))->setStyle('fa-regular');
break;
case 'recipient_role_changed':
$icon = (new Icon($this->getRoleIcon()))->setContent('fa-regular');
$icon = $this->getRoleIcon();
break;
case 'notified':
$icon = (new Icon(Icons::NOTIFIED))->setStyle('fa-regular');
Expand All @@ -69,7 +69,9 @@ protected function assembleVisual(BaseHtmlElement $visual): void
}
}

$visual->addHtml($icon);
if ($icon) {
$visual->addHtml($icon);
}
}

protected function getSeverityIcon(?string $severity = null): string
Expand All @@ -87,23 +89,23 @@ protected function getSeverityIcon(?string $severity = null): string
}
}

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

return '';
return null;
}
}

Expand Down

0 comments on commit 18a82ba

Please sign in to comment.