From 82bd8a53da62cbcd82824695b0ad9620a63afce9 Mon Sep 17 00:00:00 2001 From: Jashon Osala <64925863+osala-eng@users.noreply.github.com> Date: Wed, 27 Sep 2023 16:55:55 +0300 Subject: [PATCH] Bug/error when switching spaces (#110) * fix: Fix error when switching spaces in admin docs. * chore: Move page web/admin_docs.py to web/admin_spaces. --- web/admin_docs.py | 16 ---------------- web/admin_spaces.py | 2 -- web/utils/layout.py | 15 ++------------- 3 files changed, 2 insertions(+), 31 deletions(-) delete mode 100644 web/admin_docs.py diff --git a/web/admin_docs.py b/web/admin_docs.py deleted file mode 100644 index 3563bd3e..00000000 --- a/web/admin_docs.py +++ /dev/null @@ -1,16 +0,0 @@ -"""Page: Admin / Manage Documents.""" -import streamlit as st -from st_pages import add_page_title -from utils.layout import admin_docs_ui, auth_required, create_space_ui - -auth_required(requiring_admin=True) - -add_page_title() - -PARAM_NAME = "sid" -st.session_state["admin_docs_alert"] = st.empty() - -## Create Space UI -create_space_ui() - -admin_docs_ui(PARAM_NAME) diff --git a/web/admin_spaces.py b/web/admin_spaces.py index 3563bd3e..91d6cf5a 100644 --- a/web/admin_spaces.py +++ b/web/admin_spaces.py @@ -1,5 +1,4 @@ """Page: Admin / Manage Documents.""" -import streamlit as st from st_pages import add_page_title from utils.layout import admin_docs_ui, auth_required, create_space_ui @@ -8,7 +7,6 @@ add_page_title() PARAM_NAME = "sid" -st.session_state["admin_docs_alert"] = st.empty() ## Create Space UI create_space_ui() diff --git a/web/utils/layout.py b/web/utils/layout.py index 1f5650e5..eaa4988f 100644 --- a/web/utils/layout.py +++ b/web/utils/layout.py @@ -690,13 +690,7 @@ def create_space_ui(expanded: bool = False) -> None: if ds: _render_space_data_source_config_input_fields(ds, "create_space_") if st.button("Create Space"): - space = handle_create_space() - alert: DeltaGenerator = st.session_state["admin_docs_alert"] - if isinstance(space, SpaceKey) and alert: - alert.success(f"Successfully created space with ID: {space.id_}") - st.session_state["admin_docs_active_space"] = space.id_ - elif alert: - alert.error(f"Failed to create space. Error: {space}") + handle_create_space() def _render_view_space_details_with_container( @@ -843,9 +837,6 @@ def admin_docs_ui(q_param: str = None) -> None: if spaces: st.subheader("Select a space from below:") - def _on_change() -> None: - del st.session_state["admin_docs_active_space"] - try: # Get the space id from the query param with prefence to the newly created space. _sid = ( int(st.experimental_get_query_params()[q_param][0]) @@ -854,14 +845,12 @@ def _on_change() -> None: ) except ValueError: _sid = None - new_space = st.session_state.get("admin_docs_active_space", _sid) - default_sid = next((i for i, s in enumerate(spaces) if s[0] == new_space), None) + default_sid = next((i for i, s in enumerate(spaces) if s[0] == _sid), None) selected = st.selectbox( "Spaces", spaces, format_func=lambda x: x[2], - on_change=_on_change, label_visibility="collapsed", index=default_sid if default_sid else 0, )