fix(fiches): Correction bug sélection fiche nécessitant double-clic

Problème:
- Lors du changement de fiche dans le selectbox, l'ancienne fiche
  restait affichée et il fallait cliquer 2 fois pour changer

Cause:
- Le code assignait manuellement la valeur du selectbox au session_state
  AVANT l'affichage du widget, créant un conflit avec l'index forcé
- Streamlit réexécutait le script avec l'ancienne valeur stockée

Solution:
- Utilisation du paramètre 'key' pour lier automatiquement le selectbox
  au session_state au lieu d'une assignation manuelle
- Suppression des lignes redondantes d'assignation

Changements:
- app/fiches/interface.py: Ajout key pour les 2 selectbox
- .gitignore: Précision /Fiches/ pour ne pas ignorer app/fiches/

Impact:
- Sélection de fiche fonctionne maintenant au premier clic
- Comportement Streamlit standard et prévisible
This commit is contained in:
Stéphan Peccini 2026-02-08 09:23:49 +01:00
parent 77b6bedd6f
commit 64f041f04f
Signed by: stephan
GPG Key ID: 3A9774E9CCBF3501
2 changed files with 9 additions and 11 deletions

6
.gitignore vendored
View File

@ -28,10 +28,10 @@ Local/
HTML/
Corpus/
# Ignorer données Fiches (adapté à ton projet)
Fiches/
# Ignorer données Fiches générées (adapté à ton projet)
/Fiches/
HTML/
static/Fiches/
/static/Fiches/
# Autres spécifiques si besoin
.DS_Store

View File

@ -43,14 +43,13 @@ def interface_fiches() -> None:
except ValueError:
idx = 0
st.session_state["dossier_choisi"] = st.selectbox(
dossier_choisi = st.selectbox(
str(_("pages.fiches.choose_category")),
[str(_("pages.fiches.select_folder"))] + dossiers,
index=idx
index=idx,
key="dossier_choisi"
)
dossier_choisi = st.session_state["dossier_choisi"]
if dossier_choisi and dossier_choisi != str(_("pages.fiches.select_folder")):
fiches = arbo.get(dossier_choisi, [])
noms_fiches = [f['nom'] for f in fiches]
@ -64,14 +63,13 @@ def interface_fiches() -> None:
except ValueError:
idx_fiche = 0
st.session_state["fiche_choisie"] = st.selectbox(
fiche_choisie = st.selectbox(
str(_("pages.fiches.choose_file")),
[str(_("pages.fiches.select_file"))] + noms_fiches,
index=idx_fiche
index=idx_fiche,
key="fiche_choisie"
)
fiche_choisie = st.session_state["fiche_choisie"]
if fiche_choisie and fiche_choisie != str(_("pages.fiches.select_file")):
fiche_info = next((f for f in fiches if f["nom"] == fiche_choisie), None)
if fiche_info: