From cf231077359c4223e73b4e6c18fa156e8d631409 Mon Sep 17 00:00:00 2001 From: chihlasm Date: Sat, 21 Mar 2026 04:41:27 +0000 Subject: [PATCH] fix(escalations): add sidebar badge count + show all team escalations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- backend/app/api/endpoints/ai_sessions.py | 1 - backend/app/api/endpoints/sidebar.py | 15 +++++++++++++++ backend/app/schemas/sidebar.py | 1 + frontend/src/api/sidebar.ts | 1 + frontend/src/components/layout/Sidebar.tsx | 4 ++-- 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/backend/app/api/endpoints/ai_sessions.py b/backend/app/api/endpoints/ai_sessions.py index 07d76d06..c41cd2cf 100644 --- a/backend/app/api/endpoints/ai_sessions.py +++ b/backend/app/api/endpoints/ai_sessions.py @@ -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()) ) diff --git a/backend/app/api/endpoints/sidebar.py b/backend/app/api/endpoints/sidebar.py index a473433b..0772dd92 100644 --- a/backend/app/api/endpoints/sidebar.py +++ b/backend/app/api/endpoints/sidebar.py @@ -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, diff --git a/backend/app/schemas/sidebar.py b/backend/app/schemas/sidebar.py index 95d92291..e0ac5753 100644 --- a/backend/app/schemas/sidebar.py +++ b/backend/app/schemas/sidebar.py @@ -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] diff --git a/frontend/src/api/sidebar.ts b/frontend/src/api/sidebar.ts index 8bbf9498..6680bc1b 100644 --- a/frontend/src/api/sidebar.ts +++ b/frontend/src/api/sidebar.ts @@ -29,6 +29,7 @@ export interface SidebarStatsResponse { resolved_today: number active_count: number total_session_minutes_today: number + escalation_count: number tree_counts: SidebarTreeCounts active_sessions: SidebarActiveSession[] recent_completions: SidebarRecentSession[] diff --git a/frontend/src/components/layout/Sidebar.tsx b/frontend/src/components/layout/Sidebar.tsx index 674bf13c..abe4cd08 100644 --- a/frontend/src/components/layout/Sidebar.tsx +++ b/frontend/src/components/layout/Sidebar.tsx @@ -79,7 +79,7 @@ export function Sidebar() {
- + @@ -103,7 +103,7 @@ export function Sidebar() { Resolve
- + {/* Knowledge */}