Juntar menu-organizado ao main

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 20:48:59 +02:00
co-authored by Claude Opus 5.5
2 changed files with 155 additions and 79 deletions
+73 -23
View File
@@ -7,7 +7,7 @@ import {
Search, Search,
X, X,
} from 'lucide-react'; } from 'lucide-react';
import { Fragment, useEffect, useRef, useState } from 'react'; import { useEffect, useRef, useState } from 'react';
import type { ReactNode } from 'react'; import type { ReactNode } from 'react';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
import { import {
@@ -29,7 +29,10 @@ import {
activeProcurementEntry, activeProcurementEntry,
procurementNavigation, procurementNavigation,
} from '@/lib/procurement-navigation'; } from '@/lib/procurement-navigation';
import type { CommonFinanceNavigation } from '@/lib/procurement-navigation'; import type {
CommonFinanceNavigation,
ProcurementEntry,
} from '@/lib/procurement-navigation';
import { roleLabels } from '@/types/procurement'; import { roleLabels } from '@/types/procurement';
import type { WorkContextState } from '@/types/work-context'; import type { WorkContextState } from '@/types/work-context';
import { WorkContextChange } from '@/components/work-context-change'; import { WorkContextChange } from '@/components/work-context-change';
@@ -40,6 +43,17 @@ import {
searchProcurementMenu, searchProcurementMenu,
} from '@/lib/procurement-menu-search'; } from '@/lib/procurement-menu-search';
/** Agrupa entradas consecutivas pela secção, mantendo a ordem do menu. */
function menuSections(entries: ProcurementEntry[]) {
const sections: { label?: string; entries: ProcurementEntry[] }[] = [];
for (const entry of entries) {
const last = sections[sections.length - 1];
if (last && last.label === entry.section) last.entries.push(entry);
else sections.push({ label: entry.section, entries: [entry] });
}
return sections;
}
export function SgcWorkspaceShell({ children }: { children: ReactNode }) { export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
const page = usePage(); const page = usePage();
const user = page.props.auth?.user; const user = page.props.auth?.user;
@@ -252,14 +266,14 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
</summary> </summary>
<ul className="mt-1 mb-3 ml-5 space-y-1 border-l border-white/10 pl-3"> <ul className="mt-1 mb-3 ml-5 space-y-1 border-l border-white/10 pl-3">
{group.entries.map((entry, index) => { {group.entries.map((entry, index) => {
const className = `block rounded-md px-3 py-2 text-[13px] leading-5 transition-colors focus-visible:outline-2 focus-visible:outline-white ${activeId === entry.id ? 'bg-red-500/15 font-medium text-red-300' : 'text-slate-400 hover:bg-white/5 hover:text-white'}`; const className = `block rounded-md px-3 py-2 text-[13px] leading-5 transition-colors focus-visible:outline-2 focus-visible:outline-white ${activeId === entry.id ? 'bg-white/10 font-medium text-white shadow-[inset_2px_0_0_#ed1c24]' : 'text-slate-300 hover:bg-white/5 hover:text-white'}`;
return ( return (
<li key={entry.id}> <li key={entry.id}>
{entry.section && {entry.section &&
entry.section !== entry.section !==
group.entries[index - 1] group.entries[index - 1]
?.section && ( ?.section && (
<p className="px-3 pt-3 pb-1 text-xs font-semibold text-slate-500"> <p className="px-3 pt-3 pb-1 text-[10px] font-semibold tracking-[0.14em] text-slate-400 uppercase">
{entry.section} {entry.section}
</p> </p>
)} )}
@@ -427,27 +441,51 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
<DropdownMenuContent <DropdownMenuContent
align="start" align="start"
sideOffset={8} sideOffset={8}
className="max-h-[min(70vh,32rem)] w-72 overflow-y-auto border-white/10 bg-[#101715] p-2 text-white" className={`max-h-[min(75vh,36rem)] overflow-y-auto rounded-xl border-white/10 bg-[#101715] p-3 text-white shadow-2xl ${menuSections(group.entries).length > 1 ? 'w-[min(34rem,calc(100vw-2rem))]' : 'w-72'}`}
> >
{group.entries.map((entry, index) => ( <div
<Fragment key={entry.id}> className={
{entry.section && menuSections(group.entries)
entry.section !== .length > 1
group.entries[index - 1] ? 'grid grid-cols-2 gap-x-4 gap-y-3'
?.section && ( : ''
<DropdownMenuLabel className="px-3 pt-3 pb-1 text-xs text-slate-500"> }
{entry.section} >
{menuSections(group.entries).map(
(section) => (
<div
key={
section.label ??
group.id
}
role="group"
aria-label={
section.label ??
group.label
}
>
{section.label && (
<DropdownMenuLabel className="mb-1 border-b border-white/10 px-3 pt-1 pb-2 text-[10px] font-semibold tracking-[0.14em] text-slate-400 uppercase">
{section.label}
</DropdownMenuLabel> </DropdownMenuLabel>
)} )}
{section.entries.map(
(entry) => (
<DropdownMenuItem <DropdownMenuItem
key={entry.id} key={
entry.id
}
asChild asChild
className={`rounded-md px-3 py-2 text-[13px] leading-5 focus:bg-white/5 focus:text-white ${activeId === entry.id ? 'bg-red-500/15 font-medium text-red-300' : 'text-slate-400'}`} className={`rounded-md border-l-2 px-3 py-2 text-[13px] leading-5 focus:bg-white/10 focus:text-white ${activeId === entry.id ? 'border-[#ed1c24] bg-white/10 font-medium text-white' : 'border-transparent text-slate-200'}`}
> >
{entry.fullPage ? ( {entry.fullPage ? (
<a <a
href={entry.path} href={
onClick={navigate} entry.path
}
onClick={
navigate
}
aria-current={ aria-current={
activeId === activeId ===
entry.id entry.id
@@ -455,12 +493,18 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
: undefined : undefined
} }
> >
{entry.label} {
entry.label
}
</a> </a>
) : ( ) : (
<Link <Link
href={entry.path} href={
onClick={navigate} entry.path
}
onClick={
navigate
}
aria-current={ aria-current={
activeId === activeId ===
entry.id entry.id
@@ -468,12 +512,18 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
: undefined : undefined
} }
> >
{entry.label} {
entry.label
}
</Link> </Link>
)} )}
</DropdownMenuItem> </DropdownMenuItem>
</Fragment> ),
))} )}
</div>
),
)}
</div>
</DropdownMenuContent> </DropdownMenuContent>
</DropdownMenu> </DropdownMenu>
))} ))}
+54 -28
View File
@@ -7,6 +7,7 @@ import {
Wallet, Wallet,
Warehouse, Warehouse,
FileBarChart, FileBarChart,
Settings,
} from 'lucide-react'; } from 'lucide-react';
import type { LucideIcon } from 'lucide-react'; import type { LucideIcon } from 'lucide-react';
@@ -612,15 +613,11 @@ export function procurementNavigation(
], ],
}, },
]; ];
const purchasing = groups.filter((group) => // Agrupamento visível: pedir → comprar → receber → pagar → controlar.
['requests', 'approvals', 'sourcing', 'suppliers'].includes(group.id), const withSections = (ids: string[]) =>
); groups
const compact = [ .filter((group) => ids.includes(group.id))
{ .flatMap((group) =>
id: 'purchasing',
label: 'Compras',
icon: ClipboardList,
entries: purchasing.flatMap((group) =>
(group.id === 'sourcing' (group.id === 'sourcing'
? [ ? [
...group.entries.filter( ...group.entries.filter(
@@ -639,29 +636,58 @@ export function procurementNavigation(
: group.id === 'sourcing' && : group.id === 'sourcing' &&
entry.id.startsWith('supply_') entry.id.startsWith('supply_')
? 'Fornecimento e reposição' ? 'Fornecimento e reposição'
: group.id === 'sourcing'
? 'Cotações e ordens'
: group.label, : group.label,
})), })),
);
const byId = (id: string) =>
groups.find((group) => group.id === id) as ProcurementGroup;
const administration = byId('administration');
const audit = byId('audit');
const conflicts = administration.entries.filter(
(entry) => entry.id === 'conflicts',
);
const compact: ProcurementGroup[] = [
{
id: 'requests_area',
label: 'Pedidos',
icon: ClipboardList,
entries: withSections(['requests', 'approvals']),
},
{
id: 'purchasing',
label: 'Compras',
icon: Scale,
entries: withSections(['sourcing', 'suppliers']),
},
byId('people'),
{ ...byId('receiving'), label: 'Armazém e activos' },
byId('finance'),
byId('reports'),
{
id: 'control',
label: 'Controlo',
icon: BadgeCheck,
entries: [
...conflicts.map((entry) => ({
...entry,
section: 'Integridade',
})),
...audit.entries.map((entry) => ({
...entry,
section: 'Auditoria',
})),
],
},
{
...administration,
label: 'Administração',
icon: Settings,
entries: administration.entries.filter(
(entry) => entry.id !== 'conflicts',
), ),
}, },
...groups
.filter(
(group) =>
![
'requests',
'approvals',
'sourcing',
'suppliers',
].includes(group.id),
)
.map((group) => ({
...group,
label:
group.id === 'administration'
? 'Administração'
: group.id === 'receiving'
? 'Armazém e activos'
: group.label,
})),
]; ];
return compact return compact
.map((group) => ({ .map((group) => ({