Skip to content

Commit 2baa343

Browse files
fix(site): resize terminal when alert is dismissed (#8368)
1 parent e088303 commit 2baa343

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

site/src/pages/TerminalPage/TerminalPage.tsx

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,11 @@ export const Language = {
3030
websocketErrorMessagePrefix: "WebSocket failed: ",
3131
}
3232

33-
const useTerminalWarning = ({
34-
agent,
35-
fitAddon,
36-
}: {
37-
agent?: WorkspaceAgent
38-
fitAddon: FitAddon | null
39-
}) => {
33+
const useTerminalWarning = ({ agent }: { agent?: WorkspaceAgent }) => {
4034
const lifecycleState = agent?.lifecycle_state
4135
const [startupWarning, setStartupWarning] = useState<
4236
TerminalPageAlertType | undefined
4337
>(undefined)
44-
const shouldDisplayWarning = startupWarning !== undefined
4538

4639
useEffect(() => {
4740
if (lifecycleState === "start_error") {
@@ -58,13 +51,6 @@ const useTerminalWarning = ({
5851
}
5952
}, [lifecycleState])
6053

61-
// Resize the terminal when the warning toggles
62-
useEffect(() => {
63-
if (fitAddon) {
64-
fitAddon.fit()
65-
}
66-
}, [shouldDisplayWarning, fitAddon])
67-
6854
return {
6955
startupWarning,
7056
}
@@ -132,7 +118,6 @@ const TerminalPage: FC<TerminalPageProps> = ({ renderer }) => {
132118
: undefined
133119
const { startupWarning } = useTerminalWarning({
134120
agent: workspaceAgent,
135-
fitAddon,
136121
})
137122

138123
// handleWebLink handles opening of URLs in the terminal!
@@ -352,7 +337,14 @@ const TerminalPage: FC<TerminalPageProps> = ({ renderer }) => {
352337
)}
353338
</div>
354339
<Box display="flex" flexDirection="column" height="100vh">
355-
{startupWarning && <TerminalPageAlert alertType={startupWarning} />}
340+
{startupWarning && (
341+
<TerminalPageAlert
342+
alertType={startupWarning}
343+
onDismiss={() => {
344+
fitAddon?.fit()
345+
}}
346+
/>
347+
)}
356348
<div
357349
className={styles.terminal}
358350
ref={xtermRef}

site/src/pages/TerminalPage/TerminalPageAlert.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,27 @@ const mapAlertTypeToText: MapAlertTypeToComponent = {
8787
},
8888
}
8989

90-
export default ({ alertType }: { alertType: TerminalPageAlertType }) => {
90+
export default ({
91+
alertType,
92+
onDismiss,
93+
}: {
94+
alertType: TerminalPageAlertType
95+
onDismiss: () => void
96+
}) => {
97+
const severity = mapAlertTypeToText[alertType].severity
9198
return (
9299
<Alert
93-
severity={mapAlertTypeToText[alertType].severity}
94-
sx={{ borderRadius: 0 }}
100+
severity={severity}
101+
sx={{
102+
borderRadius: 0,
103+
borderWidth: 0,
104+
borderBottomWidth: 1,
105+
borderBottomColor: (theme) => theme.palette.divider,
106+
backgroundColor: (theme) => theme.palette.background.paperLight,
107+
borderLeft: (theme) => `3px solid ${theme.palette[severity].light}`,
108+
marginBottom: 1,
109+
}}
110+
onDismiss={onDismiss}
95111
dismissible
96112
actions={[
97113
<Button

0 commit comments

Comments
 (0)