from __future__ import annotations import streamlit as st from app.app_config import ( EDIT_PATH_OPEN_KEY, EDIT_PATH_VALUE_KEY, SFM_DEFAULT_INPUT_DIR, SFM_SMB_BASE_PATH, ) from app.path_store import get_user_path def ensure_user_path_state(user_id: str) -> str: current_path = get_user_path(user_id) st.session_state.setdefault(EDIT_PATH_OPEN_KEY, False) return current_path def open_path_editor(current_path: str) -> None: st.session_state[EDIT_PATH_OPEN_KEY] = True st.session_state[EDIT_PATH_VALUE_KEY] = current_path def close_path_editor() -> None: st.session_state[EDIT_PATH_OPEN_KEY] = False def render_path_editor() -> str | None: if not st.session_state.get(EDIT_PATH_OPEN_KEY): return None with st.container(border=True): title_col, close_col = st.columns([9, 1]) with title_col: st.markdown( "**Введите путь по которому обрабатывать файлы только для вас**" ) with close_col: if st.button("✕", key="close_edit_path"): close_path_editor() st.rerun() edited_path = st.text_input( "Путь", key=EDIT_PATH_VALUE_KEY, placeholder=r"//sgo-fc01-r13/inbox-intech/Exchange/SMBDEMO/test", help=( "Укажите абсолютный UNC-путь к папке обработки, например " f"`{SFM_SMB_BASE_PATH}/Exchange/SMBDEMO/test`." ), ) save_col, cancel_col = st.columns(2) with save_col: if st.button("Сохранить", use_container_width=True): return edited_path with cancel_col: if st.button("Отменить", use_container_width=True): close_path_editor() st.rerun() return None def get_resolved_input_dir(user_id: str) -> str: return get_user_path(user_id) or SFM_DEFAULT_INPUT_DIR