fix: resolve archive filter loss and session cache bugs in insights
- Add showArchived field to insights Zustand store so all callers (including event listeners) can access it without parameter threading - loadInsightsSessions now falls back to store.showArchived when no explicit parameter is passed, fixing newSession, renameSession, updateModelConfig, and the onInsightsSessionUpdated listener - Add in-memory cache update to SessionManager.renameSession matching the pattern used by updateSessionModelConfig - Add input validation for bulk delete/archive IPC handlers Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -190,6 +190,17 @@ export class SessionManager {
|
||||
session.title = newTitle;
|
||||
session.updatedAt = new Date();
|
||||
this.storage.saveSession(projectPath, session);
|
||||
|
||||
// Update cache if this session is cached
|
||||
for (const [projectId, cachedSession] of this.sessions) {
|
||||
if (cachedSession.id === sessionId) {
|
||||
cachedSession.title = newTitle;
|
||||
cachedSession.updatedAt = session.updatedAt;
|
||||
this.sessions.set(projectId, cachedSession);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -264,6 +264,10 @@ export function registerInsightsHandlers(getMainWindow: () => BrowserWindow | nu
|
||||
ipcMain.handle(
|
||||
IPC_CHANNELS.INSIGHTS_DELETE_SESSIONS,
|
||||
async (_, projectId: string, sessionIds: string[]): Promise<IPCResult<{ deletedIds: string[]; failedIds: string[] }>> => {
|
||||
if (!Array.isArray(sessionIds) || sessionIds.length === 0) {
|
||||
return { success: false, error: "No sessions specified" };
|
||||
}
|
||||
|
||||
const project = projectStore.getProject(projectId);
|
||||
if (!project) {
|
||||
return { success: false, error: "Project not found" };
|
||||
@@ -299,6 +303,10 @@ export function registerInsightsHandlers(getMainWindow: () => BrowserWindow | nu
|
||||
ipcMain.handle(
|
||||
IPC_CHANNELS.INSIGHTS_ARCHIVE_SESSIONS,
|
||||
async (_, projectId: string, sessionIds: string[]): Promise<IPCResult<{ archivedIds: string[]; failedIds: string[] }>> => {
|
||||
if (!Array.isArray(sessionIds) || sessionIds.length === 0) {
|
||||
return { success: false, error: "No sessions specified" };
|
||||
}
|
||||
|
||||
const project = projectStore.getProject(projectId);
|
||||
if (!project) {
|
||||
return { success: false, error: "Project not found" };
|
||||
|
||||
@@ -110,7 +110,7 @@ export function Insights({ projectId }: InsightsProps) {
|
||||
const [creatingTask, setCreatingTask] = useState<Set<string>>(new Set());
|
||||
const [taskCreated, setTaskCreated] = useState<Set<string>>(new Set());
|
||||
const [showSidebar, setShowSidebar] = useState(true);
|
||||
const [showArchived, setShowArchived] = useState(false);
|
||||
const showArchived = useInsightsStore((state) => state.showArchived);
|
||||
const [isUserAtBottom, setIsUserAtBottom] = useState(true);
|
||||
const [viewportEl, setViewportEl] = useState<HTMLElement | null>(null);
|
||||
|
||||
@@ -272,7 +272,7 @@ export function Insights({ projectId }: InsightsProps) {
|
||||
};
|
||||
|
||||
const handleToggleShowArchived = () => {
|
||||
setShowArchived(prev => !prev);
|
||||
useInsightsStore.getState().setShowArchived(!showArchived);
|
||||
};
|
||||
|
||||
const handleCreateTask = async (
|
||||
|
||||
@@ -27,6 +27,7 @@ interface InsightsState {
|
||||
currentTool: ToolUsage | null; // Currently executing tool
|
||||
toolsUsed: InsightsToolUsage[]; // Tools used during current response
|
||||
isLoadingSessions: boolean;
|
||||
showArchived: boolean; // Whether to include archived sessions in listings
|
||||
|
||||
// Actions
|
||||
setSession: (session: InsightsSession | null) => void;
|
||||
@@ -44,6 +45,7 @@ interface InsightsState {
|
||||
finalizeStreamingMessage: () => void;
|
||||
clearSession: () => void;
|
||||
setLoadingSessions: (loading: boolean) => void;
|
||||
setShowArchived: (showArchived: boolean) => void;
|
||||
}
|
||||
|
||||
const initialStatus: InsightsChatStatus = {
|
||||
@@ -62,6 +64,7 @@ export const useInsightsStore = create<InsightsState>((set, _get) => ({
|
||||
currentTool: null,
|
||||
toolsUsed: [],
|
||||
isLoadingSessions: false,
|
||||
showArchived: false,
|
||||
|
||||
// Actions
|
||||
setSession: (session) => set({ session }),
|
||||
@@ -72,6 +75,8 @@ export const useInsightsStore = create<InsightsState>((set, _get) => ({
|
||||
|
||||
setLoadingSessions: (loading) => set({ isLoadingSessions: loading }),
|
||||
|
||||
setShowArchived: (showArchived) => set({ showArchived }),
|
||||
|
||||
setPendingMessage: (message) => set({ pendingMessage: message }),
|
||||
|
||||
addMessage: (message) =>
|
||||
@@ -211,8 +216,11 @@ export async function loadInsightsSessions(projectId: string, includeArchived?:
|
||||
const store = useInsightsStore.getState();
|
||||
store.setLoadingSessions(true);
|
||||
|
||||
// Use explicit parameter if provided, otherwise read from store
|
||||
const archived = includeArchived ?? store.showArchived;
|
||||
|
||||
try {
|
||||
const result = await window.electronAPI.listInsightsSessions(projectId, includeArchived);
|
||||
const result = await window.electronAPI.listInsightsSessions(projectId, archived);
|
||||
if (result.success && result.data) {
|
||||
store.setSessions(result.data);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user