2022-06-12 19:08:26 +00:00
|
|
|
import React from 'react';
|
|
|
|
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-06-18 16:52:26 +00:00
|
|
|
import { TerminalIcon } from '@heroicons/react/solid';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import style from './style.module.css';
|
2022-06-18 20:36:19 +00:00
|
|
|
import { isObject } from '@/helpers';
|
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-06-12 19:08:26 +00:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
activity: ActivityLog;
|
|
|
|
children?: React.ReactNode;
|
|
|
|
}
|
|
|
|
|
2022-06-18 20:36:19 +00:00
|
|
|
const formatProperties = (properties: Record<string, unknown>): Record<string, unknown> => {
|
|
|
|
return Object.keys(properties).reduce((obj, key) => {
|
|
|
|
const value = properties[key];
|
|
|
|
// noinspection SuspiciousTypeOfGuard
|
|
|
|
const isCount = key === 'count' || (typeof key === 'string' && key.endsWith('_count'));
|
|
|
|
|
|
|
|
return {
|
|
|
|
...obj,
|
|
|
|
[key]: isCount || typeof value !== 'string'
|
|
|
|
? (isObject(value) ? formatProperties(value) : value)
|
|
|
|
: `<strong>${value}</strong>`,
|
|
|
|
};
|
|
|
|
}, {});
|
|
|
|
};
|
|
|
|
|
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-06-18 20:36:19 +00:00
|
|
|
const properties = formatProperties(activity.properties);
|
2022-06-18 19:28:42 +00:00
|
|
|
|
2022-06-12 19:08:26 +00:00
|
|
|
return (
|
|
|
|
<div className={'grid grid-cols-10 py-4 border-b-2 border-gray-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-06-19 17:46:15 +00:00
|
|
|
<div className={'flex items-center w-10 h-10 rounded-full bg-gray-600 overflow-hidden'}>
|
|
|
|
<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-06-12 19:08:26 +00:00
|
|
|
<div className={'flex items-center text-gray-50'}>
|
|
|
|
<Tooltip placement={'top'} content={actor?.email || 'System User'}>
|
|
|
|
<span>{actor?.username || 'System'}</span>
|
|
|
|
</Tooltip>
|
|
|
|
<span className={'text-gray-400'}> — </span>
|
|
|
|
<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-06-18 16:52:26 +00:00
|
|
|
<div className={classNames(style.icons, 'group-hover:text-gray-300')}>
|
|
|
|
{activity.isApi &&
|
|
|
|
<Tooltip placement={'top'} content={'Performed using API Key'}>
|
|
|
|
<span><TerminalIcon/></span>
|
|
|
|
</Tooltip>
|
|
|
|
}
|
|
|
|
{children}
|
|
|
|
</div>
|
2022-06-12 19:08:26 +00:00
|
|
|
</div>
|
2022-06-18 19:28:42 +00:00
|
|
|
<p className={style.description}>
|
|
|
|
<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'}>
|
|
|
|
<Link
|
2022-06-20 17:19:40 +00:00
|
|
|
to={`#${pathTo({ ip: activity.ip })}`}
|
2022-06-12 19:08:26 +00:00
|
|
|
className={'transition-colors duration-75 active:text-cyan-400 hover:text-cyan-400'}
|
|
|
|
>
|
|
|
|
{activity.ip}
|
|
|
|
</Link>
|
|
|
|
<span className={'text-gray-400'}> | </span>
|
|
|
|
<Tooltip
|
|
|
|
placement={'right'}
|
2022-06-20 15:17:33 +00:00
|
|
|
content={format(activity.timestamp, 'MMM do, yyyy H:mm:ss')}
|
2022-06-12 19:08:26 +00:00
|
|
|
>
|
|
|
|
<span>
|
|
|
|
{formatDistanceToNowStrict(activity.timestamp, { addSuffix: true })}
|
|
|
|
</span>
|
|
|
|
</Tooltip>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-06-12 19:30:49 +00:00
|
|
|
{activity.hasAdditionalMetadata && <ActivityLogMetaButton meta={activity.properties}/>}
|
2022-06-12 19:08:26 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|