Skip to content

Commit

Permalink
Merge pull request #106 from kbond/available-message-type
Browse files Browse the repository at this point in the history
feat!: refactor message type filter
  • Loading branch information
kbond authored Nov 10, 2024
2 parents 53f7064 + bd82185 commit 7b07014
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 16 deletions.
11 changes: 6 additions & 5 deletions src/History/Filters.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/*
* This file is part of the zenstruck/messenger-monitor-bundle package.
*
Expand All @@ -14,19 +12,22 @@
namespace Zenstruck\Messenger\Monitor\History;

use Zenstruck\Collection;
use Zenstruck\Messenger\Monitor\Type;

final class Filters
{
/** @var Collection<int, string> */
/** @var Collection<int,Type> */
private Collection $availableMessageTypes;

public function __construct(private readonly Storage $storage, private readonly Specification $specification)
{
}

/** @return Collection<int, string> */
/** @return Collection<int,Type> */
public function availableMessageTypes(): Collection
{
return $this->availableMessageTypes ??= $this->storage->availableMessageTypes($this->specification)->eager();
return $this->availableMessageTypes ??= $this->storage->availableMessageTypes($this->specification)->eager()->map(
static fn(string $type) => new Type($type)
);
}
}
2 changes: 1 addition & 1 deletion src/History/Model/ProcessedMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ final public function attempt(): int
}

/**
* @return Type<object>
* @return Type
*/
final public function type(): Type
{
Expand Down
2 changes: 1 addition & 1 deletion src/History/Model/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function isFailure(): bool
}

/**
* @return Type<object>|null
* @return Type|null
*/
public function handler(): ?Type
{
Expand Down
2 changes: 1 addition & 1 deletion src/History/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function averageHandlingTime(Specification $specification): ?float;
public function count(Specification $specification): int;

/**
* @return Collection<int,string>
* @return Collection<int,class-string>
*/
public function availableMessageTypes(Specification $specification): Collection;
}
2 changes: 1 addition & 1 deletion src/History/Storage/ORMStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function availableMessageTypes(Specification $specification): Collection
->orderBy('m.type', 'ASC')
;

return (new EntityResult($qb))->asString();
return (new EntityResult($qb))->asString(); // @phpstan-ignore-line
}

public function averageWaitTime(Specification $specification): ?float
Expand Down
2 changes: 1 addition & 1 deletion src/Schedule/MessageInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function redispatchTransports(): array
}

/**
* @return Type<object>
* @return Type
*/
public function type(): Type
{
Expand Down
2 changes: 1 addition & 1 deletion src/Transport/QueuedMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function id(): mixed
}

/**
* @return Type<object>
* @return Type
*/
public function message(): Type
{
Expand Down
2 changes: 1 addition & 1 deletion src/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* @author Kevin Bond <[email protected]>
*
* @template T of object
* @template T of object = object
*/
final class Type implements \Stringable
{
Expand Down
8 changes: 4 additions & 4 deletions templates/history.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

<div class="btn-group me-2" role="group">
{% set current_type = app.request.query.get('type', 'All') %}
<button type="button" class="btn {{ current_type != 'All' ? 'btn-outline-primary' : 'btn-light' }} dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
<button type="button" class="btn {{ current_type != 'All' ? 'btn-outline-primary' : 'btn-light' }} dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" {% if current_type == 'All' and not filters.availableMessageTypes|length %}disabled{% endif %}>
<small class="text-body-secondary">Message type:</small> {{ current_type }}
</button>
<ul class="dropdown-menu">
Expand All @@ -85,9 +85,9 @@
{% endif %}

{% for type in filters.availableMessageTypes %}
{% if type != current_type %}
<li><a class="dropdown-item" href="{{ path(app.current_route, app.request.query.all|merge({type: type})) }}">
{{ type | split('\\') | last }} <br>
{% if type.class != current_type %}
<li><a class="dropdown-item" href="{{ path(app.current_route, app.request.query.all|merge({type: type.class})) }}">
{{ type.shortName }} <br>
<small class="text-secondary">{{ type }}</small>
</a>
</li>
Expand Down

0 comments on commit 7b07014

Please sign in to comment.