fix(chat): hide mutation suggestion cards when no session is selected

Skip pendingSuggestions in mergedMessages and previousMutationSuggestions
rendering when activeSessionId is null. Also fix empty state check to not
consider API suggestions as content when no session is active.
This commit is contained in:
Rodrigo Verdiani 2026-07-04 18:17:25 -03:00
parent 3200f3f07c
commit a4828c4d45

View File

@ -168,9 +168,11 @@ export function AIChatPanel({
| { kind: "suggestion"; data: MutationSuggestionResponse }
> = messages.map((m) => ({ kind: "message" as const, data: m }));
for (const s of pendingSuggestions ?? []) {
if (!s.createdAt) continue;
items.push({ kind: "suggestion" as const, data: s });
if (activeSessionId) {
for (const s of pendingSuggestions ?? []) {
if (!s.createdAt) continue;
items.push({ kind: "suggestion" as const, data: s });
}
}
items.sort((a, b) => {
@ -180,7 +182,7 @@ export function AIChatPanel({
});
return items;
}, [messages, pendingSuggestions]);
}, [messages, pendingSuggestions, activeSessionId]);
// Track manual scroll to respect user reading position
useEffect(() => {
@ -319,7 +321,9 @@ export function AIChatPanel({
ref={scrollContainerRef}
className="flex min-h-0 flex-1 flex-col overflow-x-hidden overflow-y-auto"
>
{messages.length === 0 && !pendingSuggestions?.length && !isStreaming ? (
{messages.length === 0 &&
!(activeSessionId && pendingSuggestions?.length) &&
!isStreaming ? (
<div className="flex flex-1 flex-col items-center justify-center p-4">
<Bot className="text-muted-foreground mx-auto mb-4 h-12 w-12" />
<h3 className="text-foreground mb-2 font-medium">AI Analysis Assistant</h3>
@ -432,26 +436,27 @@ export function AIChatPanel({
})}
</>
)}
{previousMutationSuggestions
.filter(
(s, i, arr) =>
!pendingIds.has(s.mutationId) &&
!resolvedIds.has(s.mutationId) &&
arr.findIndex((x) => x.mutationId === s.mutationId) === i
)
.map((s) => (
<MutationSuggestionCard
key={s.mutationId}
mutationId={s.mutationId}
targetType={s.targetType}
targetId={s.targetId}
fieldName={s.fieldName}
oldValue={s.oldValue}
newValue={s.newValue}
onRenameApplied={onRenameApplied}
onResolved={handleResolved}
/>
))}
{activeSessionId &&
previousMutationSuggestions
.filter(
(s, i, arr) =>
!pendingIds.has(s.mutationId) &&
!resolvedIds.has(s.mutationId) &&
arr.findIndex((x) => x.mutationId === s.mutationId) === i
)
.map((s) => (
<MutationSuggestionCard
key={s.mutationId}
mutationId={s.mutationId}
targetType={s.targetType}
targetId={s.targetId}
fieldName={s.fieldName}
oldValue={s.oldValue}
newValue={s.newValue}
onRenameApplied={onRenameApplied}
onResolved={handleResolved}
/>
))}
{isStreaming && (
<>
<div className="mb-4 flex gap-3">