Skip to content

Commit cea820d

Browse files
fix: Updated reset configuration to use dialog instead of popover which now closes on X button click, Submit Button Now Resets Widgets to default values by clearing config (#1793)
1 parent c7f3e8d commit cea820d

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

code/backend/pages/04_Configuration.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -491,37 +491,43 @@ def validate_documents():
491491
"Configuration saved successfully! Please restart the chat service for these changes to take effect."
492492
)
493493

494-
with st.popover(":red[Reset configuration to defaults]"):
495-
496-
# Close button with a custom class
497-
if st.button("X", key="close_popup", help="Close popup"):
498-
st.session_state["popup_open"] = False
499-
st.rerun()
500-
501-
st.write(
502-
"**Resetting the configuration cannot be reversed, proceed with caution!**"
503-
)
494+
@st.dialog("Reset Configuration", width="small")
495+
def reset_config_dialog():
496+
st.write("**Resetting the configuration cannot be reversed. Proceed with caution!**")
504497

505498
st.text_input('Enter "reset" to proceed', key="reset_configuration")
506499
if st.button(
507-
":red[Reset]", disabled=st.session_state["reset_configuration"] != "reset"
500+
":red[Reset Now]",
501+
disabled=st.session_state.get("reset_configuration", "") != "reset",
502+
key="confirm_reset"
508503
):
509-
try:
510-
ConfigHelper.delete_config()
511-
except ResourceNotFoundError:
512-
pass
513-
514-
for key in st.session_state:
515-
del st.session_state[key]
516-
504+
with st.spinner("Resetting Configuration to Default values..."):
505+
try:
506+
ConfigHelper.delete_config()
507+
except ResourceNotFoundError:
508+
pass
509+
510+
ConfigHelper.clear_config()
511+
st.session_state.clear()
517512
st.session_state["reset"] = True
518513
st.session_state["reset_configuration"] = ""
514+
st.session_state["show_reset_dialog"] = False
519515
st.rerun()
520516

521-
if st.session_state.get("reset") is True:
522-
st.success("Configuration reset successfully!")
523-
del st.session_state["reset"]
524-
del st.session_state["reset_configuration"]
517+
# Reset configuration button
518+
if st.button(":red[Reset configuration to defaults]"):
519+
st.session_state["show_reset_dialog"] = True
520+
521+
# Open the dialog if needed
522+
if st.session_state.get("show_reset_dialog"):
523+
reset_config_dialog()
524+
st.session_state["show_reset_dialog"] = False
525+
526+
# After reset success
527+
if st.session_state.get("reset"):
528+
st.success("Configuration reset successfully!")
529+
del st.session_state["reset"]
530+
del st.session_state["reset_configuration"]
525531

526532
except Exception as e:
527533
logger.error(f"Error occurred: {e}")

0 commit comments

Comments
 (0)