@fish-under-sea/dsh-ssh-fish 0.0.0-stage → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.i18n.yaml +6 -0
- package/README.md +98 -2
- package/README.zh.md +99 -0
- package/cordis.patch.yml +12 -0
- package/icon.svg +3 -0
- package/lib/client.js +16487 -0
- package/lib/client.js.map +1 -0
- package/lib/index.js +3511 -0
- package/lib/types/client/api.d.ts +141 -0
- package/lib/types/client/index.d.ts +37 -0
- package/lib/types/client/locales.d.ts +164 -0
- package/lib/types/client/native-panel.d.ts +70 -0
- package/lib/types/client/panel/ClusterTab.d.ts +7 -0
- package/lib/types/client/panel/HostFormDialog.d.ts +12 -0
- package/lib/types/client/panel/HostsTab.d.ts +25 -0
- package/lib/types/client/panel/SshPanel.d.ts +14 -0
- package/lib/types/client/panel/TerminalTab.d.ts +22 -0
- package/lib/types/client/panel/TransferTab.d.ts +7 -0
- package/lib/types/client/panel/TunnelsTab.d.ts +19 -0
- package/lib/types/client/panel/controller.d.ts +89 -0
- package/lib/types/client/panel/helpers.d.ts +45 -0
- package/lib/types/client/panel/xterm.css.d.ts +2 -0
- package/lib/types/client/settings-binding.d.ts +61 -0
- package/lib/types/dsh-home.d.ts +16 -0
- package/lib/types/engine/cluster.d.ts +19 -0
- package/lib/types/engine/connection-pool.d.ts +112 -0
- package/lib/types/engine/proxy-command.d.ts +36 -0
- package/lib/types/engine/pty.d.ts +32 -0
- package/lib/types/engine/sftp.d.ts +20 -0
- package/lib/types/engine/terminal-sessions.d.ts +67 -0
- package/lib/types/engine/tunnel.d.ts +36 -0
- package/lib/types/engine.d.ts +89 -0
- package/lib/types/http.d.ts +59 -0
- package/lib/types/index.d.ts +83 -0
- package/lib/types/loopback.d.ts +24 -0
- package/lib/types/mount-once.d.ts +55 -0
- package/lib/types/protocol.d.ts +239 -0
- package/lib/types/routes.d.ts +33 -0
- package/lib/types/ssh-config.d.ts +34 -0
- package/lib/types/store.d.ts +71 -0
- package/lib/types/tool-surface.d.ts +71 -0
- package/lib/types/tools.d.ts +42 -0
- package/package.json +106 -4
- package/src/client/api.ts +562 -0
- package/src/client/css-modules.d.ts +5 -0
- package/src/client/index.ts +137 -0
- package/src/client/locales.ts +338 -0
- package/src/client/native-panel.tsx +141 -0
- package/src/client/panel/ClusterTab.tsx +123 -0
- package/src/client/panel/HostFormDialog.tsx +258 -0
- package/src/client/panel/HostsTab.tsx +325 -0
- package/src/client/panel/SshPanel.tsx +90 -0
- package/src/client/panel/TerminalTab.tsx +330 -0
- package/src/client/panel/TransferTab.tsx +232 -0
- package/src/client/panel/TunnelsTab.tsx +244 -0
- package/src/client/panel/controller.ts +167 -0
- package/src/client/panel/helpers.ts +84 -0
- package/src/client/panel/panel.module.css +876 -0
- package/src/client/panel/xterm.css.ts +2 -0
- package/src/client/settings-binding.ts +165 -0
- package/src/dsh-home.ts +42 -0
- package/src/engine/cluster.ts +60 -0
- package/src/engine/connection-pool.ts +543 -0
- package/src/engine/proxy-command.ts +248 -0
- package/src/engine/pty.ts +78 -0
- package/src/engine/sftp.ts +226 -0
- package/src/engine/terminal-sessions.ts +280 -0
- package/src/engine/tunnel.ts +194 -0
- package/src/engine.ts +176 -0
- package/src/http.ts +127 -0
- package/src/index.ts +234 -0
- package/src/loopback.ts +63 -0
- package/src/mount-once.ts +142 -0
- package/src/protocol.ts +230 -0
- package/src/routes.ts +494 -0
- package/src/ssh-config.ts +153 -0
- package/src/store.ts +419 -0
- package/src/tool-surface.ts +95 -0
- package/src/tools.ts +404 -0
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hosts tab: the host table with search (debounced through listHosts),
|
|
3
|
+
* add/edit/delete/test actions, ~/.ssh/config import, and a connect action
|
|
4
|
+
* that hands the alias to the terminal tab via onConnect.
|
|
5
|
+
*/
|
|
6
|
+
import { useCallback, useEffect, useRef, useState, type ReactNode } from 'react'
|
|
7
|
+
import type { SshApi } from '../api.ts'
|
|
8
|
+
import type { ImportSkipBlock, ImportSkipReason, SshHostSummary, TestResult } from '../../protocol.ts'
|
|
9
|
+
import type { SshKey } from '../locales.ts'
|
|
10
|
+
import { errorMessage, tt } from './helpers.ts'
|
|
11
|
+
import { HostFormDialog } from './HostFormDialog.tsx'
|
|
12
|
+
import css from './panel.module.css'
|
|
13
|
+
|
|
14
|
+
/** Hosts tab props. */
|
|
15
|
+
export interface HostsTabProps {
|
|
16
|
+
api: SshApi
|
|
17
|
+
/** Connect the given alias in the terminal tab. */
|
|
18
|
+
onConnect: (alias: string) => void
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The host-form dialog invocation. */
|
|
22
|
+
type DialogState = { mode: 'create' } | { mode: 'edit'; host: SshHostSummary }
|
|
23
|
+
|
|
24
|
+
/** Skipped-block rows rendered before the "and N more" summary. */
|
|
25
|
+
const IMPORT_SKIP_LIMIT = 8
|
|
26
|
+
|
|
27
|
+
/** Locale key per import skip reason (no dynamic key concatenation). */
|
|
28
|
+
const IMPORT_REASON_KEY: Record<ImportSkipReason, SshKey> = {
|
|
29
|
+
wildcard: 'import.reason.wildcard',
|
|
30
|
+
existing: 'import.reason.existing',
|
|
31
|
+
match: 'import.reason.match',
|
|
32
|
+
invalid: 'import.reason.invalid',
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Host list grouping modes (#379). */
|
|
36
|
+
export type HostGroupBy = 'none' | 'environment' | 'tags'
|
|
37
|
+
|
|
38
|
+
/** One collapsible group section of the grouped host list. */
|
|
39
|
+
export interface HostGroup {
|
|
40
|
+
/** Group key: the environment name, one tag, or '' for the ungrouped bucket. */
|
|
41
|
+
key: string
|
|
42
|
+
hosts: SshHostSummary[]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Bucket hosts into collapsible groups (#379). Grouping by tags places a
|
|
47
|
+
* multi-tag host in every one of its tag groups (folder view); hosts without
|
|
48
|
+
* the grouping key land in the '' bucket, which always sorts last. Groups
|
|
49
|
+
* sort alphabetically; host order inside a group follows the API listing.
|
|
50
|
+
*/
|
|
51
|
+
export function groupHosts(hosts: SshHostSummary[], groupBy: HostGroupBy): HostGroup[] {
|
|
52
|
+
if (groupBy === 'none') return [{ key: '', hosts }]
|
|
53
|
+
const buckets = new Map<string, SshHostSummary[]>()
|
|
54
|
+
const push = (key: string, host: SshHostSummary): void => {
|
|
55
|
+
const bucket = buckets.get(key)
|
|
56
|
+
if (bucket === undefined) buckets.set(key, [host])
|
|
57
|
+
else bucket.push(host)
|
|
58
|
+
}
|
|
59
|
+
for (const host of hosts) {
|
|
60
|
+
if (groupBy === 'environment') {
|
|
61
|
+
push(host.environment ?? '', host)
|
|
62
|
+
} else if (host.tags.length === 0) {
|
|
63
|
+
push('', host)
|
|
64
|
+
} else {
|
|
65
|
+
for (const tag of host.tags) push(tag, host)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return [...buckets.entries()]
|
|
69
|
+
.sort(([a], [b]) => (a === '' ? 1 : b === '' ? -1 : a.localeCompare(b)))
|
|
70
|
+
.map(([key, group]) => ({ key, hosts: group }))
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The hosts table plus its toolbar and dialogs. */
|
|
74
|
+
export function HostsTab({ api, onConnect }: HostsTabProps) {
|
|
75
|
+
const [hosts, setHosts] = useState<SshHostSummary[] | null>(null)
|
|
76
|
+
const [error, setError] = useState<string | null>(null)
|
|
77
|
+
const [search, setSearch] = useState('')
|
|
78
|
+
const [testingAlias, setTestingAlias] = useState<string | null>(null)
|
|
79
|
+
const [testResults, setTestResults] = useState<Record<string, TestResult>>({})
|
|
80
|
+
const [importing, setImporting] = useState(false)
|
|
81
|
+
const [notice, setNotice] = useState<string | null>(null)
|
|
82
|
+
/** Blocks the last import skipped, with the reason each one was left out. */
|
|
83
|
+
const [importSkips, setImportSkips] = useState<ImportSkipBlock[]>([])
|
|
84
|
+
const [dialog, setDialog] = useState<DialogState | null>(null)
|
|
85
|
+
const [groupBy, setGroupBy] = useState<HostGroupBy>('none')
|
|
86
|
+
const [collapsed, setCollapsed] = useState<Record<string, boolean>>({})
|
|
87
|
+
const [testingGroup, setTestingGroup] = useState<string | null>(null)
|
|
88
|
+
const seqRef = useRef(0)
|
|
89
|
+
// Unmount guard for the async load below: the seq check only orders
|
|
90
|
+
// overlapping loads, it does not stop a late resolution/rejection landing
|
|
91
|
+
// after the tab unmounted — a setState there races the test-environment
|
|
92
|
+
// teardown (window is not defined; observed as a main-CI flake). The
|
|
93
|
+
// sibling tabs (terminal / transfer / tunnels) already guard with a
|
|
94
|
+
// disposed flag.
|
|
95
|
+
const mountedRef = useRef(true)
|
|
96
|
+
useEffect(() => () => { mountedRef.current = false }, [])
|
|
97
|
+
|
|
98
|
+
const load = useCallback(async (query?: string): Promise<void> => {
|
|
99
|
+
const seq = ++seqRef.current
|
|
100
|
+
try {
|
|
101
|
+
const list = await api.listHosts(query)
|
|
102
|
+
if (!mountedRef.current || seq !== seqRef.current) return
|
|
103
|
+
setHosts(list)
|
|
104
|
+
setError(null)
|
|
105
|
+
} catch (cause) {
|
|
106
|
+
if (!mountedRef.current || seq !== seqRef.current) return
|
|
107
|
+
setError(errorMessage(cause))
|
|
108
|
+
}
|
|
109
|
+
}, [api])
|
|
110
|
+
|
|
111
|
+
useEffect(() => { void load() }, [load])
|
|
112
|
+
|
|
113
|
+
// Debounced search: every keystroke re-filters through the API.
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
const timer = setTimeout(() => {
|
|
116
|
+
const query = search.trim()
|
|
117
|
+
void load(query === '' ? undefined : query)
|
|
118
|
+
}, 300)
|
|
119
|
+
return () => { clearTimeout(timer) }
|
|
120
|
+
}, [search, load])
|
|
121
|
+
|
|
122
|
+
// Every async setState path guards with mountedRef, not just load(): a
|
|
123
|
+
// promise settling after unmount would setState against the torn-down
|
|
124
|
+
// environment (window is not defined, main-CI flake).
|
|
125
|
+
const runTest = async (alias: string): Promise<void> => {
|
|
126
|
+
if (!mountedRef.current) return
|
|
127
|
+
setTestingAlias(alias)
|
|
128
|
+
try {
|
|
129
|
+
const result = await api.testHost(alias)
|
|
130
|
+
if (!mountedRef.current) return
|
|
131
|
+
setTestResults(prev => ({ ...prev, [alias]: result }))
|
|
132
|
+
} catch (cause) {
|
|
133
|
+
if (!mountedRef.current) return
|
|
134
|
+
setTestResults(prev => ({ ...prev, [alias]: { ok: false, error: errorMessage(cause) } }))
|
|
135
|
+
} finally {
|
|
136
|
+
if (mountedRef.current) setTestingAlias(null)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const deleteHost = async (alias: string): Promise<void> => {
|
|
141
|
+
if (!window.confirm(tt('hosts.deleteConfirm', { alias }))) return
|
|
142
|
+
try {
|
|
143
|
+
await api.deleteHost(alias)
|
|
144
|
+
if (!mountedRef.current) return
|
|
145
|
+
void load()
|
|
146
|
+
} catch (cause) {
|
|
147
|
+
if (!mountedRef.current) return
|
|
148
|
+
setError(errorMessage(cause))
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Group-header batch action (#379): test every host in the group.
|
|
153
|
+
const testGroup = async (group: HostGroup): Promise<void> => {
|
|
154
|
+
if (!mountedRef.current) return
|
|
155
|
+
setTestingGroup(group.key)
|
|
156
|
+
try {
|
|
157
|
+
await Promise.all(group.hosts.map(host => runTest(host.alias)))
|
|
158
|
+
} finally {
|
|
159
|
+
if (mountedRef.current) setTestingGroup(null)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const importConfig = async (): Promise<void> => {
|
|
164
|
+
if (!mountedRef.current) return
|
|
165
|
+
setImporting(true)
|
|
166
|
+
try {
|
|
167
|
+
const result = await api.importSshConfig()
|
|
168
|
+
if (!mountedRef.current) return
|
|
169
|
+
setNotice(tt('hosts.imported', { parsed: result.parsed, added: result.added, skipped: result.skipped }))
|
|
170
|
+
setImportSkips(result.skippedBlocks)
|
|
171
|
+
void load()
|
|
172
|
+
} catch (cause) {
|
|
173
|
+
if (!mountedRef.current) return
|
|
174
|
+
setError(errorMessage(cause))
|
|
175
|
+
} finally {
|
|
176
|
+
if (mountedRef.current) setImporting(false)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const renderHostRow = (host: SshHostSummary): ReactNode => {
|
|
181
|
+
const test = testResults[host.alias]
|
|
182
|
+
return (
|
|
183
|
+
<tr key={host.alias}>
|
|
184
|
+
<td className={css.mono}>{host.alias}</td>
|
|
185
|
+
<td className={css.mono}>
|
|
186
|
+
{host.host}:{host.port}
|
|
187
|
+
{host.proxyCommand !== undefined && (
|
|
188
|
+
<span className={css.badge} data-kind="proxy" title={host.proxyCommand}>{tt('hosts.proxyBadge')}</span>
|
|
189
|
+
)}
|
|
190
|
+
</td>
|
|
191
|
+
<td>{host.user}</td>
|
|
192
|
+
<td><span className={css.badge} data-kind={host.auth}>{host.auth === 'key' ? tt('form.auth.key') : host.auth === 'password' ? tt('form.auth.password') : tt('form.auth.agent')}</span></td>
|
|
193
|
+
<td className={css.cellMuted}>{host.environment ?? ''}</td>
|
|
194
|
+
<td className={css.cellMuted}>{host.tags.join(', ')}</td>
|
|
195
|
+
<td className={css.cellMuted}>{host.description ?? ''}</td>
|
|
196
|
+
<td>
|
|
197
|
+
<div className={css.actions}>
|
|
198
|
+
<button type="button" className={css.linkButton} disabled={testingAlias === host.alias} onClick={() => { void runTest(host.alias) }}>
|
|
199
|
+
{testingAlias === host.alias ? tt('hosts.testing') : tt('hosts.test')}
|
|
200
|
+
</button>
|
|
201
|
+
{testingAlias === host.alias && <span className={css.spinner} aria-hidden="true" />}
|
|
202
|
+
{test !== undefined && (
|
|
203
|
+
<span className={css.inlineTest} data-status={test.ok ? 'ok' : 'fail'}>
|
|
204
|
+
{test.ok ? tt('hosts.testOk', { latency: test.latencyMs ?? 0 }) : tt('hosts.testFail', { error: test.error ?? '' })}
|
|
205
|
+
</span>
|
|
206
|
+
)}
|
|
207
|
+
<button type="button" className={css.linkButton} onClick={() => { setDialog({ mode: 'edit', host }) }}>{tt('hosts.edit')}</button>
|
|
208
|
+
<button type="button" className={css.linkButton} data-danger onClick={() => { void deleteHost(host.alias) }}>{tt('hosts.delete')}</button>
|
|
209
|
+
<button type="button" className={css.ghostButton} onClick={() => { onConnect(host.alias) }}>{tt('hosts.connected')}</button>
|
|
210
|
+
</div>
|
|
211
|
+
</td>
|
|
212
|
+
</tr>
|
|
213
|
+
)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const renderHostTable = (rows: SshHostSummary[]): ReactNode => (
|
|
217
|
+
<table className={css.table}>
|
|
218
|
+
<thead>
|
|
219
|
+
<tr>
|
|
220
|
+
<th>{tt('hosts.col.alias')}</th>
|
|
221
|
+
<th>{tt('hosts.col.host')}</th>
|
|
222
|
+
<th>{tt('hosts.col.user')}</th>
|
|
223
|
+
<th>{tt('hosts.col.auth')}</th>
|
|
224
|
+
<th>{tt('hosts.col.environment')}</th>
|
|
225
|
+
<th>{tt('hosts.col.tags')}</th>
|
|
226
|
+
<th>{tt('hosts.col.description')}</th>
|
|
227
|
+
<th>{tt('hosts.col.actions')}</th>
|
|
228
|
+
</tr>
|
|
229
|
+
</thead>
|
|
230
|
+
<tbody>
|
|
231
|
+
{rows.map(renderHostRow)}
|
|
232
|
+
</tbody>
|
|
233
|
+
</table>
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
const groups = hosts === null ? [] : groupHosts(hosts, groupBy)
|
|
237
|
+
|
|
238
|
+
return (
|
|
239
|
+
<div className={css.fillBody}>
|
|
240
|
+
<div className={css.toolbar}>
|
|
241
|
+
<input className={css.search} type="search" placeholder={tt('hosts.search')} value={search} onChange={event => { setSearch(event.target.value) }} />
|
|
242
|
+
<select
|
|
243
|
+
className={css.groupBySelect}
|
|
244
|
+
aria-label={tt('hosts.groupBy.label')}
|
|
245
|
+
value={groupBy}
|
|
246
|
+
onChange={event => { setGroupBy(event.target.value as HostGroupBy) }}
|
|
247
|
+
>
|
|
248
|
+
<option value="none">{tt('hosts.groupBy.none')}</option>
|
|
249
|
+
<option value="environment">{tt('hosts.groupBy.environment')}</option>
|
|
250
|
+
<option value="tags">{tt('hosts.groupBy.tags')}</option>
|
|
251
|
+
</select>
|
|
252
|
+
<div className={css.toolbarSpacer} />
|
|
253
|
+
<button type="button" className={css.primaryButton} onClick={() => { setDialog({ mode: 'create' }) }}>{tt('hosts.add')}</button>
|
|
254
|
+
<button type="button" className={css.ghostButton} disabled={importing} onClick={() => { void importConfig() }}>{importing ? tt('common.loading') : tt('hosts.import')}</button>
|
|
255
|
+
</div>
|
|
256
|
+
{notice !== null && <div className={css.banner} data-kind="ok">{notice}</div>}
|
|
257
|
+
{notice !== null && importSkips.length > 0 && (
|
|
258
|
+
<ul className={css.importSkips}>
|
|
259
|
+
{importSkips.slice(0, IMPORT_SKIP_LIMIT).map(block => (
|
|
260
|
+
<li key={block.name} className={css.importSkipRow}>
|
|
261
|
+
<span className={css.mono}>{block.name}</span>
|
|
262
|
+
<span className={css.cellMuted}>{tt(IMPORT_REASON_KEY[block.reason])}</span>
|
|
263
|
+
</li>
|
|
264
|
+
))}
|
|
265
|
+
{importSkips.length > IMPORT_SKIP_LIMIT && (
|
|
266
|
+
<li className={css.importSkipRow}>
|
|
267
|
+
<span className={css.cellMuted}>{tt('import.more', { count: importSkips.length - IMPORT_SKIP_LIMIT })}</span>
|
|
268
|
+
</li>
|
|
269
|
+
)}
|
|
270
|
+
</ul>
|
|
271
|
+
)}
|
|
272
|
+
{error !== null && <div className={css.banner} data-kind="error">{tt('common.error', { error })}</div>}
|
|
273
|
+
{hosts === null && error === null && <div className={css.loading}>{tt('common.loading')}</div>}
|
|
274
|
+
{hosts !== null && hosts.length === 0 && <div className={css.empty}>{tt('hosts.empty')}</div>}
|
|
275
|
+
{hosts !== null && hosts.length > 0 && groupBy === 'none' && (
|
|
276
|
+
<div className={css.tableWrap}>
|
|
277
|
+
{renderHostTable(hosts)}
|
|
278
|
+
</div>
|
|
279
|
+
)}
|
|
280
|
+
{hosts !== null && hosts.length > 0 && groupBy !== 'none' && (
|
|
281
|
+
<div className={css.tableWrap}>
|
|
282
|
+
{groups.map(group => {
|
|
283
|
+
const isCollapsed = collapsed[group.key] === true
|
|
284
|
+
const label = group.key === ''
|
|
285
|
+
? (groupBy === 'tags' ? tt('hosts.group.noTags') : tt('hosts.group.ungrouped'))
|
|
286
|
+
: group.key
|
|
287
|
+
return (
|
|
288
|
+
<section key={group.key} className={css.groupSection}>
|
|
289
|
+
<div className={css.groupHeader}>
|
|
290
|
+
<button
|
|
291
|
+
type="button"
|
|
292
|
+
className={css.groupToggle}
|
|
293
|
+
aria-expanded={!isCollapsed}
|
|
294
|
+
onClick={() => { setCollapsed(prev => ({ ...prev, [group.key]: !isCollapsed })) }}
|
|
295
|
+
>
|
|
296
|
+
<span className={css.groupChevron} data-collapsed={isCollapsed || undefined} aria-hidden="true" />
|
|
297
|
+
<span className={css.groupName}>{label}</span>
|
|
298
|
+
<span className={css.groupCount}>{tt('hosts.group.count', { count: group.hosts.length })}</span>
|
|
299
|
+
</button>
|
|
300
|
+
<button
|
|
301
|
+
type="button"
|
|
302
|
+
className={css.linkButton}
|
|
303
|
+
disabled={testingGroup === group.key}
|
|
304
|
+
onClick={() => { void testGroup(group) }}
|
|
305
|
+
>
|
|
306
|
+
{testingGroup === group.key ? tt('hosts.testing') : tt('hosts.group.testAll')}
|
|
307
|
+
</button>
|
|
308
|
+
</div>
|
|
309
|
+
{!isCollapsed && renderHostTable(group.hosts)}
|
|
310
|
+
</section>
|
|
311
|
+
)
|
|
312
|
+
})}
|
|
313
|
+
</div>
|
|
314
|
+
)}
|
|
315
|
+
{dialog !== null && (
|
|
316
|
+
<HostFormDialog
|
|
317
|
+
api={api}
|
|
318
|
+
editing={dialog.mode === 'edit' ? dialog.host : null}
|
|
319
|
+
onClose={() => { setDialog(null) }}
|
|
320
|
+
onSaved={() => { setDialog(null); void load() }}
|
|
321
|
+
/>
|
|
322
|
+
)}
|
|
323
|
+
</div>
|
|
324
|
+
)
|
|
325
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SSH operations panel shell: a header with a close control, a five-tab
|
|
3
|
+
* bar, and the active tab's content.
|
|
4
|
+
*
|
|
5
|
+
* The active tab, the pending connect request and the live terminal session id
|
|
6
|
+
* live in the controller, not in component state: the layout mounts this page
|
|
7
|
+
* only while the panel is selected, so local state would reset the tab on
|
|
8
|
+
* every panel switch and lose the id the terminal tab needs to reattach its
|
|
9
|
+
* host-side session. Inactive tabs unmount, so each tab fetches its own data
|
|
10
|
+
* on activation.
|
|
11
|
+
*/
|
|
12
|
+
import { useCallback, useSyncExternalStore } from 'react'
|
|
13
|
+
import type { SshApi } from '../api.ts'
|
|
14
|
+
import type { PanelController, SshTab } from './controller.ts'
|
|
15
|
+
import { tt, type TerminalFontSource } from './helpers.ts'
|
|
16
|
+
import { ClusterTab } from './ClusterTab.tsx'
|
|
17
|
+
import { HostsTab } from './HostsTab.tsx'
|
|
18
|
+
import { TerminalTab } from './TerminalTab.tsx'
|
|
19
|
+
import { TransferTab } from './TransferTab.tsx'
|
|
20
|
+
import { TunnelsTab } from './TunnelsTab.tsx'
|
|
21
|
+
import css from './panel.module.css'
|
|
22
|
+
|
|
23
|
+
/** Panel shell props. */
|
|
24
|
+
export interface SshPanelProps {
|
|
25
|
+
/** The panel state owner (open/close/toggle, active tab, terminal session). */
|
|
26
|
+
controller: PanelController
|
|
27
|
+
/** The SSH API client every tab operates through. */
|
|
28
|
+
api: SshApi
|
|
29
|
+
/** Live terminal-font setting source handed to the terminal tab (issue #577). */
|
|
30
|
+
terminalFont?: TerminalFontSource
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The tab bar definition (labels resolved at render time). */
|
|
34
|
+
const TABS: ReadonlyArray<{ id: SshTab; label: () => string }> = [
|
|
35
|
+
{ id: 'hosts', label: () => tt('tab.hosts') },
|
|
36
|
+
{ id: 'terminal', label: () => tt('tab.terminal') },
|
|
37
|
+
{ id: 'transfer', label: () => tt('tab.transfer') },
|
|
38
|
+
{ id: 'tunnels', label: () => tt('tab.tunnels') },
|
|
39
|
+
{ id: 'cluster', label: () => tt('tab.cluster') },
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
/** The tabbed SSH panel. */
|
|
43
|
+
export function SshPanel({ controller, api, terminalFont }: SshPanelProps) {
|
|
44
|
+
const { panelOpen, activeTab, connectRequest, terminalSessionId } = useSyncExternalStore(
|
|
45
|
+
useCallback(listener => controller.subscribe(listener), [controller]),
|
|
46
|
+
useCallback(() => controller.getSnapshot(), [controller]),
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<div className={css.panel} data-dsh-plugin="ssh">
|
|
51
|
+
<div className={css.panelHeader}>
|
|
52
|
+
{/* Shared hook: dsh-web-all offsets center-view back controls beside the collapsed mobile sidebar. */}
|
|
53
|
+
<button
|
|
54
|
+
type="button"
|
|
55
|
+
className={`${css.ghostButton} ${css.backButton}`}
|
|
56
|
+
aria-label={tt('panel.backToConversation')}
|
|
57
|
+
data-dsh-center-view-back=""
|
|
58
|
+
onClick={() => { controller.close() }}
|
|
59
|
+
>
|
|
60
|
+
<span aria-hidden="true">‹</span>
|
|
61
|
+
<span>{tt('panel.backToConversation')}</span>
|
|
62
|
+
</button>
|
|
63
|
+
<h2 className={css.panelTitle}>{tt('panel.title')}</h2>
|
|
64
|
+
</div>
|
|
65
|
+
<div className={css.tabBar} role="tablist" data-dsh-part="tab-bar">
|
|
66
|
+
{TABS.map(tab => (
|
|
67
|
+
<button key={tab.id} type="button" role="tab" aria-selected={activeTab === tab.id} data-active={activeTab === tab.id ? '' : undefined} data-dsh-part="tab" className={css.tab} onClick={() => { controller.setActiveTab(tab.id) }}>
|
|
68
|
+
{tab.label()}
|
|
69
|
+
</button>
|
|
70
|
+
))}
|
|
71
|
+
</div>
|
|
72
|
+
<div className={css.panelContent}>
|
|
73
|
+
{activeTab === 'hosts' && <HostsTab api={api} onConnect={alias => { controller.requestConnect(alias) }} />}
|
|
74
|
+
{activeTab === 'terminal' && (
|
|
75
|
+
<TerminalTab
|
|
76
|
+
api={api}
|
|
77
|
+
controller={controller}
|
|
78
|
+
presetAlias={connectRequest?.alias}
|
|
79
|
+
requestId={connectRequest?.nonce}
|
|
80
|
+
sessionId={terminalSessionId}
|
|
81
|
+
terminalFont={terminalFont}
|
|
82
|
+
/>
|
|
83
|
+
)}
|
|
84
|
+
{activeTab === 'transfer' && <TransferTab api={api} />}
|
|
85
|
+
{activeTab === 'tunnels' && <TunnelsTab api={api} active={panelOpen} />}
|
|
86
|
+
{activeTab === 'cluster' && <ClusterTab api={api} />}
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
)
|
|
90
|
+
}
|