Skip to content

Commit

Permalink
feat(canvas): update run and log viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
leoank committed Jan 7, 2025
1 parent 77fb646 commit 40f7885
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 29 deletions.
7 changes: 2 additions & 5 deletions canvas/app/dashboard/project/id/[id]/view/runs/run.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { ProjectRunBadge } from "./badge";
import { RunPathsPopover } from "./run-paths-popover";
import { useParsePathRecordToArray } from "../hooks/useParsePathRecordToArray";
import { FileInput, FileOutput, ScrollText } from "lucide-react";
import { ActionButton } from "@/components/custom/action-button";
import { FeatureNotImplementedModal } from "@/components/custom/feature-not-implemented-modal";
import { RunViewLog } from "./view-logs";

export type TProjectRun = {
run: TRun;
Expand Down Expand Up @@ -43,9 +42,7 @@ export function ProjectRun(props: TProjectRun) {
children: <FileOutput />,
}}
/>
<FeatureNotImplementedModal featureName="View Logs">
<ActionButton icon={<ScrollText />} message="View logs" />
</FeatureNotImplementedModal>
<RunViewLog run={run} />
</div>
</div>
</div>
Expand Down
33 changes: 33 additions & 0 deletions canvas/app/dashboard/project/id/[id]/view/runs/view-logs.tsx
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>
);
}
3 changes: 1 addition & 2 deletions canvas/components/custom/file-viewer/table-view/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import clsx from "clsx";
import React from "react";
import { VariableSizeGrid as Grid } from "react-window";
import { FileViewerTableViewCell } from "./cell";
Expand Down Expand Up @@ -59,7 +58,7 @@ export function FileViewerTableView(props: TFileViewerTableView) {
className="bg-accent border-l-accent border-l overflow-auto"
overscanRowCount={50}
>
{({ columnIndex, rowIndex, style, data: d }) => (
{({ columnIndex, rowIndex, style }) => (
<FileViewerTableViewCell
data={data[rowIndex][columnIndex]}
isHeader={rowIndex === 0}
Expand Down
56 changes: 34 additions & 22 deletions canvas/components/custom/log-viewer.tsx
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>
);
}

0 comments on commit 40f7885

Please sign in to comment.