forked from streamlit/streamlit
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
st.status
container (streamlit#7140)
* Add icon to expander * Add implementation for st.status * Fix * Add top comment * Add docstring * Fixes * Improve implementation * Some refactoring * Minor fixes * Add auto collapse mode * Add auto collapse mode * Various fixes and improvements * Add empty expander test * Add empty expander test * Disallow empty for normal expander * Apply various updates * Some refactoring * Update status container * Update callback handler * Change empty state for expander * Move icon implementation to expander * Add e2e tests * Add unit tests * Add empty expander e2e test * Update comment * Cleanups * Cleanup * Add metrics * Update docstring * Update snapshot * Add test for empty status * Use smaller block * Update docstrings * Don't change color on hover if empty * Update docstrings based on feedback * Minor change * Update playback tests * Integrated PR feedback * Fix test * Use descriptive names for screenshot tests * Update status snapshots * Update st.status docstring --------- Co-authored-by: Debbie Matthews <debbie.matthews@snowflake.com>
- Loading branch information
1 parent
7b5880a
commit 4926765
Showing
71 changed files
with
802 additions
and
337 deletions.
There are no files selected for viewing
Binary file added
BIN
+2.5 KB
...snapshots/linux/st_status_test/st_status-changed_label[dark_theme-chromium].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.27 KB
.../snapshots/linux/st_status_test/st_status-changed_label[dark_theme-firefox].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.27 KB
...t/snapshots/linux/st_status_test/st_status-changed_label[dark_theme-webkit].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.51 KB
...napshots/linux/st_status_test/st_status-changed_label[light_theme-chromium].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.27 KB
...snapshots/linux/st_status_test/st_status-changed_label[light_theme-firefox].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.27 KB
.../snapshots/linux/st_status_test/st_status-changed_label[light_theme-webkit].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.39 KB
...ght/snapshots/linux/st_status_test/st_status-collapsed[dark_theme-chromium].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.85 KB
...ight/snapshots/linux/st_status_test/st_status-collapsed[dark_theme-firefox].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.19 KB
...right/snapshots/linux/st_status_test/st_status-collapsed[dark_theme-webkit].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.44 KB
...ht/snapshots/linux/st_status_test/st_status-collapsed[light_theme-chromium].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.85 KB
...ght/snapshots/linux/st_status_test/st_status-collapsed[light_theme-firefox].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.19 KB
...ight/snapshots/linux/st_status_test/st_status-collapsed[light_theme-webkit].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.41 KB
...ts/linux/st_status_test/st_status-collapsed_via_update[dark_theme-chromium].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.85 KB
...ots/linux/st_status_test/st_status-collapsed_via_update[dark_theme-firefox].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.19 KB
...hots/linux/st_status_test/st_status-collapsed_via_update[dark_theme-webkit].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.42 KB
...s/linux/st_status_test/st_status-collapsed_via_update[light_theme-chromium].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.85 KB
...ts/linux/st_status_test/st_status-collapsed_via_update[light_theme-firefox].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.19 KB
...ots/linux/st_status_test/st_status-collapsed_via_update[light_theme-webkit].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.06 KB
...napshots/linux/st_status_test/st_status-complete_state[dark_theme-chromium].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.7 KB
...snapshots/linux/st_status_test/st_status-complete_state[dark_theme-firefox].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.77 KB
.../snapshots/linux/st_status_test/st_status-complete_state[dark_theme-webkit].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.09 KB
...apshots/linux/st_status_test/st_status-complete_state[light_theme-chromium].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.68 KB
...napshots/linux/st_status_test/st_status-complete_state[light_theme-firefox].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.77 KB
...snapshots/linux/st_status_test/st_status-complete_state[light_theme-webkit].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.25 KB
...t/snapshots/linux/st_status_test/st_status-empty_state[dark_theme-chromium].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.88 KB
...ht/snapshots/linux/st_status_test/st_status-empty_state[dark_theme-firefox].png
Oops, something went wrong.
Binary file added
BIN
+2.08 KB
...ght/snapshots/linux/st_status_test/st_status-empty_state[dark_theme-webkit].png
Oops, something went wrong.
Binary file added
BIN
+2.27 KB
.../snapshots/linux/st_status_test/st_status-empty_state[light_theme-chromium].png
Oops, something went wrong.
Binary file added
BIN
+2.89 KB
...t/snapshots/linux/st_status_test/st_status-empty_state[light_theme-firefox].png
Oops, something went wrong.
Binary file added
BIN
+2.08 KB
...ht/snapshots/linux/st_status_test/st_status-empty_state[light_theme-webkit].png
Oops, something went wrong.
Binary file added
BIN
+5.63 KB
...t/snapshots/linux/st_status_test/st_status-error_state[dark_theme-chromium].png
Oops, something went wrong.
Binary file added
BIN
+8.27 KB
...ht/snapshots/linux/st_status_test/st_status-error_state[dark_theme-firefox].png
Oops, something went wrong.
Binary file added
BIN
+5.25 KB
...ght/snapshots/linux/st_status_test/st_status-error_state[dark_theme-webkit].png
Oops, something went wrong.
Binary file added
BIN
+5.59 KB
.../snapshots/linux/st_status_test/st_status-error_state[light_theme-chromium].png
Oops, something went wrong.
Binary file added
BIN
+8.16 KB
...t/snapshots/linux/st_status_test/st_status-error_state[light_theme-firefox].png
Oops, something went wrong.
Binary file added
BIN
+5.16 KB
...ht/snapshots/linux/st_status_test/st_status-error_state[light_theme-webkit].png
Oops, something went wrong.
Binary file added
BIN
+3.34 KB
...hots/linux/st_status_test/st_status-uncaught_exception[dark_theme-chromium].png
Oops, something went wrong.
Binary file added
BIN
+3.73 KB
...shots/linux/st_status_test/st_status-uncaught_exception[dark_theme-firefox].png
Oops, something went wrong.
Binary file added
BIN
+3.07 KB
...pshots/linux/st_status_test/st_status-uncaught_exception[dark_theme-webkit].png
Oops, something went wrong.
Binary file added
BIN
+3.36 KB
...ots/linux/st_status_test/st_status-uncaught_exception[light_theme-chromium].png
Oops, something went wrong.
Binary file added
BIN
+3.72 KB
...hots/linux/st_status_test/st_status-uncaught_exception[light_theme-firefox].png
Oops, something went wrong.
Binary file added
BIN
+3.07 KB
...shots/linux/st_status_test/st_status-uncaught_exception[light_theme-webkit].png
Oops, something went wrong.
Binary file added
BIN
+4.88 KB
...ht/snapshots/linux/st_status_test/st_status-without_cm[dark_theme-chromium].png
Oops, something went wrong.
Binary file added
BIN
+6.67 KB
...ght/snapshots/linux/st_status_test/st_status-without_cm[dark_theme-firefox].png
Oops, something went wrong.
Binary file added
BIN
+4.52 KB
...ight/snapshots/linux/st_status_test/st_status-without_cm[dark_theme-webkit].png
Oops, something went wrong.
Binary file added
BIN
+4.9 KB
...t/snapshots/linux/st_status_test/st_status-without_cm[light_theme-chromium].png
Oops, something went wrong.
Binary file added
BIN
+6.66 KB
...ht/snapshots/linux/st_status_test/st_status-without_cm[light_theme-firefox].png
Oops, something went wrong.
Binary file added
BIN
+4.52 KB
...ght/snapshots/linux/st_status_test/st_status-without_cm[light_theme-webkit].png
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,5 @@ | |
|
||
sidebar = st.sidebar.expander("Expand me!") | ||
sidebar.write("I am in the sidebar") | ||
|
||
st.expander("Empty expander") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import streamlit as st | ||
|
||
running_status = st.status("Running status", expanded=True) | ||
running_status.write("Doing some work...") | ||
|
||
with st.status("Completed status", expanded=True, state="complete"): | ||
st.write("Hello world") | ||
|
||
with st.status("Error status", expanded=True, state="error"): | ||
st.error("Oh no, something went wrong!") | ||
|
||
with st.status("Collapsed", state="complete"): | ||
st.write("Hello world") | ||
|
||
with st.status("About to change label...", state="complete") as status: | ||
st.write("Hello world") | ||
status.update(label="Changed label") | ||
|
||
status = st.status("Without context manager", state="complete") | ||
status.write("Hello world") | ||
status.update(state="error", expanded=True) | ||
|
||
with st.status("Collapse via update...", state="complete", expanded=True) as status: | ||
st.write("Hello world") | ||
status.update(label="Collapsed", expanded=False) | ||
|
||
st.status("Empty state...", state="complete") | ||
|
||
try: | ||
with st.status("Uncaught exception"): | ||
st.write("Hello world") | ||
raise Exception("Error!") | ||
except Exception: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
from playwright.sync_api import Page, expect | ||
|
||
from conftest import ImageCompareFunction | ||
|
||
|
||
def test_status_container_rendering( | ||
themed_app: Page, assert_snapshot: ImageCompareFunction | ||
): | ||
"""Test that st.status renders correctly via screenshots.""" | ||
status_containers = themed_app.get_by_test_id("stExpander") | ||
expect(status_containers).to_have_count(9) | ||
|
||
# Don't check screenshot for first element, | ||
# since we cannot reliably screenshot test the spinner icon. | ||
|
||
assert_snapshot(status_containers.nth(1), name="st_status-complete_state") | ||
assert_snapshot(status_containers.nth(2), name="st_status-error_state") | ||
assert_snapshot(status_containers.nth(3), name="st_status-collapsed") | ||
assert_snapshot(status_containers.nth(4), name="st_status-changed_label") | ||
assert_snapshot(status_containers.nth(5), name="st_status-without_cm") | ||
assert_snapshot(status_containers.nth(6), name="st_status-collapsed_via_update") | ||
assert_snapshot(status_containers.nth(7), name="st_status-empty_state") | ||
assert_snapshot(status_containers.nth(8), name="st_status-uncaught_exception") | ||
|
||
|
||
def test_running_state(app: Page): | ||
"""Test that st.status renders a spinner when in running state.""" | ||
running_status = app.get_by_test_id("stExpander").nth(0) | ||
# Check if it has a spinner icon: | ||
expect(running_status.get_by_test_id("stExpanderIconSpinner")).to_be_visible() | ||
|
||
|
||
def test_status_collapses_and_expands(app: Page): | ||
"""Test that a status collapses and expands.""" | ||
expander_content = "Doing some work..." | ||
running_status = app.get_by_test_id("stExpander").nth(0) | ||
# Starts expanded: | ||
expect(running_status.get_by_text(expander_content)).to_be_visible() | ||
|
||
expander_header = running_status.locator(".streamlit-expanderHeader") | ||
# Collapse: | ||
expander_header.click() | ||
expect(running_status.get_by_text(expander_content)).not_to_be_attached() | ||
# Expand: | ||
expander_header.click() | ||
expect(running_status.get_by_text(expander_content)).to_be_visible() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.