feat: UX 2-Reihen-Button-Pattern — max 3 Buttons/Reihe, Nummern im Text+Button, Sonderschaltflächen separat
This commit is contained in:
@@ -153,6 +153,81 @@ def _persist_room_map_changes(
|
||||
logger.warning("FAISS-Rebuild fehlgeschlagen: %s", e)
|
||||
|
||||
|
||||
# ── UX REFACTOR: build_button_attachments() Helper ──────────────────────────
|
||||
|
||||
# Emoji-Nummern für bis zu 10 Buttons
|
||||
_EMOJI_NUMBERS = ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟"]
|
||||
|
||||
# Sonderschaltflächen-Erkennung (diese bekommen KEINE Nummer)
|
||||
_SPECIAL_BUTTON_PATTERNS = ["↩️", "⏭️", "➕"]
|
||||
|
||||
|
||||
def build_button_attachments(
|
||||
num_buttons: List[Tuple[str, str]],
|
||||
special_buttons: List[Tuple[str, str, str]],
|
||||
color: str = "#1d74f5",
|
||||
title: str = "",
|
||||
) -> List[dict]:
|
||||
"""Baut Attachments nach Andreas' 2-Reihen-Button-Pattern.
|
||||
|
||||
Regeln:
|
||||
- Nummerierte Buttons: max 3 pro Attachment, mit 1️⃣ 2️⃣ 3️⃣...
|
||||
- Sonderschaltflächen (↩️ Zurück, ⏭️ Skip, ➕ Neu): KEINE Nummer,
|
||||
IMMER in separatem (letztem) Attachment
|
||||
- Jedes Attachment hat max 3 actions
|
||||
|
||||
Args:
|
||||
num_buttons: Liste von (label, prefix) Tuples für nummerierte Buttons
|
||||
special_buttons: Liste von (label, prefix, style) Tuples für Sonderschaltflächen
|
||||
color: Attachment-Farbe
|
||||
title: Attachment-Titel (nur für erstes Attachment)
|
||||
|
||||
Returns:
|
||||
Liste von Attachment-Dicts (jedes mit max 3 actions)
|
||||
"""
|
||||
attachments: List[dict] = []
|
||||
|
||||
# Nummerierte Buttons in 3er-Blöcke aufteilen
|
||||
for i in range(0, len(num_buttons), 3):
|
||||
chunk = num_buttons[i:i + 3]
|
||||
actions = []
|
||||
for j, (label, prefix) in enumerate(chunk):
|
||||
num_idx = i + j
|
||||
emoji = _EMOJI_NUMBERS[num_idx] if num_idx < len(_EMOJI_NUMBERS) else str(num_idx + 1)
|
||||
actions.append({
|
||||
"type": "button",
|
||||
"text": f"{emoji} {label}",
|
||||
"msg": prefix,
|
||||
"msg_in_chat_window": True,
|
||||
"style": "primary",
|
||||
})
|
||||
att = {
|
||||
"color": color,
|
||||
"actions": actions,
|
||||
}
|
||||
if i == 0 and title:
|
||||
att["title"] = title
|
||||
attachments.append(att)
|
||||
|
||||
# Sonderschaltflächen in separatem Attachment
|
||||
if special_buttons:
|
||||
special_actions = []
|
||||
for label, prefix, style in special_buttons:
|
||||
special_actions.append({
|
||||
"type": "button",
|
||||
"text": label,
|
||||
"msg": prefix,
|
||||
"msg_in_chat_window": True,
|
||||
"style": style,
|
||||
})
|
||||
attachments.append({
|
||||
"color": color,
|
||||
"actions": special_actions,
|
||||
})
|
||||
|
||||
return attachments
|
||||
|
||||
|
||||
# ── Schritt 1: review_room Top-Level Renderer ─────────────────────────────
|
||||
|
||||
|
||||
@@ -182,7 +257,7 @@ def render_review_room_step(
|
||||
"",
|
||||
]
|
||||
|
||||
buttons: List[dict] = []
|
||||
num_buttons: List[Tuple[str, str]] = []
|
||||
room_count = 0
|
||||
|
||||
for rid, entry in room_map.rooms.items():
|
||||
@@ -203,39 +278,34 @@ def render_review_room_step(
|
||||
lines.append(f" KwKontext: {kwctx_str or '—'}")
|
||||
lines.append("")
|
||||
|
||||
# Pro Raum ein 'Anpassen'-Button (kurzer Name, max 9 Zeichen)
|
||||
# Pro Raum ein nummerierter Button
|
||||
prefix = f"{REVIEW_ROOM_EDIT}::{rid}::edit"
|
||||
short_name = entry.name[:9] if len(entry.name) > 9 else entry.name
|
||||
buttons.extend(_build_custom_buttons(
|
||||
[f"{room_count}️⃣ {short_name}"],
|
||||
prefix=prefix,
|
||||
style="primary",
|
||||
))
|
||||
num_buttons.append((short_name, prefix))
|
||||
|
||||
if room_count == 0:
|
||||
lines.append("_(keine Räume eingerichtet)_")
|
||||
lines.append("")
|
||||
|
||||
# Nummerierte Optionen im Text
|
||||
lines.append("👉 Klicke auf einen Raum zum Anpassen:")
|
||||
for i, (label, _) in enumerate(num_buttons):
|
||||
emoji = _EMOJI_NUMBERS[i] if i < len(_EMOJI_NUMBERS) else str(i + 1)
|
||||
lines.append(f" {emoji} {label}")
|
||||
|
||||
# Globale Buttons
|
||||
buttons.extend(_build_custom_buttons(
|
||||
["➕ Neuer"],
|
||||
prefix=REVIEW_ROOM_ADD_NEW,
|
||||
style="default",
|
||||
))
|
||||
buttons.extend(_build_custom_buttons(
|
||||
["⏭️ Skip"],
|
||||
prefix=REVIEW_ROOM_SKIP,
|
||||
style="default",
|
||||
))
|
||||
# Sonderschaltflächen
|
||||
special_buttons: List[Tuple[str, str, str]] = [
|
||||
("➕ Neuer", REVIEW_ROOM_ADD_NEW, "default"),
|
||||
("⏭️ Skip", REVIEW_ROOM_SKIP, "default"),
|
||||
]
|
||||
|
||||
text = "\n".join(lines)
|
||||
attachments = [{
|
||||
"color": "#1d74f5",
|
||||
"title": "Raum-Map Review — Raum auswählen",
|
||||
"actions": buttons,
|
||||
}]
|
||||
attachments = build_button_attachments(
|
||||
num_buttons,
|
||||
special_buttons,
|
||||
color="#1d74f5",
|
||||
title="Raum-Map Review — Raum auswählen",
|
||||
)
|
||||
|
||||
return text, attachments
|
||||
|
||||
@@ -276,46 +346,31 @@ def render_review_room_edit(
|
||||
f"KwKontext ({len(entry.keywords_context)}): {', '.join(entry.keywords_context) or '—'}",
|
||||
"",
|
||||
"👉 Was möchtest du bearbeiten?",
|
||||
" 1️⃣ Kw100",
|
||||
" 2️⃣ KwKtx",
|
||||
" 3️⃣ Theme",
|
||||
" 4️⃣ Catch-All",
|
||||
" 5️⃣ Lösch",
|
||||
]
|
||||
|
||||
buttons: List[dict] = []
|
||||
buttons.extend(_build_custom_buttons(
|
||||
["1️⃣ Kw100"],
|
||||
prefix=f"{REVIEW_ROOM_KW_ADD}::{target_room_id}",
|
||||
style="primary",
|
||||
))
|
||||
buttons.extend(_build_custom_buttons(
|
||||
["2️⃣ KwKtx"],
|
||||
prefix=f"{REVIEW_ROOM_EDIT}::{target_room_id}::keywords_context",
|
||||
style="primary",
|
||||
))
|
||||
buttons.extend(_build_custom_buttons(
|
||||
["3️⃣ Theme"],
|
||||
prefix=f"{REVIEW_ROOM_THEME_SAVE}::{target_room_id}",
|
||||
style="primary",
|
||||
))
|
||||
buttons.extend(_build_custom_buttons(
|
||||
["4️⃣ Catch-All"],
|
||||
prefix=f"{REVIEW_ROOM_CATCHALL_SET}::{target_room_id}",
|
||||
style="primary",
|
||||
))
|
||||
buttons.extend(_build_custom_buttons(
|
||||
["5️⃣ Lösch"],
|
||||
prefix=f"{REVIEW_ROOM_REMOVE_CONFIRM}::{target_room_id}",
|
||||
style="danger",
|
||||
))
|
||||
buttons.extend(_build_custom_buttons(
|
||||
["↩️ Zurück"],
|
||||
prefix=REVIEW_ROOM_BACK,
|
||||
style="default",
|
||||
))
|
||||
num_buttons: List[Tuple[str, str]] = [
|
||||
("Kw100", f"{REVIEW_ROOM_KW_ADD}::{target_room_id}"),
|
||||
("KwKtx", f"{REVIEW_ROOM_EDIT}::{target_room_id}::keywords_context"),
|
||||
("Theme", f"{REVIEW_ROOM_THEME_SAVE}::{target_room_id}"),
|
||||
("Catch", f"{REVIEW_ROOM_CATCHALL_SET}::{target_room_id}"),
|
||||
("Lösch", f"{REVIEW_ROOM_REMOVE_CONFIRM}::{target_room_id}"),
|
||||
]
|
||||
special_buttons: List[Tuple[str, str, str]] = [
|
||||
("↩️ Zurück", REVIEW_ROOM_BACK, "default"),
|
||||
]
|
||||
|
||||
text = "\n".join(lines)
|
||||
attachments = [{
|
||||
"color": "#1d74f5",
|
||||
"title": f"Raum bearbeiten: {entry.name}",
|
||||
"actions": buttons,
|
||||
}]
|
||||
attachments = build_button_attachments(
|
||||
num_buttons,
|
||||
special_buttons,
|
||||
color="#1d74f5",
|
||||
title=f"Raum bearbeiten: {entry.name}",
|
||||
)
|
||||
|
||||
return text, attachments
|
||||
|
||||
@@ -362,18 +417,17 @@ def render_review_room_keywords_edit(
|
||||
f"Aktuelle Keywords ({len(keywords)}):",
|
||||
]
|
||||
|
||||
buttons: List[dict] = []
|
||||
# X-Buttons als num_buttons (ohne Nummerierung — build_button_attachments
|
||||
# nummeriert nur wenn wir es explizit wollen; für X-Buttons nutzen wir
|
||||
# einen separaten Mechanismus)
|
||||
x_buttons: List[Tuple[str, str]] = []
|
||||
|
||||
if keywords:
|
||||
for kw in keywords:
|
||||
lines.append(f" • `{kw}`")
|
||||
# Pro Keyword ein X-Button zum Entfernen (gekürzt auf 8 Zeichen)
|
||||
short_kw = kw[:8] if len(kw) > 8 else kw
|
||||
buttons.extend(_build_custom_buttons(
|
||||
[f"❌ {short_kw}"],
|
||||
prefix=f"{remove_prefix}{kw}",
|
||||
style="danger",
|
||||
))
|
||||
x_buttons.append((f"❌ {short_kw}", f"{remove_prefix}{kw}"))
|
||||
else:
|
||||
lines.append(" _(keine)_")
|
||||
|
||||
@@ -386,18 +440,38 @@ def render_review_room_keywords_edit(
|
||||
lines.append("💬 Antworte mit einem neuen Keyword (2-30 Zeichen) "
|
||||
"oder klicke Zurück.")
|
||||
|
||||
buttons.extend(_build_custom_buttons(
|
||||
["↩️ Zurück"],
|
||||
prefix=back_prefix,
|
||||
style="default",
|
||||
))
|
||||
# X-Buttons in 3er-Blöcke aufteilen (manuell, ohne build_button_attachments
|
||||
# da diese KEINE Nummern bekommen sollen)
|
||||
attachments: List[dict] = []
|
||||
for i in range(0, len(x_buttons), 3):
|
||||
chunk = x_buttons[i:i + 3]
|
||||
actions = []
|
||||
for label, prefix in chunk:
|
||||
actions.append({
|
||||
"type": "button",
|
||||
"text": label,
|
||||
"msg": prefix,
|
||||
"msg_in_chat_window": True,
|
||||
"style": "danger",
|
||||
})
|
||||
attachments.append({
|
||||
"color": "#1d74f5",
|
||||
"actions": actions,
|
||||
})
|
||||
|
||||
# Zurück-Button in separatem Attachment
|
||||
attachments.append({
|
||||
"color": "#1d74f5",
|
||||
"actions": [{
|
||||
"type": "button",
|
||||
"text": "↩️ Zurück",
|
||||
"msg": back_prefix,
|
||||
"msg_in_chat_window": True,
|
||||
"style": "default",
|
||||
}],
|
||||
})
|
||||
|
||||
text = "\n".join(lines)
|
||||
attachments = [{
|
||||
"color": "#1d74f5",
|
||||
"title": f"{kind_label} bearbeiten: {entry.name}",
|
||||
"actions": buttons,
|
||||
}]
|
||||
|
||||
return text, attachments
|
||||
|
||||
@@ -443,19 +517,19 @@ def render_review_room_theme_edit(
|
||||
lines.append("")
|
||||
lines.append("⚠️ Das aktuelle Theme ist sehr lang (>500 Zeichen).")
|
||||
|
||||
buttons: List[dict] = []
|
||||
buttons.extend(_build_custom_buttons(
|
||||
["↩️ Zurück"],
|
||||
prefix=f"{REVIEW_ROOM_EDIT}::{target_room_id}::edit",
|
||||
style="default",
|
||||
))
|
||||
# Nur Sonderschaltfläche (keine nummerierten Buttons)
|
||||
num_buttons: List[Tuple[str, str]] = []
|
||||
special_buttons: List[Tuple[str, str, str]] = [
|
||||
("↩️ Zurück", f"{REVIEW_ROOM_EDIT}::{target_room_id}::edit", "default"),
|
||||
]
|
||||
|
||||
text = "\n".join(lines)
|
||||
attachments = [{
|
||||
"color": "#1d74f5",
|
||||
"title": f"Theme bearbeiten: {entry.name}",
|
||||
"actions": buttons,
|
||||
}]
|
||||
attachments = build_button_attachments(
|
||||
num_buttons,
|
||||
special_buttons,
|
||||
color="#1d74f5",
|
||||
title=f"Theme bearbeiten: {entry.name}",
|
||||
)
|
||||
|
||||
return text, attachments
|
||||
|
||||
@@ -510,24 +584,20 @@ def render_review_room_catch_all_toggle(
|
||||
lines.append("")
|
||||
lines.append("👉 Bestätigen?")
|
||||
|
||||
buttons: List[dict] = []
|
||||
buttons.extend(_build_custom_buttons(
|
||||
["✅ Setzen"],
|
||||
prefix=f"{REVIEW_ROOM_CATCHALL_SET}::{target_room_id}::confirm",
|
||||
style="primary",
|
||||
))
|
||||
buttons.extend(_build_custom_buttons(
|
||||
["↩️ Zurück"],
|
||||
prefix=f"{REVIEW_ROOM_EDIT}::{target_room_id}::edit",
|
||||
style="default",
|
||||
))
|
||||
num_buttons: List[Tuple[str, str]] = [
|
||||
("✅ Setzen", f"{REVIEW_ROOM_CATCHALL_SET}::{target_room_id}::confirm"),
|
||||
]
|
||||
special_buttons: List[Tuple[str, str, str]] = [
|
||||
("↩️ Zurück", f"{REVIEW_ROOM_EDIT}::{target_room_id}::edit", "default"),
|
||||
]
|
||||
|
||||
text = "\n".join(lines)
|
||||
attachments = [{
|
||||
"color": "#f5a623",
|
||||
"title": f"Catch-All ändern: {entry.name}",
|
||||
"actions": buttons,
|
||||
}]
|
||||
attachments = build_button_attachments(
|
||||
num_buttons,
|
||||
special_buttons,
|
||||
color="#f5a623",
|
||||
title=f"Catch-All ändern: {entry.name}",
|
||||
)
|
||||
|
||||
return text, attachments
|
||||
|
||||
@@ -574,24 +644,20 @@ def render_review_room_remove(
|
||||
"👉 Bestätigen?",
|
||||
]
|
||||
|
||||
buttons: List[dict] = []
|
||||
buttons.extend(_build_custom_buttons(
|
||||
["✅ Löschen"],
|
||||
prefix=f"{REVIEW_ROOM_REMOVE_CONFIRM}::{target_room_id}::confirm",
|
||||
style="danger",
|
||||
))
|
||||
buttons.extend(_build_custom_buttons(
|
||||
["↩️ Zurück"],
|
||||
prefix=f"{REVIEW_ROOM_EDIT}::{target_room_id}::edit",
|
||||
style="default",
|
||||
))
|
||||
num_buttons: List[Tuple[str, str]] = [
|
||||
("🗑️ Ja", f"{REVIEW_ROOM_REMOVE_CONFIRM}::{target_room_id}::confirm"),
|
||||
]
|
||||
special_buttons: List[Tuple[str, str, str]] = [
|
||||
("↩️ Abbrechen", f"{REVIEW_ROOM_EDIT}::{target_room_id}::edit", "default"),
|
||||
]
|
||||
|
||||
text = "\n".join(lines)
|
||||
attachments = [{
|
||||
"color": "#f5455c",
|
||||
"title": f"Raum entfernen: {entry.name}",
|
||||
"actions": buttons,
|
||||
}]
|
||||
attachments = build_button_attachments(
|
||||
num_buttons,
|
||||
special_buttons,
|
||||
color="#f5455c",
|
||||
title=f"Raum entfernen: {entry.name}",
|
||||
)
|
||||
|
||||
return text, attachments
|
||||
|
||||
@@ -629,36 +695,32 @@ def render_review_room_add_new(
|
||||
"",
|
||||
]
|
||||
|
||||
buttons: List[dict] = []
|
||||
num_buttons: List[Tuple[str, str]] = []
|
||||
for i, room in enumerate(available_rooms):
|
||||
rid = room["id"]
|
||||
name = room.get("name", rid)
|
||||
rtype = room.get("type", "c")
|
||||
type_label = "💬" if rtype == "d" else "#"
|
||||
lines.append(f" {type_label} {name}")
|
||||
emoji = _EMOJI_NUMBERS[i] if i < len(_EMOJI_NUMBERS) else str(i + 1)
|
||||
lines.append(f" {emoji} {type_label} {name}")
|
||||
# Kurzer Button-Name (max 9 Zeichen)
|
||||
short_name = name[:9] if len(name) > 9 else name
|
||||
buttons.extend(_build_custom_buttons(
|
||||
[f"{i+1}️⃣ {short_name}"],
|
||||
prefix=f"{REVIEW_ROOM_ADD_NEW}::{rid}",
|
||||
style="primary",
|
||||
))
|
||||
num_buttons.append((short_name, f"{REVIEW_ROOM_ADD_NEW}::{rid}"))
|
||||
|
||||
lines.append("")
|
||||
lines.append("👉 Klicke auf einen Raum zum Hinzufügen:")
|
||||
|
||||
buttons.extend(_build_custom_buttons(
|
||||
["↩️ Zurück"],
|
||||
prefix=REVIEW_ROOM_BACK,
|
||||
style="default",
|
||||
))
|
||||
special_buttons: List[Tuple[str, str, str]] = [
|
||||
("↩️ Zurück", REVIEW_ROOM_BACK, "default"),
|
||||
]
|
||||
|
||||
text = "\n".join(lines)
|
||||
attachments = [{
|
||||
"color": "#1d74f5",
|
||||
"title": "Neuen Raum hinzufügen",
|
||||
"actions": buttons,
|
||||
}]
|
||||
attachments = build_button_attachments(
|
||||
num_buttons,
|
||||
special_buttons,
|
||||
color="#1d74f5",
|
||||
title="Neuen Raum hinzufügen",
|
||||
)
|
||||
|
||||
return text, attachments
|
||||
|
||||
|
||||
Reference in New Issue
Block a user