-
Notifications
You must be signed in to change notification settings - Fork 899
chore(site): refactor logs and add stories #12553
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 all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4099ba6
Refact log components
BrunoQuaresma 6f46085
Add stories for LogLine
BrunoQuaresma 23b3910
Fix source_id prop
BrunoQuaresma c3e39a1
Fix resource_id parametters
BrunoQuaresma cb7cda9
Fix line height
BrunoQuaresma 8b5a831
Apply PR review suggestions
BrunoQuaresma 53dcd35
Fix missing log line space
BrunoQuaresma 5e6222a
Add output comment
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { chromatic } from "testHelpers/chromatic"; | ||
import { LogLine, LogLinePrefix } from "./LogLine"; | ||
|
||
const meta: Meta<typeof LogLine> = { | ||
title: "components/Logs/LogLine", | ||
parameters: { chromatic }, | ||
component: LogLine, | ||
args: { | ||
level: "info", | ||
children: ( | ||
<> | ||
<LogLinePrefix>13:45:31.072</LogLinePrefix> | ||
<span>info: Starting build</span> | ||
</> | ||
), | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof LogLine>; | ||
|
||
export const Info: Story = {}; | ||
|
||
export const Debug: Story = { | ||
args: { | ||
level: "debug", | ||
}, | ||
}; | ||
|
||
export const Error: Story = { | ||
args: { | ||
level: "error", | ||
}, | ||
}; | ||
|
||
export const Trace: Story = { | ||
args: { | ||
level: "trace", | ||
}, | ||
}; | ||
|
||
export const Warn: Story = { | ||
args: { | ||
level: "warn", | ||
}, | ||
}; |
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,80 @@ | ||
import type { Interpolation, Theme } from "@emotion/react"; | ||
import type { FC, HTMLAttributes } from "react"; | ||
import type { LogLevel } from "api/typesGenerated"; | ||
import { MONOSPACE_FONT_FAMILY } from "theme/constants"; | ||
|
||
export const DEFAULT_LOG_LINE_SIDE_PADDING = 24; | ||
|
||
export interface Line { | ||
time: string; | ||
output: string; | ||
level: LogLevel; | ||
sourceId: string; | ||
} | ||
|
||
type LogLineProps = { | ||
level: LogLevel; | ||
} & HTMLAttributes<HTMLPreElement>; | ||
|
||
export const LogLine: FC<LogLineProps> = ({ level, ...divProps }) => { | ||
return ( | ||
<pre | ||
css={styles.line} | ||
className={`${level} ${divProps.className} logs-line`} | ||
{...divProps} | ||
/> | ||
); | ||
}; | ||
|
||
export const LogLinePrefix: FC<HTMLAttributes<HTMLSpanElement>> = (props) => { | ||
return <pre css={styles.prefix} {...props} />; | ||
}; | ||
|
||
const styles = { | ||
line: (theme) => ({ | ||
margin: 0, | ||
wordBreak: "break-all", | ||
display: "flex", | ||
alignItems: "center", | ||
fontSize: 13, | ||
color: theme.palette.text.primary, | ||
fontFamily: MONOSPACE_FONT_FAMILY, | ||
height: "auto", | ||
padding: `0 var(--log-line-side-padding, ${DEFAULT_LOG_LINE_SIDE_PADDING}px)`, | ||
|
||
"&.error": { | ||
backgroundColor: theme.roles.error.background, | ||
color: theme.roles.error.text, | ||
|
||
"& .dashed-line": { | ||
backgroundColor: theme.roles.error.outline, | ||
}, | ||
}, | ||
|
||
"&.debug": { | ||
backgroundColor: theme.roles.info.background, | ||
color: theme.roles.info.text, | ||
|
||
"& .dashed-line": { | ||
backgroundColor: theme.roles.info.outline, | ||
}, | ||
}, | ||
|
||
"&.warn": { | ||
backgroundColor: theme.roles.warning.background, | ||
color: theme.roles.warning.text, | ||
|
||
"& .dashed-line": { | ||
backgroundColor: theme.roles.warning.outline, | ||
}, | ||
}, | ||
}), | ||
|
||
prefix: (theme) => ({ | ||
userSelect: "none", | ||
margin: 0, | ||
display: "inline-block", | ||
color: theme.palette.text.secondary, | ||
marginRight: 24, | ||
}), | ||
} satisfies Record<string, Interpolation<Theme>>; |
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,26 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { chromatic } from "testHelpers/chromatic"; | ||
import { MockWorkspaceBuildLogs } from "testHelpers/entities"; | ||
import { Logs } from "./Logs"; | ||
|
||
const meta: Meta<typeof Logs> = { | ||
title: "components/Logs", | ||
parameters: { chromatic }, | ||
component: Logs, | ||
args: { | ||
lines: MockWorkspaceBuildLogs.map((log) => ({ | ||
level: log.log_level, | ||
time: log.created_at, | ||
output: log.output, | ||
sourceId: log.log_source, | ||
})), | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Logs>; | ||
|
||
const Default: Story = {}; | ||
|
||
export { Default as Logs }; |
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,50 @@ | ||
import type { Interpolation, Theme } from "@emotion/react"; | ||
import dayjs from "dayjs"; | ||
import type { FC } from "react"; | ||
import { LogLinePrefix, LogLine, type Line } from "./LogLine"; | ||
|
||
export const DEFAULT_LOG_LINE_SIDE_PADDING = 24; | ||
|
||
export interface LogsProps { | ||
lines: Line[]; | ||
hideTimestamps?: boolean; | ||
className?: string; | ||
} | ||
|
||
export const Logs: FC<LogsProps> = ({ | ||
hideTimestamps, | ||
lines, | ||
className = "", | ||
}) => { | ||
return ( | ||
<div css={styles.root} className={`${className} logs-container`}> | ||
<div css={{ minWidth: "fit-content" }}> | ||
{lines.map((line, idx) => ( | ||
<LogLine key={idx} level={line.level}> | ||
{!hideTimestamps && ( | ||
<LogLinePrefix> | ||
{dayjs(line.time).format(`HH:mm:ss.SSS`)} | ||
</LogLinePrefix> | ||
)} | ||
<span>{line.output}</span> | ||
</LogLine> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
const styles = { | ||
root: (theme) => ({ | ||
minHeight: 156, | ||
padding: "8px 0", | ||
borderRadius: 8, | ||
overflowX: "auto", | ||
background: theme.palette.background.default, | ||
|
||
"&:not(:last-child)": { | ||
borderBottom: `1px solid ${theme.palette.divider}`, | ||
borderRadius: 0, | ||
}, | ||
}), | ||
} satisfies Record<string, Interpolation<Theme>>; |
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,55 @@ | ||
import type { Interpolation, Theme } from "@emotion/react"; | ||
import AnsiToHTML from "ansi-to-html"; | ||
import { type FC, type ReactNode, useMemo } from "react"; | ||
import { type Line, LogLine, LogLinePrefix } from "components/Logs/LogLine"; | ||
|
||
const convert = new AnsiToHTML(); | ||
|
||
interface AgentLogLineProps { | ||
line: Line; | ||
number: number; | ||
style: React.CSSProperties; | ||
sourceIcon: ReactNode; | ||
maxLineNumber: number; | ||
} | ||
|
||
export const AgentLogLine: FC<AgentLogLineProps> = ({ | ||
line, | ||
number, | ||
maxLineNumber, | ||
sourceIcon, | ||
style, | ||
}) => { | ||
const output = useMemo(() => { | ||
return convert.toHtml(line.output.split(/\r/g).pop() as string); | ||
}, [line.output]); | ||
|
||
return ( | ||
<LogLine css={{ paddingLeft: 16 }} level={line.level} style={style}> | ||
{sourceIcon} | ||
<LogLinePrefix | ||
css={styles.number} | ||
style={{ | ||
minWidth: `${maxLineNumber.toString().length - 1}em`, | ||
}} | ||
> | ||
{number} | ||
</LogLinePrefix> | ||
<span | ||
// Output contains HTML to represent ANSI-code formatting | ||
dangerouslySetInnerHTML={{ | ||
__html: output, | ||
}} | ||
/> | ||
</LogLine> | ||
); | ||
}; | ||
|
||
const styles = { | ||
number: (theme) => ({ | ||
width: 32, | ||
textAlign: "right", | ||
flexShrink: 0, | ||
color: theme.palette.text.disabled, | ||
}), | ||
} satisfies Record<string, Interpolation<Theme>>; |
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.