From 80e9b7664960f1c78a2f84893ae3116116146161 Mon Sep 17 00:00:00 2001 From: killer-cf Date: Fri, 5 Dec 2025 16:36:56 -0300 Subject: [PATCH] feat: Enhance sidebar active state logic with path exclusion and add new permissions for pedidos, atas, objetos, and empresas. --- apps/web/src/lib/components/Sidebar.svelte | 29 +++++- packages/backend/convex/permissoesAcoes.ts | 105 +++++++++++++++++++++ 2 files changed, 129 insertions(+), 5 deletions(-) diff --git a/apps/web/src/lib/components/Sidebar.svelte b/apps/web/src/lib/components/Sidebar.svelte index a6a505f..702a47c 100644 --- a/apps/web/src/lib/components/Sidebar.svelte +++ b/apps/web/src/lib/components/Sidebar.svelte @@ -58,6 +58,8 @@ label: string; link: string; permission?: MenuItemPermission; + excludePaths?: string[]; + exact?: boolean; } interface MenuItem { @@ -66,6 +68,8 @@ link: string; permission?: MenuItemPermission; submenus?: SubMenuItem[]; + excludePaths?: string[]; + exact?: boolean; } // Estrutura do menu definida no frontend @@ -107,7 +111,8 @@ { label: 'Meus Pedidos', link: '/pedidos', - permission: { recurso: 'pedidos', acao: 'listar' } + permission: { recurso: 'pedidos', acao: 'listar' }, + excludePaths: ['/pedidos/aceite', '/pedidos/minhas-analises'] }, { label: 'Pedidos para Aceite', @@ -261,7 +266,15 @@ return iconMap[name] || Home; } - function isRouteActive(path: string, exact = false) { + function isRouteActive(path: string, options: { exact?: boolean; excludePaths?: string[] } = {}) { + const { exact = false, excludePaths = [] } = options; + + if (excludePaths.length > 0) { + if (excludePaths.some((excludePath) => currentPath.startsWith(excludePath))) { + return false; + } + } + if (exact) return currentPath === path; return currentPath === path || currentPath.startsWith(path + '/'); } @@ -630,7 +643,10 @@ {#snippet menuItem(item: MenuItem)} {@const Icon = getIconComponent(item.icon)} - {@const isActive = isRouteActive(item.link, item.link === '/')} + {@const isActive = isRouteActive(item.link, { + exact: item.link === '/', + excludePaths: item.excludePaths + })} {@const hasSubmenus = item.submenus && item.submenus.length > 0}
  • @@ -651,10 +667,13 @@ class="h-4 w-4 opacity-50 transition-transform duration-200 group-open/details:rotate-180" /> -