commit compras1 2911
tests / ci (push) Waiting to run

This commit is contained in:
2026-11-29 05:28:30 +02:00
parent 1ddabbbdcc
commit 448948a487
137 changed files with 9481 additions and 1926 deletions
+44 -41
View File
@@ -7,7 +7,7 @@ import {
Search,
X,
} from 'lucide-react';
import { Fragment, useEffect, useState } from 'react';
import { Fragment, useEffect, useRef, useState } from 'react';
import type { ReactNode } from 'react';
import { Button } from '@/components/ui/button';
import {
@@ -32,6 +32,12 @@ import {
import { roleLabels } from '@/types/procurement';
import type { WorkContextState } from '@/types/work-context';
import { WorkContextChange } from '@/components/work-context-change';
import { ProcurementMenuResults } from '@/components/procurement-menu-results';
import {
matchesMenuSearch,
normalizeMenuText,
searchProcurementMenu,
} from '@/lib/procurement-menu-search';
export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
const page = usePage();
@@ -41,6 +47,7 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
| undefined;
const [mobileOpen, setMobileOpen] = useState(false);
const [search, setSearch] = useState('');
const desktopSearch = useRef<HTMLInputElement>(null);
const [expanded, setExpanded] = useState<Record<string, boolean>>({});
const access = page.props.organizationAccess as {
active: boolean;
@@ -55,6 +62,7 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
page.props.orderCancellationAvailable === true,
page.props.operationalOrdersAvailable === true,
page.props.privateAuditAvailable === true,
page.props.capitalRegisterAvailable === true,
).flatMap((group) => group.entries.map((entry) => entry.id)),
);
const groups = procurementNavigation(
@@ -64,6 +72,7 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
page.props.orderCancellationAvailable === true,
page.props.operationalOrdersAvailable === true,
page.props.privateAuditAvailable === true,
page.props.capitalRegisterAvailable === true,
)
.map((group) => ({
...group,
@@ -91,28 +100,13 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
: { ...previous, [activeGroupId]: true },
);
}, [activeId, activeGroupId]);
const normalize = (text: string) =>
text
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.toLocaleLowerCase('pt');
const normalize = normalizeMenuText;
const query = normalize(search.trim());
const visibleGroups = groups
.map((group) => ({
...group,
entries: group.entries.filter(
(entry) =>
!query ||
normalize(
group.label +
' ' +
(entry.section ?? '') +
' ' +
entry.label,
).includes(query),
),
}))
.filter((group) => group.entries.length);
const visibleGroups = searchProcurementMenu(groups, query);
const closeSearch = () => {
setSearch('');
desktopSearch.current?.focus();
};
const navigate = () => {
setMobileOpen(false);
setSearch('');
@@ -145,12 +139,22 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
aria-hidden="true"
/>
<input
ref={mobile ? undefined : desktopSearch}
type="search"
aria-label="Procurar no menu"
placeholder="Procurar no menu…"
value={search}
onChange={(event) => setSearch(event.target.value)}
className={`h-10 w-full rounded-lg border pr-9 pl-9 text-sm outline-none focus:border-red-400 focus:ring-2 focus:ring-red-400/20 ${mobile ? 'border-white/15 bg-white/5 text-white placeholder:text-slate-400' : 'border-border bg-background text-foreground'}`}
onKeyDown={(event) => {
if (event.key === 'Escape') {
event.preventDefault();
closeSearch();
}
}}
aria-controls={
!mobile && query ? 'sgc-menu-results' : undefined
}
className={`h-10 w-full rounded-lg border pr-9 pl-9 text-sm outline-none focus:border-red-400 focus:ring-2 focus:ring-red-400/20 [&::-webkit-search-cancel-button]:hidden ${mobile ? 'border-white/15 bg-white/5 text-white placeholder:text-slate-400' : 'border-border bg-background text-foreground'}`}
/>
{search && (
<button
@@ -162,6 +166,17 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
<X className="size-4" />
</button>
)}
{!mobile && query && (
<ProcurementMenuResults
groups={visibleGroups}
dashboard={matchesMenuSearch(
'Painel inicial Visão geral',
query,
)}
onNavigate={navigate}
onEscape={closeSearch}
/>
)}
</div>
);
const navigation = (
@@ -173,7 +188,7 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
ESPAÇO DE TRABALHO
</p>
{(!query ||
normalize('Painel inicial Visão geral').includes(query)) && (
matchesMenuSearch('Painel inicial Visão geral', query)) && (
<Link
href="/dashboard"
onClick={navigate}
@@ -273,12 +288,12 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
))}
{query &&
visibleGroups.length === 0 &&
!normalize('Painel inicial Visão geral').includes(query) && (
!matchesMenuSearch('Painel inicial Visão geral', query) && (
<p
role="status"
className="px-3 py-5 text-sm text-slate-400"
>
Nenhuma opção encontrada. Tenta outra palavra.
Nenhuma opção encontrada. Tente outra palavra.
</p>
)}
</nav>
@@ -359,10 +374,7 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
aria-label="Navegação principal horizontal"
className="flex min-w-0 flex-1 flex-wrap items-center gap-1 px-3 py-3"
>
{(!query ||
normalize(
'Painel inicial Visão geral',
).includes(query)) && (
{
<Link
href="/dashboard"
onClick={navigate}
@@ -379,8 +391,8 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
/>
Painel inicial
</Link>
)}
{visibleGroups.map((group) => (
}
{groups.map((group) => (
<DropdownMenu key={group.id}>
<DropdownMenuTrigger asChild>
<button
@@ -451,15 +463,6 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
</DropdownMenuContent>
</DropdownMenu>
))}
{query &&
visibleGroups.length === 0 &&
!normalize(
'Painel inicial Visão geral',
).includes(query) && (
<p className="px-3 py-2 text-sm text-slate-400">
Nenhuma opção encontrada.
</p>
)}
</nav>
</div>
<div className="flex min-h-18 items-center justify-between gap-4 px-5 py-3 lg:px-8">