SourceServerManagementPanel.tsx 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739
  1. import {
  2. useRemoteConnectionProgress,
  3. RemoteConnectionMinimizedProgress,
  4. } from "@/remote-connection-flow/ui/RemoteConnectionProgress.js";
  5. import {
  6. Dialog,
  7. DialogContent,
  8. DialogHeader,
  9. DialogTitle,
  10. DialogDescription,
  11. } from "@/components/ui/dialog.js";
  12. import { useOptionalPlatform } from "@/hooks/usePlatform.js";
  13. import { DesktopCommandIds } from "@zcode/shared";
  14. /* eslint-disable max-lines -- Source/Profile/迁移三类管理操作共享同一 Host 快照和错误状态。 */
  15. import { useCallback, useEffect, useMemo, useRef, useState } from "react";
  16. import {
  17. ArrowUpRight,
  18. ChevronDown,
  19. ChevronRight,
  20. Ellipsis,
  21. FileWarning,
  22. Folder,
  23. ListTree,
  24. Loader2,
  25. Pencil,
  26. Plus,
  27. Server,
  28. Box,
  29. TerminalSquare,
  30. Copy,
  31. Trash2,
  32. } from "lucide-react";
  33. import { resolveWorkspaceKey } from "@zcode/shared";
  34. import type {
  35. ConnectionProfile,
  36. AppSettings,
  37. SourceServerManagementSnapshot,
  38. SourceServerMigrationReport,
  39. SourceServerRecord,
  40. SourceServerWorkspaceHistoryEntry,
  41. } from "@zcode/shared";
  42. import type { ISourceServerManagementService } from "@zcode/services";
  43. import { getPathLeaf } from "@/lib/path.js";
  44. import { toast } from "@/components/ui/toast.js";
  45. import { getSourceServerManagementErrorMessage } from "@/lib/sourceServerManagementError.js";
  46. import { Button } from "@/components/ui/button.js";
  47. import { Switch } from "@/components/ui/switch.js";
  48. import { cn } from "@/components/lib/utils.js";
  49. import { useConfirmDialog } from "@/hooks/useConfirmDialog.js";
  50. import { useSourceServerManagementSnapshot } from "@/hooks/useSourceServerManagementSnapshot.js";
  51. import { useSourceServerOperationLogs } from "@/hooks/useSourceServerOperationLogs.js";
  52. import { useZCodeIntl } from "@/i18n/IntlProvider.js";
  53. import { SourceServerMigrationReportPanel } from "@/settings/SourceServerMigrationReportPanel.js";
  54. import {
  55. SourceServerLogList,
  56. SourceServerUpdateActivity,
  57. } from "@/settings/SourceServerUpdateActivity.js";
  58. import { formatRemoteConnectionError } from "@/lib/remoteConnectionPresentation.js";
  59. import {
  60. resolveRemoteConnectionPresentation,
  61. getRemoteDevicePresentationInput,
  62. classifyRemoteConnectionError,
  63. type RemoteConnectionPresentation,
  64. } from "@/lib/remoteConnectionPresentation.js";
  65. import {
  66. sourceServerUpdatePreferences,
  67. sourceServerUpdateKey,
  68. useDeferredSourceServerUpdates,
  69. } from "@/lib/sourceServerUpdatePreferences.js";
  70. import {
  71. getSourceServerForceUpdateDescription,
  72. runSourceServerUpdate,
  73. } from "@/lib/sourceServerUpdateAction.js";
  74. import {
  75. DropdownMenu,
  76. DropdownMenuContent,
  77. DropdownMenuItem,
  78. DropdownMenuSeparator,
  79. DropdownMenuTrigger,
  80. } from "@/components/ui/dropdown-menu.js";
  81. import { EditConnectionProfileDialog } from "@/remote-connection/EditConnectionProfileDialog.js";
  82. import {
  83. formatConnectionProfileTarget,
  84. RemoteConnectionKindTag,
  85. RemoteConnectionStatusTag,
  86. } from "@/remote-connection/RemoteConnectionTags.js";
  87. import type { WorkspaceTabState } from "@/store/tabStore.js";
  88. import { getWorkspaceSourceServerId } from "@/conversation-workspace-target/sourceIdentity.js";
  89. import { buildRemoteWorkspaceProjection } from "@/remote/remoteWorkspaceProjection.js";
  90. function formatTimestamp(timestamp: number, locale: string): string {
  91. return new Date(timestamp).toLocaleString(locale, {
  92. dateStyle: "medium",
  93. timeStyle: "short",
  94. });
  95. }
  96. function formatRelativeTimestamp(
  97. timestamp: number,
  98. locale: string,
  99. formatMessage: (descriptor: { id: string }, values?: Record<string, string | number>) => string,
  100. ): string {
  101. const elapsed = Math.max(0, Date.now() - timestamp);
  102. if (elapsed < 60_000) return formatMessage({ id: "common.justNow" });
  103. if (elapsed < 60 * 60_000) {
  104. return formatMessage({ id: "common.minutesAgo" }, { count: Math.floor(elapsed / 60_000) });
  105. }
  106. if (elapsed < 24 * 60 * 60_000) {
  107. return formatMessage({ id: "common.hoursAgo" }, { count: Math.floor(elapsed / (60 * 60_000)) });
  108. }
  109. if (elapsed < 48 * 60 * 60_000) return formatMessage({ id: "common.yesterday" });
  110. return new Date(timestamp).toLocaleDateString(locale, {
  111. month: "short",
  112. day: "numeric",
  113. });
  114. }
  115. export function getProjectCount(
  116. snapshot: SourceServerManagementSnapshot,
  117. sourceServerId: string,
  118. remoteConversationWorkspaceBySourceServerId?: AppSettings["remoteConversationWorkspaceBySourceServerId"],
  119. ): number {
  120. return new Set(
  121. snapshot.workspaceHistory
  122. .filter(
  123. (entry) =>
  124. entry.sourceServerId === sourceServerId &&
  125. remoteConversationWorkspaceBySourceServerId?.[sourceServerId]?.workspacePath !==
  126. entry.workspacePath,
  127. )
  128. .map((entry) => resolveWorkspaceKey(entry)),
  129. ).size;
  130. }
  131. const COLLAPSED_PROJECT_COUNT = 3;
  132. function toggleSetItem(current: Set<string>, item: string): Set<string> {
  133. const next = new Set(current);
  134. if (next.has(item)) next.delete(item);
  135. else next.add(item);
  136. return next;
  137. }
  138. function profileOperationScope(profile: ConnectionProfile): string {
  139. return profile.sourceServerId
  140. ? `source:${profile.sourceServerId}`
  141. : `profile:${profile.profileId}`;
  142. }
  143. export function SourceServerManagementPanel({
  144. management,
  145. targetSourceServerId,
  146. targetSourceServerDetails = false,
  147. onTargetSourceServerFocused,
  148. onCreateConnection,
  149. onConnectProfile,
  150. onDisconnectSource,
  151. onShowInSidebar,
  152. onOpenProject,
  153. onShowUpdateDetails,
  154. workspaceTabs = [],
  155. settings,
  156. onUpdateSettings,
  157. }: {
  158. management: ISourceServerManagementService;
  159. targetSourceServerId?: string;
  160. targetSourceServerDetails?: boolean;
  161. onTargetSourceServerFocused?: () => void;
  162. onCreateConnection?: () => void;
  163. /** 用户点击连接时交给 Root 的全局弹窗,以 preferredProfileId 直达第 4 步。 */
  164. onConnectProfile?: (profileId: string) => Promise<void> | void;
  165. /** 用户断开设备时交给 Root 的统一 RemoteWorkspaceController。 */
  166. onDisconnectSource?: (sourceServerId: string) => Promise<void>;
  167. /** 「在侧边栏中显示」菜单项:返回工作区主界面(侧边栏设备分组所在处)。 */
  168. onShowInSidebar?: (sourceServerId: string) => void;
  169. onOpenProject?: (sourceServerId: string, path: string, profileId?: string) => Promise<void>;
  170. onShowUpdateDetails?: (sourceServerId: string) => void;
  171. workspaceTabs?: WorkspaceTabState[];
  172. /** 「新任务」按钮(原型 L763):激活该设备已打开的 workspace tab 并开新草稿。 */
  173. /** 有已打开 workspace tab 的设备 id 集合;「新任务」仅对这些设备渲染。 */
  174. settings?: Pick<
  175. AppSettings,
  176. "remoteStartupAutoReconnectEnabled" | "remoteConversationWorkspaceBySourceServerId"
  177. > | null;
  178. onUpdateSettings?: (patch: Partial<AppSettings>) => Promise<unknown> | void;
  179. }) {
  180. const background = useRemoteConnectionProgress();
  181. const { intl, locale } = useZCodeIntl();
  182. const confirmDialog = useConfirmDialog();
  183. const platform = useOptionalPlatform();
  184. const deferredUpdates = useDeferredSourceServerUpdates();
  185. const [startupAutoReconnect, setStartupAutoReconnect] = useState(
  186. settings?.remoteStartupAutoReconnectEnabled ?? true,
  187. );
  188. useEffect(() => {
  189. setStartupAutoReconnect(settings?.remoteStartupAutoReconnectEnabled ?? true);
  190. }, [settings?.remoteStartupAutoReconnectEnabled]);
  191. const [editingConnection, setEditingConnection] = useState<{
  192. profile: ConnectionProfile;
  193. server?: SourceServerRecord;
  194. focusField?: "host" | "auth";
  195. } | null>(null);
  196. const [errorDetailsProfile, setErrorDetailsProfile] = useState<ConnectionProfile | null>(null);
  197. const [expandedSavedConnectionSources, setExpandedSavedConnectionSources] = useState<Set<string>>(
  198. new Set(),
  199. );
  200. const [expandedProjectSources, setExpandedProjectSources] = useState<Set<string>>(new Set());
  201. // 只记录用户手动切换过的日志展开状态;未切换时由设备是否失败决定默认值。
  202. const [logExpansionBySource, setLogExpansionBySource] = useState<ReadonlyMap<string, boolean>>(
  203. new Map(),
  204. );
  205. // 这里只拥有面板操作的防重状态;业务状态与快照版本仍由 Host 和快照 hook 负责。
  206. const operationsRef = useRef(new Map<string, readonly string[]>());
  207. const [busyOperations, setBusyOperations] = useState<ReadonlyMap<string, readonly string[]>>(
  208. new Map(),
  209. );
  210. const busyScopes = new Set([...busyOperations.values()].flat());
  211. if (background?.sourceServerId) busyScopes.add(`source:${background.sourceServerId}`);
  212. else if (background?.profileId) busyScopes.add(`profile:${background.profileId}`);
  213. const hasBusyScope = useCallback(
  214. (scope: string) => [...operationsRef.current.values()].some((scopes) => scopes.includes(scope)),
  215. [],
  216. );
  217. const mountedRef = useRef(true);
  218. useEffect(() => {
  219. mountedRef.current = true;
  220. return () => {
  221. mountedRef.current = false;
  222. };
  223. }, []);
  224. // 相对时间必须随时钟更新,不能依赖连接事件才重绘。
  225. const [, setClockTick] = useState(0);
  226. useEffect(() => {
  227. const timer = setInterval(() => setClockTick((tick) => tick + 1), 60_000);
  228. return () => clearInterval(timer);
  229. }, []);
  230. const [error, setError] = useState<string | null>(null);
  231. const [migrationReports, setMigrationReports] = useState<
  232. Record<string, SourceServerMigrationReport | undefined>
  233. >({});
  234. const {
  235. snapshot,
  236. ready,
  237. applySnapshot,
  238. refresh: refreshSnapshot,
  239. } = useSourceServerManagementSnapshot(management, {
  240. onError: (cause) => setError(getSourceServerManagementErrorMessage(cause, intl.formatMessage)),
  241. });
  242. const focusedTargetRef = useRef<string | undefined>(undefined);
  243. const deviceCardsRef = useRef(new Map<string, HTMLElement>());
  244. useEffect(() => {
  245. if (!targetSourceServerId) {
  246. focusedTargetRef.current = undefined;
  247. return;
  248. }
  249. const targetKey = `${targetSourceServerId}:${targetSourceServerDetails}`;
  250. if (!ready || focusedTargetRef.current === targetKey) return;
  251. const card = deviceCardsRef.current.get(targetSourceServerId);
  252. if (!card) return;
  253. card.scrollIntoView({ block: "center" });
  254. card.focus({ preventScroll: true });
  255. const failedProfileId = snapshot?.states.find(
  256. (state) => state.sourceServerId === targetSourceServerId && state.state === "failed",
  257. )?.profileId;
  258. const failedProfile = snapshot?.profiles.find(
  259. (profile) => profile.profileId === failedProfileId,
  260. );
  261. if (targetSourceServerDetails && failedProfile) setErrorDetailsProfile(failedProfile);
  262. focusedTargetRef.current = targetKey;
  263. onTargetSourceServerFocused?.();
  264. }, [
  265. ready,
  266. snapshot,
  267. targetSourceServerId,
  268. targetSourceServerDetails,
  269. onTargetSourceServerFocused,
  270. ]);
  271. const { logsByProfileId } = useSourceServerOperationLogs(
  272. management,
  273. snapshot?.profiles.map((profile) => profile.profileId),
  274. );
  275. const projection = useMemo(
  276. () =>
  277. buildRemoteWorkspaceProjection({
  278. managementSnapshot: snapshot,
  279. tabs: [],
  280. remoteConversationWorkspaceBySourceServerId:
  281. settings?.remoteConversationWorkspaceBySourceServerId,
  282. }),
  283. [snapshot, settings?.remoteConversationWorkspaceBySourceServerId],
  284. );
  285. const refresh = useCallback(async () => {
  286. refreshSnapshot();
  287. }, [refreshSnapshot]);
  288. const stateByProfile = useMemo(
  289. () => new Map(snapshot?.states.map((state) => [state.profileId, state]) ?? []),
  290. [snapshot?.states],
  291. );
  292. const run = useCallback(
  293. async (
  294. key: string,
  295. operation: () => Promise<SourceServerManagementSnapshot | void>,
  296. scopes: readonly string[] = [key],
  297. ) => {
  298. // 同设备的不同连接互斥;无关设备和日志查看独立,不用全局锁阻塞长时间更新。
  299. if (operationsRef.current.has(key) || scopes.some(hasBusyScope)) return;
  300. operationsRef.current.set(key, scopes);
  301. setBusyOperations(new Map(operationsRef.current));
  302. setError(null);
  303. try {
  304. const nextSnapshot = await operation();
  305. if (nextSnapshot) applySnapshot(nextSnapshot);
  306. else refreshSnapshot();
  307. } catch (cause) {
  308. setError(getSourceServerManagementErrorMessage(cause, intl.formatMessage));
  309. } finally {
  310. operationsRef.current.delete(key);
  311. setBusyOperations(new Map(operationsRef.current));
  312. }
  313. },
  314. [applySnapshot, refreshSnapshot, intl, hasBusyScope],
  315. );
  316. const removeProfile = useCallback(
  317. async (profile: ConnectionProfile) => {
  318. if (!management) return;
  319. const confirmed = await confirmDialog({
  320. title: intl.formatMessage({ id: "settings.source.removeProfileTitle" }),
  321. description: intl.formatMessage(
  322. { id: "settings.source.removeProfileDescription" },
  323. { name: profile.displayName ?? profile.transport },
  324. ),
  325. confirmLabel: intl.formatMessage({
  326. id: "settings.source.removeProfile",
  327. }),
  328. confirmVariant: "destructive",
  329. });
  330. if (!confirmed) return;
  331. await run(`remove:${profile.profileId}`, () => management.removeProfile(profile.profileId), [
  332. profileOperationScope(profile),
  333. ]);
  334. },
  335. [confirmDialog, intl, management, run],
  336. );
  337. const removeSourceServer = useCallback(
  338. async (server: SourceServerRecord) => {
  339. if (hasBusyScope(`source:${server.sourceServerId}`)) return;
  340. const affectedProjects = workspaceTabs.filter(
  341. (tab) =>
  342. getWorkspaceSourceServerId(tab, { workspaceHistory: snapshot?.workspaceHistory }) ===
  343. server.sourceServerId,
  344. );
  345. const projectNotice =
  346. affectedProjects.length > 0
  347. ? intl.formatMessage(
  348. { id: "settings.source.removeOpenProjects" },
  349. {
  350. projects: affectedProjects
  351. .map((tab) => `${tab.label} (${tab.workspacePath})`)
  352. .join("\n"),
  353. },
  354. )
  355. : intl.formatMessage({ id: "settings.source.noOpenProjects" });
  356. const confirmed = await confirmDialog({
  357. title: intl.formatMessage({
  358. id: "settings.source.removeSourceServer",
  359. }),
  360. description:
  361. intl.formatMessage(
  362. { id: "settings.source.removeSourceServerDescription" },
  363. { name: server.displayName },
  364. ) +
  365. "\n\n" +
  366. projectNotice,
  367. confirmLabel: intl.formatMessage({
  368. id: "settings.source.removeSourceServer",
  369. }),
  370. confirmVariant: "destructive",
  371. });
  372. if (!confirmed) return;
  373. await run(
  374. `remove-source:${server.sourceServerId}`,
  375. () => management.removeSourceServer(server.sourceServerId),
  376. [`source:${server.sourceServerId}`],
  377. );
  378. },
  379. [confirmDialog, intl, management, run, snapshot?.workspaceHistory, workspaceTabs, hasBusyScope],
  380. );
  381. const loadMigrationReport = useCallback(
  382. async (sourceServerId: string) => {
  383. if (!management) return;
  384. await run(`report:${sourceServerId}`, async () => {
  385. const report = await management.getMigrationReport(sourceServerId);
  386. setMigrationReports((current) => ({ ...current, [sourceServerId]: report }));
  387. });
  388. },
  389. [management, run],
  390. );
  391. const toggleMigrationReport = useCallback(
  392. (sourceServerId: string) => {
  393. if (migrationReports[sourceServerId]) {
  394. setMigrationReports((current) => {
  395. const next = { ...current };
  396. delete next[sourceServerId];
  397. return next;
  398. });
  399. return;
  400. }
  401. void loadMigrationReport(sourceServerId);
  402. },
  403. [loadMigrationReport, migrationReports],
  404. );
  405. const runMigrationOperation = useCallback(
  406. async (
  407. key: string,
  408. sourceServerId: string,
  409. operation: () => Promise<SourceServerMigrationReport>,
  410. ) => {
  411. await run(key, async () => {
  412. const report = await operation();
  413. setMigrationReports((current) => ({ ...current, [sourceServerId]: report }));
  414. }, [`source:${sourceServerId}`]);
  415. },
  416. [run],
  417. );
  418. const updateProfile = useCallback(
  419. async (profile: ConnectionProfile) => {
  420. await run(
  421. `update:${profile.profileId}`,
  422. async () => {
  423. let next: SourceServerManagementSnapshot | null;
  424. try {
  425. next = await runSourceServerUpdate({
  426. management,
  427. profileId: profile.profileId,
  428. confirmForce: async () =>
  429. await confirmDialog({
  430. title: intl.formatMessage({
  431. id: "settings.source.forceUpdateTitle",
  432. }),
  433. description: await getSourceServerForceUpdateDescription(
  434. management,
  435. profile.profileId,
  436. (id) => intl.formatMessage({ id }),
  437. ),
  438. confirmLabel: intl.formatMessage({
  439. id: "settings.source.forceUpdate",
  440. }),
  441. confirmVariant: "destructive",
  442. }),
  443. });
  444. } catch (cause) {
  445. toast(
  446. intl.formatMessage(
  447. { id: "sourceServer.updateFailedToast" },
  448. { source: profile.displayName ?? profile.transport },
  449. ),
  450. {
  451. variant: "warning",
  452. actionLabel: intl.formatMessage({ id: "remote.action.details" }),
  453. onAction: () => {
  454. // 更新可跨面板生命周期完成,不能让全局 toast 捕获已卸载组件的 setter。
  455. if (mountedRef.current) setErrorDetailsProfile(profile);
  456. else if (profile.sourceServerId) onShowUpdateDetails?.(profile.sourceServerId);
  457. },
  458. },
  459. );
  460. throw cause;
  461. }
  462. if (next)
  463. toast(
  464. intl.formatMessage(
  465. { id: "sourceServer.updateCompletedToast" },
  466. { source: profile.displayName ?? profile.transport },
  467. ),
  468. { variant: "source-server-update" },
  469. );
  470. return next ?? undefined;
  471. },
  472. [profileOperationScope(profile)],
  473. );
  474. },
  475. [confirmDialog, intl, management, onShowUpdateDetails, run],
  476. );
  477. const servers = snapshot?.servers ?? [];
  478. const profiles = snapshot?.profiles ?? [];
  479. const activeProfiles = profiles.filter((profile) => profile.lifecycleState !== "retired");
  480. const retiredProfiles = profiles.filter((profile) => profile.lifecycleState === "retired");
  481. const unboundProfiles = activeProfiles.filter((profile) => !profile.sourceServerId);
  482. const renderIdentityConfirmation = (profile: ConnectionProfile, size: "sm" | "xs") => (
  483. <Button
  484. type="button"
  485. variant="outline"
  486. size={size}
  487. disabled={
  488. busyScopes.has(profileOperationScope(profile)) ||
  489. stateByProfile.get(profile.profileId)?.state === "updating"
  490. }
  491. onClick={() =>
  492. void confirmDialog({
  493. title: intl.formatMessage({ id: "settings.source.identityChangeTitle" }),
  494. description: intl.formatMessage({ id: "settings.source.identityChangeDescription" }),
  495. confirmLabel: intl.formatMessage({ id: "settings.source.identityChangeConfirm" }),
  496. }).then((confirmed) =>
  497. confirmed
  498. ? run(
  499. `identity:${profile.profileId}`,
  500. () => management.confirmIdentityChange(profile.profileId),
  501. [profileOperationScope(profile)],
  502. )
  503. : undefined,
  504. )
  505. }
  506. >
  507. {busyOperations.has(`identity:${profile.profileId}`) ? (
  508. <Loader2 className="size-3.5 animate-spin" aria-hidden="true" />
  509. ) : null}
  510. {intl.formatMessage({ id: "settings.source.identityChangeConfirm" })}
  511. </Button>
  512. );
  513. const handleProfileAction = (
  514. profile: ConnectionProfile,
  515. presentation: RemoteConnectionPresentation,
  516. server?: SourceServerRecord,
  517. ) => {
  518. if (
  519. !["security", "details"].includes(presentation.primaryAction) &&
  520. hasBusyScope(profileOperationScope(profile))
  521. )
  522. return;
  523. switch (presentation.primaryAction) {
  524. case "update-desktop":
  525. void run("desktop-update", async () => {
  526. await platform?.executeDesktopCommand(DesktopCommandIds.CheckForUpdates);
  527. });
  528. return;
  529. case "update-server":
  530. void updateProfile(profile);
  531. return;
  532. case "disconnect":
  533. if (profile.sourceServerId && onDisconnectSource)
  534. void run(
  535. `disconnect:${profile.sourceServerId}`,
  536. () => onDisconnectSource(profile.sourceServerId!),
  537. [profileOperationScope(profile)],
  538. );
  539. return;
  540. case "credentials":
  541. case "edit-auth":
  542. setEditingConnection({ profile, server, focusField: "auth" });
  543. return;
  544. case "edit-host":
  545. setEditingConnection({ profile, server, focusField: "host" });
  546. return;
  547. case "security":
  548. case "details":
  549. setErrorDetailsProfile(profile);
  550. return;
  551. case "none":
  552. return;
  553. default:
  554. void run(
  555. `connect:${profile.profileId}`,
  556. async () => {
  557. await onConnectProfile?.(profile.profileId);
  558. },
  559. [profileOperationScope(profile)],
  560. );
  561. }
  562. };
  563. const renderProfile = (profile: ConnectionProfile, server?: SourceServerRecord) => {
  564. const state = stateByProfile.get(profile.profileId);
  565. const isOnline = state?.state === "online";
  566. const identityChangePending = state?.state === "identity-change-pending";
  567. const profileName = profile.displayName ?? profile.transport;
  568. const presentation = resolveRemoteConnectionPresentation({ ...state, target: profile.target });
  569. const mutationBusy =
  570. busyScopes.has(profileOperationScope(profile)) || presentation.status === "connecting";
  571. const actionBusy =
  572. mutationBusy && !["security", "details"].includes(presentation.primaryAction);
  573. const devicePresentation = server
  574. ? resolveRemoteConnectionPresentation(
  575. getRemoteDevicePresentationInput(snapshot, server.sourceServerId),
  576. )
  577. : null;
  578. const connectionErrorText =
  579. presentation.reason && devicePresentation?.profileId !== profile.profileId
  580. ? intl.formatMessage({ id: presentation.reason.titleId }, presentation.reason.values)
  581. : null;
  582. return (
  583. <div
  584. key={profile.profileId}
  585. className="group/line -mx-2 flex min-w-0 flex-wrap items-center gap-2.5 rounded-md px-2 py-1.5 hover:bg-hover"
  586. >
  587. <RemoteConnectionKindTag kind={profile.transport} />
  588. {!server ? <RemoteConnectionStatusTag presentation={presentation} /> : null}
  589. <span className="shrink-0 text-ui-sm font-medium text-foreground">{profileName}</span>
  590. <span className="min-w-0 truncate font-mono text-ui-xs text-remote-foreground-muted">
  591. {formatConnectionProfileTarget(profile)}
  592. </span>
  593. {server?.preferredProfileId === profile.profileId ? (
  594. <span className="shrink-0 rounded-md bg-tag px-2 py-0.5 text-ui-xs text-remote-foreground-muted">
  595. {intl.formatMessage({ id: "settings.source.defaultProfile" })}
  596. </span>
  597. ) : null}
  598. <span className="ml-auto flex min-w-0 flex-wrap items-center gap-2">
  599. {connectionErrorText ? (
  600. <span
  601. className="max-w-64 truncate text-ui-xs text-destructive-surface-foreground"
  602. title={connectionErrorText}
  603. >
  604. {connectionErrorText}
  605. </span>
  606. ) : profile.lastConnectedAt ? (
  607. <span
  608. className="text-ui-xs text-remote-foreground-muted"
  609. title={formatTimestamp(profile.lastConnectedAt, locale)}
  610. >
  611. {intl.formatMessage(
  612. { id: "settings.source.lastConnected" },
  613. {
  614. time: formatRelativeTimestamp(
  615. profile.lastConnectedAt,
  616. locale,
  617. intl.formatMessage,
  618. ),
  619. },
  620. )}
  621. </span>
  622. ) : null}
  623. {!isOnline && !identityChangePending ? (
  624. <Button
  625. type="button"
  626. variant="outline"
  627. size="xs"
  628. disabled={actionBusy}
  629. onClick={() =>
  630. handleProfileAction(
  631. profile,
  632. resolveRemoteConnectionPresentation({
  633. ...stateByProfile.get(profile.profileId),
  634. target: profile.target,
  635. }),
  636. )
  637. }
  638. >
  639. {intl.formatMessage({
  640. id: resolveRemoteConnectionPresentation({ ...state, target: profile.target })
  641. .actionMessageId,
  642. })}
  643. </Button>
  644. ) : null}
  645. {identityChangePending ? renderIdentityConfirmation(profile, "xs") : null}
  646. <Button
  647. type="button"
  648. variant="ghost"
  649. size="xs"
  650. aria-label={intl.formatMessage({
  651. id: "settings.source.editConnection",
  652. })}
  653. disabled={busyScopes.has(profileOperationScope(profile))}
  654. onClick={() => setEditingConnection({ profile })}
  655. >
  656. <Pencil className="size-3.5" />
  657. {intl.formatMessage({ id: "settings.source.editConnection" })}
  658. </Button>
  659. {server && server.preferredProfileId !== profile.profileId ? (
  660. <Button
  661. type="button"
  662. variant="ghost"
  663. size="xs"
  664. disabled={mutationBusy}
  665. onClick={() =>
  666. void run(
  667. `preferred:${profile.profileId}`,
  668. () => management.setPreferredProfile(server.sourceServerId, profile.profileId),
  669. [profileOperationScope(profile)],
  670. )
  671. }
  672. >
  673. {intl.formatMessage({ id: "settings.source.setDefault" })}
  674. </Button>
  675. ) : null}
  676. <Button
  677. type="button"
  678. variant="ghost"
  679. size="xs"
  680. disabled={mutationBusy}
  681. onClick={() => void removeProfile(profile)}
  682. >
  683. <Trash2 className="size-3.5" />
  684. {intl.formatMessage({ id: "settings.source.removeProfile" })}
  685. </Button>
  686. </span>
  687. </div>
  688. );
  689. };
  690. return (
  691. <div className="flex flex-col gap-4" aria-busy={busyOperations.size > 0}>
  692. <div className="flex flex-wrap items-start justify-between gap-3">
  693. <div className="min-w-0 max-w-xl">
  694. <p className="text-ui-sm text-remote-foreground-muted">
  695. {intl.formatMessage({ id: "settings.remoteDevicesDescription" })}
  696. </p>
  697. {error ? (
  698. <p role="alert" className="mt-2 text-ui-sm text-destructive">
  699. {error}
  700. </p>
  701. ) : null}
  702. </div>
  703. {onCreateConnection && (!ready || profiles.length > 0 || servers.length > 0) ? (
  704. <Button type="button" size="sm" onClick={onCreateConnection}>
  705. <Plus className="size-3.5" />
  706. {intl.formatMessage({ id: "settings.source.newConnection" })}
  707. </Button>
  708. ) : null}
  709. </div>
  710. {background &&
  711. !servers.some((server) => server.sourceServerId === background.sourceServerId) &&
  712. !unboundProfiles.some((profile) => profile.profileId === background.profileId) ? (
  713. <section
  714. data-unfinished-background-connection
  715. className="rounded-xl border border-card-border bg-card pt-3"
  716. >
  717. <p className="px-4 text-ui-sm font-medium">
  718. {intl.formatMessage({ id: "settings.source.unfinishedConnections" })}
  719. </p>
  720. <RemoteConnectionMinimizedProgress {...background} />
  721. </section>
  722. ) : null}
  723. {!ready && !error ? (
  724. <p
  725. role="status"
  726. className="flex items-center gap-2 text-ui-sm text-remote-foreground-muted"
  727. >
  728. <Loader2 className="size-4 animate-spin" aria-hidden="true" />
  729. {intl.formatMessage({ id: "common.loading" })}
  730. </p>
  731. ) : null}
  732. <div className="min-w-0 space-y-3">
  733. {servers.length > 0 ? (
  734. <h3 className="flex items-center gap-2 text-ui-base font-medium text-foreground">
  735. {intl.formatMessage({ id: "settings.source.devicesHeading" })}
  736. <span className="text-ui-xs font-normal text-remote-foreground-muted">
  737. {servers.length}
  738. </span>
  739. </h3>
  740. ) : null}
  741. {servers.map((server) => {
  742. const device = projection.devices.find(
  743. (candidate) => candidate.sourceServerId === server.sourceServerId,
  744. );
  745. const serverProfiles = device?.profiles ?? [];
  746. const preferredProfile =
  747. serverProfiles.find((profile) => profile.profileId === server.preferredProfileId) ??
  748. serverProfiles[0];
  749. // 旧 Source 在确认前仍可能是 uninstalled;恢复入口不能藏在安装状态或首选线路折叠后面。
  750. const pendingIdentityProfiles = serverProfiles.filter(
  751. (profile) => stateByProfile.get(profile.profileId)?.state === "identity-change-pending",
  752. );
  753. const identityChangeProfile =
  754. pendingIdentityProfiles.find((profile) => profile === preferredProfile) ??
  755. pendingIdentityProfiles[0];
  756. const currentProfile = serverProfiles.find(
  757. (profile) => stateByProfile.get(profile.profileId)?.state === "online",
  758. );
  759. const displayedProfile = currentProfile ?? preferredProfile;
  760. const ConnectionIcon =
  761. displayedProfile?.transport === "docker"
  762. ? Box
  763. : displayedProfile?.transport === "wsl"
  764. ? TerminalSquare
  765. : Server;
  766. // 同一项目可能有多条历史(不同连接),保留最近一次,并按最近打开倒序展示。
  767. const latestProjectByKey = new Map<string, SourceServerWorkspaceHistoryEntry>();
  768. for (const project of device?.knownProjects ?? []) {
  769. const key = resolveWorkspaceKey(project);
  770. const existing = latestProjectByKey.get(key);
  771. if (!existing || project.lastOpenedAt >= existing.lastOpenedAt)
  772. latestProjectByKey.set(key, project);
  773. }
  774. const projects = [...latestProjectByKey.values()].sort(
  775. (left, right) => right.lastOpenedAt - left.lastOpenedAt,
  776. );
  777. const projectsExpanded = expandedProjectSources.has(server.sourceServerId);
  778. const visibleProjects = projectsExpanded
  779. ? projects
  780. : projects.slice(0, COLLAPSED_PROJECT_COUNT);
  781. const openedProjectPaths = new Set(
  782. workspaceTabs
  783. .filter(
  784. (tab) =>
  785. getWorkspaceSourceServerId(tab, {
  786. workspaceHistory: snapshot?.workspaceHistory,
  787. }) === server.sourceServerId,
  788. )
  789. .map((tab) => tab.workspacePath),
  790. );
  791. const otherProfiles = displayedProfile
  792. ? serverProfiles.filter(
  793. (profile) =>
  794. profile !== displayedProfile && !pendingIdentityProfiles.includes(profile),
  795. )
  796. : [];
  797. const online = device?.aggregatedStatus === "online";
  798. const migrationReport = migrationReports[server.sourceServerId];
  799. const migrationCount = snapshot?.migrationCounts.find(
  800. (count) => count.sourceServerId === server.sourceServerId,
  801. );
  802. const showServerLines = server.installState !== "uninstalled";
  803. // 覆盖可更新/必须升级/更新中/更新失败四态:更新中不再携带 updateAvailability,也要选中。
  804. const profileStates = serverProfiles
  805. .map((profile) => stateByProfile.get(profile.profileId))
  806. .filter((state) => state !== undefined);
  807. const presentation = resolveRemoteConnectionPresentation(
  808. getRemoteDevicePresentationInput(snapshot, server.sourceServerId),
  809. );
  810. const actionProfile =
  811. serverProfiles.find((profile) => profile.profileId === presentation.profileId) ??
  812. preferredProfile;
  813. const deviceBusy = busyScopes.has(`source:${server.sourceServerId}`);
  814. const actionBusy =
  815. busyOperations.has(`disconnect:${server.sourceServerId}`) ||
  816. busyOperations.has(`connect:${actionProfile?.profileId}`) ||
  817. busyOperations.has(`update:${actionProfile?.profileId}`) ||
  818. (busyOperations.has("desktop-update") &&
  819. presentation.primaryAction === "update-desktop");
  820. const preferredConnectionErrorText = presentation.reason
  821. ? intl.formatMessage({ id: presentation.reason.titleId }, presentation.reason.values)
  822. : null;
  823. const serverState =
  824. profileStates.find((state) => state.state === "updating") ??
  825. profileStates.find(
  826. (state) =>
  827. (state.updateAvailability && state.updateAvailability !== "none") ||
  828. state.state === "updating",
  829. );
  830. const updateFailed = serverState?.state === "failed";
  831. const updateKey = sourceServerUpdateKey(
  832. server.sourceServerId,
  833. serverState?.availableVersion ?? "",
  834. );
  835. const showUpdate =
  836. serverState &&
  837. !(
  838. serverState.updateAvailability === "available" &&
  839. serverState.state !== "updating" &&
  840. deferredUpdates.has(updateKey)
  841. );
  842. const updateFailureText =
  843. updateFailed && serverState
  844. ? formatRemoteConnectionError({
  845. fallback: intl.formatMessage({ id: "settings.source.operationFailed" }),
  846. reasonCode: serverState.errorCode,
  847. retryable: serverState.retryable,
  848. recoveryAttempt: serverState.recoveryAttempt,
  849. recoveryLimit: serverState.recoveryLimit,
  850. formatMessage: intl.formatMessage,
  851. })
  852. : null;
  853. const updateExplainsConnectionError = Boolean(
  854. showUpdate &&
  855. serverState?.profileId === presentation.profileId &&
  856. (serverState?.state === "updating" ||
  857. (updateFailed && updateFailureText === preferredConnectionErrorText) ||
  858. (serverState?.updateAvailability === "required" &&
  859. presentation.reason?.category === "source-server-upgrade-required")),
  860. );
  861. const operationLogs =
  862. logsByProfileId[serverState?.profileId ?? actionProfile?.profileId ?? ""] ?? [];
  863. const showOtherProfiles = showServerLines && otherProfiles.length > 0;
  864. const otherProfilesExpanded =
  865. showOtherProfiles && expandedSavedConnectionSources.has(server.sourceServerId);
  866. // 更新中由更新横幅展示进度与日志,页脚不重复。
  867. const showRecentLog = operationLogs.length > 0 && serverState?.state !== "updating";
  868. const logExpanded =
  869. showRecentLog &&
  870. (logExpansionBySource.get(server.sourceServerId) ?? presentation.status === "failed");
  871. return (
  872. <section
  873. key={server.sourceServerId}
  874. data-source-server-card={server.sourceServerId}
  875. tabIndex={-1}
  876. ref={(element) => {
  877. if (element) deviceCardsRef.current.set(server.sourceServerId, element);
  878. else deviceCardsRef.current.delete(server.sourceServerId);
  879. }}
  880. className="overflow-hidden rounded-xl border border-card-border bg-card focus-visible:outline-2 focus-visible:outline-ring"
  881. >
  882. {background?.sourceServerId === server.sourceServerId ? (
  883. <RemoteConnectionMinimizedProgress {...background} />
  884. ) : null}
  885. <div className="flex min-w-0 flex-wrap items-center gap-3 px-4 py-4">
  886. <span
  887. className={cn(
  888. "flex size-10 shrink-0 items-center justify-center rounded-lg bg-surface text-remote-foreground-muted",
  889. server.installState === "uninstalled" && "opacity-60",
  890. )}
  891. >
  892. <ConnectionIcon className="size-4" />
  893. </span>
  894. <div className="min-w-0 flex-1">
  895. <div className="flex min-w-0 flex-wrap items-center gap-2">
  896. <p className="min-w-0 truncate text-ui-base font-semibold text-foreground">
  897. {server.displayName}
  898. </p>
  899. <RemoteConnectionStatusTag presentation={presentation} />
  900. </div>
  901. </div>
  902. <div
  903. className="order-2 basis-full min-w-0 flex flex-wrap items-center gap-2 text-ui-sm text-remote-foreground-muted"
  904. data-device-connection
  905. >
  906. {displayedProfile ? (
  907. <>
  908. <RemoteConnectionKindTag kind={displayedProfile.transport} />
  909. <span
  910. className="min-w-0 truncate font-mono"
  911. title={formatConnectionProfileTarget(displayedProfile)}
  912. >
  913. {formatConnectionProfileTarget(displayedProfile)}
  914. </span>
  915. {/* 只有一条连接时“当前 / 默认”没有区分意义,不显示。 */}
  916. {serverProfiles.length > 1 && currentProfile ? (
  917. <span className="shrink-0 rounded-md bg-tag px-1.5 py-0.5 text-ui-xs">
  918. {intl.formatMessage({
  919. id: "settings.source.currentProfile",
  920. })}
  921. </span>
  922. ) : null}
  923. {serverProfiles.length > 1 &&
  924. displayedProfile.profileId === server.preferredProfileId ? (
  925. <span className="shrink-0 rounded-md bg-tag px-1.5 py-0.5 text-ui-xs">
  926. {intl.formatMessage({ id: "settings.source.defaultProfile" })}
  927. </span>
  928. ) : null}
  929. {displayedProfile.profileId !== server.preferredProfileId ? (
  930. <Button
  931. type="button"
  932. variant="ghost"
  933. size="xs"
  934. disabled={deviceBusy}
  935. onClick={() =>
  936. void run(
  937. `preferred:${displayedProfile.profileId}`,
  938. () =>
  939. management.setPreferredProfile(
  940. server.sourceServerId,
  941. displayedProfile.profileId,
  942. ),
  943. [`source:${server.sourceServerId}`],
  944. )
  945. }
  946. >
  947. {intl.formatMessage({ id: "settings.source.setDefault" })}
  948. </Button>
  949. ) : null}
  950. </>
  951. ) : null}
  952. {server.lastSeenVersion ? (
  953. <span
  954. className="shrink-0"
  955. title={intl.formatMessage({ id: "settings.source.info.version" })}
  956. >
  957. {displayedProfile ? "· " : ""}v{server.lastSeenVersion.replace(/^v/i, "")}
  958. </span>
  959. ) : null}
  960. {server.lastOnlineAt && !online ? (
  961. <span className="shrink-0" title={formatTimestamp(server.lastOnlineAt, locale)}>
  962. {displayedProfile || server.lastSeenVersion ? "· " : ""}
  963. {intl.formatMessage(
  964. { id: "settings.source.lastOnline" },
  965. {
  966. time: formatRelativeTimestamp(
  967. server.lastOnlineAt,
  968. locale,
  969. intl.formatMessage,
  970. ),
  971. },
  972. )}
  973. </span>
  974. ) : null}
  975. </div>
  976. <div className="order-3 basis-full min-w-0" data-device-projects>
  977. {projects.length === 0 ? (
  978. <p className="text-ui-sm text-remote-foreground-muted">
  979. {intl.formatMessage({ id: "settings.source.projectCount" }, { count: 0 })}
  980. </p>
  981. ) : (
  982. <>
  983. <div className="flex min-w-0 items-center justify-between gap-2">
  984. <p className="text-ui-xs font-medium text-remote-foreground-muted">
  985. {intl.formatMessage({ id: "settings.source.recentProjects" })}
  986. </p>
  987. {/* Bug 原因:旧实现超出三个只显示不可点击的 +N,其余项目在此处无法打开。 */}
  988. {projects.length > COLLAPSED_PROJECT_COUNT ? (
  989. <Button
  990. type="button"
  991. variant="ghost"
  992. size="xs"
  993. className="text-remote-foreground-muted"
  994. aria-expanded={projectsExpanded}
  995. onClick={() =>
  996. setExpandedProjectSources((current) =>
  997. toggleSetItem(current, server.sourceServerId),
  998. )
  999. }
  1000. >
  1001. {intl.formatMessage(
  1002. {
  1003. id: projectsExpanded
  1004. ? "settings.source.showLessProjects"
  1005. : "settings.source.showAllProjects",
  1006. },
  1007. { count: projects.length },
  1008. )}
  1009. </Button>
  1010. ) : null}
  1011. </div>
  1012. <div className="mt-1 min-w-0">
  1013. {visibleProjects.map((project) => {
  1014. const projectName =
  1015. server.declaredWorkspaces?.find(
  1016. (item) => item.workspacePath === project.workspacePath,
  1017. )?.label ?? getPathLeaf(project.workspacePath);
  1018. return (
  1019. <Button
  1020. key={resolveWorkspaceKey(project)}
  1021. data-device-project
  1022. type="button"
  1023. variant="ghost"
  1024. size="sm"
  1025. className="group/project -mx-2 h-auto w-[calc(100%+1rem)] min-w-0 justify-start gap-2 px-2 py-1.5"
  1026. aria-label={projectName}
  1027. title={project.workspacePath}
  1028. disabled={!onOpenProject || deviceBusy}
  1029. onClick={() =>
  1030. void run(
  1031. `open:${resolveWorkspaceKey(project)}`,
  1032. () =>
  1033. onOpenProject?.(
  1034. server.sourceServerId,
  1035. project.workspacePath,
  1036. displayedProfile?.profileId,
  1037. ) ?? Promise.resolve(),
  1038. [`source:${server.sourceServerId}`],
  1039. )
  1040. }
  1041. >
  1042. <Folder className="size-3.5 text-remote-foreground-muted" />
  1043. <span className="max-w-48 shrink-0 truncate text-ui-sm font-medium">
  1044. {projectName}
  1045. </span>
  1046. <span className="min-w-0 flex-1 truncate text-left font-mono text-ui-xs text-remote-foreground-muted">
  1047. {project.workspacePath}
  1048. </span>
  1049. {openedProjectPaths.has(project.workspacePath) ? (
  1050. <span className="shrink-0 rounded-md bg-tag px-1.5 py-0.5 text-ui-xs text-remote-foreground-muted">
  1051. {intl.formatMessage({ id: "settings.source.projectOpened" })}
  1052. </span>
  1053. ) : null}
  1054. <span className="shrink-0 text-ui-xs text-remote-foreground-muted">
  1055. {formatRelativeTimestamp(
  1056. project.lastOpenedAt,
  1057. locale,
  1058. intl.formatMessage,
  1059. )}
  1060. </span>
  1061. <ArrowUpRight className="size-3.5 text-remote-foreground-muted opacity-0 group-hover/project:opacity-100 group-focus-visible/project:opacity-100" />
  1062. </Button>
  1063. );
  1064. })}
  1065. </div>
  1066. </>
  1067. )}
  1068. </div>
  1069. <div className="order-1 ml-auto flex flex-wrap items-center gap-1">
  1070. {presentation.primaryAction === "confirm-identity" && identityChangeProfile ? (
  1071. renderIdentityConfirmation(identityChangeProfile, "sm")
  1072. ) : presentation.primaryAction !== "none" ? (
  1073. <Button
  1074. type="button"
  1075. // 已连接时断开是低频操作,降为 ghost;任务继续提示放进按钮说明,不常驻占行。
  1076. variant={presentation.primaryAction === "disconnect" ? "ghost" : "outline"}
  1077. size="sm"
  1078. title={
  1079. presentation.primaryAction === "disconnect"
  1080. ? intl.formatMessage({ id: "settings.source.disconnectHint" })
  1081. : undefined
  1082. }
  1083. disabled={
  1084. (deviceBusy &&
  1085. !["security", "details"].includes(presentation.primaryAction)) ||
  1086. actionBusy ||
  1087. presentation.status === "connecting"
  1088. }
  1089. aria-busy={actionBusy}
  1090. onClick={() => {
  1091. if (actionProfile) handleProfileAction(actionProfile, presentation, server);
  1092. else onCreateConnection?.();
  1093. }}
  1094. >
  1095. {actionBusy ? (
  1096. <Loader2 className="size-3.5 animate-spin" aria-hidden="true" />
  1097. ) : null}
  1098. {intl.formatMessage({
  1099. id:
  1100. server.installState === "uninstalled" &&
  1101. presentation.primaryAction === "install"
  1102. ? "settings.source.reinstallAndConnect"
  1103. : presentation.actionMessageId,
  1104. })}
  1105. </Button>
  1106. ) : null}
  1107. {presentation.primaryAction === "update-desktop" && preferredProfile ? (
  1108. <Button
  1109. type="button"
  1110. variant="ghost"
  1111. size="sm"
  1112. disabled={deviceBusy}
  1113. aria-busy={busyOperations.has(`connect:${preferredProfile.profileId}`)}
  1114. onClick={() =>
  1115. void run(
  1116. `connect:${preferredProfile.profileId}`,
  1117. async () => {
  1118. await onConnectProfile?.(preferredProfile.profileId);
  1119. },
  1120. [profileOperationScope(preferredProfile)],
  1121. )
  1122. }
  1123. >
  1124. {busyOperations.has(`connect:${preferredProfile.profileId}`) ? (
  1125. <Loader2 className="size-3.5 animate-spin" aria-hidden="true" />
  1126. ) : null}
  1127. {intl.formatMessage({ id: "remote.action.connect" })}
  1128. </Button>
  1129. ) : null}
  1130. {displayedProfile ? (
  1131. <Button
  1132. type="button"
  1133. variant="ghost"
  1134. size="sm"
  1135. aria-label={intl.formatMessage({
  1136. id: "settings.source.editConnection",
  1137. })}
  1138. disabled={deviceBusy}
  1139. onClick={() =>
  1140. setEditingConnection({
  1141. profile: displayedProfile,
  1142. server,
  1143. })
  1144. }
  1145. >
  1146. <Pencil className="size-3.5" />
  1147. {intl.formatMessage({ id: "settings.source.editConnection" })}
  1148. </Button>
  1149. ) : null}
  1150. {
  1151. <DropdownMenu>
  1152. <DropdownMenuTrigger asChild>
  1153. <Button
  1154. type="button"
  1155. variant="ghost"
  1156. size="icon-sm"
  1157. aria-label={intl.formatMessage({ id: "common.more" })}
  1158. >
  1159. <Ellipsis className="size-3.5" />
  1160. </Button>
  1161. </DropdownMenuTrigger>
  1162. <DropdownMenuContent
  1163. align="end"
  1164. className="w-max min-w-64 [&_[data-slot=dropdown-menu-item]]:whitespace-nowrap"
  1165. >
  1166. {/*
  1167. Bug 原因:「移除全部连接」曾被包在 online 分支里,简化 UI 删掉离线态的
  1168. 「重命名 / 迁移报告」后离线菜单变成空壳,离线设备再无任何移除入口。
  1169. 移除只删本机记录与凭据,Host removeSourceServer 会先幂等断开再删记录,
  1170. 不依赖远端在线;因此对所有已安装状态都渲染,只有「在侧边栏中显示」保留在线条件。
  1171. */}
  1172. {onShowInSidebar &&
  1173. workspaceTabs.some(
  1174. (tab) =>
  1175. getWorkspaceSourceServerId(tab, {
  1176. workspaceHistory: snapshot?.workspaceHistory,
  1177. }) === server.sourceServerId,
  1178. ) ? (
  1179. <>
  1180. <DropdownMenuItem
  1181. onSelect={() => onShowInSidebar(server.sourceServerId)}
  1182. >
  1183. <ListTree className="size-3.5" />
  1184. {intl.formatMessage({
  1185. id: "settings.source.showInSidebar",
  1186. })}
  1187. </DropdownMenuItem>
  1188. <DropdownMenuSeparator />
  1189. </>
  1190. ) : null}
  1191. <div
  1192. className="max-w-80 space-y-1 px-2 py-2 text-ui-sm text-remote-foreground-muted"
  1193. data-device-info
  1194. >
  1195. {[
  1196. ["version", server.lastSeenVersion],
  1197. ["hostname", server.hostname],
  1198. ["osUser", server.osUser],
  1199. ["deviceId", server.sourceServerId],
  1200. ].map(([key, value]) => (
  1201. <p key={key} className="break-all whitespace-normal">
  1202. <span>
  1203. {intl.formatMessage({ id: `settings.source.info.${key}` })}:{" "}
  1204. </span>
  1205. {value ?? intl.formatMessage({ id: "remote.infoUnavailable" })}
  1206. </p>
  1207. ))}
  1208. </div>
  1209. <DropdownMenuItem
  1210. onSelect={() =>
  1211. void run(`copy:${server.sourceServerId}`, async () => {
  1212. await navigator.clipboard.writeText(server.sourceServerId);
  1213. })
  1214. }
  1215. >
  1216. <Copy className="size-3.5" />
  1217. {intl.formatMessage({ id: "settings.source.copyDeviceId" })}
  1218. </DropdownMenuItem>
  1219. <DropdownMenuSeparator />
  1220. <DropdownMenuItem
  1221. variant="destructive"
  1222. disabled={deviceBusy}
  1223. onSelect={() => void removeSourceServer(server)}
  1224. >
  1225. <Trash2 className="size-3.5" />
  1226. {intl.formatMessage({
  1227. id: "settings.source.removeSourceServer",
  1228. })}
  1229. </DropdownMenuItem>
  1230. </DropdownMenuContent>
  1231. </DropdownMenu>
  1232. }
  1233. </div>
  1234. </div>
  1235. {/* 更新失败只替代同一连接的相同原因,其他连接和可选更新不能吞掉连接错误。 */}
  1236. {preferredConnectionErrorText && !updateExplainsConnectionError ? (
  1237. <div className="mx-4 mb-3 rounded-md bg-destructive-surface px-3 py-2 text-ui-sm text-destructive-surface-foreground">
  1238. {preferredConnectionErrorText}
  1239. </div>
  1240. ) : null}
  1241. {showUpdate && serverState ? (
  1242. <div
  1243. className={cn(
  1244. "mx-4 mb-3 flex flex-wrap items-center justify-between gap-2 rounded-md px-3 py-2 text-ui-sm",
  1245. presentation.updateNotice.surface,
  1246. presentation.updateNotice.foreground,
  1247. )}
  1248. >
  1249. <span>
  1250. {serverState.state === "updating"
  1251. ? intl.formatMessage({
  1252. id: "settings.source.updateInProgress",
  1253. })
  1254. : updateFailed
  1255. ? updateFailureText
  1256. : serverState.updateAvailability === "required"
  1257. ? intl.formatMessage({
  1258. id: "settings.source.updateRequired",
  1259. })
  1260. : intl.formatMessage(
  1261. { id: "settings.source.updateAvailableVersion" },
  1262. {
  1263. version: serverState.availableVersion?.replace(/^v/i, "") ?? "",
  1264. },
  1265. )}
  1266. </span>
  1267. {serverState.updateAvailability === "available" &&
  1268. serverState.state !== "updating" ? (
  1269. <Button
  1270. type="button"
  1271. variant="ghost"
  1272. size="sm"
  1273. className="ml-auto"
  1274. onClick={() => sourceServerUpdatePreferences.defer(updateKey)}
  1275. >
  1276. {intl.formatMessage({ id: "updateDialog.later" })}
  1277. </Button>
  1278. ) : null}
  1279. {serverState.state !== "updating" &&
  1280. presentation.primaryAction !== "update-server" &&
  1281. presentation.primaryAction !== "update-desktop" ? (
  1282. <Button
  1283. type="button"
  1284. variant="outline"
  1285. size="sm"
  1286. disabled={deviceBusy || busyOperations.has("desktop-update")}
  1287. onClick={() => {
  1288. const profile = serverProfiles.find(
  1289. (candidate) => candidate.profileId === serverState.profileId,
  1290. );
  1291. if (serverState.upgradeTarget === "controller")
  1292. void run("desktop-update", async () => {
  1293. await platform?.executeDesktopCommand(
  1294. DesktopCommandIds.CheckForUpdates,
  1295. );
  1296. });
  1297. else if (profile) void updateProfile(profile);
  1298. }}
  1299. >
  1300. {intl.formatMessage({
  1301. id:
  1302. serverState.upgradeTarget === "controller"
  1303. ? "remote.action.update-desktop"
  1304. : updateFailed
  1305. ? "remote.action.retry"
  1306. : "remote.action.update-server",
  1307. })}
  1308. </Button>
  1309. ) : null}
  1310. {serverState.state === "updating" ? (
  1311. <SourceServerUpdateActivity
  1312. active={serverState.state === "updating"}
  1313. logs={operationLogs}
  1314. />
  1315. ) : serverState.currentVersion && serverState.minimumVersion ? (
  1316. <p className="basis-full text-ui-xs opacity-80">
  1317. {intl.formatMessage(
  1318. { id: "settings.source.versionDetails" },
  1319. {
  1320. current: serverState.currentVersion.replace(/^v/i, ""),
  1321. minimum: serverState.minimumVersion.replace(/^v/i, ""),
  1322. },
  1323. )}
  1324. </p>
  1325. ) : null}
  1326. </div>
  1327. ) : null}
  1328. {pendingIdentityProfiles.length > 1 ? (
  1329. <div className="border-t border-border px-4 py-2">
  1330. {pendingIdentityProfiles
  1331. .filter((profile) => profile !== identityChangeProfile)
  1332. .map((profile) => renderProfile(profile, server))}
  1333. </div>
  1334. ) : null}
  1335. {showOtherProfiles || showRecentLog ? (
  1336. <div className="border-t border-border px-4 py-2" data-device-card-footer>
  1337. <div className="flex min-w-0 flex-wrap items-center gap-2">
  1338. {showOtherProfiles ? (
  1339. <Button
  1340. type="button"
  1341. variant="ghost"
  1342. size="sm"
  1343. className="-ml-2 text-remote-foreground-muted"
  1344. aria-label={intl.formatMessage({
  1345. id: "settings.source.otherSavedConnections",
  1346. })}
  1347. aria-expanded={otherProfilesExpanded}
  1348. onClick={() =>
  1349. setExpandedSavedConnectionSources((current) =>
  1350. toggleSetItem(current, server.sourceServerId),
  1351. )
  1352. }
  1353. >
  1354. {otherProfilesExpanded ? (
  1355. <ChevronDown className="size-3.5" />
  1356. ) : (
  1357. <ChevronRight className="size-3.5" />
  1358. )}
  1359. {intl.formatMessage(
  1360. { id: "settings.source.otherSavedConnectionsCount" },
  1361. { count: otherProfiles.length },
  1362. )}
  1363. </Button>
  1364. ) : null}
  1365. {showRecentLog ? (
  1366. <Button
  1367. data-source-server-log-toggle
  1368. type="button"
  1369. variant="ghost"
  1370. size="sm"
  1371. // 只有日志入口时靠左,避免页脚左侧空出一整行。
  1372. className={cn(
  1373. "text-remote-foreground-muted",
  1374. showOtherProfiles ? "-mr-2 ml-auto" : "-ml-2",
  1375. )}
  1376. aria-expanded={logExpanded}
  1377. onClick={() =>
  1378. setLogExpansionBySource((current) =>
  1379. new Map(current).set(server.sourceServerId, !logExpanded),
  1380. )
  1381. }
  1382. >
  1383. <ChevronRight
  1384. className={cn(
  1385. "size-3.5 transition-transform",
  1386. logExpanded && "rotate-90",
  1387. )}
  1388. />
  1389. {intl.formatMessage({ id: "settings.source.recentLog" })}
  1390. </Button>
  1391. ) : null}
  1392. </div>
  1393. {otherProfilesExpanded ? (
  1394. <div className="mt-1 px-2 py-1">
  1395. {otherProfiles.map((profile) => renderProfile(profile, server))}
  1396. </div>
  1397. ) : null}
  1398. {logExpanded ? (
  1399. <div className="mt-1 pb-1">
  1400. <SourceServerLogList logs={operationLogs} />
  1401. </div>
  1402. ) : null}
  1403. </div>
  1404. ) : null}
  1405. {/* 产品边界:迁移账本是内部兼容机制,仅在存在待处理问题时以用户可理解的连接历史提醒暴露。 */}
  1406. {showServerLines &&
  1407. migrationCount?.status === "available" &&
  1408. migrationCount.failedPathCount + migrationCount.abandonedPathCount > 0 ? (
  1409. <div className="border-t border-border">
  1410. <Button
  1411. type="button"
  1412. variant="ghost"
  1413. size="sm"
  1414. className="w-full justify-start rounded-none px-4 py-2.5 text-ui-sm text-remote-foreground-muted"
  1415. onClick={() => toggleMigrationReport(server.sourceServerId)}
  1416. >
  1417. {migrationReport ? (
  1418. <ChevronDown className="size-3.5" />
  1419. ) : (
  1420. <ChevronRight className="size-3.5" />
  1421. )}
  1422. <FileWarning className="size-3.5 text-warning" />
  1423. {intl.formatMessage({
  1424. id: "settings.source.connectionHistoryNeedsAttention",
  1425. })}
  1426. <span className="font-medium text-warning">
  1427. {intl.formatMessage(
  1428. { id: "settings.source.pendingMigrationCount" },
  1429. {
  1430. count: migrationCount.failedPathCount + migrationCount.abandonedPathCount,
  1431. },
  1432. )}
  1433. </span>
  1434. </Button>
  1435. {migrationReport ? (
  1436. <SourceServerMigrationReportPanel
  1437. report={migrationReport}
  1438. disabled={deviceBusy}
  1439. onAbandon={(workspacePath, migrationId) => {
  1440. void confirmDialog({
  1441. title: intl.formatMessage({
  1442. id: "settings.source.abandonMigrationTitle",
  1443. }),
  1444. description: intl.formatMessage({
  1445. id: "settings.source.abandonMigrationDescription",
  1446. }),
  1447. confirmLabel: intl.formatMessage({
  1448. id: "settings.source.abandonMigration",
  1449. }),
  1450. confirmVariant: "destructive",
  1451. }).then((confirmed) => {
  1452. if (!confirmed) return;
  1453. void runMigrationOperation(
  1454. `abandon:${server.sourceServerId}:${migrationId}`,
  1455. server.sourceServerId,
  1456. () =>
  1457. management.abandonWorkspaceMigration(
  1458. server.sourceServerId,
  1459. workspacePath,
  1460. migrationId,
  1461. ),
  1462. );
  1463. });
  1464. }}
  1465. onRetry={(workspacePath, migrationId) =>
  1466. void runMigrationOperation(
  1467. `retry:${server.sourceServerId}:${migrationId}`,
  1468. server.sourceServerId,
  1469. () =>
  1470. management.retryWorkspaceMigration(
  1471. server.sourceServerId,
  1472. workspacePath,
  1473. migrationId,
  1474. ),
  1475. )
  1476. }
  1477. />
  1478. ) : null}
  1479. </div>
  1480. ) : null}
  1481. </section>
  1482. );
  1483. })}
  1484. {unboundProfiles.length > 0 ? (
  1485. <details
  1486. open={
  1487. background &&
  1488. !background.sourceServerId &&
  1489. unboundProfiles.some((profile) => profile.profileId === background.profileId)
  1490. ? true
  1491. : undefined
  1492. }
  1493. data-unfinished-connections
  1494. className="group/unfinished border-t border-border pt-4"
  1495. >
  1496. <summary className="flex cursor-pointer list-none items-center gap-2 text-ui-base font-medium">
  1497. <ChevronRight className="size-3.5 transition-transform group-open/unfinished:rotate-90" />
  1498. {intl.formatMessage({ id: "settings.source.unfinishedConnections" })}
  1499. <span className="rounded-md bg-tag px-1.5 py-0.5 text-ui-xs font-normal text-remote-foreground-muted">
  1500. {unboundProfiles.length}
  1501. </span>
  1502. </summary>
  1503. <div className="mt-2 space-y-2">
  1504. {unboundProfiles.map((profile) => (
  1505. <div key={profile.profileId}>
  1506. {renderProfile(profile)}
  1507. {background &&
  1508. !background.sourceServerId &&
  1509. background.profileId === profile.profileId ? (
  1510. <RemoteConnectionMinimizedProgress {...background} />
  1511. ) : null}
  1512. {(logsByProfileId[profile.profileId]?.length ?? 0) > 0 ? (
  1513. <SourceServerUpdateActivity
  1514. active={false}
  1515. recent
  1516. logs={logsByProfileId[profile.profileId] ?? []}
  1517. />
  1518. ) : null}
  1519. </div>
  1520. ))}
  1521. <Button
  1522. type="button"
  1523. variant="outline"
  1524. size="sm"
  1525. disabled={
  1526. busyOperations.has("clear-unfinished") ||
  1527. unboundProfiles.some((profile) => busyScopes.has(profileOperationScope(profile)))
  1528. }
  1529. onClick={() => {
  1530. void confirmDialog({
  1531. title: intl.formatMessage({ id: "settings.source.clearUnfinished" }),
  1532. description: intl.formatMessage({
  1533. id: "settings.source.clearUnfinishedDescription",
  1534. }),
  1535. confirmLabel: intl.formatMessage({ id: "settings.source.clearUnfinished" }),
  1536. confirmVariant: "destructive",
  1537. }).then((confirmed) => {
  1538. if (confirmed)
  1539. void run(
  1540. "clear-unfinished",
  1541. async () => {
  1542. // 清理时复核归属,连接刚成功的设备不能被旧列表误删。
  1543. const latest = await management.getSnapshot();
  1544. for (const profile of latest.profiles) {
  1545. if (!profile.sourceServerId && profile.lifecycleState !== "retired")
  1546. applySnapshot(await management.removeProfile(profile.profileId));
  1547. }
  1548. },
  1549. unboundProfiles.map(profileOperationScope),
  1550. );
  1551. });
  1552. }}
  1553. >
  1554. {intl.formatMessage({ id: "settings.source.clearUnfinished" })}
  1555. </Button>
  1556. </div>
  1557. </details>
  1558. ) : null}
  1559. {retiredProfiles.length > 0 ? (
  1560. <details className="group/retired border-t border-border pt-4">
  1561. <summary className="flex cursor-pointer list-none flex-wrap items-center gap-2 text-ui-base font-medium text-foreground">
  1562. <ChevronRight className="size-3.5 shrink-0 text-remote-foreground-muted transition-transform group-open/retired:rotate-90" />
  1563. {intl.formatMessage(
  1564. { id: "settings.source.retiredProfilesWithCount" },
  1565. { count: retiredProfiles.length },
  1566. )}
  1567. <span className="text-ui-xs font-normal text-remote-foreground-muted">
  1568. {intl.formatMessage({
  1569. id: "settings.source.retiredProfilesDescription",
  1570. })}
  1571. </span>
  1572. </summary>
  1573. <div className="mt-2 space-y-1 pl-6">
  1574. {retiredProfiles.map((profile) => (
  1575. <div
  1576. key={profile.profileId}
  1577. className="flex min-w-0 flex-wrap items-center gap-2 py-1.5 text-remote-foreground-muted"
  1578. >
  1579. <span className="font-mono text-ui-sm">
  1580. {profile.displayName ?? profile.transport}
  1581. {intl.formatMessage({
  1582. id: "settings.source.retiredNameSuffix",
  1583. })}
  1584. </span>
  1585. <span className="text-ui-xs">
  1586. {profile.retiredAt
  1587. ? `${intl.formatMessage(
  1588. { id: "settings.source.archivedAt" },
  1589. {
  1590. time: formatRelativeTimestamp(
  1591. profile.retiredAt,
  1592. locale,
  1593. intl.formatMessage,
  1594. ),
  1595. },
  1596. )} · ${intl.formatMessage({
  1597. id: "settings.source.retiredEntryNote",
  1598. })}`
  1599. : intl.formatMessage({
  1600. id: "settings.source.retiredEntryNote",
  1601. })}
  1602. </span>
  1603. </div>
  1604. ))}
  1605. </div>
  1606. </details>
  1607. ) : null}
  1608. <section className="border-t border-border pt-4">
  1609. <h3 className="text-ui-base font-medium text-foreground">
  1610. {intl.formatMessage({
  1611. id: "settings.source.connectionPreferences",
  1612. })}
  1613. </h3>
  1614. <div className="mt-3 space-y-4">
  1615. <div className="flex items-start justify-between gap-3">
  1616. <div>
  1617. <p className="text-ui-sm text-foreground">
  1618. {intl.formatMessage({
  1619. id: "settings.source.startupAutoReconnect",
  1620. })}
  1621. </p>
  1622. <p className="text-ui-xs text-remote-foreground-muted">
  1623. {intl.formatMessage({
  1624. id: "settings.source.startupAutoReconnectDescription",
  1625. })}
  1626. </p>
  1627. </div>
  1628. <Switch
  1629. checked={startupAutoReconnect}
  1630. disabled={busyOperations.has("startup-reconnect") || !onUpdateSettings}
  1631. aria-busy={busyOperations.has("startup-reconnect")}
  1632. onCheckedChange={(checked) => {
  1633. const previous = startupAutoReconnect;
  1634. setStartupAutoReconnect(checked);
  1635. void run("startup-reconnect", async () => {
  1636. try {
  1637. await onUpdateSettings?.({ remoteStartupAutoReconnectEnabled: checked });
  1638. } catch (cause) {
  1639. setStartupAutoReconnect(previous);
  1640. throw cause;
  1641. }
  1642. });
  1643. }}
  1644. aria-label={intl.formatMessage({
  1645. id: "settings.source.startupAutoReconnect",
  1646. })}
  1647. />
  1648. </div>
  1649. </div>
  1650. </section>
  1651. {ready && profiles.length === 0 && servers.length === 0 ? (
  1652. <div className="space-y-3 py-4 text-center text-ui-sm text-remote-foreground-muted">
  1653. <p>{intl.formatMessage({ id: "settings.source.empty" })}</p>
  1654. {onCreateConnection ? (
  1655. <Button type="button" size="sm" onClick={onCreateConnection}>
  1656. <Plus className="size-3.5" />
  1657. {intl.formatMessage({ id: "settings.source.newConnection" })}
  1658. </Button>
  1659. ) : null}
  1660. </div>
  1661. ) : null}
  1662. </div>
  1663. <Dialog
  1664. open={Boolean(errorDetailsProfile)}
  1665. onOpenChange={(open) => {
  1666. if (!open) setErrorDetailsProfile(null);
  1667. }}
  1668. >
  1669. <DialogContent>
  1670. {errorDetailsProfile
  1671. ? (() => {
  1672. const state = stateByProfile.get(errorDetailsProfile.profileId);
  1673. const classified = classifyRemoteConnectionError({
  1674. errorCode: state?.errorCode,
  1675. error: state?.error,
  1676. target: errorDetailsProfile.target,
  1677. });
  1678. return (
  1679. <>
  1680. <DialogHeader>
  1681. <DialogTitle>{intl.formatMessage({ id: classified.titleId })}</DialogTitle>
  1682. <DialogDescription>
  1683. {intl.formatMessage({ id: classified.reasonId })}
  1684. </DialogDescription>
  1685. </DialogHeader>
  1686. <details>
  1687. <summary>{intl.formatMessage({ id: "remote.error.details" })}</summary>
  1688. <pre className="whitespace-pre-wrap break-words text-ui-sm">
  1689. {state?.error ?? errorDetailsProfile.lastConnectError}
  1690. </pre>
  1691. </details>
  1692. <SourceServerUpdateActivity
  1693. active={false}
  1694. recent
  1695. logs={logsByProfileId[errorDetailsProfile.profileId] ?? []}
  1696. />
  1697. </>
  1698. );
  1699. })()
  1700. : null}
  1701. </DialogContent>
  1702. </Dialog>
  1703. <EditConnectionProfileDialog
  1704. open={editingConnection !== null}
  1705. profile={editingConnection?.profile ?? null}
  1706. source={editingConnection?.server}
  1707. focusField={editingConnection?.focusField}
  1708. management={management}
  1709. onOpenChange={(open) => {
  1710. if (!open) setEditingConnection(null);
  1711. }}
  1712. onSaved={refresh}
  1713. />
  1714. </div>
  1715. );
  1716. }