Skip to content

fix(site): resize terminal when dismissing warning #8028

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 2 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 1 addition & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,5 @@
// We often use a version of TypeScript that's ahead of the version shipped
// with VS Code.
"typescript.tsdk": "./site/node_modules/typescript/lib",
"grammarly.selectors": [
{
"language": "markdown",
"scheme": "file",
"pattern": "docs/contributing/frontend.md"
}
]
"prettier.prettierPath": "./node_modules/prettier"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not related to the PR but it should ensure we are using the right prettier binary

}
66 changes: 45 additions & 21 deletions site/src/pages/TerminalPage/TerminalPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { terminalMachine } from "../../xServices/terminal/terminalXService"
import { useProxy } from "contexts/ProxyContext"
import Box from "@mui/material/Box"
import { useDashboard } from "components/Dashboard/DashboardProvider"
import { Region } from "api/typesGenerated"
import { Region, WorkspaceAgent } from "api/typesGenerated"
import { getLatencyColor } from "utils/latency"
import Popover from "@mui/material/Popover"
import { ProxyStatusLatency } from "components/ProxyStatusLatency/ProxyStatusLatency"
Expand All @@ -29,6 +29,46 @@ export const Language = {
websocketErrorMessagePrefix: "WebSocket failed: ",
}

const useTerminalWarning = ({
agent,
fitAddon,
}: {
agent?: WorkspaceAgent
fitAddon: FitAddon | null
}) => {
const lifecycleState = agent?.lifecycle_state
const [startupWarning, setStartupWarning] = useState<
TerminalPageAlertType | undefined
>(undefined)
const shouldDisplayWarning = startupWarning !== undefined

useEffect(() => {
if (lifecycleState === "start_error") {
setStartupWarning("error")
} else if (lifecycleState === "starting") {
setStartupWarning("starting")
} else {
setStartupWarning((prev) => {
if (prev === "starting") {
return "success"
}
return undefined
})
}
Copy link
Member

Choose a reason for hiding this comment

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

copilot?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe? I just moved the existent code.

}, [lifecycleState])

// Resize the terminal when the warning toggles
useEffect(() => {
if (fitAddon) {
fitAddon.fit()
}
}, [shouldDisplayWarning, fitAddon])

return {
startupWarning,
}
}

const TerminalPage: FC = () => {
const navigate = useNavigate()
const styles = useStyles()
Expand Down Expand Up @@ -77,32 +117,16 @@ const TerminalPage: FC = () => {
websocketError,
} = terminalState.context
const reloading = useReloading(isDisconnected)
const lifecycleState = workspaceAgent?.lifecycle_state
const [startupWarning, setStartupWarning] = useState<
TerminalPageAlertType | undefined
>(undefined)

useEffect(() => {
if (lifecycleState === "start_error") {
setStartupWarning("error")
} else if (lifecycleState === "starting") {
setStartupWarning("starting")
} else {
setStartupWarning((prev) => {
if (prev === "starting") {
return "success"
}
return undefined
})
}
}, [lifecycleState])

const dashboard = useDashboard()
const proxyContext = useProxy()
const selectedProxy = proxyContext.proxy.proxy
const latency = selectedProxy
? proxyContext.proxyLatencies[selectedProxy.id]
: undefined
const { startupWarning } = useTerminalWarning({
agent: workspaceAgent,
fitAddon,
})

// handleWebLink handles opening of URLs in the terminal!
const handleWebLink = useCallback(
Expand Down
1 change: 1 addition & 0 deletions site/src/pages/TerminalPage/TerminalPageAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export default ({ alertType }: { alertType: TerminalPageAlertType }) => {
return (
<Alert
severity={mapAlertTypeToText[alertType].severity}
sx={{ borderRadius: 0 }}
dismissible
actions={[
<Button
Expand Down