feat: Display document reindexing status in the sidebar by adding document ID to logs

This commit is contained in:
Anish Sarkar 2025-12-28 01:07:42 +05:30
parent 2570360079
commit 8b10b0cd24
5 changed files with 33 additions and 4 deletions

View file

@ -319,6 +319,9 @@ async def get_logs_summary(
if log.log_metadata
else "Unknown"
)
document_id = (
log.log_metadata.get("document_id") if log.log_metadata else None
)
summary["active_tasks"].append(
{
"id": log.id,
@ -326,6 +329,7 @@ async def get_logs_summary(
"message": log.message,
"started_at": log.created_at,
"source": log.source,
"document_id": document_id,
}
)

View file

@ -1,6 +1,6 @@
"use client";
import { Loader2, RefreshCw } from "lucide-react";
import { Loader2 } from "lucide-react";
import { motion, AnimatePresence } from "motion/react";
import { useTranslations } from "next-intl";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
@ -22,7 +22,7 @@ export function ProcessingIndicator({ activeTasksCount }: ProcessingIndicatorPro
exit={{ opacity: 0, height: 0, marginBottom: 0 }}
transition={{ duration: 0.3 }}
>
<Alert className="border-primary/20 bg-primary/5">
<Alert className="border-border bg-primary/5">
<div className="flex items-center gap-4">
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-primary/10">
<Loader2 className="h-5 w-5 animate-spin text-primary" />

View file

@ -12,7 +12,8 @@ import {
} from "lucide-react";
import { usePathname, useRouter } from "next/navigation";
import { useTranslations } from "next-intl";
import { useCallback, useEffect, useState } from "react";
import { useCallback, useEffect, useMemo, useState } from "react";
import { useLogsSummary } from "@/hooks/use-logs";
import { Button } from "@/components/ui/button";
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";
import {
@ -78,6 +79,23 @@ export function NavNotes({
const [isOpen, setIsOpen] = useState(defaultOpen);
const [isAllNotesSidebarOpen, setIsAllNotesSidebarOpen] = useState(false);
// Poll for active reindexing tasks to show inline loading indicators
const { summary } = useLogsSummary(
searchSpaceId ? Number(searchSpaceId) : 0,
24,
{ refetchInterval: 2000 }
);
// Create a Set of document IDs that are currently being reindexed
const reindexingDocumentIds = useMemo(() => {
if (!summary?.active_tasks) return new Set<number>();
return new Set(
summary.active_tasks
.filter((task) => task.document_id != null)
.map((task) => task.document_id as number)
);
}, [summary?.active_tasks]);
// Auto-collapse on smaller screens when Sources is expanded
useEffect(() => {
if (isSourcesExpanded && isMobile) {
@ -159,6 +177,7 @@ export function NavNotes({
notes.map((note) => {
const isDeletingNote = isDeleting === note.id;
const isActive = pathname === note.url;
const isReindexing = note.id ? reindexingDocumentIds.has(note.id) : false;
return (
<SidebarMenuItem key={note.id || note.name} className="group/note">
@ -172,7 +191,11 @@ export function NavNotes({
isDeletingNote && "opacity-50"
)}
>
<note.icon className="h-4 w-4 shrink-0" />
{isReindexing ? (
<Loader2 className="h-4 w-4 shrink-0 animate-spin text-primary" />
) : (
<note.icon className="h-4 w-4 shrink-0" />
)}
<span className="truncate">{note.name}</span>
</SidebarMenuButton>

View file

@ -85,6 +85,7 @@ export const logActiveTask = z.object({
message: z.string(),
started_at: z.string(),
source: z.string().nullable().optional(),
document_id: z.number().nullable().optional(),
});
export const logFailure = z.object({
id: z.number(),

View file

@ -39,6 +39,7 @@ export interface LogSummary {
message: string;
started_at: string;
source?: string;
document_id?: number;
}>;
recent_failures: Array<{
id: number;