Skip to content

fix(site): resize terminal when alert is dismissed #8368

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 3 commits into from
Jul 7, 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
26 changes: 9 additions & 17 deletions site/src/pages/TerminalPage/TerminalPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,11 @@ export const Language = {
websocketErrorMessagePrefix: "WebSocket failed: ",
}

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

useEffect(() => {
if (lifecycleState === "start_error") {
Expand All @@ -58,13 +51,6 @@ const useTerminalWarning = ({
}
}, [lifecycleState])

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

return {
startupWarning,
}
Expand Down Expand Up @@ -132,7 +118,6 @@ const TerminalPage: FC<TerminalPageProps> = ({ renderer }) => {
: undefined
const { startupWarning } = useTerminalWarning({
agent: workspaceAgent,
fitAddon,
})

// handleWebLink handles opening of URLs in the terminal!
Expand Down Expand Up @@ -352,7 +337,14 @@ const TerminalPage: FC<TerminalPageProps> = ({ renderer }) => {
)}
</div>
<Box display="flex" flexDirection="column" height="100vh">
{startupWarning && <TerminalPageAlert alertType={startupWarning} />}
{startupWarning && (
<TerminalPageAlert
alertType={startupWarning}
onDismiss={() => {
fitAddon?.fit()
}}
/>
)}
<div
className={styles.terminal}
ref={xtermRef}
Expand Down
22 changes: 19 additions & 3 deletions site/src/pages/TerminalPage/TerminalPageAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,27 @@ const mapAlertTypeToText: MapAlertTypeToComponent = {
},
}

export default ({ alertType }: { alertType: TerminalPageAlertType }) => {
export default ({
alertType,
onDismiss,
}: {
alertType: TerminalPageAlertType
onDismiss: () => void
}) => {
const severity = mapAlertTypeToText[alertType].severity
return (
<Alert
severity={mapAlertTypeToText[alertType].severity}
sx={{ borderRadius: 0 }}
severity={severity}
sx={{
borderRadius: 0,
borderWidth: 0,
borderBottomWidth: 1,
borderBottomColor: (theme) => theme.palette.divider,
backgroundColor: (theme) => theme.palette.background.paperLight,
borderLeft: (theme) => `3px solid ${theme.palette[severity].light}`,
marginBottom: 1,
}}
onDismiss={onDismiss}
dismissible
actions={[
<Button
Expand Down