Skip to content

Commit

Permalink
Bug/error when switching spaces (#110)
Browse files Browse the repository at this point in the history
* fix: Fix error when switching spaces in admin docs.

* chore: Move page web/admin_docs.py to web/admin_spaces.
  • Loading branch information
osala-eng committed Sep 27, 2023
1 parent db6960a commit 82bd8a5
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 31 deletions.
16 changes: 0 additions & 16 deletions web/admin_docs.py

This file was deleted.

2 changes: 0 additions & 2 deletions web/admin_spaces.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -8,7 +7,6 @@
add_page_title()

PARAM_NAME = "sid"
st.session_state["admin_docs_alert"] = st.empty()

## Create Space UI
create_space_ui()
Expand Down
15 changes: 2 additions & 13 deletions web/utils/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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])
Expand All @@ -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,
)
Expand Down

0 comments on commit 82bd8a5

Please sign in to comment.