Skip to content

Commit

Permalink
Pass integer formspec label to vue
Browse files Browse the repository at this point in the history
Change-Id: Ica993c8a047107e9f5ff0261876ecd2d08db4ce0
  • Loading branch information
cellador committed Jun 17, 2024
1 parent fe570c8 commit c578a5f
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions cmk/gui/form_specs/vue/vue_formspec_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from collections.abc import Callable
from dataclasses import asdict, dataclass
from enum import auto, Enum
from typing import Any, Generic, Mapping, Sequence, TypeVar
from typing import Any, Generic, Mapping, Optional, Protocol, Sequence, TypeVar

from cmk.utils.exceptions import MKGeneralException

Expand Down Expand Up @@ -104,16 +104,16 @@ def _get_visitor(form_spec: FormSpec, options: VisitorOptions) -> FormSpecVisito
return visitor(supported_form_spec, options)


class SupportsLocalize(Protocol):
def localize(self, localizer: Callable[[str], str]) -> str: ...


def _localize(localizable: Optional[SupportsLocalize]) -> str:
return "" if localizable is None else localizable.localize(translate_to_current_language)


def _get_title_and_help(form_spec: FormSpec) -> tuple[str, str]:
title = (
"" if form_spec.title is None else form_spec.title.localize(translate_to_current_language)
)
help_text = (
""
if form_spec.help_text is None
else form_spec.help_text.localize(translate_to_current_language)
)
return title, help_text
return _localize(form_spec.title), _localize(form_spec.help_text)


def _optional_validation(
Expand Down Expand Up @@ -170,7 +170,10 @@ def to_vue(self, value: int) -> tuple[VueComponents.FormSpec, Value]:
title, help_text = _get_title_and_help(self.form_spec)
return (
VueComponents.Integer(
title=title, help=help_text, validators=build_vue_validators(self._validators())
title=title,
help=help_text,
label=_localize(self.form_spec.label),
validators=build_vue_validators(self._validators()),
),
value,
)
Expand Down

0 comments on commit c578a5f

Please sign in to comment.