MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / IndexesPanel

Function IndexesPanel

graph-ui/src/system/IndexesPanel.tsx:60–114  ·  view source on GitHub ↗
({ api, listProjects, active, paused, refreshToken, pollMs = 15000, onOpenProjects }: Props)

Source from the content-addressed store, hash-verified

58}
59
60export default function IndexesPanel({ api, listProjects, active, paused, refreshToken, pollMs = 15000, onOpenProjects }: Props) {
61 const previous = useRef(new Map<string, IndexReading>());
62 const enabled = useRef(active);
63 enabled.current = active;
64 const inFlight = useRef<Promise<IndexReading[]> | null>(null);
65 const readIndexes = useCallback(async () => {
66 if (inFlight.current) return inFlight.current;
67 const read = async () => {
68 if (!listProjects) throw new Error('Project inventory is unavailable.');
69 const projects = await listProjects();
70 const rows = new Array<IndexReading>(projects.length);
71 let cursor = 0;
72 const worker = async () => {
73 while (cursor < projects.length) {
74 if (!enabled.current || document.visibilityState === 'hidden') throw new Error('Index reading paused.');
75 const index = cursor++;
76 const project = projects[index];
77 try {
78 if (!api.projectHealth) throw new Error('Project health is unavailable.');
79 rows[index] = { project, health: await api.projectHealth(project.name), error: null };
80 } catch (error) {
81 rows[index] = { project, health: previous.current.get(project.name)?.health ?? null, error: failureText(error) };
82 }
83 }
84 };
85 const work = await Promise.allSettled(Array.from({ length: Math.min(4, projects.length) }, worker));
86 const failed = work.find(result => result.status === 'rejected');
87 if (failed?.status === 'rejected') throw failed.reason;
88 previous.current = new Map(rows.map(row => [row.project.name, row]));
89 return rows;
90 };
91 const request = read();
92 inFlight.current = request;
93 try { return await request; }
94 finally { if (inFlight.current === request) inFlight.current = null; }
95 }, [api, listProjects]);
96 const reading = useSystemPoll(readIndexes, active, paused, pollMs);
97 useEffect(() => { if (active && refreshToken > 0) reading.refresh(); }, [active, refreshToken, reading.refresh]);
98 return <section className="system-section system-indexes" aria-label="Project indexes">
99 <div className="system-section-heading"><div><h2>Indexes</h2><p>Persisted project indexes and background watching.</p></div><button type="button" onClick={onOpenProjects}>Add project index</button></div>
100 <WatcherSetting api={api} active={active} paused={paused} pollMs={pollMs} refreshToken={refreshToken} />
101 <div className="system-index-reading"><span>{reading.loading ? 'Updating indexes…' : paused ? 'Live updates paused' : 'Updates every 15 seconds'}</span>{reading.updatedAt !== null && <span>Read <time dateTime={new Date(reading.updatedAt).toISOString()}>{new Date(reading.updatedAt).toLocaleTimeString()}</time></span>}</div>
102 {reading.error && <p className="system-warning" role="alert">{reading.error}{reading.data ? ' Showing the last inventory reading; current watcher state is unknown.' : ''}</p>}
103 <div className="system-table-wrap"><table className="system-index-table"><thead><tr><th>Project</th><th title="Recorded index metadata time; does not prove the current files are indexed.">Index timestamp</th><th>Index contents</th><th>Background watcher</th></tr></thead><tbody>
104 {reading.data?.map(({ project, health, error }) => <tr key={project.name}>
105 <th scope="row"><strong>{project.name}</strong>{project.root_path && <small className="system-index-path" title={project.root_path}>{project.root_path}</small>}{health?.status !== 'healthy' && <small>{health?.status === 'corrupt' ? 'Index corrupt' : health?.status === 'missing' ? 'Index missing' : 'Health unknown'}</small>}{error && <small className="system-warning">Update failed: {error}{health ? ' · showing last reading' : ''}</small>}</th>
106 <td>{health?.indexedAt ? <time dateTime={health.indexedAt}>{new Date(health.indexedAt).toLocaleString()}</time> : <span>Unknown</span>}</td>
107 <td><span>{health?.nodes ?? project.nodes ?? 'Unknown'} nodes</span><small>{health?.edges ?? project.edges ?? 'Unknown'} edges</small></td>
108 <td>{watcherText(health, !!error || !!reading.error)}</td>
109 </tr>)}
110 </tbody></table></div>
111 {!reading.data && !reading.error && <p className="system-empty">Reading project indexes…</p>}
112 {reading.data?.length === 0 && <p className="system-empty">No persisted project indexes.</p>}
113 </section>;
114}

Callers

nothing calls this directly

Calls 3

useSystemPollFunction · 0.90
watcherTextFunction · 0.85
readFunction · 0.70

Tested by

no test coverage detected