fix(escalations): add sidebar badge count + show all team escalations

- Add escalation_count to sidebar stats (team-wide requesting_escalation)
- Show badge on Escalations nav item in sidebar
- Remove user_id filter from escalation queue — show all team escalations
  including your own (needed for solo users and visibility)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-21 04:41:27 +00:00
parent 79358be90f
commit cf23107735
5 changed files with 19 additions and 3 deletions

View File

@@ -415,7 +415,6 @@ async def get_escalation_queue(
.where(
AISession.team_id == current_user.team_id,
AISession.status == "requesting_escalation",
AISession.user_id != current_user.id, # Don't show own escalated sessions
)
.order_by(AISession.created_at.desc())
)

View File

@@ -8,6 +8,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from app.core.database import get_db
from app.api.deps import get_current_active_user
from app.models.ai_session import AISession
from app.models.session import Session
from app.models.tree import Tree
from app.models.user import User
@@ -146,6 +147,19 @@ async def get_sidebar_stats(
for row in recent_result.all()
]
# --- Escalation count (team-wide pending escalations) ---
escalation_count = 0
if current_user.team_id:
esc_result = await db.execute(
select(func.count()).where(
and_(
AISession.team_id == current_user.team_id,
AISession.status == "requesting_escalation",
)
)
)
escalation_count = esc_result.scalar() or 0
# --- Tree counts (for All Flows sub-items) ---
tree_counts_result = await db.execute(
select(
@@ -167,6 +181,7 @@ async def get_sidebar_stats(
resolved_today=resolved_today,
active_count=active_count,
total_session_minutes_today=total_minutes,
escalation_count=escalation_count,
tree_counts=SidebarTreeCounts(
total=tc.total,
troubleshooting=tc.troubleshooting,

View File

@@ -40,6 +40,7 @@ class SidebarStatsResponse(BaseModel):
resolved_today: int
active_count: int
total_session_minutes_today: int
escalation_count: int = 0
tree_counts: SidebarTreeCounts
active_sessions: list[SidebarActiveSession]
recent_completions: list[SidebarRecentSession]