Files
Fulfilled-Knowledge/wishfulfilled-dashboard/assets/PathFinderModal-BRgBX2u0.js
2026-05-27 15:40:32 +08:00

2 lines
6.2 KiB
JavaScript

import{a as d,j as e}from"./react-vendor-BVoutfaX.js";import{u as j}from"./index-DhPrZyEb.js";import"./xyflow-CYMCcsWN.js";import"./graph-layout-7tFr_anw.js";import"./elk-CXeXGyKz.js";import"./graphology-BgTy_cc3.js";function I({isOpen:i,onClose:o}){const h=j(t=>t.graph),v=j(t=>t.selectNode),[n,N]=d.useState(""),[l,k]=d.useState(""),[c,x]=d.useState(null),[g,m]=d.useState(!1),p=d.useRef(null);if(d.useEffect(()=>{if(!i)return;const t=r=>{p.current&&!p.current.contains(r.target)&&o()};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[i,o]),d.useEffect(()=>{if(!i)return;const t=r=>{r.key==="Escape"&&o()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[i,o]),!i||!h)return null;const f=h.nodes,w=h.edges,y=()=>{if(!n||!l||n===l){x(null);return}m(!0);const t=new Map;for(const s of w)t.has(s.source)||t.set(s.source,[]),t.get(s.source).push(s.target),t.has(s.target)||t.set(s.target,[]),t.get(s.target).push(s.source);const r=[{nodeId:n,path:[n]}],a=new Set([n]);for(;r.length>0;){const{nodeId:s,path:b}=r.shift();if(s===l){x(b),m(!1);return}const E=t.get(s)??[];for(const u of E)a.has(u)||(a.add(u),r.push({nodeId:u,path:[...b,u]}))}x([]),m(!1)},L=t=>{v(t),o()},M=new Map(f.map(t=>[t.id,t]));return e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-root/80 backdrop-blur-sm",children:e.jsxs("div",{ref:p,className:"glass-heavy rounded-xl shadow-2xl w-full max-w-2xl max-h-[80vh] overflow-hidden animate-fade-slide-in",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("svg",{className:"w-5 h-5 text-gold",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 7h8m0 0v8m0-8l-8 8-4-4-6 6"})}),e.jsx("h2",{className:"font-heading text-xl text-text-primary",children:"Dependency Path Finder"})]}),e.jsx("button",{onClick:o,className:"text-text-muted hover:text-text-primary transition-colors",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("div",{className:"p-5 space-y-4 overflow-y-auto max-h-[calc(80vh-180px)]",children:[e.jsx("p",{className:"text-sm text-text-secondary",children:"Find the shortest path between two nodes in the dependency graph."}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-text-secondary uppercase tracking-wider mb-2",children:"From Node"}),e.jsxs("select",{value:n,onChange:t=>{N(t.target.value),x(null)},className:"w-full bg-elevated text-text-primary text-sm rounded-lg px-3 py-2 border border-border-subtle focus:outline-none focus:border-gold/50",children:[e.jsx("option",{value:"",children:"Select a node..."}),f.map(t=>e.jsxs("option",{value:t.id,children:[t.name," (",t.type,")"]},t.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-text-secondary uppercase tracking-wider mb-2",children:"To Node"}),e.jsxs("select",{value:l,onChange:t=>{k(t.target.value),x(null)},className:"w-full bg-elevated text-text-primary text-sm rounded-lg px-3 py-2 border border-border-subtle focus:outline-none focus:border-gold/50",children:[e.jsx("option",{value:"",children:"Select a node..."}),f.map(t=>e.jsxs("option",{value:t.id,children:[t.name," (",t.type,")"]},t.id))]})]}),e.jsx("button",{onClick:y,disabled:!n||!l||n===l||g,className:"w-full bg-gold/10 border border-gold/30 text-gold text-sm font-medium py-2.5 px-4 rounded-lg hover:bg-gold/20 transition-all duration-200 disabled:opacity-50 disabled:cursor-not-allowed",children:g?"Searching...":"Find Path"}),c!==null&&e.jsx("div",{className:"mt-4",children:c.length===0?e.jsxs("div",{className:"bg-red-900/20 border border-red-700/50 rounded-lg p-4 text-center",children:[e.jsx("svg",{className:"w-8 h-8 text-red-400 mx-auto mb-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsx("p",{className:"text-sm text-red-200",children:"No path found between these nodes."})]}):e.jsxs("div",{className:"bg-elevated border border-border-subtle rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("svg",{className:"w-4 h-4 text-green-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsxs("h3",{className:"text-sm font-semibold text-text-primary",children:["Path Found (",c.length," nodes)"]})]}),e.jsx("div",{className:"space-y-2",children:c.map((t,r)=>{const a=M.get(t);if(!a)return null;const s=r===c.length-1;return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>L(t),className:"w-full flex items-center gap-3 p-2 bg-surface rounded-lg hover:bg-elevated transition-colors text-left",children:[e.jsx("div",{className:"w-6 h-6 shrink-0 rounded-full bg-gold/20 flex items-center justify-center text-xs font-bold text-gold",children:r+1}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm text-text-primary truncate",children:a.name}),e.jsx("div",{className:"text-xs text-text-muted capitalize",children:a.type})]}),e.jsx("svg",{className:"w-4 h-4 text-text-muted",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})]}),!s&&e.jsx("div",{className:"flex items-center justify-center my-1",children:e.jsx("svg",{className:"w-4 h-4 text-gold",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 14l-7 7m0 0l-7-7m7 7V3"})})})]},t)})})]})})]}),e.jsx("div",{className:"flex items-center justify-end gap-3 px-5 py-4 border-t border-border-subtle",children:e.jsx("button",{onClick:o,className:"px-4 py-2 text-sm text-text-secondary hover:text-text-primary transition-colors",children:"Close"})})]})})}export{I as default};