1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/dashboard/client/components/dock/terminal-window.tsx
Sebastian Malton b1ff34879a cleanup Lens repo with tighter linting
Signed-off-by: Sebastian Malton <smalton@mirantis.com>
2020-07-09 17:00:23 -04:00

50 lines
1.2 KiB
TypeScript

import "./terminal-window.scss";
import React from "react";
import { reaction } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react";
import { cssNames } from "../../utils";
import { DockTabData } from "./dock.store";
import { Terminal } from "./terminal";
import { terminalStore } from "./terminal.store";
import { themeStore } from "../../theme.store";
interface Props {
className?: string;
tab: DockTabData;
}
@observer
export class TerminalWindow extends React.Component<Props> {
public elem: HTMLElement;
public terminal: Terminal;
componentDidMount(): void {
disposeOnUnmount(this, [
reaction(() => this.props.tab.id, tabId => this.activate(tabId), {
fireImmediately: true
})
]);
}
activate(tabId = this.props.tab.id): void {
if (this.terminal) {
this.terminal.detach();
} // detach previous
this.terminal = terminalStore.getTerminal(tabId);
this.terminal.attachTo(this.elem);
}
render(): JSX.Element {
const { className } = this.props;
return (
<div
className={cssNames("TerminalWindow", className, themeStore.activeTheme.type)}
ref={(e): void => {
this.elem = e;
}}
/>
);
}
}