Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style(web): change log modal style #1644

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions web/src/pages/app/mods/StatusBar/LogsModal/index.css

This file was deleted.

31 changes: 31 additions & 0 deletions web/src/pages/app/mods/StatusBar/LogsModal/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#log-viewer-container {
.pf-v5-c-text-input-group__icon {
visibility: hidden;
}

.pf-v5-c-text-input-group__text-input:focus {
outline: none !important;
color: #000;
}

.pf-m-current {
background: #91ded9 !important;
}

.pf-m-match {
background: #daf4f2 !important;
}

[data-theme="dark"] .pf-v5-c-text-input-group__text-input:focus {
outline: none !important;
color: #fff;
}

[data-theme="dark"] .pf-m-current {
background: #47c8bf !important;
}

[data-theme="dark"] .pf-m-match {
background: #2b7873 !important;
}
}
47 changes: 19 additions & 28 deletions web/src/pages/app/mods/StatusBar/LogsModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React, { useCallback, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import {
Button,
Expand All @@ -20,7 +20,7 @@ import { useQuery } from "@tanstack/react-query";
import { formatDate } from "@/utils/format";
import { streamFetch } from "@/utils/streamFetch";

import "./index.css";
import "./index.scss";

import { PodControllerGet } from "@/apis/v1/apps";
import useCustomSettingStore from "@/pages/customSetting";
Expand Down Expand Up @@ -51,7 +51,7 @@ export default function LogsModal(props: { children: React.ReactElement }) {
},
);

const fetchLogs = () => {
const fetchLogs = useCallback(() => {
if (!podName) return;
const controller = new AbortController();
streamFetch({
Expand All @@ -61,40 +61,31 @@ export default function LogsModal(props: { children: React.ReactElement }) {
setIsLoading(false);
},
onMessage(text) {
const regex = /id:\s+\d+|data:/g;
const resultText = text.replace(regex, "");
const regex1 = /^\s*$/gm;
const resultText1 = resultText.replace(regex1, "");
const regex = /id:\s\d+\s+data:\s(.*)\s+data:/g;
const logs = [...text.matchAll(regex)];
const regexTime = /(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z)/g;
let match: RegExpExecArray | null;
const matches = new Set<string>();
while ((match = regexTime.exec(resultText1)) !== null) {
matches.add(match[1]);
}
let newLogs = resultText1;
if (matches.size > 0) {
for (const matchStr of matches) {
const newTimeStr = formatDate(matchStr, "YYYY-MM-DD HH:mm:ss.SSS");
newLogs = newLogs.replaceAll(matchStr, newTimeStr);
}
}
setLogs((pre) => {
return pre + newLogs;
});

const logStr = logs
.map((log) =>
log[1].replace(regexTime, (str) => formatDate(str, "YYYY-MM-DD HH:mm:ss.SSS")),
)
.join("\n");

setLogs((pre) => pre + logStr);
},
});
return controller;
};
}, [podName, currentApp.appid]);

useEffect(() => {
if (!isOpen) return;
setLogs("");
setIsLoading(true);
const controller = fetchLogs();
return () => {
controller?.abort();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [podName, isOpen]);
}, [podName, isOpen, fetchLogs]);

return (
<>
Expand Down Expand Up @@ -149,16 +140,16 @@ export default function LogsModal(props: { children: React.ReactElement }) {
) : (
<div
id="log-viewer-container"
className="h-[98%]"
style={{ fontSize: settingStore.commonSettings.fontSize }}
className="text-sm relative flex flex-col overflow-y-auto px-2 font-mono"
style={{ height: "98%", fontSize: settingStore.commonSettings.fontSize - 1 }}
>
<LogViewer
data={logs}
hasLineNumbers={false}
scrollToRow={100000}
height={"100%"}
toolbar={
<div className="absolute right-16 top-4">
<div className="absolute right-16 top-4 z-10">
<LogViewerSearch
placeholder="Search"
minSearchChars={1}
Expand Down