Skip to content

armgit / cogit

Public Imported from GitHub
0

Git for the intent behind agent-written code. Records what your coding agent decided and why, and links every commit to it.

fix(map): open a captured row's session card and centre the map on it

Erenab1a1cf59e2b
diff --git a/packages/template/src/CapturesView.tsx b/packages/template/src/CapturesView.tsx
index f389f48..e2371ae 100644
--- a/packages/template/src/CapturesView.tsx
+++ b/packages/template/src/CapturesView.tsx
@@ -90,7 +90,6 @@ export function CapturesView({
captures,
sessions,
dir,
- activeSessionId,
onSelectSession,
onClose,
}: {
@@ -99,8 +98,6 @@ export function CapturesView({
sessions: readonly ViewSession[];
/** The project's path, for the state write. */
dir: string;
- /** The session the map's side panel is showing, if any. */
- activeSessionId?: string | null;
/** Opens one session's card in the side panel (the row's source click). */
onSelectSession: (sessionId: string) => void;
onClose: () => void;
@@ -108,6 +105,9 @@ export function CapturesView({
// The page is a snapshot; a state change is shown at once and the live page
// swaps in the rebuilt model a moment later.
const [items, setItems] = useState<readonly ViewCapture[]>(captures ?? []);
+ // The row the user last clicked: each item is its own thing, even when three of
+ // them come from the same session and open the same card.
+ const [selectedId, setSelectedId] = useState<string | null>(null);
const [error, setError] = useState<string | null>(null);
useEffect(() => setItems(captures ?? []), [captures]);
const now = new Date().toISOString();
@@ -134,8 +134,7 @@ export function CapturesView({
function row(item: ViewCapture, actions: ReactNode) {
const source = captureSource(item.source, sessions);
const age = timeSince(item.updatedAt, now);
- const selected =
- source.sessionId !== undefined && source.sessionId === activeSessionId;
+ const selected = item.id === selectedId;
return (
<li key={item.id}>
<div className={`capture-row${selected ? " is-active" : ""}`}>
@@ -145,7 +144,9 @@ export function CapturesView({
title={formatStamp(item.updatedAt)}
disabled={source.sessionId === undefined}
onClick={() => {
- if (source.sessionId !== undefined) onSelectSession(source.sessionId);
+ if (source.sessionId === undefined) return;
+ setSelectedId(item.id);
+ onSelectSession(source.sessionId);
}}
>
<span className="capture-text">{item.text}</span>
diff --git a/packages/template/src/Graph.tsx b/packages/template/src/Graph.tsx
index f7c25c6..d8d34ff 100644
--- a/packages/template/src/Graph.tsx
+++ b/packages/template/src/Graph.tsx
@@ -507,7 +507,12 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta
const row = sessionGraph.git.rows.find(
(candidate) => candidate.kind === "message" && candidate.message.id === hit.sessionId,
);
- return row === undefined ? null : { x: sessionGraph.git.graphWidth / 2, y: row.y };
+ if (row === undefined) return null;
+ // Centre the row's text, not only its lanes: the same span a message row
+ // reports, so a session hit and a captured row land where the reader looks.
+ const left = sessionGraph.git.graphWidth + 8;
+ const width = sessionGraph.git.rowWidth;
+ return { x: left + width / 2, y: row.y, left, right: left + width };
},
[pointOf, sessionGraph],
);
@@ -585,6 +590,9 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta
setFocusedId(`session:${sessionId}`);
setSelection({ type: "session", sessionId });
setRevealCaptures((value) => value + 1);
+ // Bring the session's row into view, the way a search hit does.
+ setSessionTarget(sessionId);
+ setSessionJumps((value) => value + 1);
},
[keep],
);
@@ -657,6 +665,21 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta
() => (fileJumps === 0 || filePoint === null ? null : { key: fileJumps, point: filePoint }),
[fileJumps, filePoint],
);
+ // A captured row's click (Story 15.3): centre the project graph on that
+ // session's row, so the card that opened on the side has a place on the map.
+ const [sessionJumps, setSessionJumps] = useState(0);
+ const [sessionTarget, setSessionTarget] = useState<string | null>(null);
+ const sessionPoint = useMemo(
+ () => (sessionTarget === null ? null : pointOfHit({ sessionId: sessionTarget, messageId: null })),
+ [sessionTarget, pointOfHit],
+ );
+ const sessionJump = useMemo(
+ () =>
+ sessionJumps === 0 || sessionPoint === null
+ ? null
+ : { key: sessionJumps, point: sessionPoint },
+ [sessionJumps, sessionPoint],
+ );
const actions = useMemo(
() => ({
@@ -831,7 +854,6 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta
captures={model.captures}
sessions={model.sessions}
dir={model.project.path}
- activeSessionId={selection?.type === "session" ? selection.sessionId : null}
onSelectSession={openSessionCard}
onClose={() => setShowCaptures(false)}
/>
@@ -864,6 +886,7 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta
jump={jump}
searchJump={searchJump}
fileJump={fileJump}
+ sessionJump={sessionJump}
fit={fits}
refocus={refocus}
/>
@@ -899,6 +922,7 @@ function MapCanvas({
jump,
searchJump,
fileJump,
+ sessionJump,
fit,
refocus,
}: {
@@ -911,6 +935,8 @@ function MapCanvas({
searchJump: { key: number; point: { x: number; y: number } } | null;
/** A files-view click: the message it opened (Story 8.15). */
fileJump: { key: number; point: { x: number; y: number } } | null;
+ /** A captured row's click: the session's row on the project graph. */
+ sessionJump: { key: number; point: { x: number; y: number } } | null;
/** A new value frames the whole map again (after "Fold all"). */
fit: number;
/** A new value centres on `focusRow` again: the stored view opened more sessions. */
@@ -960,6 +986,13 @@ function MapCanvas({
centre(filePoint);
}, [fileKey, filePoint]);
+ const sessionKey = sessionJump?.key ?? 0;
+ const sessionPt = sessionJump?.point ?? null;
+ useEffect(() => {
+ if (sessionKey === 0 || sessionPt === null) return;
+ centre(sessionPt);
+ }, [sessionKey, sessionPt]);
+
useEffect(() => {
if (refocus === 0 || focusRow === null) return;
const canvas = document.querySelector(".react-flow")?.getBoundingClientRect();
diff --git a/packages/template/test/captures-view.test.tsx b/packages/template/test/captures-view.test.tsx
index 224939d..63a23f7 100644
--- a/packages/template/test/captures-view.test.tsx
+++ b/packages/template/test/captures-view.test.tsx
@@ -45,7 +45,6 @@ function render(captures: ViewCapture[] | undefined, sessionsFor = sessions): st
captures,
sessions: sessionsFor,
dir: "/p",
- activeSessionId: null,
onSelectSession: () => {},
onClose: () => {},
}),