From 4b6538839f6bceda3a1f32fc3858dfccbc78b399 Mon Sep 17 00:00:00 2001 From: viettranx Date: Fri, 3 Apr 2026 23:32:16 +0700 Subject: [PATCH] =?UTF-8?q?refactor(ui):=20gap=20closure=20Phase=202=20?= =?UTF-8?q?=E2=80=94=20extract=20memory-documents-table?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Split memory-page.tsx (314 → 244) by extracting the documents table into memory-documents-table.tsx. Remaining 14 files >300 lines assessed — no clean extraction boundaries found (dense forms, tab routers, DnD contexts). --- .../pages/memory/memory-documents-table.tsx | 144 ++++++++++++++++++ ui/web/src/pages/memory/memory-page.tsx | 110 +++---------- 2 files changed, 164 insertions(+), 90 deletions(-) create mode 100644 ui/web/src/pages/memory/memory-documents-table.tsx diff --git a/ui/web/src/pages/memory/memory-documents-table.tsx b/ui/web/src/pages/memory/memory-documents-table.tsx new file mode 100644 index 00000000..92afeb3f --- /dev/null +++ b/ui/web/src/pages/memory/memory-documents-table.tsx @@ -0,0 +1,144 @@ +import { Brain, RotateCw, Trash2 } from "lucide-react"; +import { Button } from "@/components/ui/button"; +import { Badge } from "@/components/ui/badge"; +import { Pagination } from "@/components/shared/pagination"; +import { EmptyState } from "@/components/shared/empty-state"; +import { TableSkeleton } from "@/components/shared/loading-skeleton"; +import { formatUserLabel } from "@/lib/format-user-label"; +import { useTranslation } from "react-i18next"; +import type { MemoryDocument } from "@/types/memory"; + +type ContactResolver = (id: string) => { display_name?: string; username?: string } | null; + +interface MemoryDocumentsTableProps { + documents: MemoryDocument[]; + paginatedDocs: MemoryDocument[]; + loading: boolean; + agentId: string; + agentWorkspace?: string; + page: number; + pageSize: number; + total: number; + totalPages: number; + resolveContact: ContactResolver; + agentMap: Map; + onViewDoc: (doc: MemoryDocument) => void; + onDeleteTarget: (doc: MemoryDocument) => void; + onReindex: (doc: MemoryDocument) => void; + onPageChange: (page: number) => void; + onPageSizeChange: (size: number) => void; +} + +export function MemoryDocumentsTable({ + documents, + paginatedDocs, + loading, + agentId, + agentWorkspace, + page, + pageSize, + total, + totalPages, + resolveContact, + agentMap, + onViewDoc, + onDeleteTarget, + onReindex, + onPageChange, + onPageSizeChange, +}: MemoryDocumentsTableProps) { + const { t } = useTranslation("memory"); + + if (loading && documents.length === 0) { + return ; + } + + if (documents.length === 0) { + return ( + + ); + } + + return ( +
+ + + + + {!agentId && } + + + + + + + + {paginatedDocs.map((doc) => ( + + + {!agentId && ( + + )} + + + + + + ))} + +
{t("columns.path")}{t("columns.agent")}{t("columns.scope")}{t("columns.hash")}{t("columns.updated")}{t("columns.actions")}
+ + + {doc.agent_id ? (agentMap.get(doc.agent_id) || doc.agent_id.slice(0, 8)) : "-"} + + + {doc.user_id ? t("scopeLabel.personal") : t("scopeLabel.global")} + + {doc.user_id && ( + {formatUserLabel(doc.user_id, resolveContact)} + )} + + {doc.hash.slice(0, 8)} + + {new Date(doc.updated_at).toLocaleString()} + +
+ + +
+
+ +
+ ); +} diff --git a/ui/web/src/pages/memory/memory-page.tsx b/ui/web/src/pages/memory/memory-page.tsx index eb77b207..70bd0cce 100644 --- a/ui/web/src/pages/memory/memory-page.tsx +++ b/ui/web/src/pages/memory/memory-page.tsx @@ -1,13 +1,10 @@ import { useState, useMemo } from "react"; import { useTranslation } from "react-i18next"; -import { Brain, Plus, RefreshCw, Search, Database, Trash2, RotateCw } from "lucide-react"; +import { Plus, RefreshCw, Search, Database } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Label } from "@/components/ui/label"; import { PageHeader } from "@/components/shared/page-header"; -import { EmptyState } from "@/components/shared/empty-state"; -import { TableSkeleton } from "@/components/shared/loading-skeleton"; -import { Pagination } from "@/components/shared/pagination"; import { ConfirmDialog } from "@/components/shared/confirm-dialog"; import { useAgents } from "@/pages/agents/hooks/use-agents"; import { useContactResolver } from "@/hooks/use-contact-resolver"; @@ -16,6 +13,7 @@ import { useMemoryDocuments } from "./hooks/use-memory"; import { MemoryDocumentDialog } from "./memory-document-dialog"; import { MemoryCreateDialog } from "./memory-create-dialog"; import { MemorySearchDialog } from "./memory-search-dialog"; +import { MemoryDocumentsTable } from "./memory-documents-table"; import { useMinLoading } from "@/hooks/use-min-loading"; import { useDeferredLoading } from "@/hooks/use-deferred-loading"; import { useEmbeddingStatus } from "@/hooks/use-embedding-status"; @@ -189,92 +187,24 @@ export function MemoryPage() { {/* Document table */}
- {showSkeleton ? ( - - ) : documents.length === 0 ? ( - - ) : ( -
- - - - - {!agentId && } - - - - - - - - {paginatedDocs.map((doc) => ( - - - {!agentId && ( - - )} - - - - - - ))} - -
{t("columns.path")}{t("columns.agent")}{t("columns.scope")}{t("columns.hash")}{t("columns.updated")}{t("columns.actions")}
- - - {doc.agent_id ? (agentMap.get(doc.agent_id) || doc.agent_id.slice(0, 8)) : "-"} - - - {doc.user_id ? t("scopeLabel.personal") : t("scopeLabel.global")} - - {doc.user_id && ( - {formatUserLabel(doc.user_id, resolveContact)} - )} - - {doc.hash.slice(0, 8)} - - {new Date(doc.updated_at).toLocaleString()} - -
- - -
-
- { setPageSize(size); setPage(1); }} - /> -
- )} + { setPageSize(size); setPage(1); }} + />
{/* Dialogs */}