Skip to content

Commit 9538103

Browse files
committed
refactor delete button and added dialog box for deletion confirmation.
1 parent cbaa32b commit 9538103

6 files changed

Lines changed: 127 additions & 55 deletions

File tree

locale/de/LC_MESSAGES/base.mo

65 Bytes
Binary file not shown.

locale/de/LC_MESSAGES/base.po

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,11 @@ msgstr "Chatverlauf löschen"
110110
msgid "There was an error while clearing the chat history. Please try again later."
111111
msgstr "Beim Löschen des Chatverlaufs ist ein Fehler aufgetreten. Bitte versuchen Sie es später erneut."
112112

113+
msgid "Delete"
114+
msgstr "Löschen"
115+
116+
msgid "Cancel"
117+
msgstr "Abbrechen"
118+
113119
msgid "There was an error while loading previous messages. If this issue persists, try using a different browser or contact support."
114120
msgstr "Beim Laden vorheriger Nachrichten ist ein Fehler aufgetreten. Falls das Problem weiterhin besteht, versuchen Sie es mit einem anderen Browser oder wenden Sie sich an den Support."

pages/ask_uos_chat.py

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
# max number of messages after which a summary is generated
2525
MAX_MESSAGE_HISTORY = 5
26-
MAX_MESSAGES_PER_USER = 100 # Limit for the number of messages per user (Redis)
26+
MAX_MESSAGES_PER_USER = 150 # Limit for the number of messages per user (Redis)
2727
HUMAN_AVATAR = "./static/Icon-User.svg"
2828
ASSISTANT_AVATAR = "./static/Icon-chatbot.svg"
2929
ROLES = ("ai", "human")
@@ -230,36 +230,6 @@ def display_chat_messages(self):
230230
f"Unknown message type: {m.type}. Expected one of {ROLES}."
231231
)
232232

233-
# for message in st.session_state["messages"]:
234-
# with st.chat_message(message["role"], avatar=message["avatar"]):
235-
# st.write(message["content"])
236-
237-
def show_delete_button(self):
238-
"""Display a delete button in the top-right corner."""
239-
240-
col1, col2 = st.columns([4, 1])
241-
with col2:
242-
if st.button(
243-
"🗑️",
244-
key="delete_chat",
245-
help=st.session_state["_"]("Clear chat history"),
246-
use_container_width=False,
247-
):
248-
try:
249-
user_id = self.get_user_id()
250-
history = self.get_history(user_id)
251-
history.clear()
252-
st.session_state["messages"] = []
253-
st.session_state["conversation_summary"] = []
254-
st.rerun()
255-
except Exception as e:
256-
logger.error(f"Error clearing chat history: {e}")
257-
st.error(
258-
session_state["_"](
259-
"There was an error while clearing the chat history. Please try again later."
260-
)
261-
)
262-
263233
def handle_user_input(self):
264234
"""Handle user input and generate a response."""
265235

@@ -284,9 +254,6 @@ def handle_user_input(self):
284254
if history.messages[-1].type != ROLES[0]: # "ai"
285255
self.generate_response(prompt)
286256

