Skip to content

Commit 510cc68

Browse files
committed
feat: update terminal component to allow belowTerminal content
1 parent e565409 commit 510cc68

File tree

2 files changed

+61
-14
lines changed

2 files changed

+61
-14
lines changed

Diff for: plugins/plugin-codeflare/src/controller/terminal.tsx

+42-14
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,21 @@ import ProfileExplorer from "../components/ProfileExplorer"
2626
import SelectedProfileTerminal from "../components/SelectedProfileTerminal"
2727
import Terminal, { Props as BaseProps } from "../components/RestartableTerminal"
2828

29+
import "../../web/scss/components/Allotment/_index.scss"
2930
import "allotment/dist/style.css"
3031

3132
// codeflare -p ${SELECTED_PROFILE}
3233

34+
class AllotmentFillPane extends React.PureComponent<{ minSize?: number }> {
35+
public render() {
36+
return (
37+
<Allotment.Pane className="flex-fill flex-layout flex-align-stretch" minSize={this.props.minSize}>
38+
{this.props.children}
39+
</Allotment.Pane>
40+
)
41+
}
42+
}
43+
3344
/**
3445
* This is a command handler that opens up a plain terminal that shows a login session using the user's $SHELL.
3546
*/
@@ -44,7 +55,11 @@ export async function shell(args: Arguments) {
4455
}
4556

4657
type Props = Pick<BaseProps, "tab" | "repl"> & {
58+
/** Callback when user selects a profile */
4759
onSelectProfile?(profile: string, profiles?: import("madwizard").Profiles.Profile[]): void
60+
61+
/** Content to place below the terminal */
62+
belowTerminal?: React.ReactNode
4863
}
4964

5065
type State = Partial<Pick<BaseProps, "cmdline" | "env">> & {
@@ -59,8 +74,12 @@ type State = Partial<Pick<BaseProps, "cmdline" | "env">> & {
5974
}
6075

6176
export class TaskTerminal extends React.PureComponent<Props, State> {
62-
/** Allotment initial split sizes */
63-
private readonly sizes = [40, 60]
77+
/** Allotment initial split ... allotments */
78+
private readonly splits = {
79+
horizontal: [35, 65],
80+
vertical1: [100], // no `this.props.belowTerminal`
81+
vertical2: [50, 50], // yes
82+
}
6483

6584
private readonly tasks = [{ label: "Run a Job", argv: ["codeflare", "-p", "${SELECTED_PROFILE}"] }]
6685

@@ -122,23 +141,32 @@ export class TaskTerminal extends React.PureComponent<Props, State> {
122141
}
123142

124143
return (
125-
<Allotment defaultSizes={this.sizes} snap>
126-
<Allotment.Pane className="flex-fill flex-layout flex-align-stretch" minSize={400}>
144+
<Allotment defaultSizes={this.splits.horizontal} snap>
145+
<AllotmentFillPane minSize={400}>
127146
<ProfileExplorer onSelectProfile={this.onSelectProfile} onSelectGuidebook={this.onSelectGuidebook} />
128-
</Allotment.Pane>
129-
<Allotment.Pane className="flex-fill flex-layout flex-align-stretch">
147+
</AllotmentFillPane>
148+
<AllotmentFillPane>
130149
{!this.state.selectedProfile ? (
131150
<Loading />
132151
) : (
133-
<SelectedProfileTerminal
134-
key={this.state.cmdline + "-" + this.state.selectedProfile}
135-
cmdline={this.state.cmdline}
136-
env={this.state.env}
137-
{...this.props}
138-
selectedProfile={this.state.selectedProfile}
139-
/>
152+
<Allotment
153+
vertical
154+
defaultSizes={!this.props.belowTerminal ? this.splits.vertical1 : this.splits.vertical2}
155+
snap
156+
>
157+
<AllotmentFillPane>
158+
<SelectedProfileTerminal
159+
key={this.state.cmdline + "-" + this.state.selectedProfile}
160+
cmdline={this.state.cmdline}
161+
env={this.state.env}
162+
{...this.props}
163+
selectedProfile={this.state.selectedProfile}
164+
/>
165+
</AllotmentFillPane>
166+
{this.props.belowTerminal && <AllotmentFillPane>{this.props.belowTerminal}</AllotmentFillPane>}
167+
</Allotment>
140168
)}
141-
</Allotment.Pane>
169+
</AllotmentFillPane>
142170
</Allotment>
143171
)
144172
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright 2022 The Kubernetes Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
.split-view-view {
18+
display: flex;
19+
}

0 commit comments

Comments
 (0)