gendesign/frontend/src/components/site-finder/analysis/PoiList2Gis.tsx
Light1YT 86e9ea2937 fix(week-review): автофиксы код-ревью — 169 issue (label «week ревью 1»)
Многоагентный аудит + имплементация: один воркер на файл, точечные правки.
Верификация: py_compile (47/47 .py) + tsc --noEmit (0 ошибок). Unit-тесты
не прогонялись (окружение не поднято: rollup native dep / нет pytest-venv).

Полностью исправлено (169): #1336, #1337, #1339, #1340, #1341, #1342, #1343, #1345, #1346, #1348, #1349, #1350, #1351, #1354, #1356, #1358, #1359, #1360, #1362, #1364, #1365, #1366, #1367, #1368, #1369, #1370, #1371, #1372, #1373, #1374, #1375, #1376, #1377, #1378, #1379, #1380, #1381, #1382, #1384, #1385, #1386, #1387, #1388, #1389, #1390, #1391, #1392, #1394, #1395, #1396, #1397, #1399, #1400, #1401, #1402, #1403, #1404, #1408, #1409, #1410, #1411, #1412, #1413, #1414, #1415, #1416, #1417, #1418, #1420, #1423, #1425, #1426, #1427, #1428, #1429, #1430, #1431, #1432, #1433, #1434, #1435, #1437, #1438, #1439, #1440, #1441, #1442, #1443, #1444, #1445, #1446, #1447, #1448, #1449, #1450, #1451, #1452, #1453, #1454, #1455, #1456, #1457, #1458, #1459, #1460, #1461, #1462, #1463, #1464, #1465, #1466, #1467, #1468, #1469, #1471, #1472, #1473, #1474, #1476, #1478, #1479, #1481, #1482, #1483, #1484, #1485, #1487, #1488, #1489, #1490, #1491, #1492, #1493, #1494, #1495, #1496, #1497, #1499, #1500, #1501, #1502, #1504, #1505, #1506, #1507, #1510, #1514, #1515, #1516, #1517, #1518, #1519, #1521, #1522, #1523, #1524, #1525, #1526, #1527, #1528, #1529, #1531, #1532, #1533, #1534, #1535, #1536, #1537, #1538

Частично (9, in-file часть, остаток cross-file): #1361, #1419, #1422, #1424, #1470, #1475, #1477, #1480, #1498
Требуют cross-file (3, не тронуты): #1338, #1363, #1421
Пропущено (1): #1539

Не входило в партию: 22 needs-Leha issue (нужны решения владельца).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-15 20:21:11 +05:00

