Skip to content

Commit

Permalink
RPA.Assistant return date object and fix validation (#1068)
Browse files Browse the repository at this point in the history
* return date object and fix validation

* Fix case where value is already date obj

* add PR number
  • Loading branch information
Bogdan Condurache authored Aug 24, 2023
1 parent f508502 commit 4d6fb39
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
6 changes: 6 additions & 0 deletions docs/source/releasenotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ Latest versions
`Upcoming release <https://github.com/robocorp/rpaframework/projects/3#column-16713994>`_
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

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 <https://pypi.org/project/rpaframework/#history>`_
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand Down
2 changes: 1 addition & 1 deletion packages/assistant/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "Apache-2.0"
Expand Down
3 changes: 2 additions & 1 deletion packages/assistant/src/RPA/Assistant/flet_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 7 additions & 4 deletions packages/assistant/src/RPA/Assistant/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -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"])
Expand Down Expand Up @@ -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"])
Expand Down

0 comments on commit 4d6fb39

Please sign in to comment.