Skip to content

Commit a028670

Browse files
wip
1 parent c4d93c0 commit a028670

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

application/controllers/EventRuleController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ public function searchEditorAction(): void
204204
$filter = $this->params->get('object_filter', $this->session->get('object_filter'));
205205
$hook = $this->resolveSourceHook($ruleId);
206206

207+
$parsedFilter = null;
207208
if ($filter) {
208209
try {
209210
$parsedFilter = json_decode($filter, true, flags: JSON_THROW_ON_ERROR);

library/Notifications/Hook/V2/SourceHook.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,20 @@ public function getJsonPaths(Condition $condition): array;
6363
/**
6464
* Get suggestions for a value field
6565
*
66-
* @param $column
67-
* @param $searchTerm
66+
* @param string $column
67+
* @param string $searchTerm
6868
* @param Chain $searchFilter
6969
*
7070
* @return Traversable Values to be suggested as `search` => `label`
7171
*/
72-
public function getValueSuggestions($column, $searchTerm, Chain $searchFilter): Traversable;
72+
public function getValueSuggestions(string $column, string $searchTerm, Chain $searchFilter): Traversable;
7373

7474
/**
7575
* Get suggestions for a column field
7676
*
77-
* @param $searchTerm
77+
* @param string $searchTerm
7878
*
7979
* @return Traversable Columns to be suggested as `search` => `label`
8080
*/
81-
public function getColumnSuggestions($searchTerm): Traversable;
81+
public function getColumnSuggestions(string $searchTerm): Traversable;
8282
}

library/Notifications/Web/Control/SearchEditor/RuleFilterSuggestions.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Generator;
99
use Icinga\Module\Notifications\Hook\V2\SourceHook;
10+
use ipl\Html\HtmlElement;
1011
use ipl\Stdlib\Filter;
1112
use ipl\Web\Control\SearchBar\Suggestions;
1213
use Psr\Http\Message\ServerRequestInterface;
@@ -25,19 +26,31 @@ public function __construct(SourceHook $hook)
2526
}
2627

2728
/**
28-
* These suggestions aren't used by any searchbar, so they don't need aqickfilter
29+
* These suggestions aren't used by any searchbar, so this function is never called
2930
*/
3031
protected function createQuickSearchFilter($searchTerm)
3132
{
3233
}
3334

3435
protected function fetchValueSuggestions($column, $searchTerm, Filter\Chain $searchFilter): Traversable
3536
{
36-
return $this->hook->getValueSuggestions($column, $searchTerm, $searchFilter);
37+
yield from $this->hook->getValueSuggestions($column, $searchTerm, $searchFilter);
3738
}
3839

3940
protected function fetchColumnSuggestions($searchTerm): Traversable
4041
{
41-
return $this->hook->getColumnSuggestions($searchTerm);
42+
$currentGroup = null;
43+
foreach ($this->hook->getColumnSuggestions($searchTerm) as $item) {
44+
if (isset($item['group']) && $item['group'] !== $currentGroup) {
45+
$currentGroup = $item['group'];
46+
$this->addHtml(HtmlElement::create(
47+
'li',
48+
['class' => static::SUGGESTION_TITLE_CLASS],
49+
$currentGroup
50+
));
51+
}
52+
53+
yield $item['search'] => $item['label'];
54+
}
4255
}
4356
}

0 commit comments

Comments
 (0)