Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 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 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 | 3x 3x 3x 3x 3x 701x 292x 292x 292x 292x 292x 65x 65x 65x 292x 65x 65x 292x 292x 65x 65x 292x 292x 292x 292x 65x 65x 230x 65x 96x 447x 447x 447x 447x 447x 447x 447x 447x 447x 93x 447x 447x 447x 447x 447x 447x 447x 447x 447x 447x 447x 447x 447x 447x 447x 447x 447x 447x 447x 447x 447x 447x 447x 93x 93x 93x 93x 447x 93x 93x 93x 93x 93x 93x 93x 65x 65x 65x 65x 65x 65x 65x 292x 292x 65x 65x 65x 292x 65x 65x 65x 65x 5x 5x 5x 447x 158x 4x 4x 19x 4x 3x 3x 3x 3x 447x 93x 93x 93x 447x 93x 94x 93x 93x 93x 447x 93x 93x 93x 447x 93x 93x 93x 93x 93x 447x 122x 28x 28x 447x 158x 158x 158x 447x 122x 13x 13x 122x 447x 125x 94x 94x 31x 31x 31x 31x 31x 31x 447x 190x 182x 31x 31x 120x 120x 120x 27x 27x 93x 23x 23x 31x 447x 447x 27x 27x 27x 27x 27x 27x 447x 447x 447x 447x 447x 447x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 1x 1x 1x 1x 1x 5x 4x 4x 4x 4x 4x 4x 4x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 4x 4x 4x 4x 4x 4x 4x 4x 5x 447x 3x 3x 3x 3x 2x 2x 3x 3x 2x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 447x 2220x 444x 444x 2664x 2664x 2664x 1776x 2664x 2220x 2220x 2220x 1x 1x 1x 142x 133x 133x 76x 2x 142x 123x 123x 66x | "use client";
import { fetchApi } from "@/lib/api";
import { themeChangeTarget } from "@/components/ThemeToggle";
import { Suspense, useCallback, useEffect, useRef, useState } from "react";
import { useSearchParams } from "next/navigation";
import { useSession, signIn } from "next-auth/react";
import { derivePersonaId, DEMO_PERSONAS } from "@/lib/auth";
import { useDemoPersona, setDemoPersona } from "@/lib/use-demo-persona";
const IS_STATIC = process.env.NEXT_PUBLIC_STATIC_EXPORT === "true";
import dynamic from "next/dynamic";
import {
Activity,
ArrowDownLeft,
ArrowUpRight,
BarChart2,
BookOpen,
Building2,
Check,
ChevronLeft,
ChevronRight,
Copy,
Database,
ExternalLink,
Eye,
FlaskConical,
Heart,
Lock,
Loader2,
MousePointerClick,
PanelLeftClose,
PanelRightClose,
Scale,
Settings,
ShieldCheck,
Users,
X,
} from "lucide-react";
import type { LucideProps } from "lucide-react";
import {
FILTER_PRESETS,
FILTER_PRESET_PERSONA,
PATIENT_FILTER_PRESETS,
HOSPITAL_FILTER_PRESETS,
HDAB_FILTER_PRESETS,
RESEARCHER_FILTER_PRESETS,
LAYER_COLORS,
LAYER_LABELS,
LAYER_TOOLTIPS,
NODE_ROLE_COLORS,
NODE_DISPLAY_NAMES,
NODE_TOOLTIPS,
PERSONA_VIEWS,
PERSONA_LAYER_LABELS,
PERSONA_VALUE_NODES,
PERSONA_RING_ASSIGNMENT,
RING_RADII,
type FilterPresetId,
type PatientFilterPresetId,
type HospitalFilterPresetId,
type HdabFilterPresetId,
type ResearcherFilterPresetId,
type PersonaId,
} from "@/lib/graph-constants";
const ForceGraph2D = dynamic(() => import("react-force-graph-2d"), {
ssr: false,
});
// ── Types ────────────────────────────────────────────────────────────────────
interface GraphNode {
id: string;
name: string;
label: string;
layer: number;
color: string;
group?: string;
expandable?: boolean;
expanded?: boolean;
isValueCenter?: boolean;
x?: number;
y?: number;
fx?: number;
fy?: number;
}
interface GraphLink {
source: string | GraphNode;
target: string | GraphNode;
type: string;
}
interface GraphData {
nodes: GraphNode[];
links: GraphLink[];
}
// ── Constants ────────────────────────────────────────────────────────────────
// Role-specific color legend entries (warm/vivid — shown below structural layers)
const ROLE_LEGEND: Array<{
label: string;
color: string;
description: string;
tooltip: string;
}> = [
{
label: "Organization",
color: NODE_ROLE_COLORS.Participant,
description: "Hospital, researcher, or authority",
tooltip: "DSP Participant — a registered dataspace actor",
},
{
label: "Privacy Service",
color: NODE_ROLE_COLORS.TrustCenter,
description: "Manages pseudonyms for research",
tooltip: "EHDS Art. 50/51 — Trust Center pseudonym authority",
},
{
label: "Access Decision",
color: NODE_ROLE_COLORS.HDABApproval,
description: "Approval to use health data",
tooltip: "EHDS Art. 46 — HDAB access decision",
},
{
label: "Secure Processing",
color: NODE_ROLE_COLORS.SPESession,
description: "Active data processing session",
tooltip: "EHDS Art. 50 — Secure Processing Environment",
},
{
label: "My Consent",
color: NODE_ROLE_COLORS.PatientConsent,
description: "Patient consent for data use",
tooltip: "GDPR Art. 15-22 — patient consent for secondary use",
},
];
// User-friendly relationship type names (replaces UPPER_SNAKE_CASE on links)
const FRIENDLY_REL_NAMES: Record<string, string> = {
HAS_CONDITION: "has condition",
HAS_OBSERVATION: "has observation",
HAS_ENCOUNTER: "has encounter",
HAS_MEDICATION_REQUEST: "takes medication",
HAS_PROCEDURE: "had procedure",
CODED_BY: "coded as",
MAPS_TO: "maps to",
HAS_DISTRIBUTION: "available as",
HAS_CONTRACT: "under contract",
OFFERS: "offers",
GOVERNED_BY: "governed by",
APPROVED_BY: "approved by",
SUBJECT_TO: "subject to",
APPLIED_BY: "applied by",
DESCRIBES: "describes",
CONFORMS_TO: "conforms to",
COVERS: "covers",
UNDER: "under",
MANAGES: "manages",
RESOLVES_PSEUDONYMS_FOR: "resolves pseudonyms",
MUTUALLY_RECOGNISES: "recognises",
LINKED_FROM: "linked from",
USED_IN: "used in",
HAS_CONDITION_OCCURRENCE: "has condition",
HAS_MEASUREMENT: "has measurement",
HAS_DRUG_EXPOSURE: "takes drug",
HAS_PROCEDURE_OCCURRENCE: "had procedure",
HAS_VISIT_OCCURRENCE: "visited",
REQUESTED_BY: "requested by",
PROVIDED_BY: "provided by",
PART_OF: "part of",
ACCESSED: "accessed",
TRANSFERRED_BY: "transferred by",
TRANSFERS: "transfers",
FROM_PROVIDER: "from provider",
TO_CONSUMER: "to consumer",
VALUE_FOCUS: "focus",
};
// Icon map for filter presets
type LucideIcon = React.ForwardRefExoticComponent<
Omit<LucideProps, "ref"> & React.RefAttributes<SVGSVGElement>
>;
const PRESET_ICONS: Record<string, LucideIcon> = {
// filter preset icons
Users,
Lock,
ShieldCheck,
BookOpen,
Activity,
BarChart2,
// patient filter preset icons
Eye,
FlaskConical,
Heart,
// persona icons
Building2,
Settings,
Scale,
};
// ── Helpers ──────────────────────────────────────────────────────────────────
function nId(n: string | GraphNode): string {
return typeof n === "string" ? n : n.id;
}
/** Compute fixed position on a concentric ring, persona-aware. */
function ringPosition(
label: string,
idx: number,
total: number,
persona: PersonaId,
) {
const ring = PERSONA_RING_ASSIGNMENT[persona]?.[label] ?? 4; // fallback to outermost
const r = RING_RADII[ring] ?? 580;
Iif (r === 0) return { fx: 0, fy: 0 }; // value center
const angle = (2 * Math.PI * idx) / Math.max(total, 1);
return { fx: r * Math.cos(angle), fy: r * Math.sin(angle) };
}
function mergeInto(
prev: GraphData,
newNodes: GraphNode[],
newLinks: GraphLink[],
persona: PersonaId,
): GraphData {
const existingIds = new Set(prev.nodes.map((n) => n.id));
// Count per ring for existing nodes (angle offset base)
const ringCount: Record<number, number> = {};
for (const n of prev.nodes) {
const ring = PERSONA_RING_ASSIGNMENT[persona]?.[n.label] ?? 4;
ringCount[ring] = (ringCount[ring] ?? 0) + 1;
}
const incoming = newNodes.filter((n) => !existingIds.has(n.id));
// Pre-compute final total per ring so every node gets an even angular slot
const ringTotal: Record<number, number> = { ...ringCount };
for (const n of incoming) {
const ring = PERSONA_RING_ASSIGNMENT[persona]?.[n.label] ?? 4;
ringTotal[ring] = (ringTotal[ring] ?? 0) + 1;
}
const toAdd: GraphNode[] = [];
for (const n of incoming) {
const ring = PERSONA_RING_ASSIGNMENT[persona]?.[n.label] ?? 4;
const idx = ringCount[ring] ?? 0;
ringCount[ring] = idx + 1;
toAdd.push({
...n,
// Apply client-side color if missing from API/mock
color:
n.color || NODE_ROLE_COLORS[n.label] || LAYER_COLORS[n.layer] || "#888",
...ringPosition(n.label, idx, ringTotal[ring]!, persona),
});
}
const existingLinkKeys = new Set(
prev.links.map((l) => `${nId(l.source)}→${nId(l.target)}`),
);
const linksToAdd = newLinks.filter(
(l) => !existingLinkKeys.has(`${nId(l.source)}→${nId(l.target)}`),
);
return {
nodes: [...prev.nodes, ...toAdd],
links: [...prev.links, ...linksToAdd],
};
}
// ── Page ─────────────────────────────────────────────────────────────────────
export default function GraphPage() {
return (
<Suspense
fallback={
<div className="flex h-[calc(100vh-44px)] items-center justify-center text-[var(--text-secondary)]">
<Loader2 size={16} className="mr-2 animate-spin" />
Loading…
</div>
}
>
<GraphContent />
</Suspense>
);
}
function GraphContent() {
// Read URL params first so they can seed initial state
const searchParams = useSearchParams();
const highlightId = searchParams.get("highlight");
const urlPersona = searchParams.get("persona") as PersonaId | null;
const { data: session, status: sessionStatus } = useSession();
// Always call useDemoPersona — hook rules require unconditional calls
const demoPersona = useDemoPersona();
const sessionRoles: string[] = IS_STATIC
? demoPersona
? [...demoPersona.roles]
: []
: (session as { roles?: string[] } | null)?.roles ?? [];
const sessionUsername: string = IS_STATIC
? demoPersona?.username ?? ""
: session?.user?.name ?? session?.user?.email ?? "";
const sessionPersonaId = derivePersonaId(sessionRoles, sessionUsername);
// Sync URL ?persona= to sessionStorage so Navigation/UserMenu reflect the
// correct persona. Without this, the graph fetches the right data but the
// nav still shows the old persona (e.g. "Patient / Citizen" instead of
// "EDC / Dataspace Admin").
useEffect(() => {
Eif (!IS_STATIC || !urlPersona) return;
const match = DEMO_PERSONAS.find((p) => p.personaId === urlPersona);
if (match) setDemoPersona(match.username);
}, [urlPersona]);
const [data, setData] = useState<GraphData>({ nodes: [], links: [] });
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [selected, setSelected] = useState<GraphNode | null>(null);
const [expanding, setExpanding] = useState<string | null>(null); // nodeId being expanded
const [expandedIds, setExpandedIds] = useState<Set<string>>(new Set());
const [neighbours, setNeighbours] = useState<
{ dir: "in" | "out"; type: string; node: GraphNode }[]
>([]);
// Node properties fetched from /api/graph/node for the selected node
const [nodeProps, setNodeProps] = useState<
Array<{ key: string; label: string; value: string }>
>([]);
const [propsLoading, setPropsLoading] = useState(false);
// Active filter preset — null = show all (covers both researcher and patient presets)
const [activeFilter, setActiveFilter] = useState<
| FilterPresetId
| PatientFilterPresetId
| HospitalFilterPresetId
| HdabFilterPresetId
| ResearcherFilterPresetId
| null
>(null);
// Active persona view — derived from session role; URL ?persona= overrides.
// Computed directly each render (not stale state) to avoid race conditions
// where the graph loads with "default" before the session resolves.
const derivedPersona = (sessionPersonaId || "default") as PersonaId;
const activePersona: PersonaId = urlPersona ?? derivedPersona;
const containerRef = useRef<HTMLDivElement>(null);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const fgRef = useRef<any>(null);
const [dims, setDims] = useState({ width: 800, height: 600 });
// Canvas hover tooltip state
const [hoveredNode, setHoveredNode] = useState<GraphNode | null>(null);
const [mousePos, setMousePos] = useState({ x: 0, y: 0 });
// Panel collapse state
const [leftCollapsed, setLeftCollapsed] = useState(false);
const [rightCollapsed, setRightCollapsed] = useState(false);
const [copiedKey, setCopiedKey] = useState<string | null>(null);
// Topological search — Phase 23e
const [nodeSearch, setNodeSearch] = useState("");
// ── Theme (light / dark) ─────────────────────────────────────────────────
const [isDark, setIsDark] = useState(false);
useEffect(() => {
setIsDark(document.documentElement.classList.contains("dark"));
const handler = (e: Event) => {
setIsDark((e as CustomEvent<{ dark: boolean }>).detail.dark);
};
themeChangeTarget.addEventListener("theme-change", handler);
return () => themeChangeTarget.removeEventListener("theme-change", handler);
}, []);
// ── Load graph (re-fetches when persona changes) ──────────────────────────
// Wait for session to resolve before first load — avoids double-fetch
// (default → real persona) that causes wrong center node name
useEffect(() => {
Iif (!IS_STATIC && sessionStatus === "loading") return;
setLoading(true);
setError(null);
setSelected(null);
setExpandedIds(new Set());
const url =
activePersona === "default"
? "/api/graph"
: `/api/graph?persona=${activePersona}`;
fetchApi(url)
.then(async (r) => {
Iif (r.status === 401) {
throw new Error("UNAUTHENTICATED");
}
Iif (!r.ok) {
throw new Error(`HTTP ${r.status}`);
}
return r.json();
})
.then((d) => {
Iif (!Array.isArray(d.nodes)) throw new Error("Bad response");
// Inject value-center node
const vc = PERSONA_VALUE_NODES[activePersona];
const valueCenterNode: GraphNode = {
id: vc.id,
name: vc.name,
label: "ValueCenter",
layer: 0,
color: NODE_ROLE_COLORS.ValueCenter ?? "#FBBF24",
group: "value-center",
expandable: false,
isValueCenter: true,
};
// Merge real nodes with persona-aware ring positioning
const graph = mergeInto(
{ nodes: [], links: [] },
d.nodes,
d.links,
activePersona,
);
// Mark ALL initial nodes as expanded (up to 1000) — no dashed rings
const initialNodes = graph.nodes.map((n) => ({
...n,
expanded: true,
}));
const initialIds = new Set(initialNodes.map((n) => n.id));
// Connect value center to ALL matching focus nodes (not capped)
const valueCenterLinks: GraphLink[] = [];
const focusLabelSet = new Set(vc.connectedLabels);
for (const n of initialNodes) {
Iif (focusLabelSet.has(n.label)) {
valueCenterLinks.push({
source: vc.id,
target: n.id,
type: "VALUE_FOCUS",
});
}
}
setExpandedIds(initialIds);
setData({
nodes: [{ ...valueCenterNode, fx: 0, fy: 0 }, ...initialNodes],
links: [...graph.links, ...valueCenterLinks],
});
setLoading(false);
// Auto-fit all nodes into view after data arrives
setTimeout(() => fgRef.current?.zoomToFit(400, 40), 150);
})
.catch((e: Error) => {
Iif (e.message === "UNAUTHENTICATED") {
setError("UNAUTHENTICATED");
} else {
setError("Neo4j unavailable — graph could not be loaded.");
}
setLoading(false);
});
}, [activePersona, sessionStatus]); // eslint-disable-line react-hooks/exhaustive-deps
// ── Auto-highlight from URL param ─────────────────────────────────────────
useEffect(() => {
if (!highlightId || data.nodes.length === 0) return;
const q = highlightId.toLowerCase();
const match = data.nodes.find(
(n) => n.id.toLowerCase().includes(q) || n.name.toLowerCase().includes(q),
);
if (match) {
setSelected(match);
setRightCollapsed(false); // auto-open inspector for highlighted node
setTimeout(() => {
Iif (fgRef.current && match.x != null) {
fgRef.current.centerAt(match.x, match.y, 600);
fgRef.current.zoom(3, 600);
}
}, 300);
}
}, [highlightId, data.nodes]);
// ── Auto-load subgraph when filter activated + auto-select starting node ──
useEffect(() => {
Eif (!activeFilter) return;
const preset = [
...FILTER_PRESETS,
...PATIENT_FILTER_PRESETS,
...HOSPITAL_FILTER_PRESETS,
...HDAB_FILTER_PRESETS,
...RESEARCHER_FILTER_PRESETS,
].find((p) => p.id === activeFilter);
if (!preset) return;
const filterLabels = new Set(preset.labels as readonly string[]);
// Always fetch the designated persona subgraph to ensure all relevant nodes
// are present (the default graph often lacks specialist nodes like
// ResearchPseudonym, ProviderPseudonym, etc.)
const neededPersona = FILTER_PRESET_PERSONA[activeFilter];
const shouldFetch = neededPersona && neededPersona !== activePersona;
const afterMerge = () => {
// Auto-select the most connected matching node and open inspector
setData((prev) => {
const matching = prev.nodes.filter(
(n) => filterLabels.has(n.label) && !n.isValueCenter,
);
if (matching.length === 0) return prev;
// Prefer nodes that have the most links (most connected = best starting point)
const linkCount = new Map<string, number>();
for (const l of prev.links) {
const sid = nId(l.source),
tid = nId(l.target);
linkCount.set(sid, (linkCount.get(sid) ?? 0) + 1);
linkCount.set(tid, (linkCount.get(tid) ?? 0) + 1);
}
matching.sort(
(a, b) => (linkCount.get(b.id) ?? 0) - (linkCount.get(a.id) ?? 0),
);
const best = matching[0];
// Use setTimeout so React state updates don't conflict
setTimeout(() => {
setSelected(best);
setRightCollapsed(false);
// Center the graph on the starting node
if (fgRef.current && best.x != null) {
fgRef.current.centerAt(best.x, best.y, 600);
fgRef.current.zoom(2.5, 600);
}
}, 100);
return prev;
});
};
if (shouldFetch) {
const url =
neededPersona === "default"
? "/api/graph"
: `/api/graph?persona=${neededPersona}`;
fetchApi(url)
.then((r) => r.json())
.then((d) => {
if (!Array.isArray(d.nodes)) return;
setData((prev) => mergeInto(prev, d.nodes, d.links, activePersona));
// Give the merge a tick to settle, then auto-select
setTimeout(afterMerge, 50);
})
.catch(() => afterMerge());
} else {
afterMerge();
}
}, [activeFilter]); // eslint-disable-line react-hooks/exhaustive-deps
// ── Resize ────────────────────────────────────────────────────────────────
useEffect(() => {
const update = () =>
containerRef.current &&
setDims({
width: containerRef.current.clientWidth,
height: containerRef.current.clientHeight,
});
update();
window.addEventListener("resize", update);
return () => window.removeEventListener("resize", update);
}, []);
// ── ESC deselect ──────────────────────────────────────────────────────────
useEffect(() => {
const h = (e: KeyboardEvent) => e.key === "Escape" && setSelected(null);
window.addEventListener("keydown", h);
return () => window.removeEventListener("keydown", h);
}, []);
// ── Mouse position for canvas hover tooltip ──────────────────────────────
useEffect(() => {
const el = containerRef.current;
Iif (!el) return;
const handler = (e: MouseEvent) => {
const rect = el.getBoundingClientRect();
setMousePos({ x: e.clientX - rect.left, y: e.clientY - rect.top });
};
el.addEventListener("mousemove", handler);
return () => el.removeEventListener("mousemove", handler);
}, []);
// ── Auto-collapse left sidebar when right panel opens on narrow screens ──
useEffect(() => {
if (selected && containerRef.current) {
const totalWidth = window.innerWidth;
// If viewport is < 1024px, auto-collapse left sidebar to make room
Iif (totalWidth < 1024) {
setLeftCollapsed(true);
}
}
}, [!!selected]); // eslint-disable-line react-hooks/exhaustive-deps
// ── Canvas accessibility — WCAG 1.1.1 / 4.1.2 ───────────────────────────
useEffect(() => {
Iif (!containerRef.current) return;
const canvas = containerRef.current.querySelector("canvas");
Eif (!canvas) return;
canvas.setAttribute("role", "img");
canvas.setAttribute(
"aria-label",
`Interactive force-directed knowledge graph showing ${data.nodes.length} nodes and ${data.links.length} links across 5 data layers`,
);
canvas.setAttribute("tabIndex", "0");
}, [data.nodes.length, data.links.length]);
// ── Recalculate canvas dims when panels open/close ─────────────────────
useEffect(() => {
const timer = setTimeout(() => {
Eif (containerRef.current) {
setDims({
width: containerRef.current.clientWidth,
height: containerRef.current.clientHeight,
});
}
}, 50);
return () => clearTimeout(timer);
}, [!!selected, leftCollapsed, rightCollapsed]);
// ── Fetch node properties when selection changes ────────────────────────
useEffect(() => {
if (!selected || selected.isValueCenter) {
setNodeProps([]);
return;
}
setPropsLoading(true);
fetchApi(`/api/graph/node?id=${encodeURIComponent(selected.id)}`)
.then((r) => r.json())
.then((d) => {
Iif (Array.isArray(d.properties)) {
setNodeProps(d.properties);
} else {
setNodeProps([]);
}
})
.catch(() => setNodeProps([]))
.finally(() => setPropsLoading(false));
}, [selected]);
// ── Neighbours list ───────────────────────────────────────────────────────
useEffect(() => {
if (!selected) return setNeighbours([]);
const nodeMap = new Map(data.nodes.map((n) => [n.id, n]));
const nbrs: { dir: "in" | "out"; type: string; node: GraphNode }[] = [];
for (const l of data.links) {
const s = nId(l.source),
t = nId(l.target);
if (s === selected.id) {
const nb = nodeMap.get(t);
Eif (nb) nbrs.push({ dir: "out", type: l.type, node: nb });
} else if (t === selected.id) {
const nb = nodeMap.get(s);
Eif (nb) nbrs.push({ dir: "in", type: l.type, node: nb });
}
}
setNeighbours(nbrs);
}, [selected, data]);
// ── Expand on click ───────────────────────────────────────────────────────
const expandNode = useCallback(
async (node: GraphNode) => {
if (expandedIds.has(node.id)) return; // already expanded
if (node.isValueCenter) return; // virtual node — no Neo4j expand
setExpanding(node.id);
try {
const r = await fetchApi(
`/api/graph/expand?id=${encodeURIComponent(node.id)}`,
);
const d = await r.json();
if (!Array.isArray(d.nodes)) return;
setData((prev) => mergeInto(prev, d.nodes, d.links, activePersona));
setExpandedIds((prev) => new Set(Array.from(prev).concat(node.id)));
// Mark node as expanded in place
setData((prev) => ({
...prev,
nodes: prev.nodes.map((n) =>
n.id === node.id ? { ...n, expanded: true } : n,
),
}));
} finally {
setExpanding(null);
}
},
[expandedIds, activePersona],
);
// ── Interaction handlers ──────────────────────────────────────────────────
const handleNodeClick = useCallback(
(raw: object) => {
const node = raw as GraphNode;
setSelected(node);
setRightCollapsed(false); // auto-open inspector on single click
// Clicking the value center clears any active filter to show all connections
Iif (node.isValueCenter) {
setActiveFilter(null);
}
// Centre camera
Iif (fgRef.current && node.x != null) {
fgRef.current.centerAt(node.x, node.y, 400);
}
// Auto-expand on single click if not yet expanded
Iif (!expandedIds.has(node.id) && !node.isValueCenter) {
expandNode(node);
}
},
[expandedIds, expandNode],
);
const handleBgClick = useCallback(() => setSelected(null), []);
// ── Hover handler for canvas tooltip ─────────────────────────────────────
const handleNodeHover = useCallback((node: object | null) => {
setHoveredNode(node ? (node as GraphNode) : null);
}, []);
// ── Pointer area paint (hit detection for custom-painted nodes) ──────────
const paintPointerArea = useCallback(
(n: object, color: string, ctx: CanvasRenderingContext2D, gs: number) => {
const node = n as GraphNode;
const r = node.isValueCenter
? Math.max(6, 18 / Math.sqrt(gs))
: Math.max(2, 6 / Math.sqrt(gs));
ctx.beginPath();
ctx.arc(node.x ?? 0, node.y ?? 0, r + 3, 0, 2 * Math.PI);
ctx.fillStyle = color;
ctx.fill();
},
[],
);
// ── Canvas painters ───────────────────────────────────────────────────────
const connectedIds = new Set(neighbours.map((nb) => nb.node.id));
// Active filter preset labels set (null = no filter) — searches both preset arrays
const filterLabelSet: Set<string> | null = activeFilter
? new Set(
(
[
...FILTER_PRESETS,
...PATIENT_FILTER_PRESETS,
...HOSPITAL_FILTER_PRESETS,
...HDAB_FILTER_PRESETS,
...RESEARCHER_FILTER_PRESETS,
].find((p) => p.id === activeFilter) as
| { labels: readonly string[] }
| undefined
)?.labels ?? [],
)
: null;
const paintNode = useCallback(
(n: object, ctx: CanvasRenderingContext2D, gs: number) => {
const node = n as GraphNode;
const isSel = selected?.id === node.id;
const isConn = connectedIds.has(node.id);
const isExpanding = expanding === node.id;
const isExpanded = node.expanded;
const isVC = node.isValueCenter;
// Dim: by selection context OR by active filter (non-matching labels)
const filteredOut = filterLabelSet
? !filterLabelSet.has(node.label) && !isVC
: false;
const dim = filteredOut || (!!selected && !isSel && !isConn && !isVC);
const x = node.x ?? 0,
y = node.y ?? 0;
// Value center node — larger, gradient, always visible
Iif (isVC) {
const vcR = Math.max(6, 18 / Math.sqrt(gs));
ctx.globalAlpha = 1;
// Outer glow ring
ctx.beginPath();
ctx.arc(x, y, vcR + 4, 0, 2 * Math.PI);
ctx.strokeStyle = "rgba(251, 191, 36, 0.4)";
ctx.lineWidth = 2 / gs;
ctx.stroke();
// Gradient fill
const grad = ctx.createRadialGradient(x, y, 0, x, y, vcR);
grad.addColorStop(0, "#FBBF24");
grad.addColorStop(1, "#D97706");
ctx.beginPath();
ctx.arc(x, y, vcR, 0, 2 * Math.PI);
ctx.fillStyle = grad;
ctx.fill();
// Bold label
const fs = Math.max(5, 14 / gs);
ctx.font = `bold ${fs}px sans-serif`;
ctx.fillStyle = isDark ? "#fff" : "#0f172a";
ctx.textAlign = "center";
ctx.fillText(node.name, x, y + vcR + fs * 1.3);
// Subtitle
const sfs = Math.max(3, 9 / gs);
ctx.font = `${sfs}px sans-serif`;
ctx.fillStyle = isDark ? "#fbbf24" : "#b45309";
ctx.fillText(
NODE_DISPLAY_NAMES[node.label] ?? "",
x,
y + vcR + fs * 1.3 + sfs * 1.4,
);
return;
}
const r = Math.max(3, 7 / Math.sqrt(gs));
const filterHighlighted = filterLabelSet && !filteredOut && !isVC;
// When a filter is active, make non-matching nodes dimmed but still visible
// Selection-based dimming uses a milder 0.30
ctx.globalAlpha = filteredOut ? (isDark ? 0.1 : 0.25) : dim ? 0.3 : 1;
// Outer glow for selected
if (isSel) {
ctx.beginPath();
ctx.arc(x, y, r + 4, 0, 2 * Math.PI);
ctx.strokeStyle = isDark ? "rgba(255,255,255,0.7)" : "rgba(0,0,0,0.5)";
ctx.lineWidth = 1.5 / gs;
ctx.stroke();
}
// Dashed ring for unexpanded nodes with neighbours
if (!isExpanded && !isSel) {
ctx.beginPath();
ctx.arc(x, y, r + 2.5, 0, 2 * Math.PI);
ctx.setLineDash([2 / gs, 2 / gs]);
ctx.strokeStyle = node.color + "99";
ctx.lineWidth = 0.8 / gs;
ctx.stroke();
ctx.setLineDash([]);
}
// Spinning arc while expanding
Iif (isExpanding) {
const t = (Date.now() / 300) % (2 * Math.PI);
ctx.beginPath();
ctx.arc(x, y, r + 5, t, t + Math.PI);
ctx.strokeStyle = "#93c5fd";
ctx.lineWidth = 2 / gs;
ctx.stroke();
}
// Glow ring for filter-highlighted nodes
Iif (filterHighlighted && !isSel) {
ctx.beginPath();
ctx.arc(x, y, r + 3, 0, 2 * Math.PI);
ctx.strokeStyle = node.color + "66";
ctx.lineWidth = 2 / gs;
ctx.stroke();
}
// Main node circle with border for visibility on any background
const drawR = filterHighlighted ? r * 1.3 : r;
ctx.beginPath();
ctx.arc(x, y, drawR, 0, 2 * Math.PI);
ctx.fillStyle = node.color;
ctx.fill();
// Stroke outline — ensures nodes are visible in light mode
Eif (!filteredOut) {
ctx.strokeStyle = isDark
? "rgba(255,255,255,0.25)"
: "rgba(0,0,0,0.35)";
ctx.lineWidth = 0.8 / gs;
ctx.stroke();
}
// Label — always visible (font size formula keeps it ~9 screen-px regardless of zoom)
// When a filter is active, matching nodes show their name in bold
if (gs >= 0.1 || isSel || isConn || filterHighlighted) {
const fs = Math.max(3, (filterHighlighted ? 11 : 9) / gs);
ctx.font = `${
isSel || filterHighlighted ? "bold " : ""
}${fs}px sans-serif`;
// Theme-aware label colors — high contrast in both light and dark mode
ctx.fillStyle = isSel
? isDark
? "#fff"
: "#0f172a"
: filterHighlighted
? isDark
? "#f1f5f9"
: "#0f172a"
: isConn
? isDark
? "#e2e8f0"
: "#1e293b"
: isDark
? "#94a3b8"
: "#475569";
ctx.textAlign = "center";
// Always show the friendly name (node.name) instead of raw Neo4j IDs
const labelText = node.name;
const maxLen = filterHighlighted ? 24 : 18;
ctx.fillText(
labelText.length > maxLen
? labelText.slice(0, maxLen - 2) + "…"
: labelText,
x,
y + r + fs * 1.3,
);
// Show type label below name for filter-highlighted nodes
Iif (filterHighlighted && !isSel) {
const tfs = Math.max(2.5, 7 / gs);
ctx.font = `${tfs}px sans-serif`;
ctx.fillStyle = node.color;
ctx.fillText(
NODE_DISPLAY_NAMES[node.label] ?? node.label,
x,
y + r + fs * 1.3 + tfs * 1.4,
);
}
}
ctx.globalAlpha = 1;
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[selected, connectedIds, expanding, filterLabelSet, isDark],
);
const paintLink = useCallback(
(l: object, ctx: CanvasRenderingContext2D, gs: number) => {
const link = l as GraphLink;
const s = link.source as GraphNode,
t = link.target as GraphNode;
if (s.x == null || t.x == null) return;
const isValueLink = link.type === "VALUE_FOCUS";
const isAdj =
selected &&
(nId(link.source) === selected.id || nId(link.target) === selected.id);
// Dim link if either endpoint is filtered out
const filteredOut =
filterLabelSet &&
(!filterLabelSet.has(s.label) || !filterLabelSet.has(t.label));
// Value focus links: golden dashed lines from center — dim when filter active
Iif (isValueLink) {
const filterActive = !!filterLabelSet;
ctx.globalAlpha = selected ? 0.08 : filterActive ? 0.08 : 0.5;
ctx.strokeStyle = "#FBBF24";
ctx.lineWidth = (filterActive ? 0.5 : 2.5) / gs;
ctx.setLineDash([6 / gs, 4 / gs]);
ctx.beginPath();
ctx.moveTo(s.x, s.y ?? 0);
ctx.lineTo(t.x, t.y ?? 0);
ctx.stroke();
ctx.setLineDash([]);
// Label on golden line — hidden when filter active or node selected
if (!selected && !filterLabelSet && gs >= 0.3) {
const targetNode = t.isValueCenter ? s : t;
const typeLabel =
NODE_DISPLAY_NAMES[targetNode.label] ?? targetNode.label;
const mx = (s.x + t.x) / 2,
my = ((s.y ?? 0) + (t.y ?? 0)) / 2;
const fs = Math.max(3, 7 / gs);
ctx.font = `${fs}px sans-serif`;
const tw = ctx.measureText(typeLabel).width;
ctx.globalAlpha = 0.7;
ctx.fillStyle = isDark ? "#0f172a" : "#ffffff";
ctx.fillRect(mx - tw / 2 - 2, my - fs / 2 - 1, tw + 4, fs + 2);
ctx.fillStyle = "#FBBF24";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(typeLabel, mx, my);
ctx.textBaseline = "alphabetic";
}
ctx.globalAlpha = 1;
return;
}
// When a filter is active, links between two matching nodes are highlighted
const filterMatch =
filterLabelSet &&
!filteredOut &&
filterLabelSet.has(s.label) &&
filterLabelSet.has(t.label);
ctx.globalAlpha = filteredOut
? isDark
? 0.05
: 0.12
: filterMatch
? 0.9
: isAdj
? 1
: selected
? isDark
? 0.22
: 0.3
: isDark
? 0.55
: 0.7;
const linkColor = isAdj
? "#60a5fa"
: filterMatch
? isDark
? "#93c5fd"
: "#2563eb"
: isDark
? "#64748b"
: "#475569";
ctx.strokeStyle = linkColor;
ctx.lineWidth =
(isAdj ? 1.5 : filterMatch ? 1.2 : isDark ? 0.7 : 1.0) / gs;
// Offset line end to stop before target node edge
const angle = Math.atan2((t.y ?? 0) - (s.y ?? 0), t.x - s.x);
const tR = Math.max(3, 7 / Math.sqrt(gs));
const tx = t.x - (tR + 4 / gs) * Math.cos(angle);
const ty = (t.y ?? 0) - (tR + 4 / gs) * Math.sin(angle);
ctx.beginPath();
ctx.moveTo(s.x, s.y ?? 0);
ctx.lineTo(tx, ty);
ctx.stroke();
// Arrowhead pointing at target
const aLen = Math.max(4, 10 / gs);
ctx.globalAlpha = filteredOut
? isDark
? 0.05
: 0.15
: filterMatch
? 0.9
: isAdj
? 1
: selected
? 0.3
: isDark
? 0.65
: 0.8;
ctx.fillStyle = linkColor;
ctx.beginPath();
ctx.moveTo(t.x - tR * Math.cos(angle), (t.y ?? 0) - tR * Math.sin(angle));
ctx.lineTo(
t.x - (tR + aLen) * Math.cos(angle) - aLen * 0.4 * Math.sin(angle),
(t.y ?? 0) -
(tR + aLen) * Math.sin(angle) +
aLen * 0.4 * Math.cos(angle),
);
ctx.lineTo(
t.x - (tR + aLen) * Math.cos(angle) + aLen * 0.4 * Math.sin(angle),
(t.y ?? 0) -
(tR + aLen) * Math.sin(angle) -
aLen * 0.4 * Math.cos(angle),
);
ctx.closePath();
ctx.fill();
// Relationship type label — shown on adjacent links, filter-matched links, or when zoomed in
const showLabel =
isAdj || filterMatch || (!selected && !filteredOut && gs >= 0.6);
if (showLabel) {
// User-friendly relationship label
const rawType = link.type;
const friendlyType = FRIENDLY_REL_NAMES[rawType] ?? rawType;
const mx = (s.x + t.x) / 2,
my = ((s.y ?? 0) + (t.y ?? 0)) / 2;
const fs = Math.max(3, 7 / gs);
ctx.font = `${fs}px sans-serif`;
const tw = ctx.measureText(friendlyType).width;
ctx.globalAlpha = isAdj || filterMatch ? 1 : 0.7;
ctx.fillStyle = isDark ? "#0f172a" : "#ffffff";
ctx.fillRect(mx - tw / 2 - 2, my - fs / 2 - 1, tw + 4, fs + 2);
ctx.fillStyle =
isAdj || filterMatch
? isDark
? "#93c5fd" /* bright blue adjacent / filter match */
: "#0058be" /* Stitch primary */
: isDark
? "#94a3b8"
: "#475569";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(friendlyType, mx, my);
ctx.textBaseline = "alphabetic";
}
ctx.globalAlpha = 1;
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[selected, filterLabelSet, isDark],
);
// ── Render ────────────────────────────────────────────────────────────────
return (
<div className="relative flex h-[calc(100vh-44px)]">
{/* Left sidebar — collapsible */}
<aside
className={`flex shrink-0 flex-col gap-4 overflow-y-auto border-r border-[var(--border)] bg-[var(--surface)] transition-all duration-200 ${
leftCollapsed ? "w-10 p-1" : "w-64 p-4"
}`}
>
{/* Collapse/expand toggle */}
<button
onClick={() => setLeftCollapsed((v) => !v)}
className="flex items-center justify-center rounded p-1 text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors"
aria-label={leftCollapsed ? "Expand sidebar" : "Collapse sidebar"}
aria-expanded={!leftCollapsed}
aria-controls="graph-sidebar-panel"
>
{leftCollapsed ? (
<ChevronRight size={14} aria-hidden="true" />
) : (
<PanelLeftClose size={14} aria-hidden="true" />
)}
</button>
{leftCollapsed ? null : (
<div id="graph-sidebar-panel" className="flex flex-col gap-3">
{/* ── Compact header with inline stats ── */}
<div className="pb-2 border-b border-[var(--border)]">
<div className="flex items-baseline justify-between">
<h1 className="text-sm font-bold text-[var(--accent)] leading-tight">
Knowledge Graph
</h1>
<span className="text-[10px] text-[var(--text-secondary)] tabular-nums">
{data.nodes.length} nodes · {data.links.length} links
</span>
</div>
{/* Active persona indicator — compact inline */}
{activePersona !== "default" &&
(() => {
const pv = PERSONA_VIEWS.find((p) => p.id === activePersona);
const Icon = pv ? PRESET_ICONS[pv.icon] ?? Eye : Eye;
return (
<div className="mt-1.5 flex items-center gap-1.5 text-[10px] text-[var(--accent)]">
<Icon size={10} />
<span className="font-semibold">
{pv?.label ?? activePersona}
</span>
{pv?.ehdsArticle && (
<span className="text-[var(--text-secondary)]">
· {pv.ehdsArticle}
</span>
)}
</div>
);
})()}
</div>
{/* ── Search — matches name, label, display name, and group ── */}
<div>
<input
id="graph-node-search"
type="search"
value={nodeSearch}
onChange={(e) => setNodeSearch(e.target.value)}
placeholder="e.g. Organization, Contract, Pseudonym…"
aria-label="Search graph nodes by name, type, or keyword"
className="w-full px-3 py-1.5 text-xs bg-[var(--surface-card)] border border-[var(--border-ui)] rounded-lg text-[var(--text-primary)] placeholder-[var(--text-secondary)] outline-none focus:border-[var(--accent)] transition-colors"
/>
{nodeSearch.trim() &&
(() => {
const q = nodeSearch.toLowerCase();
const matches = data.nodes.filter(
(n) =>
(n.name ?? "").toLowerCase().includes(q) ||
(n.label ?? "").toLowerCase().includes(q) ||
(NODE_DISPLAY_NAMES[n.label] ?? "")
.toLowerCase()
.includes(q) ||
(n.group ?? "").toLowerCase().includes(q),
);
return (
<div className="mt-1.5 max-h-48 overflow-y-auto flex flex-col gap-0.5">
{matches.length > 0 ? (
<>
<p className="text-[10px] text-[var(--text-secondary)] px-2 py-0.5">
{matches.length} result
{matches.length !== 1 ? "s" : ""}
</p>
{matches.slice(0, 15).map((n) => (
<button
key={n.id}
onClick={() => {
handleNodeClick(
n as Parameters<typeof handleNodeClick>[0],
);
setNodeSearch("");
setRightCollapsed(false);
}}
className="text-left px-2 py-1 rounded hover:bg-[var(--surface-2)] transition-colors flex items-center gap-2 text-xs"
>
<span
className="w-2 h-2 rounded-full shrink-0"
style={{
background:
n.color ?? "var(--text-secondary)",
}}
/>
<span className="truncate text-[var(--text-primary)] font-medium">
{n.name}
</span>
<span className="text-[var(--text-secondary)] shrink-0 text-[10px]">
{NODE_DISPLAY_NAMES[n.label] ?? n.label}
</span>
</button>
))}
</>
) : (
<p className="text-xs text-[var(--text-secondary)] px-2 py-1">
No nodes match “{nodeSearch}”
</p>
)}
</div>
);
})()}
</div>
{/* ── Filter by question — most prominent section ── */}
<div>
<p className="section-label">Ask the graph</p>
<div className="flex flex-col gap-0.5">
{(activePersona === "patient"
? PATIENT_FILTER_PRESETS
: activePersona === "hospital"
? HOSPITAL_FILTER_PRESETS
: activePersona === "hdab"
? HDAB_FILTER_PRESETS
: activePersona === "researcher"
? RESEARCHER_FILTER_PRESETS
: FILTER_PRESETS
).map((preset) => {
const Icon = PRESET_ICONS[preset.icon] ?? BookOpen;
const isActive = activeFilter === preset.id;
return (
<button
key={preset.id}
onClick={() =>
setActiveFilter((prev) =>
prev === preset.id
? null
: (preset.id as FilterPresetId &
PatientFilterPresetId &
HospitalFilterPresetId &
HdabFilterPresetId &
ResearcherFilterPresetId),
)
}
title={preset.description}
className={`flex items-center gap-2 py-1.5 text-left text-xs transition-colors ${
isActive
? "nav-item-active rounded-r"
: "px-2 rounded text-[var(--text-secondary)] hover:bg-[var(--surface-2)] hover:text-[var(--text-primary)]"
}`}
>
<Icon size={11} />
<span className="leading-tight">{preset.label}</span>
</button>
);
})}
</div>
{activeFilter && (
<p className="mt-1.5 px-2 py-1.5 text-[10px] text-[var(--text-secondary)] bg-[var(--accent-surface)] rounded leading-snug">
{
[
...FILTER_PRESETS,
...PATIENT_FILTER_PRESETS,
...HOSPITAL_FILTER_PRESETS,
...HDAB_FILTER_PRESETS,
...RESEARCHER_FILTER_PRESETS,
].find((p) => p.id === activeFilter)?.description
}
</p>
)}
</div>
{/* ── Quick links — compact icon row ── */}
<div className="border-t border-[var(--border)] pt-2">
<p className="section-label">Explore</p>
<div className="grid grid-cols-2 gap-1">
{[
{ href: "/catalog", icon: BookOpen, label: "Catalog" },
{ href: "/patient", icon: Activity, label: "Patients" },
{ href: "/analytics", icon: Database, label: "OMOP" },
{
href: "/api/graph/validate",
icon: ShieldCheck,
label: "Validate",
external: true,
},
].map(({ href, icon: Icon, label, external }) => (
<a
key={href}
href={href}
target={external ? "_blank" : undefined}
className="flex items-center gap-1.5 py-1 px-1.5 text-[10px] text-[var(--text-secondary)] hover:text-[var(--accent)] transition-colors rounded hover:bg-[var(--accent-surface)]"
>
<Icon size={10} aria-hidden="true" />
{label}
</a>
))}
</div>
</div>
{/* ── Legend — always available, collapsed by default ── */}
<details
className="border-t border-[var(--border)] pt-2"
open={!activeFilter}
>
<summary className="section-label cursor-pointer select-none hover:text-[var(--accent)] transition-colors mb-1">
Legend
</summary>
<div className="mt-2 space-y-3">
{/* Layer colors */}
<div>
<p className="text-[10px] text-[var(--text-secondary)] uppercase tracking-wider font-semibold mb-1">
Layers
</p>
{Object.entries(LAYER_LABELS)
.filter(([k]) => +k >= 1)
.map(([k, v]) => {
const personaLabel =
PERSONA_LAYER_LABELS[activePersona]?.[+k] ?? v;
return (
<div
key={k}
className="mb-0.5 flex items-center gap-2 text-[11px] cursor-help"
title={LAYER_TOOLTIPS[+k]}
>
<span
className="h-2 w-2 shrink-0 rounded-full"
style={{ background: LAYER_COLORS[+k] }}
aria-hidden="true"
/>
<span className="text-[var(--text-primary)]">
{personaLabel}
</span>
</div>
);
})}
</div>
{/* Key actors */}
<div>
<p className="text-[10px] text-[var(--text-secondary)] uppercase tracking-wider font-semibold mb-1">
Key actors
</p>
{ROLE_LEGEND.map(({ label, color, description, tooltip }) => (
<div
key={label}
className="mb-1 flex items-start gap-2 text-[11px] cursor-help"
title={tooltip}
>
<span
className="mt-0.5 h-2 w-2 shrink-0 rounded-full"
style={{ background: color }}
aria-hidden="true"
/>
<div>
<span className="font-medium text-[var(--text-primary)]">
{label}
</span>
<span className="text-[var(--text-secondary)]">
{" "}
— {description}
</span>
</div>
</div>
))}
</div>
</div>
</details>
{/* Hint — only when no selection and no filter */}
{!selected && !activeFilter && !loading && (
<div className="flex items-start gap-1.5 rounded-lg border border-[var(--border)] bg-[var(--surface-2)]/50 p-2 text-[10px] text-[var(--text-secondary)]">
<MousePointerClick
size={10}
className="mt-0.5 shrink-0 text-[var(--accent)]"
aria-hidden="true"
/>
Click a node to inspect, or pick a question above.
</div>
)}
</div>
)}
</aside>
{/* Graph canvas */}
<div ref={containerRef} className="relative flex-1 bg-[var(--bg)]">
{loading ? (
<div className="flex h-full items-center justify-center text-[var(--text-secondary)]">
<Loader2 size={14} className="mr-2 animate-spin" />
Loading {PERSONA_VALUE_NODES[activePersona]?.name ?? "graph"}…
</div>
) : error === "UNAUTHENTICATED" ? (
<div className="flex h-full flex-col items-center justify-center gap-4 text-[var(--text-secondary)]">
<p className="text-lg">Sign in to explore the knowledge graph.</p>
<p className="text-sm text-[var(--text-secondary)]">
The graph shows participants, data products, policies and clinical
entities scoped to your persona.
</p>
<button
type="button"
onClick={() => signIn("keycloak")}
className="rounded bg-[var(--accent)] px-4 py-2 text-sm font-medium text-white dark:text-[var(--bg)] hover:opacity-90"
>
Sign in
</button>
</div>
) : error ? (
<div className="flex h-full items-center justify-center text-[var(--text-secondary)]">
{error}
</div>
) : (
<ForceGraph2D
ref={fgRef}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
graphData={data as any}
width={dims.width}
height={dims.height}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
nodeCanvasObject={paintNode as any}
nodeCanvasObjectMode={() => "replace"}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
linkCanvasObject={paintLink as any}
linkCanvasObjectMode={() => "replace"}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
nodePointerAreaPaint={paintPointerArea as any}
onNodeClick={handleNodeClick}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onNodeHover={handleNodeHover as any}
onBackgroundClick={handleBgClick}
backgroundColor={isDark ? "#030712" : "#ffffff"}
// Nodes have pre-assigned ring positions — physics not needed
d3AlphaDecay={1}
d3VelocityDecay={1}
cooldownTicks={0}
warmupTicks={0}
nodeRelSize={4}
/>
)}
{/* Canvas hover tooltip */}
{hoveredNode && !selected && (
<div
className="pointer-events-none absolute z-50 max-w-xs rounded-lg border border-[var(--border)] bg-[var(--surface)]/95 px-3 py-2 shadow-xl backdrop-blur-sm"
style={{
left: Math.min(mousePos.x + 14, dims.width - 280),
top: Math.min(mousePos.y + 14, dims.height - 120),
}}
>
<div className="mb-1 flex items-center gap-2">
<span
className="h-2.5 w-2.5 shrink-0 rounded-full"
style={{ background: hoveredNode.color }}
/>
<span className="truncate text-sm font-semibold text-[var(--text-primary)]">
{hoveredNode.name}
</span>
</div>
<div className="mb-1 text-xs text-[var(--text-secondary)]">
{NODE_DISPLAY_NAMES[hoveredNode.label] ?? hoveredNode.label}
{" · "}
{(PERSONA_LAYER_LABELS[activePersona] ?? LAYER_LABELS)[
hoveredNode.layer
] ?? LAYER_LABELS[hoveredNode.layer]}
</div>
{NODE_TOOLTIPS[hoveredNode.label] && (
<p className="text-xs leading-relaxed text-[var(--text-secondary)]">
{NODE_TOOLTIPS[hoveredNode.label]}
</p>
)}
</div>
)}
{/* Expanding spinner overlay */}
{expanding && (
<div className="pointer-events-none absolute bottom-4 right-4 flex items-center gap-2 rounded-full bg-[var(--surface)]/90 px-3 py-1.5 text-xs text-[var(--text-secondary)]">
<Loader2 size={12} className="animate-spin" />
Loading neighbours…
</div>
)}
</div>
{/* ── Right-side entity inspector panel ── */}
{selected && (
<aside
className={`absolute right-0 top-0 h-full overflow-y-auto border-l border-[var(--border)] bg-[var(--surface-card)] animate-slide-in-right z-40 shadow-2xl transition-[width] duration-200 ${
rightCollapsed ? "w-10" : "w-96"
}`}
>
{/* Collapse/expand toggle */}
<button
onClick={() => setRightCollapsed((v) => !v)}
className="flex w-full items-center justify-center border-b border-[var(--border)] p-2 text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors"
aria-label={
rightCollapsed ? "Expand inspector" : "Collapse inspector"
}
aria-expanded={!rightCollapsed}
aria-controls="graph-inspector-panel"
>
{rightCollapsed ? (
<ChevronLeft size={14} aria-hidden="true" />
) : (
<PanelRightClose size={14} aria-hidden="true" />
)}
</button>
{rightCollapsed ? null : (
<div id="graph-inspector-panel">
{/* ── Header ── */}
<div className="border-b border-[var(--border)] px-5 pt-5 pb-4">
<div className="flex items-center justify-between mb-3">
<p className="text-[10px] font-black text-[var(--text-secondary)] uppercase tracking-widest">
Entity Details
</p>
<button
onClick={() => setSelected(null)}
className="text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--surface-2)] rounded-lg p-1 transition-colors"
aria-label="Close detail panel"
>
<X size={14} aria-hidden="true" />
</button>
</div>
{/* Node name with color indicator */}
<div className="flex items-start gap-2.5 mb-3">
<span
className="mt-1.5 h-3 w-3 shrink-0 rounded-full shadow-sm"
style={{ background: selected.color }}
/>
<h2
className="text-xl font-black leading-tight tracking-tight break-words"
style={{ color: selected.color }}
title={NODE_TOOLTIPS[selected.label]}
>
{selected.name}
</h2>
</div>
{/* Type + layer badges */}
<div className="flex items-center gap-2 flex-wrap">
<span
className="inline-flex items-center text-[10px] font-bold px-2 py-0.5 rounded-full"
style={{
background: selected.color + "20",
color: selected.color,
}}
>
{NODE_DISPLAY_NAMES[selected.label] ?? selected.label}
</span>
<span className="text-[10px] font-semibold text-[var(--text-secondary)]">
{PERSONA_LAYER_LABELS[activePersona]?.[selected.layer] ??
LAYER_LABELS[selected.layer]}
</span>
</div>
</div>
{/* ── Node ID (copyable) ── */}
<div className="px-5 py-3 border-b border-[var(--border)] group flex items-center gap-2">
<p className="break-all text-[10px] leading-relaxed text-[var(--text-secondary)] font-mono flex-1">
{selected.id}
</p>
<button
onClick={() => {
navigator.clipboard.writeText(selected.id);
setCopiedKey("__id__");
setTimeout(() => setCopiedKey(null), 1500);
}}
className="shrink-0 text-[var(--text-secondary)] hover:text-[var(--accent)] transition-colors"
title="Copy node ID"
aria-label="Copy node ID"
>
{copiedKey === "__id__" ? (
<Check size={12} className="text-[var(--success-text)]" />
) : (
<Copy size={12} />
)}
</button>
</div>
{/* ── Deep links ── */}
{(selected.layer === 2 ||
selected.layer === 3 ||
selected.layer === 4 ||
selected.label === "TrustCenter" ||
selected.label === "SPESession" ||
selected.label === "ResearchPseudonym") && (
<div className="px-5 py-3 border-b border-[var(--border)] flex flex-wrap gap-2">
{selected.layer === 2 && (
<a
href={`/catalog?search=${encodeURIComponent(
selected.name,
)}`}
className="inline-flex items-center gap-1.5 text-[10px] font-bold text-[var(--layer2-text)] bg-[var(--surface-2)] px-2.5 py-1.5 rounded-full hover:bg-[var(--accent-surface)] transition-colors"
>
<BookOpen size={10} /> Dataset Catalog
</a>
)}
{(selected.layer === 3 || selected.layer === 4) && (
<a
href="/patient"
className="inline-flex items-center gap-1.5 text-[10px] font-bold text-[var(--layer3-text)] bg-[var(--surface-2)] px-2.5 py-1.5 rounded-full hover:bg-[var(--accent-surface)] transition-colors"
>
<Activity size={10} /> Patient Journey
</a>
)}
{selected.layer === 4 && (
<a
href="/analytics"
className="inline-flex items-center gap-1.5 text-[10px] font-bold text-[var(--layer4-text)] bg-[var(--surface-2)] px-2.5 py-1.5 rounded-full hover:bg-[var(--accent-surface)] transition-colors"
>
<Database size={10} /> OMOP Analytics
</a>
)}
{(selected.label === "TrustCenter" ||
selected.label === "SPESession" ||
selected.label === "ResearchPseudonym") && (
<a
href="/compliance#trust-center"
className="inline-flex items-center gap-1.5 text-[10px] font-bold text-[var(--layer1-text)] bg-[var(--surface-2)] px-2.5 py-1.5 rounded-full hover:bg-[var(--accent-surface)] transition-colors"
>
<Lock size={10} /> Trust Center
</a>
)}
</div>
)}
{/* ── Graph properties ── */}
{!selected.isValueCenter && (
<div className="px-5 py-4 border-b border-[var(--border)]">
{propsLoading ? (
<div className="flex items-center gap-2 text-xs text-[var(--text-secondary)]">
<Loader2 size={12} className="animate-spin" />
Loading properties…
</div>
) : nodeProps.length > 0 ? (
<>
<p className="section-label mb-3">Graph Properties</p>
<div className="space-y-1.5">
{nodeProps.map((p) => {
const isUrl = p.value.startsWith("http");
const isEmail =
p.value.includes("@") &&
!p.value.startsWith("http");
const isPhone = p.value.startsWith("+");
const isCopied = copiedKey === p.key;
return (
<div
key={p.key}
className="flex items-start justify-between gap-2 px-3 py-2.5 bg-[var(--surface)] rounded-xl text-xs group"
>
<span className="text-[var(--text-secondary)] shrink-0 pt-0.5 w-24 leading-snug">
{p.label}
</span>
<div className="flex items-start gap-1.5 flex-1 min-w-0 justify-end">
{isUrl ? (
<a
href={p.value}
target="_blank"
rel="noopener noreferrer"
className="text-[var(--accent)] font-medium break-all hover:underline flex items-center gap-1 text-right"
>
{p.value.length > 36
? p.value.slice(0, 34) + "…"
: p.value}
<ExternalLink
size={9}
className="shrink-0"
/>
</a>
) : isEmail ? (
<a
href={`mailto:${p.value}`}
className="text-[var(--accent)] font-medium hover:underline text-right"
>
{p.value}
</a>
) : isPhone ? (
<a
href={`tel:${p.value.replace(/\s/g, "")}`}
className="text-[var(--text-primary)] font-bold hover:text-[var(--accent)] text-right"
>
{p.value}
</a>
) : (
<span className="text-[var(--text-primary)] font-bold text-right break-all">
{p.value.length > 45
? p.value.slice(0, 43) + "…"
: p.value}
</span>
)}
<button
onClick={() => {
navigator.clipboard.writeText(p.value);
setCopiedKey(p.key);
setTimeout(() => setCopiedKey(null), 1500);
}}
className="shrink-0 mt-0.5 opacity-0 group-hover:opacity-100 transition-opacity text-[var(--text-secondary)] hover:text-[var(--accent)]"
title={`Copy ${p.label}`}
aria-label={`Copy ${p.label}`}
>
{isCopied ? (
<Check
size={10}
className="text-[var(--success-text)]"
/>
) : (
<Copy size={10} />
)}
</button>
</div>
</div>
);
})}
</div>
</>
) : (
<p className="text-xs text-[var(--text-secondary)] italic">
No additional properties
</p>
)}
</div>
)}
{/* ── Expand / neighbours loaded ── */}
<div className="px-5 py-4 border-b border-[var(--border)]">
{selected.isValueCenter ? (
<p className="text-xs text-[var(--warning-text)] italic">
{PERSONA_VALUE_NODES[activePersona]?.tooltip ??
"Your starting point in the dataspace"}
</p>
) : !expandedIds.has(selected.id) ? (
<button
onClick={() => expandNode(selected)}
disabled={!!expanding}
className="btn-gradient w-full flex items-center justify-center gap-2 rounded-xl py-2.5 text-xs font-bold disabled:opacity-50"
>
{expanding === selected.id ? (
<>
<Loader2 size={12} className="animate-spin" />
Expanding…
</>
) : (
<>
<MousePointerClick size={12} />
Expand Neighbours
</>
)}
</button>
) : (
<div className="flex items-center gap-2 text-xs text-[var(--text-secondary)]">
<span className="w-2 h-2 rounded-full bg-[var(--success)] animate-pulse shrink-0" />
{neighbours.length} connections loaded
</div>
)}
</div>
{/* ── Relationships ── */}
{neighbours.length > 0 && (
<div className="px-5 py-4">
{/* Outgoing */}
{neighbours.filter((nb) => nb.dir === "out").length > 0 && (
<div className="mb-5">
<div className="flex items-center gap-2 mb-2">
<p className="section-label">Outgoing</p>
<span className="text-[10px] font-bold text-[var(--text-secondary)] bg-[var(--surface)] px-1.5 py-0.5 rounded-full border border-[var(--border)]">
{neighbours.filter((nb) => nb.dir === "out").length}
</span>
</div>
<div className="space-y-1">
{neighbours
.filter((nb) => nb.dir === "out")
.map((nb, i) => (
<button
key={`out-${i}`}
onClick={() => setSelected(nb.node)}
className="w-full flex items-center gap-2 py-2.5 px-3 text-left bg-[var(--surface)] hover:bg-[var(--accent-surface)] rounded-xl transition-colors group"
>
<ArrowUpRight
size={12}
className="shrink-0 text-[var(--accent)] opacity-60 group-hover:opacity-100"
/>
<span className="shrink-0 font-mono text-[9px] font-black text-[var(--accent)] bg-[var(--accent-surface)] group-hover:bg-white/50 px-1.5 py-0.5 rounded max-w-[90px] truncate">
{FRIENDLY_REL_NAMES[nb.type] ?? nb.type}
</span>
<span
className="h-2 w-2 shrink-0 rounded-full"
style={{ background: nb.node.color }}
/>
<span className="truncate text-xs text-[var(--text-primary)] group-hover:text-[var(--accent)] flex-1 text-left">
{nb.node.name}
</span>
<ChevronRight
size={10}
className="shrink-0 text-[var(--text-secondary)] opacity-0 group-hover:opacity-100 transition-opacity"
/>
</button>
))}
</div>
</div>
)}
{/* Incoming */}
{neighbours.filter((nb) => nb.dir === "in").length > 0 && (
<div>
<div className="flex items-center gap-2 mb-2">
<p className="section-label">Incoming</p>
<span className="text-[10px] font-bold text-[var(--text-secondary)] bg-[var(--surface)] px-1.5 py-0.5 rounded-full border border-[var(--border)]">
{neighbours.filter((nb) => nb.dir === "in").length}
</span>
</div>
<div className="space-y-1">
{neighbours
.filter((nb) => nb.dir === "in")
.map((nb, i) => (
<button
key={`in-${i}`}
onClick={() => setSelected(nb.node)}
className="w-full flex items-center gap-2 py-2.5 px-3 text-left bg-[var(--surface)] hover:bg-[var(--surface-2)] rounded-xl transition-colors group"
>
<ArrowDownLeft
size={12}
className="shrink-0 text-[var(--layer3-text)] opacity-60 group-hover:opacity-100"
/>
<span className="shrink-0 font-mono text-[9px] font-black text-[var(--layer3-text)] bg-[var(--surface-2)] px-1.5 py-0.5 rounded max-w-[90px] truncate">
{FRIENDLY_REL_NAMES[nb.type] ?? nb.type}
</span>
<span
className="h-2 w-2 shrink-0 rounded-full"
style={{ background: nb.node.color }}
/>
<span className="truncate text-xs text-[var(--text-primary)] group-hover:text-[var(--accent)] flex-1 text-left">
{nb.node.name}
</span>
<ChevronRight
size={10}
className="shrink-0 text-[var(--text-secondary)] opacity-0 group-hover:opacity-100 transition-opacity"
/>
</button>
))}
</div>
</div>
)}
</div>
)}
</div>
)}
</aside>
)}
</div>
);
}
|