From 1eae0e6ea4cd0f2e65bb26bb429cd22867a3f3d3 Mon Sep 17 00:00:00 2001 From: Nelson Kopliku Date: Wed, 10 Jul 2024 11:54:39 +0200 Subject: [PATCH] wip --- .../ActivityLogOverview.jsx | 5 ++ assets/js/common/ActivityLogOverview/index.js | 3 + assets/js/lib/api/activityLogs.js | 3 + .../pages/ActivityLogPage/ActivityLogPage.jsx | 77 +++++++++++++++++++ assets/js/pages/ActivityLogPage/index.js | 3 + assets/js/pages/Layout/Layout.jsx | 6 ++ assets/js/trento.jsx | 5 ++ 7 files changed, 102 insertions(+) create mode 100644 assets/js/common/ActivityLogOverview/ActivityLogOverview.jsx create mode 100644 assets/js/common/ActivityLogOverview/index.js create mode 100644 assets/js/lib/api/activityLogs.js create mode 100644 assets/js/pages/ActivityLogPage/ActivityLogPage.jsx create mode 100644 assets/js/pages/ActivityLogPage/index.js diff --git a/assets/js/common/ActivityLogOverview/ActivityLogOverview.jsx b/assets/js/common/ActivityLogOverview/ActivityLogOverview.jsx new file mode 100644 index 0000000000..7453144560 --- /dev/null +++ b/assets/js/common/ActivityLogOverview/ActivityLogOverview.jsx @@ -0,0 +1,5 @@ +import React, { useState, useEffect } from 'react'; + +export default function ActivityLogOverview() { + return
ActivityLogOverview
; +} diff --git a/assets/js/common/ActivityLogOverview/index.js b/assets/js/common/ActivityLogOverview/index.js new file mode 100644 index 0000000000..9c66b43746 --- /dev/null +++ b/assets/js/common/ActivityLogOverview/index.js @@ -0,0 +1,3 @@ +import ActivityLogOverview from './ActivityLogOverview'; + +export default ActivityLogOverview; diff --git a/assets/js/lib/api/activityLogs.js b/assets/js/lib/api/activityLogs.js new file mode 100644 index 0000000000..8a69fb9135 --- /dev/null +++ b/assets/js/lib/api/activityLogs.js @@ -0,0 +1,3 @@ +import { networkClient } from '@lib/network'; + +export const getActivityLog = () => networkClient.get(`/activity_log`); diff --git a/assets/js/pages/ActivityLogPage/ActivityLogPage.jsx b/assets/js/pages/ActivityLogPage/ActivityLogPage.jsx new file mode 100644 index 0000000000..ebce74ec72 --- /dev/null +++ b/assets/js/pages/ActivityLogPage/ActivityLogPage.jsx @@ -0,0 +1,77 @@ +import React, { useState, useEffect } from 'react'; + +import { logError } from '@lib/log'; + +import Table from '@common/Table'; +import { getActivityLog } from '../../lib/api/activityLogs'; +import ActivityLogOverview from '../../common/ActivityLogOverview/ActivityLogOverview'; + +export default function ActivityLogPage() { + const [activityLog, setActivityLog] = useState([]); + // const [isLoading, setIsLoading] = useState(true); + + useEffect(() => { + getActivityLog() + .then((response) => { + setActivityLog(response.data); + // setIsLoading(false); + }) + .catch((e) => logError(e)); + }, []); + + const config = { + pagination: true, + usePadding: false, + columns: [ + { + title: 'Time', + key: 'occurred_on', + }, + { + title: 'Event Type', + key: 'type', + }, + { + title: 'Resource', + key: 'metadata', + render: ({ resource_type }, { type }) => { + if (['resource_tagging', 'resource_untagging'].includes(type)) { + return resource_type; + } + return 'Resource unavailable'; + }, + }, + { + title: 'User', + key: 'actor', + }, + { + title: 'Message', + key: 'metadata', + render: (content, { type }) => { + if (type === 'resource_tagging') { + const { added_tag, resource_id } = content; + return `Tag "${added_tag}" added to "${resource_id}"`; + } + + if (type === 'resource_untagging') { + const { removed_tag, resource_id } = content; + return `Tag "${removed_tag}" removed to "${resource_id}"`; + } + + return 'message unavailable'; + }, + }, + ], + collapsibleDetailRenderer: ({ metadata }) => { + return
{JSON.stringify(metadata, null, 2)}
; + }, + }; + + return ( + <> + + + + ); +} diff --git a/assets/js/pages/ActivityLogPage/index.js b/assets/js/pages/ActivityLogPage/index.js new file mode 100644 index 0000000000..896206b0e2 --- /dev/null +++ b/assets/js/pages/ActivityLogPage/index.js @@ -0,0 +1,3 @@ +import ActivityLogPage from './ActivityLogPage'; + +export default ActivityLogPage; diff --git a/assets/js/pages/Layout/Layout.jsx b/assets/js/pages/Layout/Layout.jsx index 7d5153433d..a2ba6bf4e7 100644 --- a/assets/js/pages/Layout/Layout.jsx +++ b/assets/js/pages/Layout/Layout.jsx @@ -18,6 +18,7 @@ import { EOS_KEYBOARD_DOUBLE_ARROW_LEFT, EOS_KEYBOARD_DOUBLE_ARROW_RIGHT, EOS_SUPERVISED_USER_CIRCLE_OUTLINED, + EOS_ASSIGNMENT, } from 'eos-icons-react'; import TrentoLogo from '@static/trento-logo-stacked.svg'; @@ -59,6 +60,11 @@ const navigation = [ icon: EOS_SUPERVISED_USER_CIRCLE_OUTLINED, permittedFor: ['all:users'], }, + { + name: 'Activity Log', + href: '/activity_log', + icon: EOS_ASSIGNMENT, + }, { name: 'Settings', href: '/settings', diff --git a/assets/js/trento.jsx b/assets/js/trento.jsx index 9189533692..4c21597476 100644 --- a/assets/js/trento.jsx +++ b/assets/js/trento.jsx @@ -40,6 +40,7 @@ import SettingsPage from '@pages/SettingsPage'; import SomethingWentWrong from '@pages/SomethingWentWrong'; import UsersPage, { CreateUserPage, EditUserPage } from '@pages/Users'; import ProfilePage from '@pages/Profile'; +import ActivityLogPage from '@pages/ActivityLogPage'; import { profile } from '@lib/auth'; import { networkClient } from '@lib/network'; @@ -113,6 +114,10 @@ const createRouter = ({ getUser }) => path="hosts/:hostID/patches/:advisoryID" element={} /> + } + />