Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonkopliku committed Jul 10, 2024
1 parent 727e866 commit 1eae0e6
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 0 deletions.
5 changes: 5 additions & 0 deletions assets/js/common/ActivityLogOverview/ActivityLogOverview.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React, { useState, useEffect } from 'react';

Check failure on line 1 in assets/js/common/ActivityLogOverview/ActivityLogOverview.jsx

View workflow job for this annotation

GitHub Actions / Static Code Analysis

'useState' is defined but never used

Check failure on line 1 in assets/js/common/ActivityLogOverview/ActivityLogOverview.jsx

View workflow job for this annotation

GitHub Actions / Static Code Analysis

'useEffect' is defined but never used

export default function ActivityLogOverview() {
return <div>ActivityLogOverview</div>;
}
3 changes: 3 additions & 0 deletions assets/js/common/ActivityLogOverview/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import ActivityLogOverview from './ActivityLogOverview';

export default ActivityLogOverview;
3 changes: 3 additions & 0 deletions assets/js/lib/api/activityLogs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { networkClient } from '@lib/network';

export const getActivityLog = () => networkClient.get(`/activity_log`);
77 changes: 77 additions & 0 deletions assets/js/pages/ActivityLogPage/ActivityLogPage.jsx
Original file line number Diff line number Diff line change
@@ -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 }) => {

Check failure on line 66 in assets/js/pages/ActivityLogPage/ActivityLogPage.jsx

View workflow job for this annotation

GitHub Actions / Static Code Analysis

Do not define components during render. React will see a new component type on every render and destroy the entire subtree’s DOM nodes and state (https://reactjs.org/docs/reconciliation.html#elements-of-different-types). Instead, move this component definition out of the parent component “ActivityLogPage” and pass data as props. If you want to allow component creation in props, set allowAsProps option to true

Check failure on line 66 in assets/js/pages/ActivityLogPage/ActivityLogPage.jsx

View workflow job for this annotation

GitHub Actions / Static Code Analysis

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`
return <pre>{JSON.stringify(metadata, null, 2)}</pre>;
},
};

return (
<>
<ActivityLogOverview />
<Table config={config} data={activityLog} />
</>
);
}
3 changes: 3 additions & 0 deletions assets/js/pages/ActivityLogPage/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import ActivityLogPage from './ActivityLogPage';

export default ActivityLogPage;
6 changes: 6 additions & 0 deletions assets/js/pages/Layout/Layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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',
Expand Down
5 changes: 5 additions & 0 deletions assets/js/trento.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -113,6 +114,10 @@ const createRouter = ({ getUser }) =>
path="hosts/:hostID/patches/:advisoryID"
element={<AdvisoryDetailsPage />}
/>
<Route
path="activity_log"
element={<ActivityLogPage />}
/>
<Route
element={
<ForbiddenGuard permitted={['all:users']} outletMode />
Expand Down

0 comments on commit 1eae0e6

Please sign in to comment.