-
Notifications
You must be signed in to change notification settings - Fork 887
feat(site): display build logs on template creation #12271
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
Changes from all commits
2309bc4
e355d4c
b07a7ce
34f97e8
8ba9ed1
2de86ac
5eb9301
485ae40
9ffe1a3
1f663d9
76b5287
c4f4a6f
09e1be5
c118fd2
245101f
c56f2dd
b2bc71b
d7aa79a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { watchBuildLogsByTemplateVersionId } from "api/api"; | ||
import { ProvisionerJobLog, TemplateVersion } from "api/typesGenerated"; | ||
import { useState, useEffect } from "react"; | ||
|
||
export const useWatchVersionLogs = ( | ||
templateVersion: TemplateVersion | undefined, | ||
options?: { onDone: () => Promise<unknown> }, | ||
) => { | ||
const [logs, setLogs] = useState<ProvisionerJobLog[] | undefined>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I should've been more specific, but my original issue was really more wondering why we need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use the following:
Wdyt? I use the same idea for fetching server data. |
||
const templateVersionId = templateVersion?.id; | ||
const templateVersionStatus = templateVersion?.job.status; | ||
|
||
useEffect(() => { | ||
setLogs(undefined); | ||
BrunoQuaresma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, [templateVersionId]); | ||
|
||
useEffect(() => { | ||
if (!templateVersionId || !templateVersionStatus) { | ||
return; | ||
} | ||
|
||
if (templateVersionStatus !== "running") { | ||
return; | ||
} | ||
|
||
const socket = watchBuildLogsByTemplateVersionId(templateVersionId, { | ||
onMessage: (log) => { | ||
setLogs((logs) => (logs ? [...logs, log] : [log])); | ||
}, | ||
onDone: options?.onDone, | ||
onError: (error) => { | ||
console.error(error); | ||
}, | ||
}); | ||
|
||
return () => { | ||
socket.close(); | ||
}; | ||
}, [options?.onDone, templateVersionId, templateVersionStatus]); | ||
|
||
return logs; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { JobError } from "api/queries/templates"; | ||
import { BuildLogsDrawer } from "./BuildLogsDrawer"; | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { | ||
MockProvisionerJob, | ||
MockTemplateVersion, | ||
MockWorkspaceBuildLogs, | ||
} from "testHelpers/entities"; | ||
import { withWebSocket } from "testHelpers/storybook"; | ||
|
||
const meta: Meta<typeof BuildLogsDrawer> = { | ||
title: "pages/CreateTemplatePage/BuildLogsDrawer", | ||
component: BuildLogsDrawer, | ||
args: { | ||
open: true, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof BuildLogsDrawer>; | ||
|
||
export const Loading: Story = {}; | ||
|
||
export const MissingVariables: Story = { | ||
args: { | ||
templateVersion: MockTemplateVersion, | ||
error: new JobError( | ||
{ | ||
...MockProvisionerJob, | ||
error_code: "REQUIRED_TEMPLATE_VARIABLES", | ||
}, | ||
MockTemplateVersion, | ||
), | ||
}, | ||
}; | ||
|
||
export const Logs: Story = { | ||
args: { | ||
templateVersion: { | ||
...MockTemplateVersion, | ||
job: { | ||
...MockTemplateVersion.job, | ||
status: "running", | ||
}, | ||
}, | ||
}, | ||
decorators: [withWebSocket], | ||
parameters: { | ||
webSocket: { | ||
messages: MockWorkspaceBuildLogs.map((log) => JSON.stringify(log)), | ||
}, | ||
}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.