mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-28 21:49:40 +02:00
feat: Display document reindexing status in the sidebar by adding document ID to logs
This commit is contained in:
parent
2570360079
commit
8b10b0cd24
5 changed files with 33 additions and 4 deletions
|
|
@ -319,6 +319,9 @@ async def get_logs_summary(
|
||||||
if log.log_metadata
|
if log.log_metadata
|
||||||
else "Unknown"
|
else "Unknown"
|
||||||
)
|
)
|
||||||
|
document_id = (
|
||||||
|
log.log_metadata.get("document_id") if log.log_metadata else None
|
||||||
|
)
|
||||||
summary["active_tasks"].append(
|
summary["active_tasks"].append(
|
||||||
{
|
{
|
||||||
"id": log.id,
|
"id": log.id,
|
||||||
|
|
@ -326,6 +329,7 @@ async def get_logs_summary(
|
||||||
"message": log.message,
|
"message": log.message,
|
||||||
"started_at": log.created_at,
|
"started_at": log.created_at,
|
||||||
"source": log.source,
|
"source": log.source,
|
||||||
|
"document_id": document_id,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { Loader2, RefreshCw } from "lucide-react";
|
import { Loader2 } from "lucide-react";
|
||||||
import { motion, AnimatePresence } from "motion/react";
|
import { motion, AnimatePresence } from "motion/react";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||||
|
|
@ -22,7 +22,7 @@ export function ProcessingIndicator({ activeTasksCount }: ProcessingIndicatorPro
|
||||||
exit={{ opacity: 0, height: 0, marginBottom: 0 }}
|
exit={{ opacity: 0, height: 0, marginBottom: 0 }}
|
||||||
transition={{ duration: 0.3 }}
|
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 items-center gap-4">
|
||||||
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-primary/10">
|
<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" />
|
<Loader2 className="h-5 w-5 animate-spin text-primary" />
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,8 @@ import {
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { usePathname, useRouter } from "next/navigation";
|
import { usePathname, useRouter } from "next/navigation";
|
||||||
import { useTranslations } from "next-intl";
|
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 { Button } from "@/components/ui/button";
|
||||||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";
|
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";
|
||||||
import {
|
import {
|
||||||
|
|
@ -78,6 +79,23 @@ export function NavNotes({
|
||||||
const [isOpen, setIsOpen] = useState(defaultOpen);
|
const [isOpen, setIsOpen] = useState(defaultOpen);
|
||||||
const [isAllNotesSidebarOpen, setIsAllNotesSidebarOpen] = useState(false);
|
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
|
// Auto-collapse on smaller screens when Sources is expanded
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isSourcesExpanded && isMobile) {
|
if (isSourcesExpanded && isMobile) {
|
||||||
|
|
@ -159,6 +177,7 @@ export function NavNotes({
|
||||||
notes.map((note) => {
|
notes.map((note) => {
|
||||||
const isDeletingNote = isDeleting === note.id;
|
const isDeletingNote = isDeleting === note.id;
|
||||||
const isActive = pathname === note.url;
|
const isActive = pathname === note.url;
|
||||||
|
const isReindexing = note.id ? reindexingDocumentIds.has(note.id) : false;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SidebarMenuItem key={note.id || note.name} className="group/note">
|
<SidebarMenuItem key={note.id || note.name} className="group/note">
|
||||||
|
|
@ -172,7 +191,11 @@ export function NavNotes({
|
||||||
isDeletingNote && "opacity-50"
|
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>
|
<span className="truncate">{note.name}</span>
|
||||||
</SidebarMenuButton>
|
</SidebarMenuButton>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,7 @@ export const logActiveTask = z.object({
|
||||||
message: z.string(),
|
message: z.string(),
|
||||||
started_at: z.string(),
|
started_at: z.string(),
|
||||||
source: z.string().nullable().optional(),
|
source: z.string().nullable().optional(),
|
||||||
|
document_id: z.number().nullable().optional(),
|
||||||
});
|
});
|
||||||
export const logFailure = z.object({
|
export const logFailure = z.object({
|
||||||
id: z.number(),
|
id: z.number(),
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ export interface LogSummary {
|
||||||
message: string;
|
message: string;
|
||||||
started_at: string;
|
started_at: string;
|
||||||
source?: string;
|
source?: string;
|
||||||
|
document_id?: number;
|
||||||
}>;
|
}>;
|
||||||
recent_failures: Array<{
|
recent_failures: Array<{
|
||||||
id: number;
|
id: number;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue