From 4d6fb39e888fe34e5e708b6d1ce509821d5c2584 Mon Sep 17 00:00:00 2001 From: Bogdan Condurache Date: Thu, 24 Aug 2023 11:38:19 +0200 Subject: [PATCH] `RPA.Assistant` return date object and fix validation (#1068) * return date object and fix validation * Fix case where value is already date obj * add PR number --- docs/source/releasenotes.rst | 6 ++++++ packages/assistant/pyproject.toml | 2 +- packages/assistant/src/RPA/Assistant/flet_client.py | 3 ++- packages/assistant/src/RPA/Assistant/library.py | 11 +++++++---- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/docs/source/releasenotes.rst b/docs/source/releasenotes.rst index da0de27da..c589b71d0 100644 --- a/docs/source/releasenotes.rst +++ b/docs/source/releasenotes.rst @@ -12,6 +12,12 @@ Latest versions `Upcoming release `_ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +3.0.0 - 24 Aug 2023 +-------------------- +- Library **RPA.Assistant** (:pr:`1068`): + - Fix Date Input validations and return value as Date object instead of string. + - Add Python examples for every Keyword. + `Released `_ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/packages/assistant/pyproject.toml b/packages/assistant/pyproject.toml index b2a0b94c1..c968a1301 100644 --- a/packages/assistant/pyproject.toml +++ b/packages/assistant/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "rpaframework-assistant" -version = "2.3.0" +version = "3.0.0" description = "Interactive UI library for RPA Framework" authors = ["RPA Framework "] license = "Apache-2.0" diff --git a/packages/assistant/src/RPA/Assistant/flet_client.py b/packages/assistant/src/RPA/Assistant/flet_client.py index a1aacb220..a5cd99b10 100644 --- a/packages/assistant/src/RPA/Assistant/flet_client.py +++ b/packages/assistant/src/RPA/Assistant/flet_client.py @@ -53,11 +53,12 @@ class FletClient: def __init__(self) -> None: self.logger = getLogger(__name__) self.results: Result = {} + self.date_inputs: List[str] = [] self.page: Optional[Page] = None self.pending_operation: Optional[Callable] = None self._elements: Elements = Elements([], {}, [], None, set()) - self._to_disable: List[flet.Control] = [] + self._to_disable: List[Control] = [] self._layout_stack: List[Union[SupportedFletLayout, AppBar]] = [] self._background_flet = BackgroundFlet() diff --git a/packages/assistant/src/RPA/Assistant/library.py b/packages/assistant/src/RPA/Assistant/library.py index c1ea28a91..0ebc7593b 100644 --- a/packages/assistant/src/RPA/Assistant/library.py +++ b/packages/assistant/src/RPA/Assistant/library.py @@ -1079,7 +1079,7 @@ def add_date_input( :param default: The default set date :param label: Label for the date input field - Displays a date input widget. The selection the user makes will be available + Displays a date input. The selection the user makes will be available as a ``date`` object in the ``name`` field of the result. The ``default`` argument can be a pre-set date as object or string in "YYYY-MM-DD" format, otherwise the current date is used. @@ -1105,8 +1105,7 @@ def select_birthdate(): print("User birthdate year should be: ", result.birthdate.year) """ # noqa: E501 - def validate(e: ControlEvent): - date_text: str = e.data + def validate(date_text: str): if not date_text: return None try: @@ -1126,10 +1125,11 @@ def validate(e: ControlEvent): raise e self._client.results[name] = default + self._client.date_inputs.append(name) self._client.add_element( name=name, element=TextField(label=label, hint_text="YYYY-MM-DD", value=default), - validation_func=validate, + validation_func=self._callbacks.python_validation(name, validate), ) @keyword(tags=["input"]) @@ -1369,6 +1369,9 @@ def open_dialog(): def _get_results(self) -> DotDict: results = self._client.results + for name, value in results.items(): + if name in self._client.date_inputs and isinstance(value, str): + results[name] = date.fromisoformat(value) return DotDict(**results) @keyword(tags=["dialog"])