fix(tmux): collapse installer banner by default
This commit is contained in:
parent
51aac9b7a1
commit
80221884ed
2 changed files with 383 additions and 284 deletions
|
|
@ -12,6 +12,8 @@ import {
|
|||
|
||||
import { useTmuxInstallerBanner } from '../hooks/useTmuxInstallerBanner';
|
||||
|
||||
const SUMMARY_TITLE = 'tmux is not installed';
|
||||
|
||||
const SourceLink = ({
|
||||
label,
|
||||
url,
|
||||
|
|
@ -35,8 +37,10 @@ const SourceLink = ({
|
|||
export function TmuxInstallerBannerView(): React.JSX.Element | null {
|
||||
const { viewModel, install, cancel, submitInput, refresh, toggleDetails, openExternal } =
|
||||
useTmuxInstallerBanner();
|
||||
const [expanded, setExpanded] = React.useState(false);
|
||||
const [inputValue, setInputValue] = React.useState('');
|
||||
const [manualHintsExpanded, setManualHintsExpanded] = React.useState(false);
|
||||
const previousPhaseRef = React.useRef(viewModel.phase);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!viewModel.acceptsInput) {
|
||||
|
|
@ -50,6 +54,21 @@ export function TmuxInstallerBannerView(): React.JSX.Element | null {
|
|||
}
|
||||
}, [viewModel.manualHintsCollapsible]);
|
||||
|
||||
React.useEffect(() => {
|
||||
const previousPhase = previousPhaseRef.current;
|
||||
const becameActive =
|
||||
previousPhase === 'idle' &&
|
||||
viewModel.phase !== 'idle' &&
|
||||
viewModel.phase !== 'completed' &&
|
||||
viewModel.phase !== 'cancelled';
|
||||
|
||||
if (becameActive) {
|
||||
setExpanded(true);
|
||||
}
|
||||
|
||||
previousPhaseRef.current = viewModel.phase;
|
||||
}, [viewModel.phase]);
|
||||
|
||||
if (!viewModel.visible) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -66,297 +85,320 @@ export function TmuxInstallerBannerView(): React.JSX.Element | null {
|
|||
borderColor: 'rgba(245, 158, 11, 0.2)',
|
||||
}}
|
||||
>
|
||||
<div className="space-y-3">
|
||||
<div className="min-w-0 max-w-4xl">
|
||||
<div className="flex items-start gap-2 text-base font-semibold leading-6">
|
||||
<span className="pt-0.5">
|
||||
{viewModel.error ? (
|
||||
<AlertTriangle className="size-4 text-red-300" />
|
||||
) : (
|
||||
<Wrench className="size-4 text-amber-300" />
|
||||
)}
|
||||
</span>
|
||||
<span>{viewModel.title}</span>
|
||||
</div>
|
||||
<p
|
||||
className="mt-2 text-[15px] leading-7"
|
||||
style={{ color: 'var(--color-text-secondary)' }}
|
||||
>
|
||||
{viewModel.body}
|
||||
</p>
|
||||
{viewModel.benefitsBody && (
|
||||
<div
|
||||
className="mt-3 max-w-4xl rounded-md border px-3 py-2 text-[13px] leading-6"
|
||||
style={{
|
||||
borderColor: 'rgba(245, 158, 11, 0.18)',
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.03)',
|
||||
color: 'var(--color-text-secondary)',
|
||||
}}
|
||||
>
|
||||
{viewModel.benefitsBody}
|
||||
</div>
|
||||
)}
|
||||
{(viewModel.platformLabel ||
|
||||
viewModel.locationLabel ||
|
||||
viewModel.runtimeReadyLabel ||
|
||||
viewModel.versionLabel ||
|
||||
viewModel.phase !== 'idle') && (
|
||||
<div className="mt-3 flex flex-wrap items-center gap-2 text-[11px]">
|
||||
{viewModel.platformLabel && (
|
||||
<span
|
||||
className="rounded-full px-2 py-1"
|
||||
style={{
|
||||
color: 'var(--color-text-muted)',
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.04)',
|
||||
}}
|
||||
>
|
||||
Detected OS: {viewModel.platformLabel}
|
||||
</span>
|
||||
)}
|
||||
{viewModel.locationLabel && (
|
||||
<span
|
||||
className="rounded-full px-2 py-1"
|
||||
style={{
|
||||
color: 'var(--color-text-muted)',
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.04)',
|
||||
}}
|
||||
>
|
||||
Runtime path: {viewModel.locationLabel}
|
||||
</span>
|
||||
)}
|
||||
{viewModel.runtimeReadyLabel && (
|
||||
<span
|
||||
className="rounded-full px-2 py-1"
|
||||
style={{
|
||||
color: 'var(--color-text-muted)',
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.04)',
|
||||
}}
|
||||
>
|
||||
{viewModel.runtimeReadyLabel}
|
||||
</span>
|
||||
)}
|
||||
{viewModel.versionLabel && (
|
||||
<span
|
||||
className="rounded-full px-2 py-1"
|
||||
style={{
|
||||
color: 'var(--color-text-muted)',
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.04)',
|
||||
}}
|
||||
>
|
||||
{viewModel.versionLabel}
|
||||
</span>
|
||||
)}
|
||||
{viewModel.phase !== 'idle' && (
|
||||
<span
|
||||
className="rounded-full px-2 py-1"
|
||||
style={{
|
||||
color: 'var(--color-text-muted)',
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.04)',
|
||||
}}
|
||||
>
|
||||
Phase: {viewModel.phase}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
aria-expanded={expanded}
|
||||
onClick={() => setExpanded((current) => !current)}
|
||||
className="flex w-full items-center justify-between gap-3 text-left"
|
||||
>
|
||||
<span className="flex min-w-0 items-start gap-2 text-base font-semibold leading-6">
|
||||
<span className="pt-0.5">
|
||||
{viewModel.error ? (
|
||||
<AlertTriangle className="size-4 text-red-300" />
|
||||
) : (
|
||||
<Wrench className="size-4 text-amber-300" />
|
||||
)}
|
||||
</span>
|
||||
<span className="truncate">{SUMMARY_TITLE}</span>
|
||||
</span>
|
||||
{expanded ? (
|
||||
<ChevronUp className="size-4 shrink-0" />
|
||||
) : (
|
||||
<ChevronDown className="size-4 shrink-0" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2 pt-1">
|
||||
{viewModel.installSupported && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void install()}
|
||||
disabled={viewModel.installDisabled}
|
||||
className={`inline-flex items-center gap-2 rounded-md border px-3 py-2 text-sm transition-colors disabled:cursor-not-allowed disabled:opacity-60 ${
|
||||
viewModel.installButtonPrimary ? 'hover:bg-emerald-500/20' : 'hover:bg-white/5'
|
||||
}`}
|
||||
style={
|
||||
viewModel.installButtonPrimary
|
||||
? {
|
||||
borderColor: 'rgba(34, 197, 94, 0.75)',
|
||||
backgroundColor: 'rgba(34, 197, 94, 0.16)',
|
||||
color: '#dcfce7',
|
||||
}
|
||||
: { borderColor: 'var(--color-border)' }
|
||||
}
|
||||
{expanded && (
|
||||
<div className="mt-4 space-y-3">
|
||||
<div className="min-w-0 max-w-4xl">
|
||||
{viewModel.title !== SUMMARY_TITLE && (
|
||||
<div
|
||||
className="text-sm font-medium leading-6"
|
||||
style={{ color: 'var(--color-text-secondary)' }}
|
||||
>
|
||||
{viewModel.title}
|
||||
</div>
|
||||
)}
|
||||
<p
|
||||
className="mt-2 text-[15px] leading-7"
|
||||
style={{ color: 'var(--color-text-secondary)' }}
|
||||
>
|
||||
<Wrench className="size-4" />
|
||||
{viewModel.installLabel}
|
||||
</button>
|
||||
)}
|
||||
{viewModel.canCancel && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void cancel()}
|
||||
className="inline-flex items-center gap-2 rounded-md border px-3 py-2 text-sm transition-colors hover:bg-white/5"
|
||||
style={{ borderColor: 'var(--color-border)' }}
|
||||
>
|
||||
<XCircle className="size-4" />
|
||||
Cancel
|
||||
</button>
|
||||
)}
|
||||
{viewModel.primaryGuideUrl && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void openExternal(viewModel.primaryGuideUrl)}
|
||||
className="inline-flex items-center gap-2 rounded-md border px-3 py-2 text-sm transition-colors hover:bg-white/5"
|
||||
style={{ borderColor: 'var(--color-border)' }}
|
||||
>
|
||||
<ExternalLink className="size-4" />
|
||||
Manual guide
|
||||
</button>
|
||||
)}
|
||||
{viewModel.manualHintsCollapsible && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setManualHintsExpanded((current) => !current)}
|
||||
className="inline-flex items-center gap-2 rounded-md border px-3 py-2 text-sm transition-colors hover:bg-white/5"
|
||||
style={{ borderColor: 'var(--color-border)' }}
|
||||
>
|
||||
{manualHintsExpanded ? (
|
||||
<ChevronUp className="size-4" />
|
||||
) : (
|
||||
<ChevronDown className="size-4" />
|
||||
)}
|
||||
{manualHintsExpanded
|
||||
? 'Hide setup steps'
|
||||
: `Show setup steps (${viewModel.manualHints.length})`}
|
||||
</button>
|
||||
)}
|
||||
{viewModel.showRefreshButton && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void refresh()}
|
||||
className="inline-flex items-center gap-2 rounded-md border px-3 py-2 text-sm transition-colors hover:bg-white/5"
|
||||
style={{ borderColor: 'var(--color-border)' }}
|
||||
>
|
||||
<RefreshCw className="size-4" />
|
||||
Re-check
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{viewModel.progressPercent !== null && (
|
||||
<div className="mt-3">
|
||||
<div className="mb-1 flex items-center justify-between text-[11px]">
|
||||
<span style={{ color: 'var(--color-text-muted)' }}>Installer progress</span>
|
||||
<span style={{ color: 'var(--color-text-secondary)' }}>
|
||||
{viewModel.progressPercent}%
|
||||
</span>
|
||||
{viewModel.body}
|
||||
</p>
|
||||
{viewModel.benefitsBody && (
|
||||
<div
|
||||
className="mt-3 max-w-4xl rounded-md border px-3 py-2 text-[13px] leading-6"
|
||||
style={{
|
||||
borderColor: 'rgba(245, 158, 11, 0.18)',
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.03)',
|
||||
color: 'var(--color-text-secondary)',
|
||||
}}
|
||||
>
|
||||
{viewModel.benefitsBody}
|
||||
</div>
|
||||
)}
|
||||
{(viewModel.platformLabel ||
|
||||
viewModel.locationLabel ||
|
||||
viewModel.runtimeReadyLabel ||
|
||||
viewModel.versionLabel ||
|
||||
viewModel.phase !== 'idle') && (
|
||||
<div className="mt-3 flex flex-wrap items-center gap-2 text-[11px]">
|
||||
{viewModel.platformLabel && (
|
||||
<span
|
||||
className="rounded-full px-2 py-1"
|
||||
style={{
|
||||
color: 'var(--color-text-muted)',
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.04)',
|
||||
}}
|
||||
>
|
||||
Detected OS: {viewModel.platformLabel}
|
||||
</span>
|
||||
)}
|
||||
{viewModel.locationLabel && (
|
||||
<span
|
||||
className="rounded-full px-2 py-1"
|
||||
style={{
|
||||
color: 'var(--color-text-muted)',
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.04)',
|
||||
}}
|
||||
>
|
||||
Runtime path: {viewModel.locationLabel}
|
||||
</span>
|
||||
)}
|
||||
{viewModel.runtimeReadyLabel && (
|
||||
<span
|
||||
className="rounded-full px-2 py-1"
|
||||
style={{
|
||||
color: 'var(--color-text-muted)',
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.04)',
|
||||
}}
|
||||
>
|
||||
{viewModel.runtimeReadyLabel}
|
||||
</span>
|
||||
)}
|
||||
{viewModel.versionLabel && (
|
||||
<span
|
||||
className="rounded-full px-2 py-1"
|
||||
style={{
|
||||
color: 'var(--color-text-muted)',
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.04)',
|
||||
}}
|
||||
>
|
||||
{viewModel.versionLabel}
|
||||
</span>
|
||||
)}
|
||||
{viewModel.phase !== 'idle' && (
|
||||
<span
|
||||
className="rounded-full px-2 py-1"
|
||||
style={{
|
||||
color: 'var(--color-text-muted)',
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.04)',
|
||||
}}
|
||||
>
|
||||
Phase: {viewModel.phase}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div
|
||||
className="h-2 overflow-hidden rounded-full"
|
||||
style={{ backgroundColor: 'rgba(255, 255, 255, 0.08)' }}
|
||||
>
|
||||
<div
|
||||
className="h-full rounded-full transition-all duration-300"
|
||||
style={{
|
||||
width: `${viewModel.progressPercent}%`,
|
||||
backgroundColor: viewModel.error ? '#ef4444' : '#f59e0b',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{viewModel.acceptsInput && (
|
||||
<div className="mt-3 space-y-2">
|
||||
<form
|
||||
className="flex flex-col gap-2 sm:flex-row sm:items-center"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
void (async () => {
|
||||
const submitted = await submitInput(inputValue);
|
||||
if (submitted) {
|
||||
setInputValue('');
|
||||
<div className="flex flex-wrap items-center gap-2 pt-1">
|
||||
{viewModel.installSupported && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void install()}
|
||||
disabled={viewModel.installDisabled}
|
||||
className={`inline-flex items-center gap-2 rounded-md border px-3 py-2 text-sm transition-colors disabled:cursor-not-allowed disabled:opacity-60 ${
|
||||
viewModel.installButtonPrimary ? 'hover:bg-emerald-500/20' : 'hover:bg-white/5'
|
||||
}`}
|
||||
style={
|
||||
viewModel.installButtonPrimary
|
||||
? {
|
||||
borderColor: 'rgba(34, 197, 94, 0.75)',
|
||||
backgroundColor: 'rgba(34, 197, 94, 0.16)',
|
||||
color: '#dcfce7',
|
||||
}
|
||||
: { borderColor: 'var(--color-border)' }
|
||||
}
|
||||
})();
|
||||
}}
|
||||
>
|
||||
<input
|
||||
type={viewModel.inputSecret ? 'password' : 'text'}
|
||||
value={inputValue}
|
||||
onChange={(event) => setInputValue(event.target.value)}
|
||||
placeholder={viewModel.inputPrompt ?? 'Send input to the installer'}
|
||||
className="min-w-0 flex-1 rounded-md border px-3 py-2 text-sm"
|
||||
style={{
|
||||
borderColor: 'var(--color-border)',
|
||||
backgroundColor: 'rgba(0, 0, 0, 0.12)',
|
||||
color: 'var(--color-text)',
|
||||
}}
|
||||
autoComplete="current-password"
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
className="inline-flex items-center justify-center rounded-md border px-3 py-2 text-sm transition-colors hover:bg-white/5 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
style={{ borderColor: 'var(--color-border)' }}
|
||||
>
|
||||
Send input
|
||||
</button>
|
||||
</form>
|
||||
{viewModel.inputSecret && (
|
||||
<div className="text-[11px]" style={{ color: 'var(--color-text-muted)' }}>
|
||||
Password input is sent directly to the installer terminal and is not added to the log
|
||||
output.
|
||||
>
|
||||
<Wrench className="size-4" />
|
||||
{viewModel.installLabel}
|
||||
</button>
|
||||
)}
|
||||
{viewModel.canCancel && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void cancel()}
|
||||
className="inline-flex items-center gap-2 rounded-md border px-3 py-2 text-sm transition-colors hover:bg-white/5"
|
||||
style={{ borderColor: 'var(--color-border)' }}
|
||||
>
|
||||
<XCircle className="size-4" />
|
||||
Cancel
|
||||
</button>
|
||||
)}
|
||||
{viewModel.primaryGuideUrl && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void openExternal(viewModel.primaryGuideUrl)}
|
||||
className="inline-flex items-center gap-2 rounded-md border px-3 py-2 text-sm transition-colors hover:bg-white/5"
|
||||
style={{ borderColor: 'var(--color-border)' }}
|
||||
>
|
||||
<ExternalLink className="size-4" />
|
||||
Manual guide
|
||||
</button>
|
||||
)}
|
||||
{viewModel.manualHintsCollapsible && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setManualHintsExpanded((current) => !current)}
|
||||
className="inline-flex items-center gap-2 rounded-md border px-3 py-2 text-sm transition-colors hover:bg-white/5"
|
||||
style={{ borderColor: 'var(--color-border)' }}
|
||||
>
|
||||
{manualHintsExpanded ? (
|
||||
<ChevronUp className="size-4" />
|
||||
) : (
|
||||
<ChevronDown className="size-4" />
|
||||
)}
|
||||
{manualHintsExpanded
|
||||
? 'Hide setup steps'
|
||||
: `Show setup steps (${viewModel.manualHints.length})`}
|
||||
</button>
|
||||
)}
|
||||
{viewModel.showRefreshButton && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void refresh()}
|
||||
className="inline-flex items-center gap-2 rounded-md border px-3 py-2 text-sm transition-colors hover:bg-white/5"
|
||||
style={{ borderColor: 'var(--color-border)' }}
|
||||
>
|
||||
<RefreshCw className="size-4" />
|
||||
Re-check
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{viewModel.progressPercent !== null && (
|
||||
<div>
|
||||
<div className="mb-1 flex items-center justify-between text-[11px]">
|
||||
<span style={{ color: 'var(--color-text-muted)' }}>Installer progress</span>
|
||||
<span style={{ color: 'var(--color-text-secondary)' }}>
|
||||
{viewModel.progressPercent}%
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
className="h-2 overflow-hidden rounded-full"
|
||||
style={{ backgroundColor: 'rgba(255, 255, 255, 0.08)' }}
|
||||
>
|
||||
<div
|
||||
className="h-full rounded-full transition-all duration-300"
|
||||
style={{
|
||||
width: `${viewModel.progressPercent}%`,
|
||||
backgroundColor: viewModel.error ? '#ef4444' : '#f59e0b',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{manualHintsVisible && (
|
||||
<div className="mt-3 grid gap-2 lg:grid-cols-2">
|
||||
{viewModel.manualHints.map((hint) => (
|
||||
<div
|
||||
key={`${hint.title}-${hint.command ?? hint.url ?? hint.description}`}
|
||||
className="rounded-md border px-3 py-2"
|
||||
style={{
|
||||
borderColor: 'rgba(245, 158, 11, 0.18)',
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.02)',
|
||||
}}
|
||||
>
|
||||
<div className="text-xs font-semibold" style={{ color: 'var(--color-text)' }}>
|
||||
{hint.title}
|
||||
</div>
|
||||
<div className="mt-1 text-[11px]" style={{ color: 'var(--color-text-muted)' }}>
|
||||
{hint.description}
|
||||
</div>
|
||||
{hint.command && (
|
||||
<code className="mt-2 block rounded bg-black/20 px-2 py-1 font-mono text-[11px]">
|
||||
{hint.command}
|
||||
</code>
|
||||
)}
|
||||
{hint.url && (
|
||||
<div className="mt-2">
|
||||
<SourceLink label={hint.title} url={hint.url} onOpen={openExternal} />
|
||||
{viewModel.acceptsInput && (
|
||||
<div className="space-y-2">
|
||||
<form
|
||||
className="flex flex-col gap-2 sm:flex-row sm:items-center"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
void (async () => {
|
||||
const submitted = await submitInput(inputValue);
|
||||
if (submitted) {
|
||||
setInputValue('');
|
||||
}
|
||||
})();
|
||||
}}
|
||||
>
|
||||
<input
|
||||
type={viewModel.inputSecret ? 'password' : 'text'}
|
||||
value={inputValue}
|
||||
onChange={(event) => setInputValue(event.target.value)}
|
||||
placeholder={viewModel.inputPrompt ?? 'Send input to the installer'}
|
||||
className="min-w-0 flex-1 rounded-md border px-3 py-2 text-sm"
|
||||
style={{
|
||||
borderColor: 'var(--color-border)',
|
||||
backgroundColor: 'rgba(0, 0, 0, 0.12)',
|
||||
color: 'var(--color-text)',
|
||||
}}
|
||||
autoComplete="current-password"
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
className="inline-flex items-center justify-center rounded-md border px-3 py-2 text-sm transition-colors hover:bg-white/5 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
style={{ borderColor: 'var(--color-border)' }}
|
||||
>
|
||||
Send input
|
||||
</button>
|
||||
</form>
|
||||
{viewModel.inputSecret && (
|
||||
<div className="text-[11px]" style={{ color: 'var(--color-text-muted)' }}>
|
||||
Password input is sent directly to the installer terminal and is not added to
|
||||
the log output.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
)}
|
||||
|
||||
{(viewModel.logs.length > 0 || viewModel.error) && (
|
||||
<div className="mt-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={toggleDetails}
|
||||
className="text-xs underline-offset-4 hover:underline"
|
||||
style={{ color: 'var(--color-text-secondary)' }}
|
||||
>
|
||||
{viewModel.detailsOpen ? 'Hide details' : 'Show details'}
|
||||
</button>
|
||||
{viewModel.detailsOpen && (
|
||||
<pre
|
||||
className="mt-2 max-h-64 overflow-auto rounded-md border p-3 text-xs"
|
||||
style={{
|
||||
borderColor: 'var(--color-border)',
|
||||
backgroundColor: 'rgba(0, 0, 0, 0.18)',
|
||||
color: 'var(--color-text-secondary)',
|
||||
}}
|
||||
>
|
||||
{[viewModel.error, ...viewModel.logs].filter(Boolean).join('\n')}
|
||||
</pre>
|
||||
{manualHintsVisible && (
|
||||
<div className="grid gap-2 lg:grid-cols-2">
|
||||
{viewModel.manualHints.map((hint) => (
|
||||
<div
|
||||
key={`${hint.title}-${hint.command ?? hint.url ?? hint.description}`}
|
||||
className="rounded-md border px-3 py-2"
|
||||
style={{
|
||||
borderColor: 'rgba(245, 158, 11, 0.18)',
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.02)',
|
||||
}}
|
||||
>
|
||||
<div className="text-xs font-semibold" style={{ color: 'var(--color-text)' }}>
|
||||
{hint.title}
|
||||
</div>
|
||||
<div className="mt-1 text-[11px]" style={{ color: 'var(--color-text-muted)' }}>
|
||||
{hint.description}
|
||||
</div>
|
||||
{hint.command && (
|
||||
<code className="mt-2 block rounded bg-black/20 px-2 py-1 font-mono text-[11px]">
|
||||
{hint.command}
|
||||
</code>
|
||||
)}
|
||||
{hint.url && (
|
||||
<div className="mt-2">
|
||||
<SourceLink label={hint.title} url={hint.url} onOpen={openExternal} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{(viewModel.logs.length > 0 || viewModel.error) && (
|
||||
<div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={toggleDetails}
|
||||
className="text-xs underline-offset-4 hover:underline"
|
||||
style={{ color: 'var(--color-text-secondary)' }}
|
||||
>
|
||||
{viewModel.detailsOpen ? 'Hide details' : 'Show details'}
|
||||
</button>
|
||||
{viewModel.detailsOpen && (
|
||||
<pre
|
||||
className="mt-2 max-h-64 overflow-auto rounded-md border p-3 text-xs"
|
||||
style={{
|
||||
borderColor: 'var(--color-border)',
|
||||
backgroundColor: 'rgba(0, 0, 0, 0.18)',
|
||||
color: 'var(--color-text-secondary)',
|
||||
}}
|
||||
>
|
||||
{[viewModel.error, ...viewModel.logs].filter(Boolean).join('\n')}
|
||||
</pre>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -93,16 +93,32 @@ describe('TmuxInstallerBannerView', () => {
|
|||
it('keeps Windows setup steps collapsed by default and expands them on demand', async () => {
|
||||
const { host, root } = renderBanner(baseViewModel);
|
||||
|
||||
expect(host.textContent).toContain('Show setup steps (2)');
|
||||
expect(host.textContent).toContain('tmux is not installed');
|
||||
expect(host.textContent).not.toContain('WSL is available, but no Linux distribution is installed yet.');
|
||||
expect(host.textContent).not.toContain('Show setup steps (2)');
|
||||
expect(host.textContent).not.toContain('wsl --install --no-distribution');
|
||||
|
||||
const toggleButton = [...host.querySelectorAll('button')].find((button) =>
|
||||
button.textContent?.includes('Show setup steps')
|
||||
const summaryButton = [...host.querySelectorAll('button')].find((button) =>
|
||||
button.textContent?.includes('tmux is not installed')
|
||||
);
|
||||
expect(toggleButton).toBeDefined();
|
||||
expect(summaryButton).toBeDefined();
|
||||
|
||||
await act(async () => {
|
||||
toggleButton?.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
||||
summaryButton?.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
||||
await Promise.resolve();
|
||||
});
|
||||
|
||||
expect(host.textContent).toContain('WSL is available, but no Linux distribution is installed yet.');
|
||||
expect(host.textContent).toContain('Show setup steps (2)');
|
||||
expect(host.textContent).not.toContain('Hide setup steps');
|
||||
|
||||
const setupToggle = [...host.querySelectorAll('button')].find((button) =>
|
||||
button.textContent?.includes('Show setup steps')
|
||||
);
|
||||
expect(setupToggle).toBeDefined();
|
||||
|
||||
await act(async () => {
|
||||
setupToggle?.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
||||
await Promise.resolve();
|
||||
});
|
||||
|
||||
|
|
@ -125,6 +141,15 @@ describe('TmuxInstallerBannerView', () => {
|
|||
],
|
||||
});
|
||||
|
||||
const summaryButton = [...host.querySelectorAll('button')].find((button) =>
|
||||
button.textContent?.includes('tmux is not installed')
|
||||
);
|
||||
expect(summaryButton).toBeDefined();
|
||||
|
||||
act(() => {
|
||||
summaryButton?.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
||||
});
|
||||
|
||||
expect(host.textContent).toContain('brew install tmux');
|
||||
expect(host.textContent).not.toContain('Show setup steps');
|
||||
|
||||
|
|
@ -132,4 +157,36 @@ describe('TmuxInstallerBannerView', () => {
|
|||
root.unmount();
|
||||
});
|
||||
});
|
||||
|
||||
it('auto-expands when installer flow becomes active', async () => {
|
||||
const { host, root } = renderBanner(baseViewModel);
|
||||
|
||||
mockUseTmuxInstallerBanner.mockReturnValue({
|
||||
viewModel: {
|
||||
...baseViewModel,
|
||||
title: 'tmux needs a restart',
|
||||
body: 'Restart Windows before continuing.',
|
||||
phase: 'needs_restart',
|
||||
progressPercent: 96,
|
||||
},
|
||||
install: vi.fn(),
|
||||
cancel: vi.fn(),
|
||||
submitInput: vi.fn(),
|
||||
refresh: vi.fn(),
|
||||
toggleDetails: vi.fn(),
|
||||
openExternal: vi.fn(),
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
root.render(React.createElement(TmuxInstallerBannerView));
|
||||
await Promise.resolve();
|
||||
});
|
||||
|
||||
expect(host.textContent).toContain('Restart Windows before continuing.');
|
||||
expect(host.textContent).toContain('96%');
|
||||
|
||||
act(() => {
|
||||
root.unmount();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue