varias alteracoes

This commit is contained in:
2026-09-29 08:41:57 +02:00
parent b77714b156
commit 2e0217b486
51 changed files with 2605 additions and 270 deletions
+131 -109
View File
@@ -1,5 +1,8 @@
import { Link, router, useForm, usePage } from "@inertiajs/react";
import { useEffect, useState } from "react";
import { useEffect, useRef, useState } from "react";
import Map from "@/components/interactive-investment-map";
import { TerritoryLevel, type TerritoryOption } from "@/components/investment-territory";
import { MATURITY_LEVELS } from "@/lib/investment-maturity";
import { Frame, Field, input, button, card, money, api, groupLabels } from "./shared";
import type { Opportunity, References } from "./shared";
@@ -13,6 +16,7 @@ export default function Catalogue({
results,
favourites,
territorial,
territorySelection,
}: {
filters: Record<string, string | string[] | boolean>;
references: References;
@@ -23,6 +27,7 @@ export default function Catalogue({
next_page_url: string | null;
};
favourites: number[];
territorySelection: TerritoryOption[];
territorial: {
id: string;
title: string;
@@ -40,6 +45,10 @@ export default function Catalogue({
sector: String(filters.sector ?? ""),
province: String(filters.province ?? ""),
district: String(filters.district ?? ""),
province_id: String(filters.province_id ?? ""),
district_id: String(filters.district_id ?? ""),
admin_post_id: String(filters.admin_post_id ?? ""),
locality_id: String(filters.locality_id ?? ""),
cluster_id: String(filters.cluster_id ?? ""),
zee_id: String(filters.zee_id ?? ""),
zfi_id: String(filters.zfi_id ?? ""),
@@ -53,19 +62,49 @@ export default function Catalogue({
currency: String(filters.currency ?? ""),
maturity_level: String(filters.maturity_level ?? ""),
before: String(filters.before ?? ""),
sort: String(filters.sort ?? "recent"),
sort: typeof filters.sort === "string" ? filters.sort : "recent",
facets: (Array.isArray(filters.facets) ? filters.facets : []).map(Number),
});
const view = String(filters.view ?? "grid");
const [territoryPath, setTerritoryPath] = useState(territorySelection);
const [saved, setSaved] = useState(favourites);
const [selected, setSelected] = useState<number[]>([]);
const [comparison, setComparison] = useState<{ record: Opportunity }[]>([]);
const [points, setPoints] = useState<Feature[] | null>(null);
const [unlocated, setUnlocated] = useState<
{ id: number; title: string; location: string; url: string }[]
>([]);
const [truncated, setTruncated] = useState(false);
const [error, setError] = useState("");
const [suggestions, setSuggestions] = useState<{ title: string; slug: string }[]>([]);
const filterKey = JSON.stringify(filters);
const draftFilterKey = JSON.stringify(form.data);
const lastRequest = useRef(draftFilterKey);
useEffect(() => {
if (draftFilterKey === lastRequest.current) return;
let cancel: (() => void) | undefined;
const timer = setTimeout(() => {
const data = JSON.parse(draftFilterKey);
lastRequest.current = draftFilterKey;
router.get(
"/oportunidades",
{ ...data, education: data.education ? 1 : 0 },
{
preserveState: true,
preserveScroll: true,
replace: true,
onCancelToken: (token) => {
cancel = () => token.cancel();
},
},
);
}, 350);
return () => {
clearTimeout(timer);
cancel?.();
};
}, [draftFilterKey]);
useEffect(() => {
if (view !== "map" && view !== "combined") return;
let active = true;
const values = JSON.parse(filterKey) as Record<string, string | string[] | boolean>;
const params = new URLSearchParams();
@@ -75,10 +114,16 @@ export default function Catalogue({
params.set(key, String(value === true ? 1 : value === false ? 0 : value));
}
setPoints(null);
setUnlocated([]);
setTruncated(false);
setError("");
api(`/api/v1/investment/map?${params}`)
.then((data) => {
if (active) setPoints(data.features);
if (active) {
setPoints(data.features);
setUnlocated(data.unlocated ?? []);
setTruncated(Boolean(data.truncated));
}
})
.catch(() => {
if (active)
@@ -166,6 +211,7 @@ export default function Catalogue({
setPoints(null);
setComparison([]);
setSelected([]);
form.transform((data) => ({ ...data, education: data.education ? 1 : 0 }));
form.get("/oportunidades", { preserveState: true });
}}
>
@@ -218,39 +264,30 @@ export default function Catalogue({
</select>
</Field>
))}
{(["clusters", "corridors", "projects", "locations"] as const).map(
(group, i) => {
const key = (
[
"cluster_id",
"corridor_id",
"project_id",
"geo_location_id",
] as const
)[i];
return (
<Field
key={group}
label={
["Cluster", "Corredor", "Projecto âncora", "Localização"][i]
}
{(["clusters", "corridors", "projects"] as const).map((group, i) => {
const key = (
["cluster_id", "corridor_id", "project_id", "geo_location_id"] as const
)[i];
return (
<Field
key={group}
label={["Cluster", "Corredor", "Projecto âncora", "Localização"][i]}
>
<select
className={input}
value={form.data[key]}
onChange={(e) => form.setData(key, e.target.value)}
>
<select
className={input}
value={form.data[key]}
onChange={(e) => form.setData(key, e.target.value)}
>
<option value="">Todos</option>
{references[group].map((r) => (
<option value={r.id} key={r.id}>
{r.name}
</option>
))}
</select>
</Field>
);
},
)}
<option value="">Todos</option>
{references[group].map((r) => (
<option value={r.id} key={r.id}>
{r.name}
</option>
))}
</select>
</Field>
);
})}
<Field label="Sector">
<select
className={input}
@@ -265,16 +302,34 @@ export default function Catalogue({
))}
</select>
</Field>
{(["province", "district"] as const).map((key) => (
<Field key={key} label={key === "province" ? "Província" : "Distrito"}>
<input
className={input}
value={form.data[key]}
onChange={(e) => form.setData(key, e.target.value)}
maxLength={100}
{(["province_id", "district_id", "admin_post_id", "locality_id"] as const).map(
(key, index) => (
<TerritoryLevel
key={`${key}-${territoryPath[index - 1]?.id ?? ""}`}
index={index}
parent={territoryPath[index - 1]?.id ?? ""}
selected={territoryPath[index]}
endpoint="/api/v1/investment/territory-options"
onChange={(value) => {
const path = [
...territoryPath.slice(0, index),
...(value ? [value] : []),
];
setTerritoryPath(path);
form.setData((data) => ({
...data,
province: "",
district: "",
geo_location_id: "",
province_id: path[0]?.id ?? "",
district_id: path[1]?.id ?? "",
admin_post_id: path[2]?.id ?? "",
locality_id: path[3]?.id ?? "",
}));
}}
/>
</Field>
))}
),
)}
<Field label="Estado de preparação">
<select
className={input}
@@ -282,9 +337,9 @@ export default function Catalogue({
onChange={(e) => form.setData("maturity_level", e.target.value)}
>
<option value="">Todos os níveis</option>
{[1, 2, 3, 4, 5, 6].map((n) => (
<option key={n} value={n}>
Maturidade {n}
{MATURITY_LEVELS.map((label, index) => (
<option key={index + 1} value={index + 1}>
{label}
</option>
))}
</select>
@@ -434,7 +489,34 @@ export default function Catalogue({
</Link>
</div>
{error && <p role="alert">{error}</p>}
{(view === "map" || view === "combined") && !error && <Map points={points} />}
{!error && <Map points={points} />}
{truncated && (
<p role="alert">
O mapa atingiu o limite de 1.000 registos; refine os filtros. A cobertura não
está completa.
</p>
)}
{unlocated.length > 0 && (
<section className={card} aria-label="Investimentos a georreferenciar">
<h2 className="text-xl font-bold">
{unlocated.length} investimentos sem coordenadas de local confirmadas
</h2>
<p>
Continuam nos resultados. Seleccionar uma província não determina a posição
exacta do investimento.
</p>
<ul>
{unlocated.map((record) => (
<li key={record.id}>
<Link href={record.url} className="underline">
{record.title}
</Link>{" "}
— {record.location || "Localização por completar"}
</li>
))}
</ul>
</section>
)}
{(view !== "map" || error || points?.length === 0) && (
<div
className={
@@ -583,63 +665,3 @@ export default function Catalogue({
</Frame>
);
}
function Map({ points }: { points: Feature[] | null }) {
if (points === null) return <p role="status">A carregar localizações…</p>;
if (!points.length)
return (
<p className={card}>
Sem coordenadas públicas associadas aos resultados. Não são atribuídas localizações
aproximadas.
</p>
);
const xs = points.map((p) => p.geometry.coordinates[0]),
ys = points.map((p) => p.geometry.coordinates[1]);
const minX = Math.min(...xs) - 0.1,
maxX = Math.max(...xs) + 0.1,
minY = Math.min(...ys) - 0.1,
maxY = Math.max(...ys) + 0.1;
return (
<section className={card}>
<h2 className="text-xl font-bold">Localizações georreferenciadas</h2>
<p>
Coordenadas WGS84 publicadas, sem mapa base externo. Até 1.000 pontos; a lista
acessível apresenta os mesmos dados.
</p>
<svg
viewBox="0 0 900 400"
role="img"
aria-label="Distribuição das localizações por longitude e latitude"
className="my-4 w-full rounded bg-sky-50"
>
<path d="M30 10 V370 H880" fill="none" stroke="#475569" />
{points.map((p, i) => (
<a
key={`${p.properties.id}-${i}`}
href={p.properties.url}
aria-label={`${p.properties.title}, ${p.properties.location}`}
>
<circle
cx={45 + ((p.geometry.coordinates[0] - minX) / (maxX - minX)) * 810}
cy={350 - ((p.geometry.coordinates[1] - minY) / (maxY - minY)) * 310}
r="8"
fill="#065f46"
>
<title>{p.properties.title}</title>
</circle>
</a>
))}
</svg>
<ul className="space-y-2">
{points.map((p, i) => (
<li key={i}>
<Link className="underline" href={p.properties.url}>
{p.properties.title}
</Link>{" "}
— {p.properties.location}; longitude {p.geometry.coordinates[0]}, latitude{" "}
{p.geometry.coordinates[1]}
</li>
))}
</ul>
</section>
);
}
+5
View File
@@ -1,5 +1,6 @@
import { Link, router, usePage } from "@inertiajs/react";
import { useState } from "react";
import InvestmentMapPanel from "@/components/investment-map-panel";
import { Frame, card, button, money, groupLabels } from "./shared";
import type { Opportunity, Context } from "./shared";
export default function Detail({
@@ -19,6 +20,10 @@ export default function Detail({
{r.reference} · {r.sector?.name} · {r.province} {r.district}
</p>
<p className="text-xl">{r.summary}</p>
<InvestmentMapPanel filters={{ opportunity_id: r.id }} />
{c.primary_territory_path && c.primary_territory_path.length > 0 && (
<p>Localização: {c.primary_territory_path.map((node) => node.name).join(" → ")}</p>
)}
<div className="flex flex-wrap gap-4">
{auth.user ? (
<button
+1
View File
@@ -40,6 +40,7 @@ export type Opportunity = {
status: string;
};
export type Context = {
primary_territory_path?: { id: string; name: string; location_type: string }[];
zones?: {
id: string;
name: string;
+14 -4
View File
@@ -1,4 +1,6 @@
import { Link, router, useForm } from "@inertiajs/react";
import InvestmentTerritory from "@/components/investment-territory";
import InvestmentMapPanel from "@/components/investment-map-panel";
import { useState } from "react";
import { Frame, Field, input, button, card, api } from "./shared";
import ZoneRelations from "./zone-relations";
@@ -91,8 +93,6 @@ function Editor({
name_en: z.name_en ?? "",
description: z.description ?? "",
description_en: z.description_en ?? "",
province: z.province ?? "",
district: z.district ?? "",
operator_id: z.operator_id ?? "",
legal_source_id: z.legal_source_id ?? "",
});
@@ -153,8 +153,6 @@ function Editor({
["code", "Código"],
["name", "Nome PT"],
["name_en", "Nome EN"],
["province", "Província"],
["district", "Distrito"],
] as const
).map(([key, label]) => (
<Field key={key} label={label}>
@@ -484,6 +482,18 @@ function Editor({
</section>
</>
)}
{management && <InvestmentTerritory kind="zones" id={z.id} />}
{!management && ["zee", "zfi", "industrial_park"].includes(z.category) && (
<InvestmentMapPanel
filters={{
[z.category === "zee"
? "zee_id"
: z.category === "zfi"
? "zfi_id"
: "park_id"]: z.id,
}}
/>
)}
</Frame>
);
}
+5
View File
@@ -1,5 +1,6 @@
import { Link, router } from "@inertiajs/react";
import { useState } from "react";
import { TerritoryFields, type TerritoryOption } from "@/components/investment-territory";
import { Frame, Field, input, button, card, api } from "./shared";
type Zone = {
@@ -17,6 +18,7 @@ export default function Zones({
records,
filters,
management,
territorySelection = [],
}: {
records: {
data: Zone[];
@@ -26,6 +28,7 @@ export default function Zones({
};
filters: { q?: string; category?: string };
management: boolean;
territorySelection?: TerritoryOption[];
}) {
const [error, setError] = useState("");
const [busy, setBusy] = useState(false);
@@ -56,6 +59,7 @@ export default function Zones({
<option value="industrial_park">Parque industrial</option>
</select>
</Field>
<TerritoryFields initial={territorySelection} />
<button className={button}>Pesquisar</button>
</form>
<p role="status">{records.total} registos disponíveis</p>
@@ -115,6 +119,7 @@ export default function Zones({
}}
>
<h2 className="text-xl font-bold">Criar rascunho</h2>
<TerritoryFields />
<Field label="Código">
<input name="code" className={input} required maxLength={80} />
</Field>