Skip to content

Commit

Permalink
Implement legacy converter (form spec -> valuespec) for ListOfStrings
Browse files Browse the repository at this point in the history
CMK-19497

Change-Id: Ia03aae1cdbc24d589f2c7734fc38628823a22a6d
  • Loading branch information
jherbel committed Oct 9, 2024
1 parent 2ecad42 commit c640b16
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions cmk/gui/utils/rule_specs/legacy_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
from cmk.gui.form_specs.private import (
DictionaryExtended,
ListExtended,
ListOfStrings,
)
from cmk.gui.form_specs.vue.shared_type_defs import ListOfStringsLayout
from cmk.gui.form_specs.vue.visitors import DefaultValue as VueDefaultValue
from cmk.gui.utils.autocompleter_config import ContextAutocompleterConfig
from cmk.gui.utils.rule_specs.loader import RuleSpec as APIV1RuleSpec
Expand Down Expand Up @@ -721,6 +723,9 @@ def _convert_to_inner_legacy_valuespec(
case ruleset_api_v1.form_specs.List() | ListExtended():
return _convert_to_legacy_list(to_convert, localizer)

case ListOfStrings():
return _convert_to_legacy_list_of_strings(to_convert, localizer)

case ruleset_api_v1.form_specs.FixedValue():
return _convert_to_legacy_fixed_value(to_convert, localizer)

Expand Down Expand Up @@ -1517,6 +1522,35 @@ def _convert_to_legacy_list(
return legacy_valuespecs.ListOf(**converted_kwargs)


def _convert_to_legacy_list_of_strings(
to_convert: ListOfStrings, localizer: Callable[[str], str]
) -> legacy_valuespecs.ListOfStrings:
template = convert_to_legacy_valuespec(to_convert.string_spec, localizer)
match to_convert.layout:
case ListOfStringsLayout.horizontal:
orientation = "horizontal"
case ListOfStringsLayout.vertical:
orientation = "vertical"
case _:
assert_never(to_convert.layout)

converted_kwargs: dict[str, Any] = {
"valuespec": template,
"title": _localize_optional(to_convert.title, localizer),
"help": _localize_optional(to_convert.help_text, localizer),
"orientation": orientation,
"default_value": to_convert.prefill.value,
**_get_allow_empty_conf(to_convert, localizer),
}

if to_convert.custom_validate is not None:
converted_kwargs["validate"] = _convert_to_legacy_validation(
to_convert.custom_validate, localizer
)

return legacy_valuespecs.ListOfStrings(**converted_kwargs)


def _convert_to_legacy_fixed_value(
to_convert: ruleset_api_v1.form_specs.FixedValue, localizer: Callable[[str], str]
) -> legacy_valuespecs.FixedValue:
Expand Down

0 comments on commit c640b16

Please sign in to comment.