Unify institution profiles and reduce primary menu to six groups
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
type PublicFunding = {
|
||||
export type PublicFunding = {
|
||||
title: string;
|
||||
kind: string;
|
||||
summary: string;
|
||||
@@ -8,6 +8,8 @@ type PublicFunding = {
|
||||
title: string;
|
||||
instrument?: string | null;
|
||||
availability?: string;
|
||||
contact_url?: string | null;
|
||||
source_url?: string | null;
|
||||
}[];
|
||||
};
|
||||
const descriptions: Record<string, string> = {
|
||||
@@ -45,9 +47,10 @@ const services: Record<string, string> = {
|
||||
};
|
||||
export function fundingPublicPresentation(p: PublicFunding) {
|
||||
const generic =
|
||||
!p.summary.trim() ||
|
||||
p.summary.trim() ===
|
||||
'Instituição identificada no documento fornecido. Categoria, localização e contactos são informativos; produtos, disponibilidade e condições não documentados permanecem por confirmar.';
|
||||
const description = generic
|
||||
'Instituição identificada no documento fornecido. Categoria, localização e contactos são informativos; produtos, disponibilidade e condições não documentados permanecem por confirmar.';
|
||||
let description = generic
|
||||
? (descriptions[p.institution_types?.[0] ?? ''] ??
|
||||
'Entidade do sector financeiro.')
|
||||
: p.summary
|
||||
@@ -58,9 +61,31 @@ export function fundingPublicPresentation(p: PublicFunding) {
|
||||
.replace(/Público\/finalidade:/g, 'Soluções para')
|
||||
.replace(/\.\./g, '.')
|
||||
.trim();
|
||||
const repeatedInstrument = (p.products ?? []).some(
|
||||
(product) =>
|
||||
product.instrument?.trim() &&
|
||||
description.startsWith(product.instrument.trim()),
|
||||
);
|
||||
if (repeatedInstrument) {
|
||||
const audience = description.match(
|
||||
/Soluções para\s+(.+?)(?:\.|$)/i,
|
||||
)?.[1];
|
||||
description = audience
|
||||
? 'Soluções financeiras para ' +
|
||||
audience.charAt(0).toLowerCase() +
|
||||
audience.slice(1) +
|
||||
'.'
|
||||
: (descriptions[p.institution_types?.[0] ?? ''] ?? description);
|
||||
}
|
||||
const products = (p.products ?? [])
|
||||
.filter((x) => x.availability !== 'closed')
|
||||
.map((x) => ({ title: x.title, detail: x.instrument?.trim() ?? '' }));
|
||||
.map((x) => ({
|
||||
title: x.title.startsWith(p.title + ' — ')
|
||||
? x.title.slice(p.title.length + 3)
|
||||
: x.title,
|
||||
detail: x.instrument?.trim() ?? '',
|
||||
url: x.contact_url || x.source_url || null,
|
||||
}));
|
||||
return {
|
||||
description,
|
||||
products,
|
||||
@@ -73,3 +98,74 @@ export function fundingPublicPresentation(p: PublicFunding) {
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
const normal = (s: string) =>
|
||||
s
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, ' ')
|
||||
.trim();
|
||||
export function publicInstitutionContacts<
|
||||
T extends { kind: string; value: string },
|
||||
>(rows: T[]) {
|
||||
const seen = new Set<string>();
|
||||
return rows.flatMap((row) => {
|
||||
const value =
|
||||
row.kind === 'phone'
|
||||
? row.value.replace(/\s*Não encontrado\.?$/i, '').trim()
|
||||
: row.value.trim();
|
||||
if (!value) return [];
|
||||
const key =
|
||||
row.kind +
|
||||
':' +
|
||||
(row.kind === 'phone'
|
||||
? value.replace(/\D/g, '')
|
||||
: value.toLowerCase().replace(/\/$/, ''));
|
||||
if (seen.has(key)) return [];
|
||||
seen.add(key);
|
||||
return [{ ...row, value }];
|
||||
});
|
||||
}
|
||||
export function publicInstitutionLocations<
|
||||
T extends {
|
||||
role: string;
|
||||
address?: string | null;
|
||||
location_text?: string;
|
||||
territory_path?: { name: string }[];
|
||||
},
|
||||
>(rows: T[]) {
|
||||
const result: T[] = [];
|
||||
for (const row of [...rows].sort(
|
||||
(a, b) =>
|
||||
(a.role === 'headquarters' ? 0 : 1) -
|
||||
(b.role === 'headquarters' ? 0 : 1),
|
||||
)) {
|
||||
if (!row.address?.trim()) continue;
|
||||
const address = normal(row.address);
|
||||
const duplicate = result.some((previous) => {
|
||||
const other = normal(previous.address ?? '');
|
||||
if (address === other) return true;
|
||||
const short = address.length < other.length ? address : other,
|
||||
long = address.length < other.length ? other : address;
|
||||
if (!long.startsWith(short + ' ')) return false;
|
||||
const rest = long.slice(short.length).trim();
|
||||
const localities = [
|
||||
row.location_text ?? '',
|
||||
previous.location_text ?? '',
|
||||
...(row.territory_path ?? []).map((x) => x.name),
|
||||
...(previous.territory_path ?? []).map((x) => x.name),
|
||||
].map(normal);
|
||||
return (
|
||||
localities.includes(rest) ||
|
||||
localities.some(
|
||||
(x) =>
|
||||
x.replace(/^cidade de /, '') ===
|
||||
rest.replace(/^cidade de /, ''),
|
||||
)
|
||||
);
|
||||
});
|
||||
if (!duplicate) result.push(row);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -478,40 +478,41 @@ export function portalNavigation(access: PortalNavAccess): PortalNavItem[] {
|
||||
: null)
|
||||
: null;
|
||||
return uniqueNavigationDestinations([
|
||||
...(access.procurement
|
||||
? [
|
||||
{
|
||||
id: 'procurement-area',
|
||||
label: 'Concursos e anúncios',
|
||||
children: [
|
||||
link(
|
||||
'procurement',
|
||||
'Consultar concursos e anúncios',
|
||||
'/concursos',
|
||||
),
|
||||
...(access.authenticated
|
||||
? [
|
||||
link(
|
||||
'procurement-watched',
|
||||
'Os concursos que acompanho',
|
||||
'/concursos/acompanhar',
|
||||
),
|
||||
]
|
||||
: []),
|
||||
],
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
id: 'discovery',
|
||||
label: 'Descoberta',
|
||||
children: [
|
||||
...(access.procurement
|
||||
? [
|
||||
{
|
||||
id: 'procurement-area',
|
||||
label: 'Concursos e anúncios',
|
||||
children: [
|
||||
link(
|
||||
'procurement',
|
||||
'Consultar concursos e anúncios',
|
||||
'/concursos',
|
||||
),
|
||||
...(access.authenticated
|
||||
? [
|
||||
link(
|
||||
'procurement-watched',
|
||||
'Os concursos que acompanho',
|
||||
'/concursos/acompanhar',
|
||||
),
|
||||
]
|
||||
: []),
|
||||
],
|
||||
},
|
||||
]
|
||||
: []),
|
||||
|
||||
link('locations', 'Localizações', '/oportunidades?view=map'),
|
||||
...(access.funding
|
||||
? [
|
||||
link(
|
||||
'funding',
|
||||
'Instituições financeiras e seguros',
|
||||
'Instituições financeiras',
|
||||
'/fundos',
|
||||
),
|
||||
...(access.authenticated
|
||||
@@ -580,7 +581,7 @@ export function portalNavigation(access: PortalNavAccess): PortalNavItem[] {
|
||||
id: 'support',
|
||||
label: 'Suporte',
|
||||
children: [
|
||||
link('documents', 'Biblioteca de documentos', '/documentos'),
|
||||
link('documents', 'Biblioteca', '/documentos'),
|
||||
link('legislation', 'Legislação', '/legislacao'),
|
||||
link(
|
||||
'services',
|
||||
|
||||
Reference in New Issue
Block a user