Separate dashboard functions from grouped administration operations
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -14,6 +14,7 @@ export type PortalNavAccess = {
|
||||
};
|
||||
scopedAdministration?: { label: string; href: string }[];
|
||||
dashboardNavigation?: { label: string; href: string }[];
|
||||
administrationNavigation?: { label: string; href: string }[];
|
||||
procurement?: boolean;
|
||||
funding?: boolean;
|
||||
authenticated: boolean;
|
||||
@@ -422,7 +423,9 @@ export function currentNavigationGroup(
|
||||
for (const [key, value] of target.searchParams)
|
||||
if (current.searchParams.get(key) !== value) return;
|
||||
const score =
|
||||
target.pathname.length + target.searchParams.size * 100;
|
||||
target.pathname.length +
|
||||
target.searchParams.size * 100 +
|
||||
(target.hash ? 10000 : 0);
|
||||
if (!match || score > match.score) match = { group, score };
|
||||
});
|
||||
for (const group of groups) visit(group.children ?? [], group.id);
|
||||
@@ -449,7 +452,7 @@ export function currentNavigationItem(
|
||||
)
|
||||
)
|
||||
continue;
|
||||
const score = target.searchParams.size;
|
||||
const score = target.searchParams.size + (target.hash ? 10000 : 0);
|
||||
if (score > best.score) {
|
||||
best.id = item.id;
|
||||
best.score = score;
|
||||
@@ -479,43 +482,125 @@ export function portalNavigation(access: PortalNavAccess): PortalNavItem[] {
|
||||
: null)
|
||||
: null;
|
||||
const dashboardActivities = access.authenticated
|
||||
? [
|
||||
...(access.dashboardNavigation ?? []),
|
||||
...previous
|
||||
? access.dashboardNavigation?.length
|
||||
? access.dashboardNavigation
|
||||
: previous
|
||||
.filter((group) => group.id === 'account')
|
||||
.flatMap((group) => group.children ?? [])
|
||||
.filter((item) => item.href === '/dashboard')
|
||||
.map((item) => ({
|
||||
label: 'Painel operacional',
|
||||
href: item.href!,
|
||||
})),
|
||||
]
|
||||
.map((item) => ({ label: 'Visão geral', href: item.href! }))
|
||||
: [];
|
||||
const administration = access.authenticated
|
||||
const flatten = (items: PortalNavItem[]): PortalNavItem[] =>
|
||||
items.flatMap((item) =>
|
||||
item.children ? flatten(item.children) : [item],
|
||||
);
|
||||
const profileAdministration = new Set([
|
||||
'profile-administration',
|
||||
'profile-installation',
|
||||
'profile-audit',
|
||||
]);
|
||||
const candidates = access.authenticated
|
||||
? [
|
||||
...(dashboardActivities.length
|
||||
...(workHub
|
||||
? [link('work-entry', 'Gestão de conteúdos', workHub)]
|
||||
: []),
|
||||
...(workCreate
|
||||
? [
|
||||
{
|
||||
id: 'collaborative-dashboard',
|
||||
label: 'Dashboard',
|
||||
children: dashboardActivities.map((item, index) =>
|
||||
link(
|
||||
'dashboard-activity-' + index,
|
||||
item.label,
|
||||
item.href,
|
||||
),
|
||||
),
|
||||
},
|
||||
link(
|
||||
'prepare-analysis',
|
||||
'Preparar análise e ideia',
|
||||
workCreate + '?analysis=proactive',
|
||||
),
|
||||
]
|
||||
: []),
|
||||
...previous
|
||||
.filter((group) => group.id === 'management')
|
||||
.flatMap((group) => group.children ?? []),
|
||||
...(workOpportunities
|
||||
? [
|
||||
link(
|
||||
'work-opportunities',
|
||||
'Oportunidades em preparação',
|
||||
workOpportunities.index,
|
||||
),
|
||||
]
|
||||
: []),
|
||||
...(access.administrationNavigation ?? []).map((item, index) =>
|
||||
link(
|
||||
'administrative-activity-' + index,
|
||||
item.label,
|
||||
item.href,
|
||||
),
|
||||
),
|
||||
...flatten(
|
||||
previous
|
||||
.filter((group) => group.id === 'management')
|
||||
.flatMap((group) => group.children ?? []),
|
||||
),
|
||||
...(access.scopedAdministration ?? []).map((item, index) =>
|
||||
link('scoped-' + index, item.label, item.href),
|
||||
),
|
||||
...previous
|
||||
.filter((group) => group.id === 'profile-opportunities')
|
||||
.flatMap((group) => group.children ?? [])
|
||||
.filter((item) => profileAdministration.has(item.id)),
|
||||
]
|
||||
: [];
|
||||
const categories = [
|
||||
{
|
||||
id: 'administration-content',
|
||||
label: 'Conteúdos e oportunidades',
|
||||
children: [] as PortalNavItem[],
|
||||
},
|
||||
{
|
||||
id: 'administration-records',
|
||||
label: 'Cadastros e investimento',
|
||||
children: [] as PortalNavItem[],
|
||||
},
|
||||
{
|
||||
id: 'administration-followup',
|
||||
label: 'Pedidos e acompanhamento',
|
||||
children: [] as PortalNavItem[],
|
||||
},
|
||||
{
|
||||
id: 'administration-access',
|
||||
label: 'Acessos e configuração',
|
||||
children: [] as PortalNavItem[],
|
||||
},
|
||||
];
|
||||
for (const item of candidates) {
|
||||
const path = new URL(item.href!, 'https://portal.invalid').pathname;
|
||||
const category =
|
||||
/^\/(gestao-conteudos|management\/(portal-services|opportunities|concursos)|minhas-oportunidades)(\/|$)/.test(
|
||||
path,
|
||||
)
|
||||
? 0
|
||||
: /^\/management\/(interests|crm|balcao\/atribuicoes)(\/|$)/.test(
|
||||
path,
|
||||
)
|
||||
? 2
|
||||
: profileAdministration.has(item.id) ||
|
||||
/-install$/.test(path) ||
|
||||
path === '/management/ai'
|
||||
? 3
|
||||
: 1;
|
||||
categories[category].children.push(item);
|
||||
}
|
||||
const administration = [
|
||||
...(dashboardActivities.length
|
||||
? [
|
||||
{
|
||||
id: 'collaborative-dashboard',
|
||||
label: 'Dashboard',
|
||||
children: dashboardActivities.map((item, index) =>
|
||||
link(
|
||||
'dashboard-activity-' + index,
|
||||
item.label,
|
||||
item.href,
|
||||
),
|
||||
),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...categories.filter((group) => group.children.length > 0),
|
||||
];
|
||||
return uniqueNavigationDestinations([
|
||||
{
|
||||
id: 'discovery',
|
||||
@@ -655,34 +740,13 @@ export function portalNavigation(access: PortalNavAccess): PortalNavItem[] {
|
||||
id: 'work',
|
||||
label: 'Área de trabalho',
|
||||
children: [
|
||||
link(
|
||||
'work-entry',
|
||||
workHub
|
||||
? 'Gestão de conteúdos e oportunidades'
|
||||
: 'Acesso à gestão',
|
||||
workHub || '/acesso-gestao',
|
||||
),
|
||||
...(workCreate
|
||||
? [
|
||||
link(
|
||||
'prepare-analysis',
|
||||
'Preparar análise e ideia',
|
||||
workCreate + '?analysis=proactive',
|
||||
),
|
||||
]
|
||||
: []),
|
||||
...(workOpportunities
|
||||
? [
|
||||
link(
|
||||
'work-opportunities',
|
||||
'Oportunidades em preparação',
|
||||
workOpportunities.index,
|
||||
),
|
||||
]
|
||||
...(!workHub
|
||||
? [link('work-entry', 'Acesso à gestão', '/acesso-gestao')]
|
||||
: []),
|
||||
...previous
|
||||
.filter((group) => group.id === 'profile-opportunities')
|
||||
.flatMap((group) => group.children ?? []),
|
||||
.flatMap((group) => group.children ?? [])
|
||||
.filter((item) => !profileAdministration.has(item.id)),
|
||||
],
|
||||
},
|
||||
...previous.filter((group) => group.id === 'account'),
|
||||
|
||||
Reference in New Issue
Block a user