2022-11-25 20:25:03 +00:00
|
|
|
import * as React from 'react';
|
2022-06-12 19:08:26 +00:00
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
import Tooltip from '@/components/elements/tooltip/Tooltip';
|
|
|
|
import Translate from '@/components/elements/Translate';
|
|
|
|
import { format, formatDistanceToNowStrict } from 'date-fns';
|
|
|
|
import { ActivityLog } from '@definitions/user';
|
|
|
|
import ActivityLogMetaButton from '@/components/elements/activity/ActivityLogMetaButton';
|
2022-07-09 23:30:38 +00:00
|
|
|
import { FolderOpenIcon, TerminalIcon } from '@heroicons/react/solid';
|
2022-06-18 16:52:26 +00:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import style from './style.module.css';
|
2022-06-19 17:46:15 +00:00
|
|
|
import Avatar from '@/components/Avatar';
|
2022-06-20 17:19:40 +00:00
|
|
|
import useLocationHash from '@/plugins/useLocationHash';
|
2022-07-01 01:06:50 +00:00
|
|
|
import { getObjectKeys, isObject } from '@/lib/objects';
|
2022-06-12 19:08:26 +00:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
activity: ActivityLog;
|
|
|
|
children?: React.ReactNode;
|
|
|
|
}
|
|
|
|
|
2022-07-01 01:06:50 +00:00
|
|
|
function wrapProperties(value: unknown): any {
|
|
|
|
if (value === null || typeof value === 'string' || typeof value === 'number') {
|
|
|
|
return `<strong>${String(value)}</strong>`;
|
|
|
|
}
|
2022-06-18 20:36:19 +00:00
|
|
|
|
2022-07-01 01:06:50 +00:00
|
|
|
if (isObject(value)) {
|
|
|
|
return getObjectKeys(value).reduce((obj, key) => {
|
|
|
|
if (key === 'count' || (typeof key === 'string' && key.endsWith('_count'))) {
|
|
|
|
return { ...obj, [key]: value[key] };
|
|
|
|
}
|
|
|
|
return { ...obj, [key]: wrapProperties(value[key]) };
|
|
|
|
}, {} as Record<string, unknown>);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Array.isArray(value)) {
|
|
|
|
return value.map(wrapProperties);
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
2022-06-18 20:36:19 +00:00
|
|
|
|
2022-06-12 19:08:26 +00:00
|
|
|
export default ({ activity, children }: Props) => {
|
2022-06-20 17:19:40 +00:00
|
|
|
const { pathTo } = useLocationHash();
|
2022-06-12 19:08:26 +00:00
|
|
|
const actor = activity.relationships.actor;
|
2022-07-01 01:06:50 +00:00
|
|
|
const properties = wrapProperties(activity.properties);
|
2022-06-18 19:28:42 +00:00
|
|
|
|
2022-06-12 19:08:26 +00:00
|
|
|
return (
|
2022-12-16 02:06:14 +00:00
|
|
|
<div className={'grid grid-cols-10 py-4 border-b-2 border-slate-800 last:rounded-b last:border-0 group'}>
|
2022-06-12 19:40:14 +00:00
|
|
|
<div className={'hidden sm:flex sm:col-span-1 items-center justify-center select-none'}>
|
2022-12-16 02:06:14 +00:00
|
|
|
<div className={'flex items-center w-10 h-10 rounded-full bg-slate-600 overflow-hidden'}>
|
2022-06-19 17:46:15 +00:00
|
|
|
<Avatar name={actor?.uuid || 'system'} />
|
2022-06-12 19:08:26 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-06-12 19:40:14 +00:00
|
|
|
<div className={'col-span-10 sm:col-span-9 flex'}>
|
|
|
|
<div className={'flex-1 px-4 sm:px-0'}>
|
2022-12-16 02:06:14 +00:00
|
|
|
<div className={'flex items-center text-slate-50'}>
|
2022-06-12 19:08:26 +00:00
|
|
|
<Tooltip placement={'top'} content={actor?.email || 'System User'}>
|
|
|
|
<span>{actor?.username || 'System'}</span>
|
|
|
|
</Tooltip>
|
2022-12-16 02:06:14 +00:00
|
|
|
<span className={'text-slate-400'}> — </span>
|
2022-06-12 19:08:26 +00:00
|
|
|
<Link
|
2022-06-20 17:19:40 +00:00
|
|
|
to={`#${pathTo({ event: activity.event })}`}
|
2022-06-12 19:08:26 +00:00
|
|
|
className={'transition-colors duration-75 active:text-cyan-400 hover:text-cyan-400'}
|
|
|
|
>
|
|
|
|
{activity.event}
|
|
|
|
</Link>
|
2022-12-16 02:06:14 +00:00
|
|
|
<div className={classNames(style.icons, 'group-hover:text-slate-300')}>
|
2022-06-26 19:13:52 +00:00
|
|
|
{activity.isApi && (
|
2022-07-09 23:30:38 +00:00
|
|
|
<Tooltip placement={'top'} content={'Using API Key'}>
|
|
|
|
<TerminalIcon />
|
|
|
|
</Tooltip>
|
|
|
|
)}
|
2022-07-10 17:47:19 +00:00
|
|
|
{activity.event.startsWith('server:sftp.') && (
|
2022-07-09 23:30:38 +00:00
|
|
|
<Tooltip placement={'top'} content={'Using SFTP'}>
|
|
|
|
<FolderOpenIcon />
|
2022-06-18 16:52:26 +00:00
|
|
|
</Tooltip>
|
2022-06-26 19:13:52 +00:00
|
|
|
)}
|
2022-06-18 16:52:26 +00:00
|
|
|
{children}
|
|
|
|
</div>
|
2022-06-12 19:08:26 +00:00
|
|
|
</div>
|
2022-06-18 19:28:42 +00:00
|
|
|
<p className={style.description}>
|
2022-06-26 19:13:52 +00:00
|
|
|
<Translate ns={'activity'} values={properties} i18nKey={activity.event.replace(':', '.')} />
|
2022-06-12 19:08:26 +00:00
|
|
|
</p>
|
|
|
|
<div className={'mt-1 flex items-center text-sm'}>
|
2022-06-28 00:52:27 +00:00
|
|
|
{activity.ip && (
|
|
|
|
<span>
|
|
|
|
{activity.ip}
|
2022-12-16 02:06:14 +00:00
|
|
|
<span className={'text-slate-400'}> | </span>
|
2022-06-28 00:52:27 +00:00
|
|
|
</span>
|
|
|
|
)}
|
2022-06-26 19:13:52 +00:00
|
|
|
<Tooltip placement={'right'} content={format(activity.timestamp, 'MMM do, yyyy H:mm:ss')}>
|
|
|
|
<span>{formatDistanceToNowStrict(activity.timestamp, { addSuffix: true })}</span>
|
2022-06-12 19:08:26 +00:00
|
|
|
</Tooltip>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-06-26 19:13:52 +00:00
|
|
|
{activity.hasAdditionalMetadata && <ActivityLogMetaButton meta={activity.properties} />}
|
2022-06-12 19:08:26 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|