@linxin666/dsh-client-ui-task-board-ssh 0.0.0-stage → 0.4.21
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 +96 -2
- package/README.zh.md +97 -0
- package/cordis.patch.yml +15 -0
- package/icon.svg +5 -0
- package/lib/client.js +4435 -0
- package/lib/index.js +7082 -0
- package/lib/types/client/PluginSettingsCard.d.ts +255 -0
- package/lib/types/client/RangeBubble.d.ts +46 -0
- package/lib/types/client/SegmentGroup.d.ts +28 -0
- package/lib/types/client/index.d.ts +100 -0
- package/lib/types/client/locales.d.ts +125 -0
- package/lib/types/client/seat-props.d.ts +53 -0
- package/lib/types/client/settings-entry-form.d.ts +49 -0
- package/lib/types/client/settings-form.d.ts +237 -0
- package/lib/types/client/ssh/card-decoration.d.ts +23 -0
- package/lib/types/client/ssh/compose-section.d.ts +7 -0
- package/lib/types/client/ssh/detail-section.d.ts +7 -0
- package/lib/types/client/ssh/extension.d.ts +54 -0
- package/lib/types/client/ssh/log-buffer.d.ts +128 -0
- package/lib/types/client/ssh/log-view.d.ts +37 -0
- package/lib/types/client/ssh/model.d.ts +130 -0
- package/lib/types/client/ssh/settings-section.d.ts +134 -0
- package/lib/types/client/ssh/summary.d.ts +160 -0
- package/lib/types/client/ssh/target-form.d.ts +60 -0
- package/lib/types/core/action.d.ts +89 -0
- package/lib/types/core/adapters/claude.d.ts +15 -0
- package/lib/types/core/adapters/codex.d.ts +15 -0
- package/lib/types/core/adapters/custom.d.ts +29 -0
- package/lib/types/core/adapters/dsh.d.ts +21 -0
- package/lib/types/core/adapters/index.d.ts +25 -0
- package/lib/types/core/adapters/types.d.ts +76 -0
- package/lib/types/core/contract.d.ts +453 -0
- package/lib/types/core/launcher-script.d.ts +13 -0
- package/lib/types/core/launcher.d.ts +153 -0
- package/lib/types/core/ledger.d.ts +123 -0
- package/lib/types/core/shell.d.ts +61 -0
- package/lib/types/core/target.d.ts +149 -0
- package/lib/types/core/task-record.d.ts +74 -0
- package/lib/types/core/workspace.d.ts +74 -0
- package/lib/types/host/board.d.ts +75 -0
- package/lib/types/host/engine.d.ts +563 -0
- package/lib/types/host/extension.d.ts +61 -0
- package/lib/types/host/inspect.d.ts +99 -0
- package/lib/types/host/logs.d.ts +135 -0
- package/lib/types/host/payload.d.ts +75 -0
- package/lib/types/host/prompt.d.ts +44 -0
- package/lib/types/host/queue.d.ts +53 -0
- package/lib/types/host/remote.d.ts +137 -0
- package/lib/types/host/settings.d.ts +149 -0
- package/lib/types/host/timers.d.ts +20 -0
- package/lib/types/host/tools.d.ts +17 -0
- package/lib/types/host/workspace/errors.d.ts +29 -0
- package/lib/types/host/workspace/git.d.ts +108 -0
- package/lib/types/host/workspace/in-place.d.ts +36 -0
- package/lib/types/host/workspace/index.d.ts +28 -0
- package/lib/types/host/workspace/layout.d.ts +62 -0
- package/lib/types/host/workspace/local-git.d.ts +72 -0
- package/lib/types/host/workspace/remote-git.d.ts +111 -0
- package/lib/types/host/workspace/remote.d.ts +85 -0
- package/lib/types/host/workspace/types.d.ts +28 -0
- package/lib/types/host/workspace-seam.d.ts +100 -0
- package/lib/types/index.d.ts +97 -0
- package/lib/types/mount-once.d.ts +55 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +89 -3
- package/src/client/PluginSettingsCard.tsx +838 -0
- package/src/client/RangeBubble.tsx +164 -0
- package/src/client/SegmentGroup.tsx +93 -0
- package/src/client/css-modules.d.ts +5 -0
- package/src/client/index.ts +195 -0
- package/src/client/locales.ts +257 -0
- package/src/client/seat-props.ts +58 -0
- package/src/client/settings-card.module.css +821 -0
- package/src/client/settings-entry-form.ts +141 -0
- package/src/client/settings-form.ts +529 -0
- package/src/client/ssh/card-decoration.tsx +55 -0
- package/src/client/ssh/compose-section.tsx +147 -0
- package/src/client/ssh/detail-section.tsx +345 -0
- package/src/client/ssh/extension.ts +271 -0
- package/src/client/ssh/log-buffer.ts +224 -0
- package/src/client/ssh/log-view.tsx +149 -0
- package/src/client/ssh/model.ts +299 -0
- package/src/client/ssh/settings-section.tsx +401 -0
- package/src/client/ssh/summary.ts +388 -0
- package/src/client/ssh/target-form.tsx +380 -0
- package/src/client/ssh.module.css +617 -0
- package/src/core/action.ts +270 -0
- package/src/core/adapters/claude.ts +64 -0
- package/src/core/adapters/codex.ts +83 -0
- package/src/core/adapters/custom.ts +88 -0
- package/src/core/adapters/dsh.ts +87 -0
- package/src/core/adapters/index.ts +74 -0
- package/src/core/adapters/types.ts +95 -0
- package/src/core/contract.ts +515 -0
- package/src/core/launcher-script.ts +313 -0
- package/src/core/launcher.ts +283 -0
- package/src/core/ledger.ts +377 -0
- package/src/core/shell.ts +77 -0
- package/src/core/target.ts +420 -0
- package/src/core/task-record.ts +73 -0
- package/src/core/workspace.ts +78 -0
- package/src/host/board.ts +107 -0
- package/src/host/engine.ts +2026 -0
- package/src/host/extension.ts +310 -0
- package/src/host/inspect.ts +264 -0
- package/src/host/logs.ts +297 -0
- package/src/host/payload.ts +134 -0
- package/src/host/prompt.ts +89 -0
- package/src/host/queue.ts +73 -0
- package/src/host/remote.ts +356 -0
- package/src/host/settings.ts +294 -0
- package/src/host/timers.ts +33 -0
- package/src/host/tools.ts +449 -0
- package/src/host/workspace/errors.ts +43 -0
- package/src/host/workspace/git.ts +305 -0
- package/src/host/workspace/in-place.ts +58 -0
- package/src/host/workspace/index.ts +37 -0
- package/src/host/workspace/layout.ts +122 -0
- package/src/host/workspace/local-git.ts +164 -0
- package/src/host/workspace/remote-git.ts +244 -0
- package/src/host/workspace/remote.ts +181 -0
- package/src/host/workspace/types.ts +34 -0
- package/src/host/workspace-seam.ts +132 -0
- package/src/index.ts +243 -0
- package/src/mount-once.ts +142 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The target form: everything one card pins about where and how it runs.
|
|
3
|
+
*
|
|
4
|
+
* Two frames render these fields — the detail seat's form, which saves one
|
|
5
|
+
* target onto an existing card, and the create dialog's picker, which reports a
|
|
6
|
+
* draft the board stores on the card it is about to create. Both frames render
|
|
7
|
+
* the same {@link SshTargetFields}, so which fields a mode and a workspace kind
|
|
8
|
+
* actually ask for, and how a refusal is worded, cannot drift between them.
|
|
9
|
+
*
|
|
10
|
+
* Only the fields the chosen mode and workspace kind actually use are on
|
|
11
|
+
* screen, and the value sent is built from exactly those fields — a hidden
|
|
12
|
+
* field can neither pass nor fail, so what the reader sees is what the parser
|
|
13
|
+
* judges. Validation runs the frozen core parser before anything leaves the
|
|
14
|
+
* frame, and its refusals land under the field that carries them, addressed to
|
|
15
|
+
* the input through `aria-describedby` and `aria-invalid`.
|
|
16
|
+
*
|
|
17
|
+
* @module dsh-task-board-ssh/client/ssh/target-form
|
|
18
|
+
*/
|
|
19
|
+
import { type FormEvent, useEffect, useId, useState } from 'react'
|
|
20
|
+
import { validateDraft, type SshDraftField, type SshTargetDraft } from './model.ts'
|
|
21
|
+
import type { SshAgentKind, SshExecutionMode, SshTarget, SshValidationIssue, SshWorkspaceKind } from '../../core/target.ts'
|
|
22
|
+
import { useBoardWorkspaces, type SshBoardWorkspaceOption, type SshSummaryHost } from './summary.ts'
|
|
23
|
+
import { t, type TaskBoardSshKey } from '../locales.ts'
|
|
24
|
+
import css from '../ssh.module.css'
|
|
25
|
+
|
|
26
|
+
/** The two execution modes, in the order the form offers them. */
|
|
27
|
+
const MODES: readonly SshExecutionMode[] = ['direct', 'proxy']
|
|
28
|
+
|
|
29
|
+
/** The agent CLIs the form offers, in the order the form offers them. */
|
|
30
|
+
const AGENTS: readonly SshAgentKind[] = ['dsh', 'claude', 'codex', 'custom']
|
|
31
|
+
|
|
32
|
+
/** The two filesystem mechanisms, in the order the form offers them. */
|
|
33
|
+
const WORKSPACE_KINDS: readonly SshWorkspaceKind[] = ['in-place', 'git']
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Localized copy for one parser refusal.
|
|
37
|
+
* @param field - the field the refusal is addressed to.
|
|
38
|
+
* @param issue - the parser's own sentence, used when the field has no copy of its own.
|
|
39
|
+
* @returns the sentence to render under the field.
|
|
40
|
+
*/
|
|
41
|
+
export function refusalText(field: SshDraftField, issue: SshValidationIssue): string {
|
|
42
|
+
switch (field) {
|
|
43
|
+
case 'host': return t('detail.error.host')
|
|
44
|
+
case 'workspacePath': return t('detail.error.path')
|
|
45
|
+
case 'agentCommand': return t('detail.error.agentCommand')
|
|
46
|
+
case 'repositoryUrl': return t('detail.error.url')
|
|
47
|
+
case 'workspaceId': return t('detail.error.workspaceId')
|
|
48
|
+
default: return t('detail.error.generic', { error: issue.message })
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Props of the field set both target surfaces render. */
|
|
53
|
+
export interface SshTargetFieldsProps {
|
|
54
|
+
/** The values to render. */
|
|
55
|
+
draft: SshTargetDraft
|
|
56
|
+
/** Refusals to show, keyed by the field that carries each one. */
|
|
57
|
+
errors: Partial<Record<SshDraftField, SshValidationIssue>>
|
|
58
|
+
/** Hosts the picker offers; empty when the provider publishes none. */
|
|
59
|
+
hosts: readonly SshSummaryHost[]
|
|
60
|
+
/** Local workspaces the picker offers for `git` -> `workspace` source; falls back to board mirror. */
|
|
61
|
+
workspaces?: readonly SshBoardWorkspaceOption[]
|
|
62
|
+
/** The pinned alias that is no longer in the host list, when there is one. */
|
|
63
|
+
unknownHost?: string
|
|
64
|
+
/** Whether every control is read-only because a write is in flight. */
|
|
65
|
+
disabled?: boolean
|
|
66
|
+
/** One line under the mode choice; a frame with room for it passes one, a dialog skips it. */
|
|
67
|
+
modeHint?: string
|
|
68
|
+
/** Called when the operator leaves a field (blur), so progressive validation can surface refusals. */
|
|
69
|
+
onTouch?(field: SshDraftField): void
|
|
70
|
+
/** Called with the fields one control changed. */
|
|
71
|
+
onChange(patch: Partial<SshTargetDraft>): void
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Render the fields of one target, in the order a reader walks them.
|
|
76
|
+
* @param props - the values, the refusals, the hosts to offer and the edit callback.
|
|
77
|
+
* @returns the field set, in the shape the current draft asks for.
|
|
78
|
+
*/
|
|
79
|
+
export function SshTargetFields({ draft, errors, hosts, workspaces, unknownHost, disabled = false, modeHint, onTouch, onChange }: SshTargetFieldsProps) {
|
|
80
|
+
const baseId = useId()
|
|
81
|
+
const mirrorWorkspaces = useBoardWorkspaces()
|
|
82
|
+
const workspaceOptions = workspaces ?? mirrorWorkspaces
|
|
83
|
+
const isProxy = draft.mode === 'proxy'
|
|
84
|
+
|
|
85
|
+
const errorFor = (field: SshDraftField): string | undefined => {
|
|
86
|
+
const issue = errors[field]
|
|
87
|
+
return issue === undefined ? undefined : refusalText(field, issue)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Render one labelled text input and its refusal. */
|
|
91
|
+
const textField = (
|
|
92
|
+
field: SshDraftField,
|
|
93
|
+
labelKey: TaskBoardSshKey,
|
|
94
|
+
value: string,
|
|
95
|
+
onChangeText: (next: string) => void,
|
|
96
|
+
placeholder?: string,
|
|
97
|
+
) => {
|
|
98
|
+
const id = `${baseId}-${field}`
|
|
99
|
+
const error = errorFor(field)
|
|
100
|
+
return (
|
|
101
|
+
<div className={css.field} key={field}>
|
|
102
|
+
<label className={css.fieldLabel} htmlFor={id}>{t(labelKey)}</label>
|
|
103
|
+
<input
|
|
104
|
+
id={id}
|
|
105
|
+
className={css.input}
|
|
106
|
+
type="text"
|
|
107
|
+
value={value}
|
|
108
|
+
placeholder={placeholder}
|
|
109
|
+
aria-invalid={error !== undefined}
|
|
110
|
+
aria-describedby={error === undefined ? undefined : `${id}-error`}
|
|
111
|
+
onChange={event => onChangeText(event.target.value)}
|
|
112
|
+
onBlur={() => onTouch?.(field)}
|
|
113
|
+
disabled={disabled}
|
|
114
|
+
/>
|
|
115
|
+
{error !== undefined && <p className={css.fieldError} id={`${id}-error`}>{error}</p>}
|
|
116
|
+
</div>
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Render one labelled choice group whose options are radio inputs. */
|
|
121
|
+
const choiceGroup = <Value extends string>(
|
|
122
|
+
field: SshDraftField,
|
|
123
|
+
labelKey: TaskBoardSshKey,
|
|
124
|
+
options: readonly { value: Value, label: TaskBoardSshKey }[],
|
|
125
|
+
value: Value,
|
|
126
|
+
onChangeChoice: (next: Value) => void,
|
|
127
|
+
) => {
|
|
128
|
+
const error = errorFor(field)
|
|
129
|
+
const errorId = `${baseId}-${field}-error`
|
|
130
|
+
return (
|
|
131
|
+
<fieldset
|
|
132
|
+
className={css.field}
|
|
133
|
+
data-invalid={error !== undefined || undefined}
|
|
134
|
+
aria-describedby={error === undefined ? undefined : errorId}
|
|
135
|
+
key={field}
|
|
136
|
+
>
|
|
137
|
+
<legend className={css.fieldLabel}>{t(labelKey)}</legend>
|
|
138
|
+
<div className={css.segments}>
|
|
139
|
+
{options.map(option => (
|
|
140
|
+
<label key={option.value} className={css.segment} data-disabled={disabled || undefined}>
|
|
141
|
+
<input
|
|
142
|
+
type="radio"
|
|
143
|
+
name={`${baseId}-${field}`}
|
|
144
|
+
value={option.value}
|
|
145
|
+
checked={value === option.value}
|
|
146
|
+
onChange={() => onChangeChoice(option.value)}
|
|
147
|
+
disabled={disabled}
|
|
148
|
+
/>
|
|
149
|
+
<span>{t(option.label)}</span>
|
|
150
|
+
</label>
|
|
151
|
+
))}
|
|
152
|
+
</div>
|
|
153
|
+
{error !== undefined && <p className={css.fieldError} id={errorId}>{error}</p>}
|
|
154
|
+
</fieldset>
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const hostOptions = hosts.map(host => ({ alias: host.alias, label: `${host.alias} · ${host.user}@${host.host}` }))
|
|
159
|
+
const hostInList = hostOptions.some(option => option.alias === draft.host)
|
|
160
|
+
// With no host to pick the hint says everything there is to say, so a refusal
|
|
161
|
+
// would only repeat it: an error speaks while the field can still be answered.
|
|
162
|
+
const hostHint = hostOptions.length === 0 ? t('detail.hostMissing') : undefined
|
|
163
|
+
const hostError = hostHint === undefined ? errorFor('host') : undefined
|
|
164
|
+
const hostDescribedBy = [
|
|
165
|
+
hostHint === undefined ? undefined : `${baseId}-host-hint`,
|
|
166
|
+
hostError === undefined ? undefined : `${baseId}-host-error`,
|
|
167
|
+
].filter(part => part !== undefined).join(' ')
|
|
168
|
+
const agentError = errorFor('agent')
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<div className={css.fields} data-dsh-part="target-fields">
|
|
172
|
+
{choiceGroup(
|
|
173
|
+
'mode',
|
|
174
|
+
'detail.mode',
|
|
175
|
+
MODES.map(value => ({ value, label: `detail.mode.${value}` as TaskBoardSshKey })),
|
|
176
|
+
draft.mode,
|
|
177
|
+
next => onChange({ mode: next }),
|
|
178
|
+
)}
|
|
179
|
+
{modeHint !== undefined && <p className={css.fieldHint}>{modeHint}</p>}
|
|
180
|
+
|
|
181
|
+
<div className={css.field}>
|
|
182
|
+
<label className={css.fieldLabel} htmlFor={`${baseId}-host`}>{t('detail.host')}</label>
|
|
183
|
+
<select
|
|
184
|
+
id={`${baseId}-host`}
|
|
185
|
+
className={css.select}
|
|
186
|
+
value={draft.host}
|
|
187
|
+
aria-invalid={hostError !== undefined}
|
|
188
|
+
aria-describedby={hostDescribedBy === '' ? undefined : hostDescribedBy}
|
|
189
|
+
onChange={event => onChange({ host: event.target.value })}
|
|
190
|
+
onBlur={() => onTouch?.('host')}
|
|
191
|
+
disabled={disabled || hostOptions.length === 0}
|
|
192
|
+
>
|
|
193
|
+
<option value="">{t(hostOptions.length === 0 ? 'detail.hostNone' : 'detail.host')}</option>
|
|
194
|
+
{!hostInList && unknownHost !== undefined && unknownHost !== '' && (
|
|
195
|
+
<option value={unknownHost}>{t('detail.hostUnknown', { alias: unknownHost })}</option>
|
|
196
|
+
)}
|
|
197
|
+
{hostOptions.map(option => (
|
|
198
|
+
<option key={option.alias} value={option.alias}>{option.label}</option>
|
|
199
|
+
))}
|
|
200
|
+
</select>
|
|
201
|
+
{hostHint !== undefined && <p className={css.fieldHint} id={`${baseId}-host-hint`}>{hostHint}</p>}
|
|
202
|
+
{hostError !== undefined && <p className={css.fieldError} id={`${baseId}-host-error`}>{hostError}</p>}
|
|
203
|
+
</div>
|
|
204
|
+
|
|
205
|
+
{!isProxy && (
|
|
206
|
+
<div className={css.field}>
|
|
207
|
+
<label className={css.fieldLabel} htmlFor={`${baseId}-agent`}>{t('detail.agent')}</label>
|
|
208
|
+
<select
|
|
209
|
+
id={`${baseId}-agent`}
|
|
210
|
+
className={css.select}
|
|
211
|
+
value={draft.agent}
|
|
212
|
+
aria-invalid={agentError !== undefined}
|
|
213
|
+
aria-describedby={agentError === undefined ? undefined : `${baseId}-agent-error`}
|
|
214
|
+
onChange={event => onChange({ agent: event.target.value as SshAgentKind })}
|
|
215
|
+
disabled={disabled}
|
|
216
|
+
>
|
|
217
|
+
{AGENTS.map(agent => (
|
|
218
|
+
<option key={agent} value={agent}>{t(`detail.agent.${agent}` as TaskBoardSshKey)}</option>
|
|
219
|
+
))}
|
|
220
|
+
</select>
|
|
221
|
+
{agentError !== undefined && <p className={css.fieldError} id={`${baseId}-agent-error`}>{agentError}</p>}
|
|
222
|
+
</div>
|
|
223
|
+
)}
|
|
224
|
+
|
|
225
|
+
{!isProxy && draft.agent === 'custom' && (
|
|
226
|
+
<>
|
|
227
|
+
{textField('agentCommand', 'detail.agentCommand', draft.agentCommand, next => onChange({ agentCommand: next }), '{prompt_file}')}
|
|
228
|
+
{textField('agentResumeCommand', 'detail.agentResumeCommand', draft.agentResumeCommand, next => onChange({ agentResumeCommand: next }))}
|
|
229
|
+
</>
|
|
230
|
+
)}
|
|
231
|
+
|
|
232
|
+
{choiceGroup(
|
|
233
|
+
'workspaceKind',
|
|
234
|
+
'detail.workspace',
|
|
235
|
+
WORKSPACE_KINDS.map(value => ({ value, label: `detail.workspace.${value}` as TaskBoardSshKey })),
|
|
236
|
+
draft.workspaceKind,
|
|
237
|
+
next => onChange({ workspaceKind: next }),
|
|
238
|
+
)}
|
|
239
|
+
|
|
240
|
+
{draft.workspaceKind === 'in-place'
|
|
241
|
+
? textField('workspacePath', 'detail.workspace.path', draft.workspacePath, next => onChange({ workspacePath: next }), '/home/me/project')
|
|
242
|
+
: (
|
|
243
|
+
<>
|
|
244
|
+
{!isProxy && choiceGroup(
|
|
245
|
+
'gitSource',
|
|
246
|
+
'detail.workspace.source',
|
|
247
|
+
[
|
|
248
|
+
{ value: 'url' as const, label: 'detail.workspace.source.url' as TaskBoardSshKey },
|
|
249
|
+
{ value: 'workspace' as const, label: 'detail.workspace.source.workspace' as TaskBoardSshKey },
|
|
250
|
+
],
|
|
251
|
+
draft.gitSource,
|
|
252
|
+
next => onChange({ gitSource: next }),
|
|
253
|
+
)}
|
|
254
|
+
{(isProxy || draft.gitSource === 'url')
|
|
255
|
+
? (
|
|
256
|
+
<>
|
|
257
|
+
{textField('repositoryUrl', 'detail.workspace.url', draft.repositoryUrl, next => onChange({ repositoryUrl: next }), 'git@example.com:team/repo.git')}
|
|
258
|
+
{textField('baseBranch', 'detail.workspace.base', draft.baseBranch, next => onChange({ baseBranch: next }), 'main')}
|
|
259
|
+
</>
|
|
260
|
+
)
|
|
261
|
+
: workspaceOptions.length > 0
|
|
262
|
+
? (() => {
|
|
263
|
+
const id = `${baseId}-workspaceId`
|
|
264
|
+
const wsError = errorFor('workspaceId')
|
|
265
|
+
const known = workspaceOptions.some(item => item.workspaceId === draft.workspaceId)
|
|
266
|
+
return (
|
|
267
|
+
<div className={css.field} key="workspaceId">
|
|
268
|
+
<label className={css.fieldLabel} htmlFor={id}>{t('detail.workspace.workspaceId')}</label>
|
|
269
|
+
<select
|
|
270
|
+
id={id}
|
|
271
|
+
className={css.select}
|
|
272
|
+
value={draft.workspaceId}
|
|
273
|
+
aria-invalid={wsError !== undefined}
|
|
274
|
+
aria-describedby={wsError === undefined ? undefined : `${id}-error`}
|
|
275
|
+
onChange={event => onChange({ workspaceId: event.target.value })}
|
|
276
|
+
onBlur={() => onTouch?.('workspaceId')}
|
|
277
|
+
disabled={disabled}
|
|
278
|
+
>
|
|
279
|
+
<option value="">{t('detail.workspace.workspaceIdPlaceholder')}</option>
|
|
280
|
+
{!known && draft.workspaceId !== '' && (
|
|
281
|
+
<option value={draft.workspaceId}>{draft.workspaceId}</option>
|
|
282
|
+
)}
|
|
283
|
+
{workspaceOptions.map(item => (
|
|
284
|
+
<option key={item.workspaceId} value={item.workspaceId}>{item.title}</option>
|
|
285
|
+
))}
|
|
286
|
+
</select>
|
|
287
|
+
{wsError !== undefined && <p className={css.fieldError} id={`${id}-error`}>{wsError}</p>}
|
|
288
|
+
</div>
|
|
289
|
+
)
|
|
290
|
+
})()
|
|
291
|
+
: textField('workspaceId', 'detail.workspace.workspaceId', draft.workspaceId, next => onChange({ workspaceId: next }), t('detail.workspace.workspaceIdPlaceholder'))}
|
|
292
|
+
</>
|
|
293
|
+
)}
|
|
294
|
+
</div>
|
|
295
|
+
)
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** Props of the target form. */
|
|
299
|
+
export interface SshTargetFormProps {
|
|
300
|
+
/** State the form opens with. */
|
|
301
|
+
initial: SshTargetDraft
|
|
302
|
+
/** Hosts the picker offers; empty when the provider publishes none. */
|
|
303
|
+
hosts: readonly SshSummaryHost[]
|
|
304
|
+
/** The pinned alias that is no longer in the host list, when there is one. */
|
|
305
|
+
unknownHost?: string
|
|
306
|
+
/** Whether a write is in flight. */
|
|
307
|
+
saving: boolean
|
|
308
|
+
/** Text of the submit control. */
|
|
309
|
+
submitLabel: string
|
|
310
|
+
/** Drop the form without writing, when the caller has somewhere to go back to. */
|
|
311
|
+
onCancel?: () => void
|
|
312
|
+
/** Called with the parsed target once every field passes. */
|
|
313
|
+
onSubmit(target: SshTarget): void
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Render the target form: the same fields, framed by one save action.
|
|
318
|
+
* @param props - the opening state, the hosts to offer and the write callbacks.
|
|
319
|
+
* @returns the form, in the shape the current draft asks for.
|
|
320
|
+
*/
|
|
321
|
+
export function SshTargetForm({ initial, hosts, unknownHost, saving, submitLabel, onCancel, onSubmit }: SshTargetFormProps) {
|
|
322
|
+
const [draft, setDraft] = useState<SshTargetDraft>(initial)
|
|
323
|
+
const [dirty, setDirty] = useState(false)
|
|
324
|
+
const [errors, setErrors] = useState<Partial<Record<SshDraftField, SshValidationIssue>>>({})
|
|
325
|
+
|
|
326
|
+
// Adopt late-arriving provider defaults until the operator starts editing.
|
|
327
|
+
useEffect(() => {
|
|
328
|
+
if (!dirty) setDraft(initial)
|
|
329
|
+
}, [dirty, initial.mode, initial.host, initial.agent, initial.agentCommand, initial.agentResumeCommand, initial.workspaceKind, initial.gitSource, initial.workspacePath, initial.repositoryUrl, initial.baseBranch, initial.workspaceId])
|
|
330
|
+
|
|
331
|
+
const edit = (patch: Partial<SshTargetDraft>): void => {
|
|
332
|
+
setDirty(true)
|
|
333
|
+
setDraft(current => ({ ...current, ...patch }))
|
|
334
|
+
// A field that changed is re-judged on the next submit; its old refusal
|
|
335
|
+
// must not outlive the value it was about.
|
|
336
|
+
setErrors(current => {
|
|
337
|
+
const fields = Object.keys(patch)
|
|
338
|
+
if (!fields.some(field => current[field as SshDraftField] !== undefined)) return current
|
|
339
|
+
const kept = { ...current }
|
|
340
|
+
for (const field of fields) delete kept[field as SshDraftField]
|
|
341
|
+
return kept
|
|
342
|
+
})
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const submit = (event: FormEvent<HTMLFormElement>): void => {
|
|
346
|
+
event.preventDefault()
|
|
347
|
+
const result = validateDraft(draft)
|
|
348
|
+
if (result.target === undefined) {
|
|
349
|
+
setErrors(result.errors)
|
|
350
|
+
return
|
|
351
|
+
}
|
|
352
|
+
setErrors({})
|
|
353
|
+
onSubmit(result.target)
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return (
|
|
357
|
+
<form className={css.form} onSubmit={submit} data-dsh-part="target-form">
|
|
358
|
+
<SshTargetFields
|
|
359
|
+
draft={draft}
|
|
360
|
+
errors={errors}
|
|
361
|
+
hosts={hosts}
|
|
362
|
+
{...(unknownHost === undefined ? {} : { unknownHost })}
|
|
363
|
+
disabled={saving}
|
|
364
|
+
modeHint={t(draft.mode === 'direct' ? 'detail.modeHintDirect' : 'detail.modeHintProxy')}
|
|
365
|
+
onChange={edit}
|
|
366
|
+
/>
|
|
367
|
+
|
|
368
|
+
<div className={css.actions}>
|
|
369
|
+
<button type="submit" className={css.primaryButton} disabled={saving}>
|
|
370
|
+
{submitLabel}
|
|
371
|
+
</button>
|
|
372
|
+
{onCancel !== undefined && (
|
|
373
|
+
<button type="button" className={css.ghostButton} onClick={onCancel} disabled={saving}>
|
|
374
|
+
{t('detail.cancelEdit')}
|
|
375
|
+
</button>
|
|
376
|
+
)}
|
|
377
|
+
</div>
|
|
378
|
+
</form>
|
|
379
|
+
)
|
|
380
|
+
}
|