import React from 'react'; import { Link } from '@tanstack/react-router'; import Tooltip from '@/components/elements/tooltip/Tooltip'; import Translate from '@/components/elements/Translate'; import type { TranslationValue, TranslationValues } from '@/components/elements/Translate'; import dayjs from '@/lib/dayjs'; import ActivityLogMetaButton from '@/components/elements/activity/ActivityLogMetaButton'; import { FolderOpen, Terminal } from 'lucide-react'; import { cn } from '@/lib/cn'; import Avatar from '@/components/Avatar'; import type { ActivityLog } from '@/api/activity'; import { isNumber, isString } from '@/lib/objects'; import { relationshipAttributes } from '@/api/relationships'; type ActorAttributes = { username?: string; email?: string }; interface Props { activity: ActivityLog; children?: React.ReactNode; } const activityIconClass = 'flex space-x-1 mx-2 transition-colors duration-100 text-muted-foreground [&_svg]:px-1 [&_svg]:py-px [&_svg]:cursor-pointer [&_svg]:h-5 [&_svg]:w-auto [&_svg]:hover:text-foreground'; const activityDescriptionClass = 'mt-1 text-sm break-words line-clamp-2 pr-4 [&_strong]:break-all [&_strong]:font-semibold [&_strong]:text-foreground'; function wrapProperty(value: TranslationValue): TranslationValue { if (value === null || isString(value) || isNumber(value)) { return `${String(value)}`; } if (Array.isArray(value)) { return value.map(wrapProperty); } if (value === true || value === false) { return value; } return Object.fromEntries( Object.entries(value).map(([key, item]) => [ key, key === 'count' || key.endsWith('_count') ? item : wrapProperty(item), ]) ); } const wrapProperties = (properties: TranslationValues): TranslationValues => Object.fromEntries(Object.entries(properties).map(([key, value]) => [key, wrapProperty(value)])); export default function ActivityLogEntry({ activity, children }: Props) { const { attributes } = activity; const actor = relationshipAttributes(attributes.relationships?.actor); const properties = wrapProperties(attributes.properties); return (
{actor?.username || 'System'}  —  {attributes.event}
{attributes.is_api && ( )} {attributes.event.startsWith('server:sftp.') && ( )} {children}

{attributes.ip && ( {attributes.ip}  |  )} {dayjs(attributes.timestamp).fromNow()}
{attributes.has_additional_metadata && }
); }