Skip to content

Commit f3109ed

Browse files
committed
fix: Reolve review comments
1 parent cd25882 commit f3109ed

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ protected function fetchColumnSuggestions($searchTerm)
223223

224224
$parsedArrayVars = [];
225225
$exactSearchTerm = trim($searchTerm, ' *');
226-
$exactVarMatches = [];
226+
$exactVarSearches = [];
227227
$titleAdded = false;
228228

229229
// Suggest exact custom variable matches first
@@ -237,6 +237,7 @@ protected function fetchColumnSuggestions($searchTerm)
237237
)) as $customVar
238238
) {
239239
$search = $name = $customVar->flatname;
240+
$exactVarSearches[] = $search;
240241
if (preg_match('/\w+(?:\[(\d*)])+$/', $search, $matches)) {
241242
$name = substr($search, 0, -(strlen($matches[1]) + 2));
242243
if (isset($parsedArrayVars[$name])) {
@@ -249,7 +250,6 @@ protected function fetchColumnSuggestions($searchTerm)
249250

250251
foreach ($this->customVarSources as $relation => $label) {
251252
if (isset($customVar->$relation)) {
252-
$varRelation = $relation . '.vars.' . $search;
253253
if ($titleAdded === false) {
254254
$this->addHtml(HtmlElement::create(
255255
'li',
@@ -260,9 +260,7 @@ protected function fetchColumnSuggestions($searchTerm)
260260
$titleAdded = true;
261261
}
262262

263-
$exactVarMatches[] = $varRelation;
264-
265-
yield $varRelation => sprintf($label, $name);
263+
yield $relation . '.vars.' . $search => sprintf($label, $name);
266264
}
267265
}
268266
}
@@ -289,9 +287,16 @@ protected function fetchColumnSuggestions($searchTerm)
289287

290288
// Finally, the other custom variable suggestions
291289
$titleAdded = false;
292-
foreach (
293-
$this->getDb()->select($this->queryCustomvarConfig(Filter::like('flatname', $searchTerm))) as $customVar
294-
) {
290+
if (! empty($exactVarSearches)) {
291+
$filter = Filter::all(
292+
Filter::like('flatname', $searchTerm),
293+
Filter::unequal('flatname', $exactVarSearches)
294+
);
295+
} else {
296+
$filter = Filter::like('flatname', $searchTerm);
297+
}
298+
299+
foreach ($this->getDb()->select($this->queryCustomvarConfig($filter)) as $customVar) {
295300
$search = $name = $customVar->flatname;
296301
if (preg_match('/\w+(?:\[(\d*)])+$/', $search, $matches)) {
297302
$name = substr($search, 0, -(strlen($matches[1]) + 2));
@@ -305,25 +310,18 @@ protected function fetchColumnSuggestions($searchTerm)
305310

306311
foreach ($this->customVarSources as $relation => $label) {
307312
if (isset($customVar->$relation)) {
308-
$varRelation = $relation . '.vars.' . $search;
309-
$varLabel = sprintf($label, $name);
310313
// Suggest exact custom variable matches first
311-
if (
312-
! in_array($varRelation, $exactVarMatches)
313-
&& $this->matchSuggestion($varRelation, $varLabel, $searchTerm)
314-
) {
315-
if ($titleAdded === false) {
316-
$this->addHtml(HtmlElement::create(
317-
'li',
318-
['class' => static::SUGGESTION_TITLE_CLASS],
319-
t('Custom Variables')
320-
));
321-
322-
$titleAdded = true;
323-
}
324-
325-
yield $varRelation => $varLabel;
314+
if ($titleAdded === false) {
315+
$this->addHtml(HtmlElement::create(
316+
'li',
317+
['class' => static::SUGGESTION_TITLE_CLASS],
318+
t('Custom Variables')
319+
));
320+
321+
$titleAdded = true;
326322
}
323+
324+
yield $relation . '.vars.' . $search => sprintf($label, $name);
327325
}
328326
}
329327
}

0 commit comments

Comments
 (0)