Skip to content

Commit

Permalink
Stash selection fixed (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
lum4chi authored Jul 20, 2023
1 parent d5cf551 commit d908589
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
30 changes: 20 additions & 10 deletions pages/2_🛒_Stash.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
from st_widgets.download import download_dataframe_button
from st_widgets.stateful import stateful_data_editor

# from st_widgets.stateful import stateful_data_editor

app_config("Stash")
session = st.session_state


def show_stash():
if "history" in st.session_state:
history = st.session_state.history
if "history" in session:
history = session.history

# Prepare history view on stash vars only
history_frame = (
pd.Series(
{
Expand All @@ -30,19 +31,28 @@ def show_stash():
.rename(columns={"index": "dataset"})
)

# Forget previous modification
if "_selected_history_data" in session:
del session["_selected_history_data"]

def _update_history():
# Reflect changes on saved history
history_frame = session["_selected_history_data"]
for dataset_code, is_stashed in (
history_frame.set_index("dataset")["stash"].to_dict().items()
):
history[dataset_code]["stash"] = is_stashed

# Show history view
with st.sidebar:
history_frame = stateful_data_editor(
history_frame,
disabled=["dataset"],
use_container_width=True,
key="_selected_history_dataset",
key="_selected_history",
on_change=_update_history,
)

for dataset_code, is_stashed in (
history_frame.set_index("dataset")["stash"].to_dict().items()
):
history[dataset_code]["stash"] = is_stashed

stash = read_stash_from_history(history)
dataset = empty_eurostat_dataframe()

Expand Down
3 changes: 2 additions & 1 deletion st_widgets/stateful/data_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def stateful_data_editor(
session: MutableMapping[Key, Any] = st.session_state,
on_change: Optional[WidgetCallback] = None,
multiedit: bool = False,
button_label: str = "Submit",
**kwargs,
):
"""
Expand All @@ -51,7 +52,7 @@ def stateful_data_editor(
**kwargs,
)

submitted = position.form_submit_button("Edit")
submitted = position.form_submit_button(button_label)
if submitted:
return session[f"{key}_data"]

Expand Down

0 comments on commit d908589

Please sign in to comment.