-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(lab): new component ConfirmationDialog #286
feat(lab): new component ConfirmationDialog #286
Conversation
Great to see this Hans. For code quality checks I recommend you follow the pre-commit steps as suggested in https://solara.dev/docs/development . This will run some linters when you commit for a faster feedback loop. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Hans, I did a first pass. Generally, it looks good 👍 , I'm a bit uncertain about the naming (especially is_open_rv)
|
||
@solara.component | ||
def ConfirmationDialog( | ||
is_open_rv: solara.Reactive[bool], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep using the pattern as in https://github.com/widgetti/solara/pull/185/files#diff-fb21e018d759a3a11489bdab98c0bd0b7841a772f45ba556178a82c39db6eec1R12
open is a bool or reactive variable, and locally convert it to a reactive variable (if not already) using use_reactive
:
https://github.com/widgetti/solara/pull/185/files#diff-fb21e018d759a3a11489bdab98c0bd0b7841a772f45ba556178a82c39db6eec1R54
Then we also need a callback. Maybe we should call it is_open
and on_is_open
, or just open
and on_open
, or even value
and on_value
.
@mariobuikhuizen and @iisakkirotko opinions on naming are appreciated :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, value
seems a bit too vague in my opinion... that makes sense for a switch etc, but maybe less so for a dialog... what is the "value" of a dialog?? It might be better to use something with "open". is_open
seems to be more in line with what is usually used in Python, indicating a boolean.
I'm not sure what the callback is for? Is it called when is_open
(or whatever we end up calling it) changes value?
@solara.component | ||
def ConfirmationDialog( | ||
is_open_rv: solara.Reactive[bool], | ||
action: Callable[[], None], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for consistency, call it on_ok
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK! :) The other one should probably be on_cancel
then...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or does on_cancel
or on_close
(as it is currently called) become redundant?
if isinstance(ok, str): | ||
solara.Button(label=ok, on_click=perform_action) | ||
else: | ||
solara.display(ok) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see an issue here is that a user provided button will not trigger perform_action. It would be nice to expose this during the tests. It might be that if we need to use use_event
for this that we hit this bug: widgetti/reacton#14
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a user provides their own Button, shouldn't it also be linked up to an action already? Like
def my_cool_action():
...
ConfirmationDialog(..., ok=Button(label="Yeah", on_click=my_cool_action), ...)
Then again we currently have on_ok
(or on_action
) as a required argument, which kind of clashes with that... 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, as I mentioned in our call, if you write a test we can find a solution to this later on, I have some ideas about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory, we should be able to use solara.v.use_event
, but it has issues due to widgetti/reacton#14
I think we can do a different approach, which is to inspect ok.kwargs["on_click"] and replace it by a new dict where on_click points to our perform_action, and the perform_action also calls the previous on_click
set by the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, if I understand this correctly, if you pass a custom Button
named ok
, then ok.kwargs['on_click']
is only present if you passed an on_click
event to your button. Should we allow for a case where a user passes in a custom button that has no on_click
? Perhaps because they just want to execute on_ok
as intended.
Related: what do we do in the case that both on_ok
and a custom button's on_click
are set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For context, I currently have this:
with solara.CardActions():
if isinstance(ok, str):
solara.Button(label=ok, on_click=perform_action)
else:
solara.display(ok)
if ok.kwargs.get('on_click'):
ok.kwargs['on_click'] = perform_action
...which passes the test. I think there is no point in checking ok.kwargs
if ok
is a string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think we should support no on_click as well. I suggest we also don't modify the dict, but create a new one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory, we should be able to use
solara.v.use_event
, but it has issues due to widgetti/reacton#14I think we can do a different approach, which is to inspect ok.kwargs["on_click"] and replace it by a new dict where on_click points to our perform_action, and the perform_action also calls the previous
on_click
set by the user.
I should have read this more carefully, you're literally describing what to do in a situation with both on_ok
and on_click
being present.
7d7c6e5
to
f7fd209
Compare
4cccec4
to
ebdc42b
Compare
ebdc42b
to
c1c0009
Compare
This is released in v1.20.0 |
This is a nice component. Before this, I used v.Dialog which is good too. this ConfirmationDialog would be great if it supports content_class just like v.Dialog and draggable feature. Currently, I adapted this vuetifyjs/vuetify#4058 for draggable dialog in Solara. Love to see it as built-in feature for dialog, just like griddraggable. |
First, very rough, version of
ConfirmationDialog
.