From 0b4936ff1c2c214116509a276291c0a34658af5f Mon Sep 17 00:00:00 2001 From: DaneEveritt Date: Sun, 12 Jun 2022 15:08:26 -0400 Subject: [PATCH] Break out rows for activity; show metadata icon --- .../Api/Client/ActivityLogController.php | 2 +- .../activity/ActivityLogContainer.tsx | 75 +++-------------- .../elements/activity/ActivityLogEntry.tsx | 80 +++++++++++++++++++ .../activity/ActivityLogMetaButton.tsx | 35 ++++++++ 4 files changed, 125 insertions(+), 67 deletions(-) create mode 100644 resources/scripts/components/elements/activity/ActivityLogEntry.tsx create mode 100644 resources/scripts/components/elements/activity/ActivityLogMetaButton.tsx diff --git a/app/Http/Controllers/Api/Client/ActivityLogController.php b/app/Http/Controllers/Api/Client/ActivityLogController.php index 91b679854..3fbfa11a9 100644 --- a/app/Http/Controllers/Api/Client/ActivityLogController.php +++ b/app/Http/Controllers/Api/Client/ActivityLogController.php @@ -21,7 +21,7 @@ class ActivityLogController extends ClientApiController AllowedFilter::partial('event'), ]) ->allowedSorts(['timestamp']) - ->paginate(min($request->query('per_page', 50), 100)) + ->paginate(min($request->query('per_page', 25), 100)) ->appends($request->query()); return $this->fractal->collection($activity) diff --git a/resources/scripts/components/dashboard/activity/ActivityLogContainer.tsx b/resources/scripts/components/dashboard/activity/ActivityLogContainer.tsx index e8e8eb860..bb02bee6b 100644 --- a/resources/scripts/components/dashboard/activity/ActivityLogContainer.tsx +++ b/resources/scripts/components/dashboard/activity/ActivityLogContainer.tsx @@ -3,17 +3,15 @@ import { ActivityLogFilters, useActivityLogs } from '@/api/account/activity'; import { useFlashKey } from '@/plugins/useFlash'; import PageContentBlock from '@/components/elements/PageContentBlock'; import FlashMessageRender from '@/components/FlashMessageRender'; -import { format, formatDistanceToNowStrict } from 'date-fns'; import { Link } from 'react-router-dom'; import PaginationFooter from '@/components/elements/table/PaginationFooter'; -import { UserIcon } from '@heroicons/react/outline'; -import Tooltip from '@/components/elements/tooltip/Tooltip'; import { DesktopComputerIcon, XCircleIcon } from '@heroicons/react/solid'; import { useLocation } from 'react-router'; import Spinner from '@/components/elements/Spinner'; import { styles as btnStyles } from '@/components/elements/button/index'; import classNames from 'classnames'; -import Translate from '@/components/elements/Translate'; +import ActivityLogEntry from '@/components/elements/activity/ActivityLogEntry'; +import Tooltip from '@/components/elements/tooltip/Tooltip'; export default () => { const location = useLocation(); @@ -35,15 +33,6 @@ export default () => { clearAndAddHttpError(error); }, [ error ]); - const queryTo = (params: Record): string => { - const current = new URLSearchParams(location.search); - Object.keys(params).forEach(key => { - current.set(key, params[key]); - }); - - return current.toString(); - }; - return ( @@ -63,59 +52,13 @@ export default () => { :
{data?.items.map((activity) => ( -
-
-
- {activity.relationships.actor ? - {'User - : - - } -
-
-
-
- {activity.relationships.actor?.username || 'system'} -  —  - - {activity.event} - - {typeof activity.properties.useragent === 'string' && - - - - } -
-

- - {activity.event.replace(':', '.')} - -

-
- - {activity.ip} - -  |  - - - {formatDistanceToNowStrict(activity.timestamp, { addSuffix: true })} - - -
-
-
+ + {typeof activity.properties.useragent === 'string' && + + + + } + ))}
} diff --git a/resources/scripts/components/elements/activity/ActivityLogEntry.tsx b/resources/scripts/components/elements/activity/ActivityLogEntry.tsx new file mode 100644 index 000000000..942f9551d --- /dev/null +++ b/resources/scripts/components/elements/activity/ActivityLogEntry.tsx @@ -0,0 +1,80 @@ +import React from 'react'; +import { UserIcon } from '@heroicons/react/outline'; +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 { useLocation } from 'react-router'; +import ActivityLogMetaButton from '@/components/elements/activity/ActivityLogMetaButton'; + +interface Props { + activity: ActivityLog; + children?: React.ReactNode; +} + +export default ({ activity, children }: Props) => { + const location = useLocation(); + const actor = activity.relationships.actor; + + const queryTo = (params: Record): string => { + const current = new URLSearchParams(location.search); + Object.keys(params).forEach(key => current.set(key, params[key])); + + return current.toString(); + }; + + return ( +
+
+
+ {actor ? + {'User + : + + } +
+
+
+
+
+ + {actor?.username || 'System'} + +  —  + + {activity.event} + + {children} +
+

+ + {activity.event.replace(':', '.')} + +

+
+ + {activity.ip} + +  |  + + + {formatDistanceToNowStrict(activity.timestamp, { addSuffix: true })} + + +
+
+ +
+
+ ); +}; diff --git a/resources/scripts/components/elements/activity/ActivityLogMetaButton.tsx b/resources/scripts/components/elements/activity/ActivityLogMetaButton.tsx new file mode 100644 index 000000000..bcb576990 --- /dev/null +++ b/resources/scripts/components/elements/activity/ActivityLogMetaButton.tsx @@ -0,0 +1,35 @@ +import React, { useState } from 'react'; +import { isEmptyObject } from '@/helpers'; +import { ClipboardListIcon } from '@heroicons/react/outline'; +import { Dialog } from '@/components/elements/dialog'; +import { Button } from '@/components/elements/button/index'; + +export default ({ meta }: { meta: Record }) => { + const [ open, setOpen ] = useState(false); + + if (isEmptyObject(meta)) { + return null; + } + + return ( +
+ setOpen(false)} + hideCloseIcon + title={'Metadata'} + > +
{JSON.stringify(meta, null, 2)}
+ + setOpen(false)}>Close + +
+ +
+ ); +};