Skip to content
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

Limit terminal width to parent container size #77

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
44 changes: 31 additions & 13 deletions src/ImageBuilder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ async function buildImage(repo, ref, term, fitAddon) {

function ImageLogs({ setTerm, setFitAddon, name }) {
const terminalId = `${name}--terminal`;
const observedElementRef = useRef(null);

useEffect(() => {
let observer;
async function setup() {
const { Terminal } = await import("xterm");
const { FitAddon } = await import("xterm-addon-fit");
Expand All @@ -75,12 +78,24 @@ function ImageLogs({ setTerm, setFitAddon, name }) {
setTerm(term);
setFitAddon(fitAddon);
term.write("Logs will appear here when image is being built");

if (observedElementRef.current) {
observer = new ResizeObserver(() => {
console.log("resize");
fitAddon.fit();
});
observer.observe(observedElementRef.current);
}
}
setup();

return () => {
if (observer) observer.disconnect();
};
}, []);

return (
<div className="terminal-container">
<div className="terminal-container" ref={observedElementRef}>
<div id={terminalId}></div>
</div>
);
Expand Down Expand Up @@ -147,21 +162,24 @@ export function ImageBuilder({ name, isActive }) {
// don't generate the hidden input that posts the built image out.
return (
<>
<div className="profile-option-container">
<div className="profile-option-label-container">
<b>Provider</b>
<div className="row mb-4 align-items-center ">
<div className="col-sm-3">
<div className="form-label">Provider</div>
</div>
<div className="profile-option-control-container">GitHub</div>
<div className="col-sm-9">GitHub</div>
</div>

<div
className={`profile-option-container ${repoError ? "has-error" : ""}`}
className={`row mb-4 align-items-center ${repoError ? "has-error" : ""}`}
>
<div className="profile-option-label-container">
<label htmlFor="repo">Repository</label>
<div className="col-sm-12 col-xl-3">
<label htmlFor="repo" className="form-label">
Repository
</label>
</div>
<div className="profile-option-control-container">
<div className="col-sm-12 col-xl-9">
<input
className="form-control"
id="repo"
type="text"
ref={repoFieldRef}
Expand Down Expand Up @@ -212,11 +230,11 @@ export function ImageBuilder({ name, isActive }) {
}
onChange={() => {}} // Hack to prevent a console error, while at the same time allowing for this field to be validatable, ie. not making it read-only
/>
<div className="profile-option-container">
<div className="profile-option-label-container">
<b>Build Logs</b>
<div className="row mb-4 align-items-center">
<div className="col-sm-12 col-xl-3">
<div className="form-label">Build Logs</div>
</div>
<div className="profile-option-control-container">
<div className="col-sm-12 col-xl-9">
<ImageLogs setFitAddon={setFitAddon} setTerm={setTerm} name={name} />
{customImageError && (
<div className="profile-option-control-error">
Expand Down
11 changes: 7 additions & 4 deletions src/components/form/fields.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ function validateField(value, validateConfig, touched) {

function Field({ id, label, hint, children, error }) {
return (
<div className={`profile-option-container ${error ? "has-error" : ""}`}>
<div className="profile-option-label-container">
<label htmlFor={id}>{label}</label>
<div className={`row mb-4 align-items-center ${error ? "has-error" : ""}`}>
<div className="col-sm-12 col-xl-3">
<label className="form-label" htmlFor={id}>
{label}
</label>
</div>
<div className="profile-option-control-container">
<div className="col-sm-12 col-xl-9">
{children}
{error && <div className="profile-option-control-error">{error}</div>}
{hint && <div className="profile-option-control-hint">{hint}</div>}
Expand Down Expand Up @@ -88,6 +90,7 @@ function _TextField(
return (
<Field id={id} label={label} hint={hint} error={touched && error}>
<input
className="form-control"
ref={ref}
type="text"
id={id}
Expand Down
18 changes: 1 addition & 17 deletions src/form.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,6 @@
margin: 0 !important;
}

.profile-option-container {
display: grid;
grid-template-columns: 10rem minmax(0, 1fr);
gap: 1rem;
margin-bottom: 2rem;
width: 100%;
}

.profile-option-label-container {
grid-column-start: 1;
align-self: center;
}

.profile-option-control-container {
grid-column-start: 2;
}

.selected-profile {
background-color: #f8f8f8;
}
Expand All @@ -70,6 +53,7 @@
background-color: black;
padding: 16px;
}

.profile-option-control-container input[type="text"] {
width: 100%;
/* 8px here, even though we only use 4px for .react-select-item-container.
Expand Down
Loading