Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(site): show available logs consistently on template creation page#19832

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
aslilac merged 10 commits intomainfromlilac/fix-bad-logging-conditions
Sep 16, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
import{type Interpolation,typeTheme, useTheme } from "@emotion/react";
import type{Interpolation, Theme } from "@emotion/react";
import type { ProvisionerJobLog, WorkspaceBuild } from "api/typesGenerated";
import type { Line } from "components/Logs/LogLine";
import { DEFAULT_LOG_LINE_SIDE_PADDING, Logs } from "components/Logs/Logs";
import dayjs from "dayjs";
import { type FC, Fragment, type HTMLAttributes, useMemo } from "react";
import { BODY_FONT_FAMILY, MONOSPACE_FONT_FAMILY } from "theme/constants";
import {
type FC,
Fragment,
type HTMLAttributes,
useLayoutEffect,
useRef,
} from "react";
import { BODY_FONT_FAMILY } from "theme/constants";

const Language = {
seconds: "seconds",
Expand DownExpand Up@@ -43,45 +49,32 @@ interface WorkspaceBuildLogsProps extends HTMLAttributes<HTMLDivElement> {
sticky?: boolean;
logs: ProvisionerJobLog[];
build?: WorkspaceBuild;
disableAutoscroll?: boolean;
}

export const WorkspaceBuildLogs: FC<WorkspaceBuildLogsProps> = ({
hideTimestamps,
sticky,
logs,
build,
disableAutoscroll,
className,
...attrs
}) => {
const theme = useTheme();

const _processedLogs = useMemo(() => {
const allLogs = logs || [];

// Add synthetic overflow message if needed
if (build?.job?.logs_overflowed) {
allLogs.push({
id: -1,
created_at: new Date().toISOString(),
log_level: "error",
log_source: "provisioner",
output:
"Provisioner logs exceeded the max size of 1MB. Will not continue to write provisioner logs for workspace build.",
stage: "overflow",
});
}

return allLogs;
}, [logs, build?.job?.logs_overflowed]);

const groupedLogsByStage = groupLogsByStage(logs);

const ref = useRef<HTMLDivElement>(null);
useLayoutEffect(() => {
if (disableAutoscroll || logs.length === 0) {
return;
}
ref.current?.scrollIntoView({ block: "end" });
}, [logs, disableAutoscroll]);

return (
<div
css={{
border: `1px solid ${theme.palette.divider}`,
borderRadius: 8,
fontFamily: MONOSPACE_FONT_FAMILY,
}}
ref={ref}
className="font-mono border border-border rounded-lg"
{...attrs}
>
{Object.entries(groupedLogsByStage).map(([stage, logs]) => {
Expand Down
55 changes: 19 additions & 36 deletionssite/src/pages/CreateTemplatePage/BuildLogsDrawer.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,7 @@ import { AlertVariant } from "modules/provisioners/ProvisionerAlert";
import { ProvisionerStatusAlert } from "modules/provisioners/ProvisionerStatusAlert";
import { useWatchVersionLogs } from "modules/templates/useWatchVersionLogs";
import { WorkspaceBuildLogs } from "modules/workspaces/WorkspaceBuildLogs/WorkspaceBuildLogs";
import{typeFC, useLayoutEffect, useRef } from "react";
import type{ FC } from "react";
import { navHeight } from "theme/constants";

type BuildLogsDrawerProps = {
Expand All@@ -29,27 +29,6 @@ export const BuildLogsDrawer: FC<BuildLogsDrawerProps> = ({
...drawerProps
}) => {
const logs = useWatchVersionLogs(templateVersion);
const logsContainer = useRef<HTMLDivElement>(null);

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

// biome-ignore lint/correctness/useExhaustiveDependencies: consider refactoring
useLayoutEffect(() => {
scrollToBottom();
}, [logs]);

// biome-ignore lint/correctness/useExhaustiveDependencies: consider refactoring
useLayoutEffect(() => {
if (drawerProps.open) {
scrollToBottom();
}
}, [drawerProps.open]);

const isMissingVariables =
error instanceof JobError &&
Expand All@@ -58,6 +37,7 @@ export const BuildLogsDrawer: FC<BuildLogsDrawerProps> = ({
const matchingProvisioners = templateVersion?.matched_provisioners?.count;
const availableProvisioners =
templateVersion?.matched_provisioners?.available;
const hasLogs = logs && logs.length > 0;

return (
<Drawer anchor="right" {...drawerProps}>
Expand All@@ -70,8 +50,6 @@ export const BuildLogsDrawer: FC<BuildLogsDrawerProps> = ({
</IconButton>
</header>

{}

{isMissingVariables ? (
<MissingVariablesBanner
onFillVariables={() => {
Expand All@@ -80,23 +58,28 @@ export const BuildLogsDrawer: FC<BuildLogsDrawerProps> = ({
});
const firstVariableInput =
variablesSectionRef.current?.querySelector("input");
setTimeout(() =>firstVariableInput?.focus(), 0);
firstVariableInput?.focus();
drawerProps.onClose();
}}
/>
) : availableProvisioners && availableProvisioners > 0 && logs ? (
<section ref={logsContainer} css={styles.logs}>
<WorkspaceBuildLogs logs={logs} css={{ border: 0 }} />
</section>
) : (
<>
<ProvisionerStatusAlert
matchingProvisioners={matchingProvisioners}
availableProvisioners={availableProvisioners}
tags={templateVersion?.job.tags ?? {}}
variant={AlertVariant.Inline}
/>
<Loader />
{(matchingProvisioners === 0 || !hasLogs) && (
<ProvisionerStatusAlert
matchingProvisioners={matchingProvisioners}
availableProvisioners={availableProvisioners}
tags={templateVersion?.job.tags ?? {}}
variant={AlertVariant.Inline}
/>
)}

{hasLogs ? (
<section css={styles.logs}>
<WorkspaceBuildLogs logs={logs} className="border-0" />
</section>
) : (
<Loader />
)}
</>
)}
</div>
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -197,15 +197,6 @@ export const TemplateVersionEditor: FC<TemplateVersionEditorProps> = ({
const isEditorValueBinary =
typeof editorValue === "string" ? isBinaryData(editorValue) : false;

// Auto scroll
const logsContentRef = useRef<HTMLDivElement>(null);
// biome-ignore lint/correctness/useExhaustiveDependencies: consider refactoring
useEffect(() => {
if (logsContentRef.current) {
logsContentRef.current.scrollTop = logsContentRef.current.scrollHeight;
}
}, [buildLogs, resources]);

useLeaveSiteWarning(dirty);

const canBuild = !isBuilding;
Expand DownExpand Up@@ -596,10 +587,7 @@ export const TemplateVersionEditor: FC<TemplateVersionEditorProps> = ({
</div>

{selectedTab === "logs" && (
<div
css={[styles.logs, styles.tabContent]}
ref={logsContentRef}
>
<div css={[styles.logs, styles.tabContent]}>
{templateVersion.job.error ? (
<div>
<ProvisionerAlert
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -299,6 +299,7 @@ const BuildLogsContent: FC<{
}}
logs={sortLogsByCreatedAt(logs)}
build={build}
disableAutoscroll
/>
);
};
Expand Down
18 changes: 2 additions & 16 deletionssite/src/pages/WorkspacePage/WorkspaceBuildLogsSection.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,7 @@ import { useTheme } from "@emotion/react";
import type { ProvisionerJobLog } from "api/typesGenerated";
import { Loader } from "components/Loader/Loader";
import { WorkspaceBuildLogs } from "modules/workspaces/WorkspaceBuildLogs/WorkspaceBuildLogs";
import{typeFC, useEffect, useRef } from "react";
import type{ FC } from "react";

interface WorkspaceBuildLogsSectionProps {
logs?: ProvisionerJobLog[];
Expand All@@ -11,22 +11,8 @@ interface WorkspaceBuildLogsSectionProps {
export const WorkspaceBuildLogsSection: FC<WorkspaceBuildLogsSectionProps> = ({
logs,
}) => {
const scrollRef = useRef<HTMLDivElement>(null);
const theme = useTheme();

// biome-ignore lint/correctness/useExhaustiveDependencies: reset scroll when logs change
useEffect(() => {
// Auto scrolling makes hard to snapshot test using Chromatic
if (process.env.STORYBOOK === "true") {
return;
}

const scrollEl = scrollRef.current;
if (scrollEl) {
scrollEl.scrollTop = scrollEl.scrollHeight;
}
}, [logs]);

return (
<div
css={{
Expand All@@ -50,7 +36,7 @@ export const WorkspaceBuildLogsSection: FC<WorkspaceBuildLogsSectionProps> = ({
>
Build logs
</header>
<divref={scrollRef}css={{ height: "400px", overflowY: "auto" }}>
<div css={{ height: "400px", overflowY: "auto" }}>
{logs ? (
<WorkspaceBuildLogs
sticky
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp