Skip to content

Commit

Permalink
filters: refactor autocompletion 2
Browse files Browse the repository at this point in the history
* more explicit configuration of autocompleter
* moved autocompleter from QueryFilter to Filter

Change-Id: I915dc4bb2cadebc140a7ac8c8216d3116537fba6
  • Loading branch information
Benedikt Seidl committed Apr 5, 2022
1 parent d0df92e commit 684d04f
Show file tree
Hide file tree
Showing 9 changed files with 325 additions and 232 deletions.
10 changes: 8 additions & 2 deletions cmk/gui/plugins/dashboard/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from cmk.gui.plugins.metrics.valuespecs import vs_graph_render_options
from cmk.gui.plugins.visuals.utils import get_only_sites_from_context
from cmk.gui.type_defs import Choices, GraphIdentifier, VisualContext
from cmk.gui.utils.autocompleter_config import ContextAutocompleterConfig
from cmk.gui.valuespec import (
Dictionary,
DictionaryElements,
Expand All @@ -59,9 +60,8 @@ class AvailableGraphs(DropdownChoiceWithHostAndServiceHints):

def __init__(self, **kwargs: Any):
kwargs_with_defaults: Mapping[str, Any] = {
"css_spec": ["ajax-vals", "graph-selector", self.ident],
"css_spec": ["ajax-vals"],
"hint_label": _("graph"),
"choices": [(None, _("Select graph"))],
"title": _("Graph"),
"help": _(
"Select the graph to be displayed by this element. In case the current selection "
Expand All @@ -72,6 +72,12 @@ def __init__(self, **kwargs: Any):
"select the graph. To check which graph is currently selected, look at the title "
"of the element in the dashboard.",
),
"autocompleter": ContextAutocompleterConfig(
ident=self.ident,
strict=True,
show_independent_of_context=True,
dynamic_params_callback_name="host_and_service_hinted_autocompleter",
),
**kwargs,
}
super().__init__(**kwargs_with_defaults)
Expand Down
9 changes: 7 additions & 2 deletions cmk/gui/plugins/metrics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
UnitInfo,
VisualContext,
)
from cmk.gui.utils.autocompleter_config import ContextAutocompleterConfig
from cmk.gui.utils.html import HTML
from cmk.gui.utils.speaklater import LazyString
from cmk.gui.valuespec import DropdownChoiceModel, DropdownChoiceWithHostAndServiceHints
Expand Down Expand Up @@ -1338,15 +1339,19 @@ def __init__(self, **kwargs: Any):
# only selects from available options we skip the input validation(invalid_choice=None)
# Since it is not possible anymore on the backend to collect the host & service hints
kwargs_with_defaults: Mapping[str, Any] = {
"css_spec": ["ajax-vals", "metric-selector", self.ident],
"css_spec": ["ajax-vals"],
"hint_label": _("metric"),
"choices": [(None, _("Select metric"))],
"title": _("Metric"),
"regex": re.compile("^[a-zA-Z][a-zA-Z0-9_]*$"),
"regex_error": _(
"Metric names must only consist of letters, digits and "
"underscores and they must start with a letter."
),
"autocompleter": ContextAutocompleterConfig(
ident=self.ident,
show_independent_of_context=True,
dynamic_params_callback_name="host_and_service_hinted_autocompleter",
),
**kwargs,
}
super().__init__(**kwargs_with_defaults)
Expand Down

0 comments on commit 684d04f

Please sign in to comment.