-
Notifications
You must be signed in to change notification settings - Fork 894
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2309bc4
Show build logs during template creation
BrunoQuaresma e355d4c
Merge branch 'main' of https://github.com/coder/coder into bq/show-bu…
BrunoQuaresma b07a7ce
Merge branch 'main' of https://github.com/coder/coder into bq/show-bu…
BrunoQuaresma 34f97e8
Add minor adjustments
BrunoQuaresma 8ba9ed1
Refactor how version logs were consumed
BrunoQuaresma 2de86ac
Decrease poll time when pending
BrunoQuaresma 5eb9301
Fix enable update
BrunoQuaresma 485ae40
Apply suggestions from code review
BrunoQuaresma 9ffe1a3
Apply minor improvements
BrunoQuaresma 1f663d9
Merge branches 'main' and 'bq/show-build-logs-on-template-create' of …
BrunoQuaresma 76b5287
Add upload file handler
BrunoQuaresma c4f4a6f
Fix template version editor page tests
BrunoQuaresma 09e1be5
Fix create template page test
BrunoQuaresma c118fd2
Apply review suggestions
BrunoQuaresma 245101f
Add storybook
BrunoQuaresma c56f2dd
Improve ws decorator
BrunoQuaresma b2bc71b
Remove console.log
BrunoQuaresma d7aa79a
Remove old story
BrunoQuaresma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Show build logs during template creation
- Loading branch information
commit 2309bc45f8acc1f29d250b61b65dfd7278eb06e4
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
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. Extracted from |
This file contains hidden or 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,47 @@ | ||
import { watchBuildLogsByTemplateVersionId } from "api/api"; | ||
import { | ||
ProvisionerJobLog, | ||
ProvisionerJobStatus, | ||
TemplateVersion, | ||
} from "api/typesGenerated"; | ||
import { useState, useEffect } from "react"; | ||
|
||
export const useVersionLogs = ( | ||
templateVersion: TemplateVersion | undefined, | ||
options?: { onDone: () => Promise<unknown> }, | ||
) => { | ||
const [logs, setLogs] = useState<ProvisionerJobLog[]>(); | ||
const templateVersionId = templateVersion?.id; | ||
const templateVersionStatus = templateVersion?.job.status; | ||
|
||
useEffect(() => { | ||
const enabledStatuses: ProvisionerJobStatus[] = ["running", "pending"]; | ||
|
||
if (!templateVersionId || !templateVersionStatus) { | ||
return; | ||
} | ||
|
||
if (!enabledStatuses.includes(templateVersionStatus)) { | ||
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, | ||
setLogs, | ||
}; | ||
}; |
This file contains hidden or 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,75 @@ | ||
import Drawer from "@mui/material/Drawer"; | ||
import Close from "@mui/icons-material/Close"; | ||
import IconButton from "@mui/material/IconButton"; | ||
import { visuallyHidden } from "@mui/utils"; | ||
import { FC, useEffect, useRef } from "react"; | ||
import { TemplateVersion } from "api/typesGenerated"; | ||
import { WorkspaceBuildLogs } from "modules/workspaces/WorkspaceBuildLogs/WorkspaceBuildLogs"; | ||
import { useTheme } from "@emotion/react"; | ||
import { navHeight } from "theme/constants"; | ||
import { useVersionLogs } from "modules/templates/useVersionLogs"; | ||
|
||
type BuildLogsDrawerProps = { | ||
open: boolean; | ||
onClose: () => void; | ||
templateVersion: TemplateVersion | undefined; | ||
}; | ||
|
||
export const BuildLogsDrawer: FC<BuildLogsDrawerProps> = ({ | ||
templateVersion, | ||
...drawerProps | ||
}) => { | ||
const theme = useTheme(); | ||
const { logs } = useVersionLogs(templateVersion); | ||
|
||
// Auto scroll | ||
const logsContainer = useRef<HTMLDivElement>(null); | ||
useEffect(() => { | ||
if (logsContainer.current) { | ||
logsContainer.current.scrollTop = logsContainer.current.scrollHeight; | ||
} | ||
}, [logs]); | ||
|
||
return ( | ||
<Drawer anchor="right" {...drawerProps}> | ||
<div | ||
css={{ | ||
width: 800, | ||
height: "100%", | ||
display: "flex", | ||
flexDirection: "column", | ||
}} | ||
> | ||
<header | ||
css={{ | ||
height: navHeight, | ||
padding: "0 20px", | ||
display: "flex", | ||
alignItems: "center", | ||
justifyContent: "space-between", | ||
borderBottom: `1px solid ${theme.palette.divider}`, | ||
}} | ||
> | ||
<h3 css={{ margin: 0, fontWeight: 500, fontSize: 16 }}> | ||
Creating template... | ||
</h3> | ||
<IconButton size="small" onClick={drawerProps.onClose}> | ||
<Close css={{ fontSize: 20 }} /> | ||
<span style={visuallyHidden}>Close build logs</span> | ||
</IconButton> | ||
</header> | ||
|
||
<section | ||
ref={logsContainer} | ||
css={{ | ||
flex: 1, | ||
overflow: "auto", | ||
backgroundColor: theme.palette.background.default, | ||
}} | ||
> | ||
<WorkspaceBuildLogs logs={logs ?? []} css={{ border: 0 }} /> | ||
</section> | ||
</div> | ||
</Drawer> | ||
); | ||
}; |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.