Skip to content

Commit 2153fd3

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

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

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

Lines changed: 19 additions & 23 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
}
@@ -290,7 +288,12 @@ protected function fetchColumnSuggestions($searchTerm)
290288
// Finally, the other custom variable suggestions
291289
$titleAdded = false;
292290
foreach (
293-
$this->getDb()->select($this->queryCustomvarConfig(Filter::like('flatname', $searchTerm))) as $customVar
291+
$this->getDb()->select($this->queryCustomvarConfig(
292+
Filter::all(
293+
Filter::like('flatname', $searchTerm),
294+
Filter::unequal('flatname', $exactVarSearches)
295+
)
296+
)) as $customVar
294297
) {
295298
$search = $name = $customVar->flatname;
296299
if (preg_match('/\w+(?:\[(\d*)])+$/', $search, $matches)) {
@@ -305,25 +308,18 @@ protected function fetchColumnSuggestions($searchTerm)
305308

306309
foreach ($this->customVarSources as $relation => $label) {
307310
if (isset($customVar->$relation)) {
308-
$varRelation = $relation . '.vars.' . $search;
309-
$varLabel = sprintf($label, $name);
310311
// 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;
312+
if ($titleAdded === false) {
313+
$this->addHtml(HtmlElement::create(
314+
'li',
315+
['class' => static::SUGGESTION_TITLE_CLASS],
316+
t('Custom Variables')
317+
));
318+
319+
$titleAdded = true;
326320
}
321+
322+
yield $relation . '.vars.' . $search => sprintf($label, $name);
327323
}
328324
}
329325
}

0 commit comments

Comments
 (0)