287-
# if st.session_state.messages[-1]["role"] != "assistant":
288-
# self.generate_response(prompt)
289-
290257
def get_agent(self):
291258
if st.session_state["agent"] is None:
292259
st.session_state["agent"] = CampusManagementOpenAIToolsAgent.run(
@@ -784,14 +751,52 @@ def log_feedback(self):
784751
logger.info(f"Feedback= {feedback}")
785752
session_state.feedback_saved = True
786753

754+
@st.dialog("ask.UOS")
755+
def delete_chat_history(self):
756+
"""Display a dialog to confirm chat history deletion."""
757+
message = (
758+
settings.chat_page.delete_message_dialog_box_german
759+
if settings.language == "Deutsch"
760+
else settings.chat_page.delete_message_dialog_box_english
761+
)
762+
st.markdown(message)
763+
if st.button(
764+
session_state["_"]("Delete"),
765+
key="confirm_delete_chat",
766+
use_container_width=True,
767+
):
768+
user_id = self.get_user_id()
769+
history = self.get_history(user_id)
770+
history.clear()
771+
st.session_state["messages"] = []
772+
st.session_state["conversation_summary"] = []
773+
st.rerun()
774+
if st.button(
775+
session_state["_"]("Cancel"),
776+
key="cancel_delete_chat",
777+
use_container_width=True,
778+
):
779+
st.rerun()
780+
781+
def show_delete_button(self):
782+
"""Display a delete button below the chat input, full width and horizontal."""
783+
# Add a small space
784+
if st.button(
785+
f'🗑️ {session_state["_"]("Clear chat history")}',
786+
key="delete_chat",
787+
help=session_state["_"]("Clear all chat history"),
788+
):
789+
self.delete_chat_history()
790+
st.write("") # Add a small space
791+
787792
def run(self):
788793
"""Main method to run the application logic."""
789794
st.title("ask.UOS")
790795
initialize_session_sate()
791796
RemoveEmptyElementContainer()
792797
# Get or create user ID using our method
793798
user_id = self.get_user_id()
794-
self.show_delete_button()
799+
795800
# self.show_warning()
796801
# DO NOT CHANGE THE ORDER IN WHICH THESE METHODS ARE CALLED
797802

@@ -801,6 +806,9 @@ def run(self):
801806
self.show_feedback_faces()
802807
self.ask_further_feedback()
803808

809+
# Move the delete button to the very end
810+
self.show_delete_button()
811+
804812

805813
if __name__ == "__main__":
806814
app = ChatApp()

pages/static/style.css

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -222,39 +222,86 @@ span[data-testid="stHeaderActionElements"] a {
222222

223223
/* Delete button styling */
224224
.st-key-delete_chat {
225-
float: right !important;
226-
text-align: right !important;
225+
position: static !important;
226+
float: none !important;
227+
margin: 16px 0 !important;
228+
background-color: transparent !important;
229+
box-shadow: none !important;
230+
padding: 0 !important;
231+
display: flex !important;
232+
justify-content: flex-end !important;
233+
width: 100% !important;
227234
}
228235

229236
.st-key-delete_chat .stButton {
230-
display: flex !important;
231-
justify-content: flex-end !important;
237+
display: block !important;
238+
justify-content: flex-start !important;
239+
width: auto !important;
232240
}
233241

234242
.st-key-delete_chat button {
235-
margin-left: auto !important;
243+
margin: 0 !important;
244+
background-color: #f8f8f8 !important;
245+
border: 1px solid #e0e0e0 !important;
246+
border-radius: 6px !important; /* normal button */
247+
width: auto !important;
248+
min-width: 160px !important;
249+
height: 40px !important;
250+
display: inline-flex !important;
251+
align-items: center !important;
252+
justify-content: center !important;
253+
font-size: 16px !important;
254+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05) !important;
255+
padding: 0 24px !important;
256+
transition: all 0.2s ease !important;
236257
}
237258

238-
/* Mobile responsive delete button */
259+
.st-key-delete_chat button:hover {
260+
background-color: #f0f0f0 !important;
261+
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.10) !important;
262+
}
263+
264+
/* Adjust for mobile devices */
239265
@media (max-width: 768px) {
240-
.stHorizontalBlock .stColumn:last-child {
241-
text-align: right !important;
242-
display: flex !important;
243-
justify-content: flex-end !important;
244-
align-items: flex-start !important;
245-
}
246-
247266
.st-key-delete_chat {
248-
float: right !important;
249-
text-align: right !important;
250-
margin-left: auto !important;
251-
width: auto !important;
267+
justify-content: flex-end !important;
268+
margin: 16px 0 !important;
269+
padding-right: 0 !important;
252270
}
253271

254-
.st-key-delete_chat .stButton {
255-
justify-content: flex-end !important;
256-
margin-left: auto !important;
272+
.st-key-delete_chat button {
273+
min-width: 140px !important;
274+
height: 36px !important;
275+
font-size: 14px !important;
276+
padding: 0 16px !important;
257277
}
258278
}
259279

280+
/* Delete confirmation button styling */
281+
.st-key-confirm_delete_chat button {
282+
background-color: #ad1034 !important;
283+
border: 1px solid #ad1034 !important;
284+
color: white !important;
285+
}
286+
287+
.st-key-confirm_delete_chat button:hover {
288+
background-color: #8f2133 !important;
289+
border: 1px solid #8f2133 !important;
290+
color: white !important;
291+
}
292+
293+
.st-key-confirm_delete_chat button p {
294+
color: white !important;
295+
}
296+
297+
/* Remove the fixed positioning styles that were causing issues */
298+
.stChatInput {
299+
position: relative !important;
300+
}
301+
302+
/* Remove the bottom padding we added before */
303+
.stBottom {
304+
padding-bottom: 0 !important;
305+
}
306+
260307

src/config/core_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from .models import (
1313
ApplicationConfig,
14+
ChatPageConfig,
1415
EmbeddingSettings,
1516
Legal,
1617
LogSettings,
@@ -39,6 +40,7 @@ class Settings(BaseSettings):
3940
milvus_settings: MilvusSettings
4041
language: Literal["Deutsch", "English"]
4142
start_page: StartPageConfig
43+
chat_page: ChatPageConfig
4244
legal: Optional[Legal] = (
4345
None # Optional legal information (e.g., data protection, imprint)
4446
)

src/config/models.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,12 @@ class StartPageConfig(BaseModel):
8585

8686
welcome_message_english: str
8787
welcome_message_german: str
88+
89+
90+
class ChatPageConfig(BaseModel):
91+
"""
92+
Configuration for the chat page.
93+
"""
94+
95+
delete_message_dialog_box_english: str
96+
delete_message_dialog_box_german: str

0 commit comments

Comments
 (0)