// Base ActivityLogModal styles (.activity-log-*, .activity-icon, etc.) currently live // in ScriptsModal.css. Until fully extracted, import that file so this eager modal is styled. import "./ScriptsModal.css"; // Embedded (right-dock) activity-log styles were extracted to their own file next to this component. import "./ActivityLogModal.css"; import { useState, useEffect } from "react"; import { useTranslation } from "react-i18next"; import type { TFunction } from "i18next"; import { X, History, Trash2, Filter, RefreshCw, CheckCircle, XCircle, ArrowRight, Plus, Settings, AlertCircle, Loader2, Folder } from "lucide-react"; import { clearActivityLog, type ActivityLogEntry, type ActivityEventType, type ActivityFeedEntry } from "../api"; import { useActivityLog } from "../hooks/useActivityLog"; import { useEmbeddedPresentation, type ModalPresentation } from "../hooks/useEmbeddedPresentation"; import type { Task, ProjectInfo } from "@fusion/core"; import { linkifyFilePaths } from "../utils/filePathLinkify"; import { getRelativeTimeBucket } from "../utils/relativeTimeAgo"; interface ActivityLogModalProps { isOpen: boolean; onClose: () => void; tasks: Task[]; onOpenTaskDetail?: (taskId: string) => void; /** When provided, shows only activity for this project */ projectId?: string; /** List of all projects for filter dropdown */ projects?: ProjectInfo[]; /** Called when project filter changes */ onProjectFilterChange?: (projectId: string | undefined) => void; /** Current project context - when set, uses per-project activity log */ currentProject?: ProjectInfo | null; /* FNXC:RightDockEmbedded 2026-06-22-00:00: Right-dock redesign renders dock items inline (not as fixed popup overlays). When presentation="embedded" the component drops the .modal-overlay fixed full-screen host and the modal close button (the dock owns its own header/close), and disables modal-only Escape-to-close. presentation="modal" (default) stays byte-identical to preserve existing modal behavior. */ presentation?: ModalPresentation; } function getEventTypeLabels(t: TFunction<"app">): Record { return { "task:created": t("activityLog.eventType.taskCreated", "Task Created"), "task:moved": t("activityLog.eventType.taskMoved", "Task Moved"), "task:updated": t("activityLog.eventType.taskUpdated", "Task Updated"), "task:deleted": t("activityLog.eventType.taskDeleted", "Task Deleted"), "task:merged": t("activityLog.eventType.taskMerged", "Task Merged"), "task:failed": t("activityLog.eventType.taskFailed", "Task Failed"), "task:duplicate-warning-overridden": t("activityLog.eventType.duplicateWarningOverridden", "Duplicate Warning Overridden"), "task:auto-archived-ghost-bug": t("activityLog.eventType.autoArchivedGhostBug", "Task Auto-Archived (Ghost Bug)"), "task:auto-archived-duplicate": t("activityLog.eventType.autoArchivedDuplicate", "Task Auto-Archived (Duplicate)"), "task:merge-worktree-reacquired": t("activityLog.eventType.mergeWorktreeReacquired", "Merge Worktree Reacquired"), "task:auto-archived-deterministic-duplicate": t("activityLog.eventType.autoArchivedDeterministicDuplicate", "Task Auto-Archived (Deterministic Duplicate)"), "task:auto-archived-near-duplicate": t("activityLog.eventType.autoArchivedNearDuplicate", "Task Auto-Archived (Near-Duplicate)"), "task:near-duplicate-flagged": t("activityLog.eventType.nearDuplicateFlagged", "Near-Duplicate Flagged"), "settings:updated": t("activityLog.eventType.settingsUpdated", "Settings Updated"), "project:isolation-transition": t("activityLog.eventType.projectIsolationTransition", "Project Isolation Transition"), }; } const EVENT_TYPE_ICONS: Record = { "task:created": , "task:moved": , "task:updated": , "task:deleted": , "task:merged": , "task:failed": , "task:duplicate-warning-overridden": , "task:auto-archived-ghost-bug": , "task:auto-archived-duplicate": , "task:auto-archived-deterministic-duplicate": , "task:auto-archived-near-duplicate": , "task:near-duplicate-flagged": , "task:merge-worktree-reacquired": , "settings:updated": , "project:isolation-transition": , }; function formatTimestamp(timestamp: string, t: TFunction<"app">): string { /* * FNXC:RelativeTime 2026-06-17-20:48: * FN-6618 centralizes ActivityLogModal bucket math without changing its activityLog.time.* keys, uppercase Just now default, future-as-just-now behavior, or Invalid Date fallback. */ const bucket = getRelativeTimeBucket(timestamp); if (!bucket) { const timestampMs = Date.parse(timestamp); if (Number.isFinite(timestampMs) && Date.now() - timestampMs < 0) return t("activityLog.time.justNow", "Just now"); return new Date(timestamp).toLocaleDateString(undefined, { month: "short", day: "numeric" }); } switch (bucket.bucket) { case "just-now": return t("activityLog.time.justNow", "Just now"); case "minutes": return t("activityLog.time.minutesAgo", "{{count}}m ago", { count: bucket.count }); case "hours": return t("activityLog.time.hoursAgo", "{{count}}h ago", { count: bucket.count }); case "days": return t("activityLog.time.daysAgo", "{{count}}d ago", { count: bucket.count }); case "weeks": case "older": return bucket.date.toLocaleDateString(undefined, { month: "short", day: "numeric" }); } } /** * ActivityLogModal - Activity log with project attribution and filtering * * Data source selection: * - Project view (currentProject set): reads from the per-project activity * log via /api/activity, which is always populated with task lifecycle events. * - Overview mode (no currentProject): reads from the unified central * feed via /api/activity-feed, which aggregates activity across all projects. * The project filter dropdown allows narrowing results to a specific project. * * Features: * - Project name badge for each activity entry * - Project filter dropdown (when projects list provided) * - Event type filter * - Real-time updates via useActivityLog hook */ export function ActivityLogModal({ isOpen, onClose, tasks: _tasks, onOpenTaskDetail, projectId, projects = [], onProjectFilterChange, currentProject, presentation = "modal", }: ActivityLogModalProps) { const { isEmbedded, escapeEnabled } = useEmbeddedPresentation(presentation); const { t } = useTranslation("app"); const EVENT_TYPE_LABELS = getEventTypeLabels(t); const [filteredType, setFilteredType] = useState("all"); const [filteredProjectId, setFilteredProjectId] = useState(projectId || "all"); const [showConfirmClear, setShowConfirmClear] = useState(false); // Sync with external projectId prop useEffect(() => { setFilteredProjectId(projectId || "all"); }, [projectId]); // Convert filters to the format expected by useActivityLog const activityType = filteredType === "all" ? undefined : filteredType; const activeProjectId = filteredProjectId === "all" ? undefined : filteredProjectId; // Determine data source: // - In project view (currentProject set): use per-project activity log (/api/activity) // which is always populated with task lifecycle events for the current project. // - In overview mode (no currentProject): use unified central feed (/api/activity-feed) // which aggregates activity across all registered projects. // The project filter dropdown (projects prop) still appears to filter by project, // but the default data source is the per-project log in project view. const useCentralFeed = !currentProject && projects.length > 0; // Use the hook for data fetching const { entries, loading: isLoading, error, refresh, hasMore } = useActivityLog({ projectId: activeProjectId, type: activityType, limit: 100, autoRefresh: isOpen, useCentralFeed, }); // Convert entries to ActivityLogEntry format for compatibility const convertedEntries: ActivityLogEntry[] = entries.map((entry: ActivityFeedEntry) => ({ id: entry.id, timestamp: entry.timestamp, type: entry.type, taskId: entry.taskId, taskTitle: entry.taskTitle, details: entry.details, metadata: entry.metadata, projectId: entry.projectId, projectName: entry.projectName, })); const handleClearLog = async () => { try { await clearActivityLog(); refresh(); setShowConfirmClear(false); } catch { // Error handled by hook setShowConfirmClear(false); } }; const handleTaskClick = (taskId: string) => { if (onOpenTaskDetail) { onOpenTaskDetail(taskId); } }; const handleProjectFilterChange = (value: string) => { setFilteredProjectId(value); onProjectFilterChange?.(value === "all" ? undefined : value); }; // Handle escape key to close. // FNXC:RightDockEmbedded 2026-06-22-00:00: Embedded presentation must not auto-close on Escape; the dock owns lifecycle. useEffect(() => { if (!isOpen || !escapeEnabled) return; const handleKey = (e: KeyboardEvent) => { if (e.key === "Escape") { if (showConfirmClear) { setShowConfirmClear(false); } else { onClose(); } } }; document.addEventListener("keydown", handleKey); return () => document.removeEventListener("keydown", handleKey); }, [isOpen, escapeEnabled, onClose, showConfirmClear]); // Determine if any filter is active const isFilterActive = filteredType !== "all" || filteredProjectId !== "all"; if (!isOpen) return null; /* FNXC:RightDockEmbedded 2026-06-22-00:00: Shared modal body for both presentations. In embedded mode the root is a plain flow container (.activity-log-embedded.right-dock-embedded-view) instead of a position:fixed .modal-overlay, the inner panel gains --embedded sizing, and the modal close "×" is dropped (dock supplies its own header/close). Modal mode stays byte-identical. */ const body = (
{/* Header — uses shared modal-header pattern for consistent close control */}
{t("activityLog.title", "Activity Log")}
{/* Project filter dropdown (when projects provided) */} {projects.length > 0 && (
)} {/* Event type filter dropdown */}
{/* Refresh button */} {/* Clear button */} {convertedEntries.length > 0 && ( )}
{/* Close button — uses shared modal-close for consistent sizing and alignment. FNXC:RightDockEmbedded 2026-06-22-00:00: Dropped in embedded mode; the dock provides its own close. */} {!isEmbedded && ( )}
{/* Active filters display */} {isFilterActive && (
{t("activityLog.activeFilters", "Active filters:")} {filteredProjectId !== "all" && ( {t("activityLog.projectFilterBadge", "Project: {{project}}", { project: projects.find(p => p.id === filteredProjectId)?.name || filteredProjectId })} )} {filteredType !== "all" && ( {t("activityLog.typeFilterBadge", "Type: {{type}}", { type: EVENT_TYPE_LABELS[filteredType] })} )}
)} {/* Content */}
{error && (
{error}
)} {convertedEntries.length === 0 && !isLoading && !error && (

{isFilterActive ? t("activityLog.noMatchingActivity", "No activity matches the current filters") : t("activityLog.noActivityRecorded", "No activity recorded yet")}

{isFilterActive && ( )}
)}
{convertedEntries.map((entry) => (
{EVENT_TYPE_ICONS[entry.type]}
{EVENT_TYPE_LABELS[entry.type]} {formatTimestamp(entry.timestamp, t)}
{entry.taskId && ( )} {entry.taskTitle && ( {entry.taskTitle} )} {linkifyFilePaths(entry.details ?? "")}
{entry.metadata && Object.keys(entry.metadata).length > 0 && (
{typeof entry.metadata.from === "string" && typeof entry.metadata.to === "string" && ( {entry.metadata.from} → {entry.metadata.to} )} {typeof entry.metadata.merged === "boolean" && ( {entry.metadata.merged ? t("activityLog.merged", "Merged") : t("activityLog.notMerged", "Not merged")} )}
)}
))}
{hasMore && !isLoading && ( )} {isLoading && convertedEntries.length > 0 && (
)}
{/* Confirmation dialog for clear */} {showConfirmClear && (

{t("activityLog.confirmClear", "Clear Activity Log?")}

{t("activityLog.confirmClearMessage", "This will permanently delete all activity log entries. This action cannot be undone.")}

)}
); if (isEmbedded) { // FNXC:RightDockEmbedded 2026-06-22-00:00: Plain flow container — no fixed overlay, no backdrop click-to-close. Dock owns the chrome. return
{body}
; } return (
{ if (e.target === e.currentTarget) onClose(); }} role="dialog" aria-modal="true" data-testid="activity-log-modal-overlay" > {body}
); }