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

chore(web): Optimize log display logic #2013

Merged
merged 5 commits into from
Jun 19, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ const AddDependenceModal = () => {
>
{t("FunctionPanel.Select")}:
</span>
{/* {t("FunctionPanel.Select")}: */}
<span className="mx-2 text-blue-500 ">
{isEdit ? (
packageList.length
Expand Down
13 changes: 8 additions & 5 deletions web/src/pages/app/mods/StatusBar/LogsModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,11 @@ export default function LogsModal(props: { children: React.ReactElement }) {

useEffect(() => {
if (!isOpen) return;
setRowCount(0);
setPaused(false);
setLogs([]);
setRowCount(0);
setIsLoading(true);
setPaused(false);

const ctrl = fetchLogs();

return () => {
Expand All @@ -168,7 +169,9 @@ export default function LogsModal(props: { children: React.ReactElement }) {
}, [podName, containerName, isOpen, refresh, fetchLogs]);

useEffect(() => {
const sortedLogs = logs.sort((a, b) => parseInt(a.id) - parseInt(b.id));
if (logs.length === 0) return;

const sortedLogs = [...logs].sort((a, b) => parseInt(a.id) - parseInt(b.id));
const concatenatedLogs = sortedLogs.map((log) => log.data).join("");
setRenderLogs(concatenatedLogs);
const totalRows = concatenatedLogs.split("\n").length;
Expand Down Expand Up @@ -260,10 +263,10 @@ export default function LogsModal(props: { children: React.ReactElement }) {
<LogViewer
data={renderLogs}
hasLineNumbers={true}
scrollToRow={paused ? undefined : rowCount + 300}
scrollToRow={paused ? undefined : rowCount + 1}
height={"98%"}
onScroll={(e) => {
if (e.scrollOffsetToBottom <= 0) {
if (e.scrollOffsetToBottom <= 5) {
setPaused(false);
return;
}
Expand Down
23 changes: 14 additions & 9 deletions web/src/pages/app/mods/StatusBar/LogsModal/initLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ export default function InitLog() {
}, [currentApp.appid]);

useEffect(() => {
setRowCount(0);
setPaused(false);
setLogs([]);
setRowCount(0);
setIsLoading(true);
setPaused(false);

const ctrl = fetchLogs();

return () => {
Expand All @@ -94,11 +95,15 @@ export default function InitLog() {
}, [fetchLogs]);

useEffect(() => {
const sortedLogs = logs.sort((a, b) => parseInt(a.id) - parseInt(b.id));
const concatenatedLogs = sortedLogs.map((log) => log.data).join("");
setRenderLogs(concatenatedLogs);
const totalRows = concatenatedLogs.split("\n").length;
setRowCount(totalRows);
if (logs.length === 0) return;

const sortedLogs = [...logs].sort((a, b) => parseInt(a.id) - parseInt(b.id));
const logLines = sortedLogs.flatMap((log) => log.data.split("\n"));
const filteredLogLines = logLines.filter((line) => line.trim() !== "");
const uniqueLogLines = Array.from(new Set(filteredLogLines));

setRenderLogs(uniqueLogLines.join("\n"));
setRowCount(uniqueLogLines.length);
}, [logs]);

return (
Expand All @@ -121,10 +126,10 @@ export default function InitLog() {
<LogViewer
data={renderLogs}
hasLineNumbers={false}
scrollToRow={paused ? undefined : rowCount + 300}
scrollToRow={paused ? undefined : rowCount + 1}
height={"100%"}
onScroll={(e) => {
if (e.scrollOffsetToBottom <= 0) {
if (e.scrollOffsetToBottom <= 5) {
setPaused(false);
return;
}
Expand Down
Loading