Skip to content

Commit 48cdb84

Browse files
added stats for audit logs
1 parent b83abc8 commit 48cdb84

File tree

4 files changed

+112
-61
lines changed

4 files changed

+112
-61
lines changed

client/packages/lowcoder/src/api/enterpriseApi.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ export const getAuditLogs = async (params = {}) => {
6565
return response.data;
6666
};
6767

68-
export const getAuditLogStatistics = async (groupByParam : string) => {
69-
const response = await axios.get(`/api/plugins/enterprise/audit-logs/statistics?groupByParam=${groupByParam}`);
68+
export const getAuditLogStatistics = async (params = {}) => {
69+
const query = new URLSearchParams(params).toString();
70+
const response = await axios.get(`/api/plugins/enterprise/audit-logs/statistics?groupByParam=eventTypeId${query ? `&${query}` : ''}`);
7071
return response.data;
7172
};
7273

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,98 @@
11
import ReactECharts from 'echarts-for-react';
22
import { styled } from 'styled-components';
3+
import { trans } from "i18n";
34

45
export const StyledReactECharts = styled(ReactECharts)`
56
width: 100%;
67
height: 400px;
78
`;
9+
10+
type EventType = | "USER_LOGIN"
11+
| "USER_LOGOUT"
12+
| "APPLICATION_CREATE"
13+
| "APPLICATION_DELETE"
14+
| "APPLICATION_UPDATE"
15+
| "APPLICATION_MOVE"
16+
| "APPLICATION_RECYCLED"
17+
| "APPLICATION_RESTORE"
18+
| "APPLICATION_PUBLISH"
19+
| "APPLICATION_VERSION_CHANGE"
20+
| "APPLICATION_SHARING_CHANGE"
21+
| "APPLICATION_PERMISSION_CHANGE"
22+
| "FOLDER_CREATE"
23+
| "FOLDER_DELETE"
24+
| "FOLDER_UPDATE"
25+
| "QUERY_EXECUTION"
26+
| "GROUP_CREATE"
27+
| "GROUP_UPDATE"
28+
| "GROUP_DELETE"
29+
| "GROUP_MEMBER_ADD"
30+
| "GROUP_MEMBER_ROLE_UPDATE"
31+
| "GROUP_MEMBER_LEAVE"
32+
| "GROUP_MEMBER_REMOVE"
33+
| "SERVER_START_UP"
34+
| "SERVER_INFO"
35+
| "DATA_SOURCE_CREATE"
36+
| "DATA_SOURCE_UPDATE"
37+
| "DATA_SOURCE_DELETE"
38+
| "DATA_SOURCE_PERMISSION_GRANT"
39+
| "DATA_SOURCE_PERMISSION_UPDATE"
40+
| "DATA_SOURCE_PERMISSION_DELETE"
41+
| "LIBRARY_QUERY_CREATE"
42+
| "LIBRARY_QUERY_UPDATE"
43+
| "LIBRARY_QUERY_DELETE"
44+
| "LIBRARY_QUERY_PUBLISH"
45+
| "API_CALL_EVENT";
46+
47+
export type AuditLog = {
48+
eventType: EventType;
49+
eventTime: string;
50+
environmentId: string;
51+
orgId: string;
52+
userId: string;
53+
appId: string;
54+
};
55+
56+
export type AuditLogStat = {
57+
eventType: EventType;
58+
groupCountResult: number;
59+
}
60+
61+
export const eventTypes = [
62+
{ value: "USER_LOGIN", label: trans("enterprise.USER_LOGIN"), color: "#1890ff" },
63+
{ value: "USER_LOGOUT", label: trans("enterprise.USER_LOGOUT"), color: "#1d39c4" },
64+
{ value: "APPLICATION_CREATE", label: trans("enterprise.APPLICATION_CREATE"), color: "#52c41a" },
65+
{ value: "APPLICATION_DELETE", label: trans("enterprise.APPLICATION_DELETE"), color: "#389e0d" },
66+
{ value: "APPLICATION_UPDATE", label: trans("enterprise.APPLICATION_UPDATE"), color: "#237804" },
67+
{ value: "APPLICATION_MOVE", label: trans("enterprise.APPLICATION_MOVE"), color: "#135200" },
68+
{ value: "APPLICATION_RECYCLED", label: trans("enterprise.APPLICATION_RECYCLED"), color: "#00474f" },
69+
{ value: "APPLICATION_RESTORE", label: trans("enterprise.APPLICATION_RESTORE"), color: "#003a8c" },
70+
{ value: "APPLICATION_PUBLISH", label: trans("enterprise.APPLICATION_PUBLISH"), color: "#002766" },
71+
{ value: "APPLICATION_VERSION_CHANGE", label: trans("enterprise.APPLICATION_VERSION_CHANGE"), color: "#0050b3" },
72+
{ value: "APPLICATION_SHARING_CHANGE", label: trans("enterprise.APPLICATION_SHARING_CHANGE"), color: "#1890ff" },
73+
{ value: "APPLICATION_PERMISSION_CHANGE", label: trans("enterprise.APPLICATION_PERMISSION_CHANGE"), color: "#1d39c4" },
74+
{ value: "FOLDER_CREATE", label: trans("enterprise.FOLDER_CREATE"), color: "#faad14" },
75+
{ value: "FOLDER_DELETE", label: trans("enterprise.FOLDER_DELETE"), color: "#d48806" },
76+
{ value: "FOLDER_UPDATE", label: trans("enterprise.FOLDER_UPDATE"), color: "#ad6800" },
77+
{ value: "QUERY_EXECUTION", label: trans("enterprise.QUERY_EXECUTION"), color: "#722ed1" },
78+
{ value: "GROUP_CREATE", label: trans("enterprise.GROUP_CREATE"), color: "#f5222d" },
79+
{ value: "GROUP_UPDATE", label: trans("enterprise.GROUP_UPDATE"), color: "#cf1322" },
80+
{ value: "GROUP_DELETE", label: trans("enterprise.GROUP_DELETE"), color: "#a8071a" },
81+
{ value: "GROUP_MEMBER_ADD", label: trans("enterprise.GROUP_MEMBER_ADD"), color: "#820014" },
82+
{ value: "GROUP_MEMBER_ROLE_UPDATE", label: trans("enterprise.GROUP_MEMBER_ROLE_UPDATE"), color: "#5c0011" },
83+
{ value: "GROUP_MEMBER_LEAVE", label: trans("enterprise.GROUP_MEMBER_LEAVE"), color: "#8c8c8c" },
84+
{ value: "GROUP_MEMBER_REMOVE", label: trans("enterprise.GROUP_MEMBER_REMOVE"), color: "#595959" },
85+
{ value: "SERVER_START_UP", label: trans("enterprise.SERVER_START_UP"), color: "#8c8c8c" },
86+
{ value: "SERVER_INFO", label: trans("enterprise.SERVER_INFO"), color: "#595959" },
87+
{ value: "DATA_SOURCE_CREATE", label: trans("enterprise.DATA_SOURCE_CREATE"), color: "#f5222d" },
88+
{ value: "DATA_SOURCE_UPDATE", label: trans("enterprise.DATA_SOURCE_UPDATE"), color: "#cf1322" },
89+
{ value: "DATA_SOURCE_DELETE", label: trans("enterprise.DATA_SOURCE_DELETE"), color: "#a8071a" },
90+
{ value: "DATA_SOURCE_PERMISSION_GRANT", label: trans("enterprise.DATA_SOURCE_PERMISSION_GRANT"), color: "#820014" },
91+
{ value: "DATA_SOURCE_PERMISSION_UPDATE", label: trans("enterprise.DATA_SOURCE_PERMISSION_UPDATE"), color: "#5c0011" },
92+
{ value: "DATA_SOURCE_PERMISSION_DELETE", label: trans("enterprise.DATA_SOURCE_PERMISSION_DELETE"), color: "#8c8c8c" },
93+
{ value: "LIBRARY_QUERY_CREATE", label: trans("enterprise.LIBRARY_QUERY_CREATE"), color: "#722ed1" },
94+
{ value: "LIBRARY_QUERY_UPDATE", label: trans("enterprise.LIBRARY_QUERY_UPDATE"), color: "#531dab" },
95+
{ value: "LIBRARY_QUERY_DELETE", label: trans("enterprise.LIBRARY_QUERY_DELETE"), color: "#391085" },
96+
{ value: "LIBRARY_QUERY_PUBLISH", label: trans("enterprise.LIBRARY_QUERY_PUBLISH"), color: "#22075e" },
97+
{ value: "API_CALL_EVENT", label: trans("enterprise.API_CALL_EVENT"), color: "#8c8c8c" },
98+
];

client/packages/lowcoder/src/pages/setting/audit/dashboard.tsx

Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import {
1010
} from "../theme/styledComponents";
1111
import { HeaderBack } from "pages/setting/permission/styledComponents";
1212
import { getUser } from "@lowcoder-ee/redux/selectors/usersSelectors";
13-
import { fetchCommonSettings } from "@lowcoder-ee/redux/reduxActions/commonSettingsActions";
14-
import ReactECharts from "echarts-for-react";
15-
import { getAuditLogs } from "api/enterpriseApi";
13+
import { getAuditLogs, getAuditLogStatistics } from "api/enterpriseApi";
1614
import EventTypeTimeChart from "./charts/eventTypesTime";
1715
import { debounce } from "lodash";
1816
import { DatePicker } from "antd";
@@ -21,6 +19,8 @@ import { Link, useLocation } from "react-router-dom";
2119
import history from "util/history";
2220
import { SETTING_URL } from "@lowcoder-ee/constants/routesURL";
2321
import { EyeOutlined } from "@ant-design/icons";
22+
import { AuditLog, AuditLogStat, eventTypes } from "./auditContants";
23+
import Statistics from "./components/statistics";
2424

2525
const { RangePicker } = DatePicker;
2626

@@ -42,45 +42,6 @@ const StyleThemeSettingsCover = styled.div`
4242
border-radius: 10px 10px 0 0;
4343
`;
4444

45-
const eventTypes = [
46-
{ value: "USER_LOGIN", label: trans("enterprise.USER_LOGIN"), color: "#1890ff" },
47-
{ value: "USER_LOGOUT", label: trans("enterprise.USER_LOGOUT"), color: "#1d39c4" },
48-
{ value: "APPLICATION_CREATE", label: trans("enterprise.APPLICATION_CREATE"), color: "#52c41a" },
49-
{ value: "APPLICATION_DELETE", label: trans("enterprise.APPLICATION_DELETE"), color: "#389e0d" },
50-
{ value: "APPLICATION_UPDATE", label: trans("enterprise.APPLICATION_UPDATE"), color: "#237804" },
51-
{ value: "APPLICATION_MOVE", label: trans("enterprise.APPLICATION_MOVE"), color: "#135200" },
52-
{ value: "APPLICATION_RECYCLED", label: trans("enterprise.APPLICATION_RECYCLED"), color: "#00474f" },
53-
{ value: "APPLICATION_RESTORE", label: trans("enterprise.APPLICATION_RESTORE"), color: "#003a8c" },
54-
{ value: "APPLICATION_PUBLISH", label: trans("enterprise.APPLICATION_PUBLISH"), color: "#002766" },
55-
{ value: "APPLICATION_VERSION_CHANGE", label: trans("enterprise.APPLICATION_VERSION_CHANGE"), color: "#0050b3" },
56-
{ value: "APPLICATION_SHARING_CHANGE", label: trans("enterprise.APPLICATION_SHARING_CHANGE"), color: "#1890ff" },
57-
{ value: "APPLICATION_PERMISSION_CHANGE", label: trans("enterprise.APPLICATION_PERMISSION_CHANGE"), color: "#1d39c4" },
58-
{ value: "FOLDER_CREATE", label: trans("enterprise.FOLDER_CREATE"), color: "#faad14" },
59-
{ value: "FOLDER_DELETE", label: trans("enterprise.FOLDER_DELETE"), color: "#d48806" },
60-
{ value: "FOLDER_UPDATE", label: trans("enterprise.FOLDER_UPDATE"), color: "#ad6800" },
61-
{ value: "QUERY_EXECUTION", label: trans("enterprise.QUERY_EXECUTION"), color: "#722ed1" },
62-
{ value: "GROUP_CREATE", label: trans("enterprise.GROUP_CREATE"), color: "#f5222d" },
63-
{ value: "GROUP_UPDATE", label: trans("enterprise.GROUP_UPDATE"), color: "#cf1322" },
64-
{ value: "GROUP_DELETE", label: trans("enterprise.GROUP_DELETE"), color: "#a8071a" },
65-
{ value: "GROUP_MEMBER_ADD", label: trans("enterprise.GROUP_MEMBER_ADD"), color: "#820014" },
66-
{ value: "GROUP_MEMBER_ROLE_UPDATE", label: trans("enterprise.GROUP_MEMBER_ROLE_UPDATE"), color: "#5c0011" },
67-
{ value: "GROUP_MEMBER_LEAVE", label: trans("enterprise.GROUP_MEMBER_LEAVE"), color: "#8c8c8c" },
68-
{ value: "GROUP_MEMBER_REMOVE", label: trans("enterprise.GROUP_MEMBER_REMOVE"), color: "#595959" },
69-
{ value: "SERVER_START_UP", label: trans("enterprise.SERVER_START_UP"), color: "#8c8c8c" },
70-
{ value: "SERVER_INFO", label: trans("enterprise.SERVER_INFO"), color: "#595959" },
71-
{ value: "DATA_SOURCE_CREATE", label: trans("enterprise.DATA_SOURCE_CREATE"), color: "#f5222d" },
72-
{ value: "DATA_SOURCE_UPDATE", label: trans("enterprise.DATA_SOURCE_UPDATE"), color: "#cf1322" },
73-
{ value: "DATA_SOURCE_DELETE", label: trans("enterprise.DATA_SOURCE_DELETE"), color: "#a8071a" },
74-
{ value: "DATA_SOURCE_PERMISSION_GRANT", label: trans("enterprise.DATA_SOURCE_PERMISSION_GRANT"), color: "#820014" },
75-
{ value: "DATA_SOURCE_PERMISSION_UPDATE", label: trans("enterprise.DATA_SOURCE_PERMISSION_UPDATE"), color: "#5c0011" },
76-
{ value: "DATA_SOURCE_PERMISSION_DELETE", label: trans("enterprise.DATA_SOURCE_PERMISSION_DELETE"), color: "#8c8c8c" },
77-
{ value: "LIBRARY_QUERY_CREATE", label: trans("enterprise.LIBRARY_QUERY_CREATE"), color: "#722ed1" },
78-
{ value: "LIBRARY_QUERY_UPDATE", label: trans("enterprise.LIBRARY_QUERY_UPDATE"), color: "#531dab" },
79-
{ value: "LIBRARY_QUERY_DELETE", label: trans("enterprise.LIBRARY_QUERY_DELETE"), color: "#391085" },
80-
{ value: "LIBRARY_QUERY_PUBLISH", label: trans("enterprise.LIBRARY_QUERY_PUBLISH"), color: "#22075e" },
81-
{ value: "API_CALL_EVENT", label: trans("enterprise.API_CALL_EVENT"), color: "#8c8c8c" },
82-
];
83-
8445
export const getEventColor = (eventType: string): string => {
8546
const matchedType = eventTypes.find((et) => et.value === eventType);
8647
return matchedType ? matchedType.color : "#8c8c8c";
@@ -92,23 +53,13 @@ export const getEventLabel = (eventType: string): string => {
9253
};
9354

9455
export function AuditLogDashboard() {
95-
96-
type AuditLog = {
97-
eventType: string;
98-
eventTime: string;
99-
environmentId: string;
100-
orgId: string;
101-
userId: string;
102-
appId: string;
103-
};
104-
10556
const currentUser = useSelector(getUser);
10657
const location = useLocation();
10758

10859
const [allLogs, setAllLogs] = useState<AuditLog[]>([]);
10960
const [currentPageLogs, setCurrentPageLogs] = useState<AuditLog[]>([]);
61+
const [statistics, setStatistics] = useState<AuditLogStat[]>([]);
11062

111-
// const [logs, setLogs] = useState([]);
11263
const [total, setTotal] = useState(0);
11364
const [loading, setLoading] = useState(false);
11465
const [form] = Form.useForm();
@@ -175,6 +126,9 @@ export function AuditLogDashboard() {
175126
setLoading(true);
176127
try {
177128
const data = await getAuditLogs(cleanedParams);
129+
const stats = await getAuditLogStatistics(cleanedParams);
130+
131+
setStatistics(stats?.data || []);
178132

179133
if (resetData) {
180134
setAllLogs(data.data || []);
@@ -418,6 +372,9 @@ export function AuditLogDashboard() {
418372
</Flex>
419373
</Form>
420374
</Card>
375+
{Boolean(statistics.length) && !loading && (
376+
<Statistics stats={statistics} />
377+
)}
421378
<Card>
422379
{loading ? (
423380
<Skeleton active paragraph={{ rows: 5 }} />

client/packages/lowcoder/src/pages/setting/audit/detail.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,14 @@ export function AuditLogDetail() {
257257
<h2 style={{ color: "#ffffff", marginTop: "8px" }}>Event Detail</h2>
258258
</StyleThemeSettingsCover>
259259
<Card size="small" style={{ marginBottom: "20px", borderTopLeftRadius: 0, borderTopRightRadius: 0 }}>
260-
<StyledTree
261-
showLine
262-
defaultExpandAll
263-
selectable={false}
264-
treeData={eventHierarchy}
265-
/>
260+
{Boolean(eventHierarchy.length) && (
261+
<StyledTree
262+
showLine
263+
defaultExpandAll
264+
selectable={false}
265+
treeData={eventHierarchy}
266+
/>
267+
)}
266268
</Card>
267269
</DetailContent>
268270
</DetailContainer>

0 commit comments

Comments
 (0)