-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(canvas): update run and log viewer
- Loading branch information
Showing
4 changed files
with
70 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
canvas/app/dashboard/project/id/[id]/view/runs/view-logs.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ActionButton } from "@/components/custom/action-button"; | ||
import { LogViewer } from "@/components/custom/log-viewer"; | ||
import { Modal } from "@/components/custom/modal"; | ||
import { WS_BASE_URL } from "@/services/api"; | ||
import { TRun } from "@/services/run"; | ||
import { ScrollText } from "lucide-react"; | ||
import React from "react"; | ||
|
||
export type TRunViewLogProps = { | ||
run: TRun; | ||
}; | ||
|
||
export function RunViewLog(props: TRunViewLogProps) { | ||
const { run } = props; | ||
return ( | ||
<Modal | ||
title="Logs" | ||
trigger={<ActionButton icon={<ScrollText />} message="View logs" />} | ||
contentProps={{ | ||
className: | ||
"sm:max-w-[95vw] md:max-w-[95vw] xl:max-w-[1250px] h-[95vh] max-h-[800px] flex flex-col gap-0", | ||
}} | ||
headerProps={{ | ||
className: "border-b-transparent", | ||
}} | ||
footerProps={{ | ||
className: "border-t-transparent", | ||
}} | ||
> | ||
<LogViewer endpoint={`${WS_BASE_URL}/ws/run/log/${run.id}`} /> | ||
</Modal> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,49 @@ | ||
"use client"; | ||
|
||
import { useDimension } from "@/hooks/useDimension"; | ||
import { LazyLog, ScrollFollow } from "@melloware/react-logviewer"; | ||
import React from "react"; | ||
import { PageSpinner } from "./page-spinner"; | ||
|
||
export type TLogViewerProps = { | ||
endpoint: string; | ||
}; | ||
|
||
export function LogViewer(props: TLogViewerProps) { | ||
const { endpoint } = props; | ||
let socket = null; | ||
const ref = React.useRef<HTMLDivElement>(null); | ||
|
||
const { width, height } = useDimension({ ref }); | ||
|
||
return ( | ||
<ScrollFollow | ||
startFollowing={true} | ||
render={({ follow, onScroll }) => ( | ||
<LazyLog | ||
extraLines={1} | ||
enableSearch | ||
url={endpoint} | ||
websocket | ||
websocketOptions={{ | ||
onOpen: (_e, sock) => { | ||
socket = sock; | ||
sock.send(JSON.stringify({ message: "Socket has been opened!" })); | ||
}, | ||
formatMessage: (e) => JSON.parse(e).message, | ||
reconnect: true, | ||
reconnectWait: 5, | ||
}} | ||
onScroll={onScroll} | ||
follow={follow} | ||
/> | ||
<div ref={ref} className="flex-1"> | ||
{width === 0 || height === 0 ? ( | ||
<PageSpinner /> | ||
) : ( | ||
/** | ||
* ScrollFollow wrapper should have a parent with a fixed width and height. | ||
* @link https://github.com/melloware/react-logviewer?tab=readme-ov-file#usage-1 | ||
*/ | ||
<div style={{ width, height }}> | ||
<ScrollFollow | ||
startFollowing={true} | ||
render={({ follow, onScroll }) => ( | ||
<LazyLog | ||
extraLines={1} | ||
enableSearch | ||
url={endpoint} | ||
websocket | ||
websocketOptions={{ | ||
reconnect: true, | ||
reconnectWait: 5, | ||
}} | ||
onScroll={onScroll} | ||
follow={follow} | ||
/> | ||
)} | ||
/> | ||
</div> | ||
)} | ||
/> | ||
</div> | ||
); | ||
} |