From 6dfef89e6907662e864cab51603b431ffd06f942 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 26 Jun 2023 23:45:56 +0200 Subject: [PATCH] replace userId with username and give each data a color --- src/Components/LogCard/index.js | 67 ++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/src/Components/LogCard/index.js b/src/Components/LogCard/index.js index 6d1868f..c466fa6 100644 --- a/src/Components/LogCard/index.js +++ b/src/Components/LogCard/index.js @@ -4,15 +4,17 @@ import { ReloadOutlined, } from "@ant-design/icons"; import { Card, Checkbox, Space, Spin, Tooltip } from "antd"; -import { useEffect, useState } from "react"; +import { createElement, useContext, useEffect, useState } from "react"; import { Constants, FormatDatetime, + WebSocketContext, getUserSessionFromLocalStorage, handleUnauthorizedStatus, } from "../../utils"; export default function LogCard({ type }) { + const webSocketContext = useContext(WebSocketContext); const [checkboxInfoChecked, setCheckboxInfoChecked] = useState(true); const [checkboxErrorChecked, setCheckboxErrorChecked] = useState(true); @@ -30,6 +32,12 @@ export default function LogCard({ type }) { loadLogs(selectedDate); }, [selectedDate]); + const getColorCode = (index) => { + const colorCodes = ["#3498db", "#9b59b6", "#1abc9c"]; + const colorIndex = index % colorCodes.length; + return colorCodes[colorIndex]; + }; + const loadLogs = (date) => { setLoadingSpinner(true); @@ -54,6 +62,63 @@ export default function LogCard({ type }) { if (data.Logs === null) { data.Logs = []; + } else { + for (let i = 0; i < data.Logs.length; i++) { + let items = []; + let splittedMessage = data.Logs[i].Message.split(" "); + + for (let s = 0; s < splittedMessage.length; s++) { + if (splittedMessage[s].includes("%")) { + if (splittedMessage[s] === "%userId%") { + const foundData = data.Logs[i].LogData.find( + (data) => data.Type === "userId" + ); + + if (foundData !== undefined) { + const foundUser = webSocketContext.AllUsers.find( + (user) => user.Id === foundData.Value + ); + + if (foundUser !== undefined) { + items.push( + + {foundUser.Username}{" "} + + ); + } else { + items.push({splittedMessage[s]} ); + } + } else { + items.push({splittedMessage[s]} ); + } + } else { + const logDataIndex = data.Logs[i].LogData.findIndex( + (data) => + data.Type === + splittedMessage[s].replace(new RegExp("%", "g"), "") + ); + + if (logDataIndex !== -1) { + items.push( + + {data.Logs[i].LogData[logDataIndex].Value}{" "} + + ); + } + } + } else { + items.push({splittedMessage[s]} ); + } + } + + data.Logs[i].Message = items; + } } setLogData(data);