228 lines
7.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* PoiList2Gis — top-7 POI list with weighted score.
* Category icons: Lucide Train / TreePine / GraduationCap / Baby /
* ShoppingBag / Hospital / Banknote
* Per row: icon + name + distance + weight badge.
*/
import {
Train,
TreePine,
GraduationCap,
Baby,
ShoppingBag,
Hospital,
Banknote,
MapPin,
} from "lucide-react";
import type { ReactNode } from "react";
import { Badge } from "@/components/ui/Badge";
import type { PoiScoreItem } from "@/lib/site-finder-api";
// ── Icon mapping ──────────────────────────────────────────────────────────────
const CATEGORY_ICONS: Record<string, ReactNode> = {
metro_stop: <Train size={16} strokeWidth={1.5} />,
tram_stop: <Train size={16} strokeWidth={1.5} />,
bus_stop: <Train size={16} strokeWidth={1.5} />,
park: <TreePine size={16} strokeWidth={1.5} />,
school: <GraduationCap size={16} strokeWidth={1.5} />,
kindergarten: <Baby size={16} strokeWidth={1.5} />,
shop_mall: <ShoppingBag size={16} strokeWidth={1.5} />,
shop_supermarket: <ShoppingBag size={16} strokeWidth={1.5} />,
shop_small: <ShoppingBag size={16} strokeWidth={1.5} />,
hospital: <Hospital size={16} strokeWidth={1.5} />,
pharmacy: <Hospital size={16} strokeWidth={1.5} />,
bank: <Banknote size={16} strokeWidth={1.5} />,
};
const CATEGORY_LABELS: Record<string, string> = {
metro_stop: "Метро",
tram_stop: "Трамвай",
bus_stop: "Автобус",
park: "Парк",
school: "Школа",
kindergarten: "Детский сад",
shop_mall: "ТЦ",
shop_supermarket: "Супермаркет",
shop_small: "Магазин",
hospital: "Больница",
pharmacy: "Аптека",
bank: "Банк",
};
function weightBadgeVariant(
weight: number,
): "success" | "info" | "neutral" | "warning" {
if (weight >= 0.2) return "success";
if (weight >= 0.12) return "info";
if (weight >= 0.08) return "neutral";
return "warning";
}
// ── Props ─────────────────────────────────────────────────────────────────────
interface Props {
items: PoiScoreItem[];
totalScore: number;
}
// ── Component ─────────────────────────────────────────────────────────────────
export function PoiList2Gis({ items, totalScore }: Props) {
// POI-weighted score is presented as «X / 100», so clamp to 0..100 defensively:
// the adapter sums round(weight*100) per POI без нормировки и при достаточном
// числе POI может выдать >100 → бессмысленное «137 / 100» (#1470). Корневую
// нормировку нужно чинить в site-finder-api.ts (useParcelPoiScoreQuery).
const displayScore = Math.min(100, Math.max(0, totalScore));
// Top-7, sorted by score_contribution desc
const top7 = [...items]
.sort((a, b) => b.score_contribution - a.score_contribution)
.slice(0, 7);
if (top7.length === 0) {
return (
<div
style={{
padding: "20px 16px",
color: "var(--fg-tertiary)",
fontSize: 13,
textAlign: "center",
border: "1px solid var(--border-card)",
borderRadius: 12,
}}
>
POI данные недоступны
</div>
);
}
return (
<div
style={{
border: "1px solid var(--border-card)",
borderRadius: 12,
overflow: "hidden",
background: "var(--bg-card)",
}}
>
{/* Header */}
<div
style={{
padding: "10px 16px",
borderBottom: "1px solid var(--border-soft)",
display: "flex",
alignItems: "center",
justifyContent: "space-between",
}}
>
<span
style={{
fontSize: 12,
fontWeight: 500,
textTransform: "uppercase",
letterSpacing: "0.04em",
color: "var(--fg-tertiary)",
}}
>
POI · 2ГИС / OSM
</span>
<span
style={{
fontSize: 13,
fontWeight: 700,
color: "var(--accent)",
fontVariantNumeric: "tabular-nums",
}}
>
{displayScore.toFixed(0)} / 100
</span>
</div>
{/* List */}
<ul style={{ listStyle: "none", margin: 0, padding: 0 }}>
{top7.map((item, i) => {
const icon = CATEGORY_ICONS[item.category] ?? (
<MapPin size={16} strokeWidth={1.5} />
);
const categoryLabel = CATEGORY_LABELS[item.category] ?? item.category;
const isLast = i === top7.length - 1;
return (
<li
key={`${item.category}-${i}`}
style={{
display: "flex",
alignItems: "center",
gap: 12,
padding: "10px 16px",
borderBottom: isLast ? "none" : "1px solid var(--border-soft)",
background:
i % 2 === 0 ? "var(--bg-card)" : "var(--bg-card-alt)",
}}
>
{/* Icon */}
<span
style={{
color: "var(--accent)",
flexShrink: 0,
display: "flex",
alignItems: "center",
}}
aria-label={categoryLabel}
>
{icon}
</span>
{/* Name + category */}
<div style={{ flex: 1, minWidth: 0 }}>
<div
style={{
fontSize: 13,
fontWeight: 500,
color: "var(--fg-primary)",
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
}}
>
{item.name}
</div>
<div
style={{
fontSize: 11,
color: "var(--fg-tertiary)",
marginTop: 1,
}}
>
{categoryLabel}
</div>
</div>
{/* Distance */}
<span
style={{
fontSize: 12,
color: "var(--fg-secondary)",
fontVariantNumeric: "tabular-nums",
flexShrink: 0,
whiteSpace: "nowrap",
}}
>
{item.distance_m < 1000
? `${Math.round(item.distance_m)} м`
: `${(item.distance_m / 1000).toFixed(1)} км`}
</span>
{/* Weight badge */}
<Badge variant={weightBadgeVariant(item.weight)} size="sm">
×{item.weight.toFixed(2)}
</Badge>
</li>
);
})}
</ul>
</div>
);
}