Commit Graph

1639 Commits

Author SHA1 Message Date
abulvenz
d90fa8a266
fix: Using default components instead of chakra. (#3570) 2024-06-26 09:23:53 -07:00
Thomas Brandého
764f723829
fix small typing issue (#3562) 2024-06-26 09:23:20 -07:00
Masen Furer
956bc0a397
Add Clipboard component for handling global on_paste event (#3513)
* Add Clipboard component for handling global on_paste event

* py3.8 compat

* py3.8 compat (p2)
2024-06-26 09:22:24 -07:00
benedikt-bartscher
9d71bcbbb5
bare sqlalchemy session + tests (#3522)
* add bare sqlalchemy session, Closes #3512

* expose sqla_session at module level, add tests, improve typing

* fix table name

* add model_registry fixture, improve typing

* did not meant to push this

* add docstring to model_registry

* do not expose sqla_session in reflex namespace
2024-06-25 15:29:01 +02:00
Emmanuel Onwuegbusi
e4c17deafb
Fix radix radio cards component (#3545)
* ruff format

* fix radio card component

* generated radio_cards.pyi

* ruff format
2024-06-25 15:23:30 +02:00
Masen Furer
0314d19e7e
Ensure rx.match gets memoized to avoid excessive re-rendering (#3552) 2024-06-25 15:20:04 +02:00
Masen Furer
6947ec3a28
bump to 0.5.5 (#3550) 2024-06-24 18:36:20 -07:00
benedikt-bartscher
41efe12e9a
Validate ComputedVar dependencies, add tests (#3527) 2024-06-24 16:11:42 -07:00
Elijah Ahianyo
f037df0977
[REF-3056] Config knob for redis StateManager expiration times (#3523) 2024-06-24 16:03:30 -07:00
alex
44233c9cd1
Added german translation and updated the language links in the README.md files to include german. (#3547)
Co-authored-by: alex <alex@alexdot.me>
2024-06-24 16:35:35 +02:00
Masen Furer
b2b0da036d
[REF-3149] Bring back py3.12 hot reload warning (#3537)
Warning for issue #3536

Co-authored-by: Lendemor <thomas.brandeho@gmail.com>
2024-06-24 16:24:42 +02:00
Thomas Brandého
046dbdef63
fix hydration error (#3542) 2024-06-21 21:34:47 +02:00
Masen Furer
1a74ff4d45
[REF-3079] state.js: disconnect websocket for window "pagehide" event (#3540)
All major browser use a "bfcache" to freeze pages when navigating away from the
domain, then they restore the page when going back.

However if the page uses websockets, these get kind of stuck unless you
disconnect them before freezing (and have a mechanism for reconnecting, which
we already do).

Ref: https://web.dev/articles/bfcache

Fix #3478
2024-06-21 18:28:29 +02:00
HongyuHansonYao
f41e852b0d
Hanson/radial bar chart (#3532)
* refactored event triggers

* update eventhandler method

* updated pyi files

* .

* Update pyi

* new pyis

* lower passing bar for test coverage to 60

---------

Co-authored-by: Hongyu Yao <hongyuyao@hongyus-mbp-3.lan>
Co-authored-by: Nikhil Rao <nikhil@reflex.dev>
Co-authored-by: Hongyu Yao <hongyuyao@Hongyus-MacBook-Pro-3.local>
2024-06-20 21:41:10 -07:00
Masen Furer
c2c6286537
Always treat the call_script callback as a string of JS code (#3521) 2024-06-20 18:05:25 -07:00
Masen Furer
958c4fa7f2
Abstract color_mode related Var creation (#3533)
* StatefulComponent event handler useCallback dependency array

Ensure the useCallback dependency array for event handlers also handled
destructuring objects and the `...` rest parameter.

Avoid hooks that are not variable declarations.

* Abstract color_mode related Var creation

* Allow `set_color_mode` to take a parameter at compile time
* Update type hinting of `Var._replace` to indicate that it returns BaseVar

* color_mode_button with allow_system=True uses new set_color_mode API

`set_color_mode` is now a CallableVar and uses very similar logic internally,
so this bit of code can be replaced.

* Fix for pydantic v1.10.17
2024-06-20 16:46:48 -07:00
HongyuHansonYao
4318bb597f
Hanson/tooltip-improvement/props (#3525)
* added props for tooltip

* formatted

* added pyi

* new pyi

---------

Co-authored-by: Hongyu Yao <hongyuyao@Hongyus-MacBook-Pro-3.local>
2024-06-20 15:09:33 -07:00
Tom Gotsman
a4a5d52e21
add in rx.el.style (#3511) 2024-06-20 11:59:08 -07:00
Thomas Brandého
6709b49cfa
pass validation of valid_parent if inheriting from valid class (#3519) 2024-06-19 23:00:18 +02:00
Thomas Brandého
6ad679ad66
fix segmented_control (#3516)
* fix segmented_control

* fix 3.8 imports

* fix 3.8 typing

* add valid_parent for SegmentedControlItem
2024-06-19 17:47:49 +02:00
Masen Furer
ffb24ceeee
Improve ClientState compatibility with rx.input (#3490)
* Ignore type checking for generic aliases in _var_name_unwrapped

* Allow ClientStateVar.set_value to be used with text inputs

* client_state: If var_name is not provided, create a random name

* client_state: partition the arg value to get `_e0` from `_e0.target.value`
2024-06-19 07:01:46 -07:00
Thomas Brandého
0d39237b3c
upgrade to latest ruff (#3497)
* upgrade to latest ruff

* try to fix dep review

* try to fix dep review (2)

* upgrade black

* upgrade black (2)

* update allowed dependencies

* update allowed dependencies (2)

* update allowed dependencies (3)

* wait between interim and final in yield test

* remove previous commit, increase delay between yield

* forgot to save on the time.sleep(1) removal

* fix integration (maybe?)

* fix pyi?

* what even is going on

* what is realityi?

* test another fix for app harness

* try to wait even longer?

* force uvloop to be optional

* downpin fastapi < 0.111, remove changes to test
2024-06-19 12:32:13 +02:00
Thomas Brandého
d6d14b3f72
add allow_system prop to colormode iconbutton, and clean up logic (#3507)
* add allow_system prop to colormode iconbutton, and clean up logic

* remove segmentedcontrol change from this PR

* make it work for chakraColorProvider too

* add comment to explain resolved_color_mode
2024-06-19 02:02:27 +02:00
Masen Furer
af3c9be97c
Protect StateProxy with an asyncio.Lock (#3508)
* test_background_task: dispatch multiple async tasks

Use asyncio.gather to dispatch multiple tasks from a single background task
that all compete over the `async with self` lock. Even though the state itself
has a lock, each StateProxy instance should only allow a single `async with
self` context to run at a time.

* Protect StateProxy with an asyncio.Lock

Allow multiple tasks to reference the same StateProxy without stomping on each
other when entering an `async with self` context to acquire the state lock and
ultimately modify the state.
2024-06-18 09:48:12 -07:00
HongyuHansonYao
eb397dacc4
(WIP) recharts fixes batch #3 (#3496)
* remove stroke and fill from label as they are unsupported by recharts

* refacted legend

* added props to reference line

* updated type for stroke_width, added stroke, updated type for x y

* added x y to reference dot

* updated reference area

* regenerated pyi

* new pyis

* regenerated pyi

---------

Co-authored-by: Hongyu Yao <hongyuyao@Hongyus-MacBook-Pro-3.local>
Co-authored-by: Hongyu Yao <hongyuyao@hongyus-mbp-3.lan>
2024-06-17 17:07:24 -07:00
Kelechi Ebiri
2b2cdf9847
Feat: Add Session storage to store data on client storage (#3420) 2024-06-17 17:31:36 -04:00
Emmanuel Onwuegbusi
b78fa6f210
fix checkbox_group component (#3454) 2024-06-17 17:02:20 -04:00
Thomas Brandého
ed05f57fc9
Make .web configurable with REFLEX_WEB_WORKDIR (#3462) 2024-06-17 16:17:00 -04:00
Sagar Hedaoo
6fdc5a84db
Updated radio group component (#3474) 2024-06-17 16:10:03 -04:00
Thomas Brandého
44d2bd4970
fix missing event triggers from docs (#3495)
* fix missing event triggers from docs

* fix nit

* go for simpler fix
2024-06-14 22:03:35 +02:00
Elijah Ahianyo
69e4bbc301
[REF-2830] server side events and stateless components should not require not require a backend (#3475)
* `rx.color_mode.icon`, `rx.color_mode.button` and `rx.color_mode.switch` should not require a backend`

* remove print statement

* unit tests and precommit fix

* add unit tests

* change logic to check if event handlers actually contain state. Also delay websocket object check in state.js so server side events can get executed for stateless apps

* make sure events are not queued for server side events particularly ones that call queueEvents(clear_local_storage, clear_cookies, remove_local_storage, remove_cookies) when the app is stateless(no ws)

* fix unit tests

* fix broken unit tests in test_app

* modify socket check in processEvent to only return if socket exists and theres any event in the queue that requires state

* Apply suggestions from code review

make queueEvent call async

Co-authored-by: Masen Furer <m_github@0x26.net>

* await queueEventIfSocketExists

* Revert "await queueEventIfSocketExists"

This reverts commit 9ef8070b87.

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
2024-06-14 09:48:53 -07:00
Thomas Brandého
bdc0defa4a
update launch message (#3453)
* update launch message

* update for nit

* address changes
2024-06-13 11:03:42 -07:00
Masen Furer
b15cee4f10
pyproject.toml: bump to 0.5.4 (#3480) 2024-06-13 10:23:57 -07:00
Thomas Brandého
1c8bebcaf6
allow return from run_in_thread (#3477) 2024-06-13 09:59:05 -07:00
Thomas Brandého
42f34f763e
add event triggers for rx.video (#2700) 2024-06-13 08:03:44 -07:00
HongyuHansonYao
5d3eef7031
Hanson recharts batch #2 (#3472)
1. Updated recharts version to the newest - recharts.py
2. Added `legend_type` back for cartesian class, it was currently commented out - cartesian.py
3. Added `vertical_points` and `horizontal_points` to CartesianGrid class - cartesian.py
4. Added `ticks` `tick` `tick_count` `tick_line` `tick_size` `min_tick_gap`props to Axis class - cartesian.py
5. Refactored `on_click` `on_mouse_down` `on_mouse_up` `on_mouse_move` `on_mouse_out` `on_mouse_enter` `on_mouse_leave` event triggers of `Axis` class using Masen's new method - cartesian.py
6. Added `on_animation_begin` and `on_animation_end` event trigger to `Bar(Cartesian)` class - cartesian.py
7. Added `id` `is_animation_active` `animation_begin` `animation_duration` `animation_easing` `unit` `min_point_size` `name`  prop to `Bar(Cartesian)` class - cartesian.py.
8. Added `unit` `name` props to `Area(Cartesian)` class - cartesian.py
9. Added `unit` `name` props to `Line(Cartesian)` class - cartesian.py
10. Added `id` `is_animation_active` `animation_begin` `animation_duration` `animation_easing` props to `Scatter(Recharts)` class - cartesian.py
11. Refactored eventtriggers for `Scatter(Recharts)` class using Masen's new method - cartesian.py
12. Change the var type of stack_id in `Area(Cartesian)` class to be string and int, it used to be only a string. - cartesian.py
13. Added `name_key` prop and `on_animation_start` and `on_animation_end` prop to `Funnul(Recharts)` class cartesian.py
14. Added `on_mouse_down` `on_mouse_up` `on_mouse_over` `on_mouse_out` event triggers to `PieChart(ChartBase)` and also refactored using Masen's new method - Charts.py
15. Refaactored event triggers for referenceDot(Reference) class using Masen's new method. - Cartesian.py
16. Refactored event triggers for ChartBase(RechartsCharts) class using Masen's new method. - Cartesian.py
17. Refactored event triggers for Piechart(ChartBase) class using Masen's new method, Added `on_mouse_down` `on_mouse_up` `on_mouse_over` `on_mouse_out` event triggers - Cartesian.py

Co-authored-by: Hongyu Yao <hongyuyao@hongyus-mbp-3.lan>
2024-06-12 11:40:05 -07:00
Thomas Brandého
463f7829d4
swap all use of get_event_triggers to rx.EventHandler props (#3458) 2024-06-12 11:11:29 -07:00
Thomas Brandého
462b023019
use add_imports everywhere (#3448) 2024-06-12 09:26:45 -07:00
Carlos
991f6e0183
[REF-3012] Add defs, lineargradient and stop html elements (#3467) 2024-06-12 09:21:36 -07:00
Elijah Ahianyo
8c8156f3aa
[REF-3016] Allow special characters in upload ID (#3449) 2024-06-12 09:21:21 -07:00
Masen Furer
c3c06a1fcb
compat: do not patch pydantic if the installed version starts with "1." (#3482)
In pydantic 1.10.16 (hopefully the last version), they added the `pydantic.v1`
namespace to make transitioning to the v2 package easier without changing code.

However, Reflex was depending on pydantic v1 NOT having `pydantic.v1` to skip
patching names from `v1` into the top level `pydantic` (normally we do this to
force sqlmodel to use v1, even when the v2 package is installed).

Unbreak CI
2024-06-11 19:16:35 -07:00
Masen Furer
bd799a2680
Override _var_is_string when handling str literals (#3473)
* Override _var_is_string when handling str literals

Maintain the pre 0.5.4 behavior when dealing with string literal
props, without displaying the deprecation warning.

Wait, isn't it weird to pass `_var_is_string=False` when the type is actually a str??

Yes, yes it is. However this is currently needed to avoid raising the
DeprecationWarning internally. These str-type vars with
_var_is_string set to false are handled by
`reflex.utils.format.format_prop`, but setting them to be
_var_is_string=True causes them to get quoted twice, which is not
what we want.

Var operations refactor will take care of cleaning this up, but for
now, we will go with the hack.

* Ignore type checks

Since I'm using an `isinstance` check now, the type checker thinks that `value`
could possibly be a string (instead of Any), which raises typing errors that
have to be ignored (they were ignored before implicitly due to being Any-typed)
2024-06-11 13:18:34 -07:00
Masen Furer
66f0a49b75
Pass _var_is_string parameter to Var.create (#3470) 2024-06-10 14:32:32 -07:00
Tom Gotsman
ccf617ba85
small update to fix radial bar chart (#3468)
* small update to fix radial bar chart

* update add data prop to radar

---------

Co-authored-by: Tom Gotsman <tomgotsman@toms-mbp.lan>
2024-06-10 14:03:47 -07:00
Tom Gotsman
cc0f0bcc22
Fix recharts errors part 1 (#3450) 2024-06-07 17:30:09 -07:00
Alexander Morgan
ad3134413b
Make better/less use of dict.keys() calls (#3455) 2024-06-07 14:28:44 -07:00
Masen Furer
bb44d51f2f
[REF-2879] Make client_state work without global refs (local only) (#3379)
* Make client_state work without global refs (local only)

* client_state: if the default is str, mark _var_is_string=True

Ensure that a string default is not rendered literally

* add `to_int` as a Var operation

* Allow an event handler lambda to return a Var in some cases

If an lambda is passed to an event trigger and it returns a single Var, then
treat it like the Var was directly passed for the event trigger.

This allows ClientState.set_var to be used within a lambda.
2024-06-07 13:29:52 -07:00
Masen Furer
e138d9dfd0
state.js: set event_processing = false when websocket connects (#3443)
* test_connection_banner: Improve assertions

* Actually assert on the presence or absense of the connection banner
* Update XPATH selector to find the connection toast
* Add event handling while backend down to verify queue functionality
* Bring backend down while an event is running to ensure queue does not get
  blocked (#3404)

* state.js: set event_processing = false when websocket connects

In case an event was pending when the websocket went down, allow further events
to be processed when it comes back up.

Fix #3404

* test_connection_banner: wait for token indicating backend is connected

* test_connection_banner: increase delay time

make the time window longer in which the backend can go down and get stuck in
event_processing=true for better test reliability

* Ensure the redis connection is reset in new backend thread

Redis has an event loop affinity and needs to be attached to the event loop
that the thread is running.

* Reset event_processing on disconnect

* if the socket never comes back up, it still allows client-side events to be
  processed
* on_mount events may start running before the socket is up, so resetting the
  flag on connect may break event determinism (test_event_chain.py)
2024-06-07 13:29:25 -07:00
Thomas Brandého
c04ed58d2e
default color_mode is now system color (#3457) 2024-06-07 09:56:07 -07:00
benedikt-bartscher
e42d4ed9ef
[REF-3009] type transforming serializers (#3227)
* wip type transforming serializers

* old python sucks

* typing fixups

* Expose the `to` parameter on `rx.serializer` for type conversion

Serializers can also return a tuple of `(serialized_value, type)`, if both ways
are specified, then the returned value MUST match the `to` parameter.

When initializing a new rx.Var, if `_var_is_string` is not specified and the serializer returns a `str` type, then mark `_var_is_string=True` to indicate that the Var should be treated like a string literal.

Include datetime, color, types, and paths as "serializing to str" type.

Avoid other changes at this point to reduce fallout from this change:

  Notably, the `serialize_str` function does NOT cast to `str`, which
  would cause existing code to treat all Var initialized with a str as a
  str literal even though this was NOT the default before.

Update test cases to accomodate these changes.

* Raise deprecation warning for rx.Var.create with string literal

In the future, we will treat strings as string literals in the JS code. To get
a Var that is not treated like a string, pass _var_is_string=False.

This will allow our serializers to automatically identify cast string literals
with less special cases (and the special cases need to be explicitly
identified).

* Add test case for mismatched serialized types

* fix old python

* Remove serializer returning a tuple feature

Simplify the logic; instead of making a wrapper function that returns
a tuple, just save the type conversions in a separate global.

* Reset the LRU cache when adding new serializers

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
2024-06-07 09:50:10 -07:00