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,
X,
} from 'lucide-react';
import { Fragment, useEffect, useRef, useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import type { ReactNode } from 'react';
import { Button } from '@/components/ui/button';
import {
@@ -29,7 +29,10 @@ import {
activeProcurementEntry,
procurementNavigation,
} 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 type { WorkContextState } from '@/types/work-context';
import { WorkContextChange } from '@/components/work-context-change';
@@ -40,6 +43,17 @@ import {
searchProcurementMenu,
} 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 }) {
const page = usePage();
const user = page.props.auth?.user;
@@ -252,14 +266,14 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
</summary>
<ul className="mt-1 mb-3 ml-5 space-y-1 border-l border-white/10 pl-3">
{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 (
<li key={entry.id}>
{entry.section &&
entry.section !==
group.entries[index - 1]
?.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}
</p>
)}
@@ -427,27 +441,51 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
<DropdownMenuContent
align="start"
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) => (
<Fragment key={entry.id}>
{entry.section &&
entry.section !==
group.entries[index - 1]
?.section && (
<DropdownMenuLabel className="px-3 pt-3 pb-1 text-xs text-slate-500">
{entry.section}
<div
className={
menuSections(group.entries)
.length > 1
? 'grid grid-cols-2 gap-x-4 gap-y-3'
: ''
}
>
{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>
)}
{section.entries.map(
(entry) => (
<DropdownMenuItem
key={entry.id}
key={
entry.id
}
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 ? (
<a
href={entry.path}
onClick={navigate}
href={
entry.path
}
onClick={
navigate
}
aria-current={
activeId ===
entry.id
@@ -455,12 +493,18 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
: undefined
}
>
{entry.label}
{
entry.label
}
</a>
) : (
<Link
href={entry.path}
onClick={navigate}
href={
entry.path
}
onClick={
navigate
}
aria-current={
activeId ===
entry.id
@@ -468,12 +512,18 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
: undefined
}
>
{entry.label}
{
entry.label
}
</Link>
)}
</DropdownMenuItem>
</Fragment>
))}
),
)}
</div>
),
)}
</div>
</DropdownMenuContent>
</DropdownMenu>
))}
+54 -28
View File
@@ -7,6 +7,7 @@ import {
Wallet,
Warehouse,
FileBarChart,
Settings,
} from 'lucide-react';
import type { LucideIcon } from 'lucide-react';
@@ -612,15 +613,11 @@ export function procurementNavigation(
],
},
];
const purchasing = groups.filter((group) =>
['requests', 'approvals', 'sourcing', 'suppliers'].includes(group.id),
);
const compact = [
{
id: 'purchasing',
label: 'Compras',
icon: ClipboardList,
entries: purchasing.flatMap((group) =>
// Agrupamento visível: pedir → comprar → receber → pagar → controlar.
const withSections = (ids: string[]) =>
groups
.filter((group) => ids.includes(group.id))
.flatMap((group) =>
(group.id === 'sourcing'
? [
...group.entries.filter(
@@ -639,29 +636,58 @@ export function procurementNavigation(
: group.id === 'sourcing' &&
entry.id.startsWith('supply_')
? 'Fornecimento e reposição'
: group.id === 'sourcing'
? 'Cotações e ordens'
: 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
.map((group) => ({