feat: Enhance sidebar active state logic with path exclusion and add new permissions for pedidos, atas, objetos, and empresas.

This commit is contained in:
2025-12-05 16:36:56 -03:00
parent 6a99ab74f1
commit 80e9b76649
2 changed files with 129 additions and 5 deletions

View File

@@ -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 @@
<!-- Sidebar menu items -->
{#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}
<li class="mb-1">
@@ -651,10 +667,13 @@
class="h-4 w-4 opacity-50 transition-transform duration-200 group-open/details:rotate-180"
/>
</summary>
<ul class="border-base-200 mt-1 ml-4 space-y-1 border-l-2 pl-2">
<ul class="border-base-200 mt-1 ml-4 space-y-1 pl-2">
{#if item.submenus}
{#each item.submenus as sub (sub.link)}
{@const isSubActive = isRouteActive(sub.link)}
{@const isSubActive = isRouteActive(sub.link, {
excludePaths: sub.excludePaths,
exact: sub.exact
})}
<li>
<a href={resolve(sub.link)} class={getMenuClasses(isSubActive, true)}>
<span>{sub.label}</span>