feat: implement interactive row selection in history table
This commit is contained in:
@@ -773,6 +773,10 @@ def page_history():
|
|||||||
|
|
||||||
st.markdown("---")
|
st.markdown("---")
|
||||||
|
|
||||||
|
# 세션 상태에 선택된 분석 ID 저장 및 동기화 초기화
|
||||||
|
if "selected_analysis_id" not in st.session_state:
|
||||||
|
st.session_state["selected_analysis_id"] = records[0]["id"] if records else 1
|
||||||
|
|
||||||
# 이력 테이블
|
# 이력 테이블
|
||||||
status_emoji = {"critical": "🔴", "warning": "🟡", "healthy": "🟢"}
|
status_emoji = {"critical": "🔴", "warning": "🟡", "healthy": "🟢"}
|
||||||
table_data = [{
|
table_data = [{
|
||||||
@@ -788,7 +792,23 @@ def page_history():
|
|||||||
"메모": (r.get("memo") or "")[:50],
|
"메모": (r.get("memo") or "")[:50],
|
||||||
} for r in records]
|
} for r in records]
|
||||||
|
|
||||||
st.dataframe(pd.DataFrame(table_data), use_container_width=True, hide_index=True)
|
# st.dataframe의 selection 기능을 사용하여 마우스 행 선택 감지 및 Rerun 트리거
|
||||||
|
df_display = pd.DataFrame(table_data)
|
||||||
|
selection_event = st.dataframe(
|
||||||
|
df_display,
|
||||||
|
use_container_width=True,
|
||||||
|
hide_index=True,
|
||||||
|
selection_mode="single-row",
|
||||||
|
on_select="rerun",
|
||||||
|
key="history_table"
|
||||||
|
)
|
||||||
|
|
||||||
|
# 테이블에서 마우스 클릭으로 행을 선택했을 때 세션 상태 ID 갱신
|
||||||
|
selected_rows = selection_event.get("selection", {}).get("rows", [])
|
||||||
|
if selected_rows:
|
||||||
|
selected_row_idx = selected_rows[0]
|
||||||
|
if selected_row_idx < len(records):
|
||||||
|
st.session_state["selected_analysis_id"] = records[selected_row_idx]["id"]
|
||||||
|
|
||||||
# 상세 조회
|
# 상세 조회
|
||||||
st.markdown("---")
|
st.markdown("---")
|
||||||
@@ -800,13 +820,24 @@ def page_history():
|
|||||||
for r in records
|
for r in records
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# 현재 선택된 ID에 해당하는 옵션의 인덱스 찾기 (양방향 연동용)
|
||||||
|
default_index = 0
|
||||||
|
for idx, opt in enumerate(history_options):
|
||||||
|
if opt[0] == st.session_state["selected_analysis_id"]:
|
||||||
|
default_index = idx
|
||||||
|
break
|
||||||
|
|
||||||
selected_option = st.selectbox(
|
selected_option = st.selectbox(
|
||||||
"조회할 보고서 선택",
|
"조회할 보고서 선택",
|
||||||
options=history_options,
|
options=history_options,
|
||||||
|
index=default_index,
|
||||||
format_func=lambda x: x[1]
|
format_func=lambda x: x[1]
|
||||||
)
|
)
|
||||||
|
|
||||||
selected_id = selected_option[0] if selected_option else records[0]["id"]
|
if selected_option:
|
||||||
|
st.session_state["selected_analysis_id"] = selected_option[0]
|
||||||
|
|
||||||
|
selected_id = st.session_state["selected_analysis_id"]
|
||||||
|
|
||||||
detail = get_analysis_detail(selected_id)
|
detail = get_analysis_detail(selected_id)
|
||||||
if not detail:
|
if not detail:
|
||||||
|
|||||||
Reference in New Issue
Block a user