Skip to content

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 18 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add minor adjustments
  • Loading branch information
BrunoQuaresma committed Feb 22, 2024
commit 34f97e895ad42f8b61c65d369a11dfcfbd5f239f
101 changes: 54 additions & 47 deletions site/src/components/Form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
useContext,
ReactNode,
ComponentProps,
forwardRef,
} from "react";
import { AlphaBadge, DeprecatedBadge } from "components/Badges/Badges";
import { Stack } from "components/Stack/Stack";
Expand Down Expand Up @@ -81,59 +82,65 @@ interface FormSectionProps {
deprecated?: boolean;
}

export const FormSection: FC<FormSectionProps> = ({
children,
title,
description,
classes = {},
alpha = false,
deprecated = false,
}) => {
const { direction } = useContext(FormContext);
const theme = useTheme();

return (
<div
css={{
display: "flex",
alignItems: "flex-start",
flexDirection: direction === "horizontal" ? "row" : "column",
gap: direction === "horizontal" ? 120 : 24,

[theme.breakpoints.down("md")]: {
flexDirection: "column",
gap: 16,
},
}}
className={classes.root}
>
<div
export const FormSection = forwardRef<HTMLDivElement, FormSectionProps>(
(
{
children,
title,
description,
classes = {},
alpha = false,
deprecated = false,
},
ref,
) => {
const { direction } = useContext(FormContext);
const theme = useTheme();

return (
<section
ref={ref}
css={{
width: "100%",
maxWidth: direction === "horizontal" ? 312 : undefined,
flexShrink: 0,
position: direction === "horizontal" ? "sticky" : undefined,
top: 24,
display: "flex",
alignItems: "flex-start",
flexDirection: direction === "horizontal" ? "row" : "column",
gap: direction === "horizontal" ? 120 : 24,

[theme.breakpoints.down("md")]: {
width: "100%",
position: "initial" as const,
flexDirection: "column",
gap: 16,
},
}}
className={classes.sectionInfo}
className={classes.root}
>
<h2 css={styles.formSectionInfoTitle} className={classes.infoTitle}>
{title}
{alpha && <AlphaBadge />}
{deprecated && <DeprecatedBadge />}
</h2>
<div css={styles.formSectionInfoDescription}>{description}</div>
</div>

{children}
</div>
);
};
<div
css={{
width: "100%",
maxWidth: direction === "horizontal" ? 312 : undefined,
flexShrink: 0,
position: direction === "horizontal" ? "sticky" : undefined,
top: 24,

[theme.breakpoints.down("md")]: {
width: "100%",
position: "initial" as const,
},
}}
className={classes.sectionInfo}
>
<h2 css={styles.formSectionInfoTitle} className={classes.infoTitle}>
{title}
{alpha && <AlphaBadge />}
{deprecated && <DeprecatedBadge />}
</h2>
<div css={styles.formSectionInfoDescription}>{description}</div>
</div>

{children}
</section>
);
},
);

export const FormFields: FC<ComponentProps<typeof Stack>> = (props) => {
return (
Expand Down
3 changes: 3 additions & 0 deletions site/src/components/FormFooter/FormFooter.tsx
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This component needs to be refactored to make it easier to extend and use #12272

Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ export interface FormFooterProps {
styles?: FormFooterStyles;
submitLabel?: string;
submitDisabled?: boolean;
extraActions?: React.ReactNode;
}

export const FormFooter: FC<FormFooterProps> = ({
onCancel,
extraActions,
isLoading,
submitDisabled,
submitLabel = Language.defaultSubmitLabel,
Expand Down Expand Up @@ -52,6 +54,7 @@ export const FormFooter: FC<FormFooterProps> = ({
>
{Language.cancelLabel}
</Button>
{extraActions}
</div>
);
};
Expand Down
1 change: 1 addition & 0 deletions site/src/modules/templates/useVersionLogs.ts
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted from ImportStarterTemplateView

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const useVersionLogs = (
const templateVersionStatus = templateVersion?.job.status;

useEffect(() => {
setLogs([]);
const enabledStatuses: ProvisionerJobStatus[] = ["running", "pending"];

if (!templateVersionId || !templateVersionStatus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export const WorkspaceBuildLogs: FC<WorkspaceBuildLogsProps> = ({
}}
{...attrs}
>
{stages.length === 0 && (
<div css={styles.header(theme)}>Waiting for logs...</div>
)}
{stages.map((stage) => {
const logs = groupedLogsByStage[stage];
const isEmpty = logs.every((log) => log.output === "");
Expand Down
69 changes: 63 additions & 6 deletions site/src/pages/CreateTemplatePage/BuildLogsDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,52 @@ import { WorkspaceBuildLogs } from "modules/workspaces/WorkspaceBuildLogs/Worksp
import { useTheme } from "@emotion/react";
import { navHeight } from "theme/constants";
import { useVersionLogs } from "modules/templates/useVersionLogs";
import { JobError } from "api/queries/templates";
import AlertTitle from "@mui/material/AlertTitle";
import { Alert, AlertDetail } from "components/Alert/Alert";
import Button from "@mui/material/Button";
import Collapse from "@mui/material/Collapse";

type BuildLogsDrawerProps = {
error: unknown;
open: boolean;
onClose: () => void;
templateVersion: TemplateVersion | undefined;
variablesSectionRef: React.RefObject<HTMLDivElement>;
};

export const BuildLogsDrawer: FC<BuildLogsDrawerProps> = ({
templateVersion,
error,
variablesSectionRef,
...drawerProps
}) => {
const theme = useTheme();
const { logs } = useVersionLogs(templateVersion);

// Auto scroll
const logsContainer = useRef<HTMLDivElement>(null);

const scrollToBottom = () => {
setTimeout(() => {
if (logsContainer.current) {
logsContainer.current.scrollTop = logsContainer.current.scrollHeight;
}
}, 0);
};

useEffect(() => {
if (logsContainer.current) {
logsContainer.current.scrollTop = logsContainer.current.scrollHeight;
}
scrollToBottom();
}, [logs]);

useEffect(() => {
if (drawerProps.open) {
scrollToBottom();
}
}, [drawerProps.open]);

const isMissingVariables =
error instanceof JobError &&
error.job.error_code === "REQUIRED_TEMPLATE_VARIABLES";

return (
<Drawer anchor="right" {...drawerProps}>
<div
Expand All @@ -43,7 +67,7 @@ export const BuildLogsDrawer: FC<BuildLogsDrawerProps> = ({
<header
css={{
height: navHeight,
padding: "0 20px",
padding: "0 24px",
display: "flex",
alignItems: "center",
justifyContent: "space-between",
Expand All @@ -59,6 +83,39 @@ export const BuildLogsDrawer: FC<BuildLogsDrawerProps> = ({
</IconButton>
</header>

<Collapse in={isMissingVariables}>
<Alert
css={{
borderTop: 0,
borderRight: 0,
backgroundColor: theme.palette.background.paper,
borderRadius: 0,
borderBottomColor: theme.palette.divider,
paddingLeft: 24,
}}
severity="warning"
actions={
<Button
size="small"
variant="text"
onClick={() => {
variablesSectionRef.current?.scrollIntoView({
behavior: "smooth",
});
const firstVariableInput =
variablesSectionRef.current?.querySelector("input");
setTimeout(() => firstVariableInput?.focus(), 0);
drawerProps.onClose();
}}
>
Add variables
</Button>
}
>
<AlertTitle>Failed to create template</AlertTitle>
<AlertDetail>{isMissingVariables && error.message}</AlertDetail>
</Alert>
</Collapse>
<section
ref={logsContainer}
css={{
Expand Down
Loading