Skip to content

Commit cbd49ab

Browse files
fix(site): resize terminal when dismissing warning (#8028)
1 parent 3619a3a commit cbd49ab

File tree

3 files changed

+47
-28
lines changed

3 files changed

+47
-28
lines changed

.vscode/settings.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,5 @@
212212
// We often use a version of TypeScript that's ahead of the version shipped
213213
// with VS Code.
214214
"typescript.tsdk": "./site/node_modules/typescript/lib",
215-
"grammarly.selectors": [
216-
{
217-
"language": "markdown",
218-
"scheme": "file",
219-
"pattern": "docs/contributing/frontend.md"
220-
}
221-
]
215+
"prettier.prettierPath": "./node_modules/prettier"
222216
}

site/src/pages/TerminalPage/TerminalPage.tsx

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { terminalMachine } from "../../xServices/terminal/terminalXService"
1717
import { useProxy } from "contexts/ProxyContext"
1818
import Box from "@mui/material/Box"
1919
import { useDashboard } from "components/Dashboard/DashboardProvider"
20-
import { Region } from "api/typesGenerated"
20+
import { Region, WorkspaceAgent } from "api/typesGenerated"
2121
import { getLatencyColor } from "utils/latency"
2222
import Popover from "@mui/material/Popover"
2323
import { ProxyStatusLatency } from "components/ProxyStatusLatency/ProxyStatusLatency"
@@ -29,6 +29,46 @@ export const Language = {
2929
websocketErrorMessagePrefix: "WebSocket failed: ",
3030
}
3131

32+
const useTerminalWarning = ({
33+
agent,
34+
fitAddon,
35+
}: {
36+
agent?: WorkspaceAgent
37+
fitAddon: FitAddon | null
38+
}) => {
39+
const lifecycleState = agent?.lifecycle_state
40+
const [startupWarning, setStartupWarning] = useState<
41+
TerminalPageAlertType | undefined
42+
>(undefined)
43+
const shouldDisplayWarning = startupWarning !== undefined
44+
45+
useEffect(() => {
46+
if (lifecycleState === "start_error") {
47+
setStartupWarning("error")
48+
} else if (lifecycleState === "starting") {
49+
setStartupWarning("starting")
50+
} else {
51+
setStartupWarning((prev) => {
52+
if (prev === "starting") {
53+
return "success"
54+
}
55+
return undefined
56+
})
57+
}
58+
}, [lifecycleState])
59+
60+
// Resize the terminal when the warning toggles
61+
useEffect(() => {
62+
if (fitAddon) {
63+
fitAddon.fit()
64+
}
65+
}, [shouldDisplayWarning, fitAddon])
66+
67+
return {
68+
startupWarning,
69+
}
70+
}
71+
3272
const TerminalPage: FC = () => {
3373
const navigate = useNavigate()
3474
const styles = useStyles()
@@ -77,32 +117,16 @@ const TerminalPage: FC = () => {
77117
websocketError,
78118
} = terminalState.context
79119
const reloading = useReloading(isDisconnected)
80-
const lifecycleState = workspaceAgent?.lifecycle_state
81-
const [startupWarning, setStartupWarning] = useState<
82-
TerminalPageAlertType | undefined
83-
>(undefined)
84-
85-
useEffect(() => {
86-
if (lifecycleState === "start_error") {
87-
setStartupWarning("error")
88-
} else if (lifecycleState === "starting") {
89-
setStartupWarning("starting")
90-
} else {
91-
setStartupWarning((prev) => {
92-
if (prev === "starting") {
93-
return "success"
94-
}
95-
return undefined
96-
})
97-
}
98-
}, [lifecycleState])
99-
100120
const dashboard = useDashboard()
101121
const proxyContext = useProxy()
102122
const selectedProxy = proxyContext.proxy.proxy
103123
const latency = selectedProxy
104124
? proxyContext.proxyLatencies[selectedProxy.id]
105125
: undefined
126+
const { startupWarning } = useTerminalWarning({
127+
agent: workspaceAgent,
128+
fitAddon,
129+
})
106130

107131
// handleWebLink handles opening of URLs in the terminal!
108132
const handleWebLink = useCallback(

site/src/pages/TerminalPage/TerminalPageAlert.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export default ({ alertType }: { alertType: TerminalPageAlertType }) => {
9191
return (
9292
<Alert
9393
severity={mapAlertTypeToText[alertType].severity}
94+
sx={{ borderRadius: 0 }}
9495
dismissible
9596
actions={[
9697
<Button

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy