Skip to content

Commit 6e1032c

Browse files
committed
Add Storybook
1 parent b1b3fcb commit 6e1032c

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

site/src/components/Resources/AgentRow.stories.tsx

+12
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ Starting.args = {
100100
workspace: MockWorkspace,
101101
applicationsHost: "",
102102
showApps: true,
103+
104+
storybookStartupLogs: [
105+
"Cloning Git repository...",
106+
"Starting Docker Daemon...",
107+
"Adding some 🧙magic🧙...",
108+
"Starting VS Code...",
109+
].map((line, index) => ({
110+
id: index,
111+
level: "info",
112+
output: line,
113+
time: "",
114+
})),
103115
}
104116

105117
export const StartTimeout = Template.bind({})

site/src/components/Resources/AgentRow.tsx

+27-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"
2525
import { darcula } from "react-syntax-highlighter/dist/cjs/styles/prism"
2626
import AutoSizer from "react-virtualized-auto-sizer"
2727
import { FixedSizeList as List, ListOnScrollProps } from "react-window"
28-
import { workspaceAgentLogsMachine } from "xServices/workspaceAgentLogs/workspaceAgentLogsXService"
28+
import {
29+
LineWithID,
30+
workspaceAgentLogsMachine,
31+
} from "xServices/workspaceAgentLogs/workspaceAgentLogsXService"
2932
import { Workspace, WorkspaceAgent } from "../../api/typesGenerated"
3033
import { AppLink } from "../AppLink/AppLink"
3134
import { SSHButton } from "../SSHButton/SSHButton"
@@ -44,6 +47,8 @@ export interface AgentRowProps {
4447
hideVSCodeDesktopButton?: boolean
4548
serverVersion: string
4649
onUpdateAgent: () => void
50+
51+
storybookStartupLogs?: LineWithID[]
4752
}
4853

4954
export const AgentRow: FC<AgentRowProps> = ({
@@ -55,15 +60,28 @@ export const AgentRow: FC<AgentRowProps> = ({
5560
hideVSCodeDesktopButton,
5661
serverVersion,
5762
onUpdateAgent,
63+
storybookStartupLogs,
5864
}) => {
5965
const styles = useStyles()
6066
const { t } = useTranslation("agent")
67+
6168
const [logsMachine, sendLogsEvent] = useMachine(workspaceAgentLogsMachine, {
6269
context: { agentID: agent.id },
70+
services: process.env.STORYBOOK
71+
? {
72+
getStartupLogs: async () => {
73+
return storybookStartupLogs || []
74+
},
75+
streamStartupLogs: () => async () => {
76+
// noop
77+
},
78+
}
79+
: undefined,
6380
})
6481
const theme = useTheme()
6582
const startupScriptAnchorRef = useRef<HTMLLinkElement>(null)
6683
const [startupScriptOpen, setStartupScriptOpen] = useState(false)
84+
6785
const hasStartupFeatures =
6886
Boolean(agent.startup_script) ||
6987
Boolean(logsMachine.context.startupLogs?.length)
@@ -73,6 +91,14 @@ export const AgentRow: FC<AgentRowProps> = ({
7391
useEffect(() => {
7492
setShowStartupLogs(agent.lifecycle_state !== "ready" && hasStartupFeatures)
7593
}, [agent.lifecycle_state, hasStartupFeatures])
94+
// External applications can provide startup logs for an agent during it's spawn.
95+
// These could be Kubernetes logs, or other logs that are useful to the user.
96+
// For this reason, we want to fetch these logs when the agent is starting.
97+
useEffect(() => {
98+
if (agent.lifecycle_state === "starting") {
99+
sendLogsEvent("FETCH_STARTUP_LOGS")
100+
}
101+
}, [sendLogsEvent, agent.lifecycle_state])
76102
useEffect(() => {
77103
// We only want to fetch logs when they are actually shown,
78104
// otherwise we can make a lot of requests that aren't necessary.

site/src/components/Workspace/Workspace.stories.tsx

-10
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,3 @@ CancellationError.args = {
122122
}),
123123
},
124124
}
125-
126-
export const StartupLogsError = Template.bind({})
127-
StartupLogsError.args = {
128-
StartupLogs: new Error("Unable to fetch startup logs"),
129-
}
130-
131-
export const StartupLogs = Template.bind({})
132-
StartupLogs.args = {
133-
StartupLogs: [{ agent_id: "agent", job_id: "job", output: "startup logs" }],
134-
}

site/src/xServices/workspaceAgentLogs/workspaceAgentLogsXService.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Line } from "components/Logs/Logs"
66
// Logs are stored as the Line interface to make rendering
77
// much more efficient. Instead of mapping objects each time, we're
88
// able to just pass the array of logs to the component.
9-
interface LineWithID extends Line {
9+
export interface LineWithID extends Line {
1010
id: number
1111
}
1212

0 commit comments

Comments
 (0)