-
Notifications
You must be signed in to change notification settings - Fork 4k
Make st.page_link inherit icon from st.Page
#10694
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
Make st.page_link inherit icon from st.Page
#10694
Conversation
st.page_link inherit icon from st.Page
|
I think since previously we did not send the icon in the proto and now we will send it always when a StreamlitPage is provided, it would be good to add some test coverage to the frontend tests that verify the beahviour when an empty string is provided for the icon (this seems to be the default in |
|
Pending behaviour change approval from @jrieke |
Sure, I'll add more tests. But before, I wonder why streamlit/lib/streamlit/navigation/page.py Lines 229 to 230 in 1585ce4
streamlit/lib/streamlit/elements/widgets/button.py Lines 920 to 921 in 1585ce4
|
In |
I'm saying that because it feels a bit counter intuitive to me (both in terms of consistency and the fact that page = st.Page(
"a_page_path_stem.py",
title="A title",
icon="",
)
st.page_link(page) # works fine
st.page_link(page, icon="") # triggers an errorBy the way, I added a few more tests but the last one is failing because of this behaviour.. |
I don't follow your concern about consistency. You must assign the value to the proto message in An empty string is not a valid emoji, so this error seems correct to me. We want to let people know that they haven't provided an actual icon at the API level so that they can correct their code. Internally, whether we send an empty string for this property or leave it out of the proto message is an implementation detail and as long as it is handled correctly E2E either way should be fine. |
Thanks for the explanation. Actually, I used the term consistency because I was expecting the error to be triggered in both cases (see below) but I'm overlooking something for sure. # case 1
page_1 = st.Page(
"a_page_path_stem.py",
title="A title",
icon="", # should? trigger an error
)
# case 2
page_2 = st.Page(
"a_page_path_stem.py",
title="A title",
icon=":material/animation:",
)
st.page_link(page_2, icon="") # triggers an error |
I see, this is a bit different then the example you provided previously, I agree that it would be clearer if |
|
Note: I was thinking of React tests to cover a blank string for the icon in the proto. I think currently we don't have tests for that but it seems we do check if icon is truthy and skip rendering if it is not. |
|
Yeah this seems fine to me! I'm wondering if there are situations where you have an icon on the page but don't want it to show up on the page link. But that seems like such a small niche case that I wouldn't worry about it now and just wait to see if someone complains. In the original issue, it was mentioned that we could allow |
|
@abokey1 I think the pending items before merging this PR are:
Are you able to look into these items? If not I might be able to find some time to finish this off so we can merge it. |
🎉 Snyk checks have passed. No issues have been found so far.✅ security/snyk check is complete. No issues have been found. (View Details) ✅ license/snyk check is complete. No issues have been found. (View Details) |
lukasmasuch
left a comment
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.
LGTM 👍
|
@abokey1 made some updates to add tests and make the change you suggested to keep the handling of |
Describe your changes
This PR enables
st.page_linkto automatically pick theicon(if any) from anst.Page.GitHub Issue Link (if applicable)
Closes #9743
Testing Plan
There is a typo in one of the commits, "e2e" instead of "unit"
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.