Skip to content

Commit 6f0ba5b

Browse files
chore(site): add AgentLogs storybook (coder#12601)
1 parent 25b605f commit 6f0ba5b

File tree

7 files changed

+1178
-16
lines changed

7 files changed

+1178
-16
lines changed

site/src/modules/resources/AgentLogLine.tsx renamed to site/src/modules/resources/AgentLogs/AgentLogLine.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ import AnsiToHTML from "ansi-to-html";
33
import { type FC, type ReactNode, useMemo } from "react";
44
import { type Line, LogLine, LogLinePrefix } from "components/Logs/LogLine";
55

6+
// Logs are stored as the Line interface to make rendering
7+
// much more efficient. Instead of mapping objects each time, we're
8+
// able to just pass the array of logs to the component.
9+
export interface LineWithID extends Line {
10+
id: number;
11+
}
12+
13+
// Approximate height of a log line. Used to control virtualized list height.
14+
export const AGENT_LOG_LINE_HEIGHT = 20;
15+
616
const convert = new AnsiToHTML();
717

818
interface AgentLogLineProps {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { Meta, StoryObj } from "@storybook/react";
2+
import { AGENT_LOG_LINE_HEIGHT } from "./AgentLogLine";
3+
import { AgentLogs } from "./AgentLogs";
4+
import { MockLogs, MockSources } from "./mocks";
5+
6+
const meta: Meta<typeof AgentLogs> = {
7+
title: "modules/resources/AgentLogs",
8+
component: AgentLogs,
9+
args: {
10+
sources: MockSources,
11+
logs: MockLogs,
12+
height: MockLogs.length * AGENT_LOG_LINE_HEIGHT,
13+
},
14+
parameters: {
15+
layout: "fullscreen",
16+
},
17+
};
18+
19+
export default meta;
20+
type Story = StoryObj<typeof AgentLogs>;
21+
22+
const Default: Story = {};
23+
24+
export { Default as AgentLogs };

site/src/modules/resources/AgentLogs.tsx renamed to site/src/modules/resources/AgentLogs/AgentLogs.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ import {
1010
import { FixedSizeList as List } from "react-window";
1111
import * as API from "api/api";
1212
import type { WorkspaceAgentLogSource } from "api/typesGenerated";
13-
import { AgentLogLine } from "./AgentLogLine";
14-
import { AGENT_LOG_LINE_HEIGHT, type LineWithID } from "./AgentRow";
13+
import {
14+
AGENT_LOG_LINE_HEIGHT,
15+
AgentLogLine,
16+
type LineWithID,
17+
} from "./AgentLogLine";
1518

1619
type AgentLogsProps = Omit<
1720
ComponentProps<typeof List>,

0 commit comments

Comments
 (0)