-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHostListRow.tsx
More file actions
152 lines (148 loc) · 5.6 KB
/
Copy pathHostListRow.tsx
File metadata and controls
152 lines (148 loc) · 5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import type { Dispatch, DragEvent as ReactDragEvent, MutableRefObject, SetStateAction } from "react";
import type { HostRowViewModel } from "../features/view-profile-filters";
import type { ContextMenuState } from "../features/session-model";
import type { DragPayload } from "../features/pane-dnd";
import type { HostConfig } from "../types";
export type HostListRowProps = {
row: HostRowViewModel;
activeHost: string;
suppressHostClickAliasRef: MutableRefObject<string | null>;
setContextMenu: Dispatch<SetStateAction<ContextMenuState>>;
setHostContextMenu: Dispatch<SetStateAction<{ x: number; y: number; host: HostConfig } | null>>;
setHoveredHostAlias: Dispatch<SetStateAction<string | null>>;
setActiveHost: Dispatch<SetStateAction<string>>;
setDragOverPaneIndex: Dispatch<SetStateAction<number | null>>;
toggleFavoriteForHost: (hostAlias: string) => void | Promise<void>;
connectToHostInNewPane: (host: HostConfig) => void | Promise<void>;
setDragPayload: (event: ReactDragEvent, payload: DragPayload) => void;
setDraggingKind: (kind: DragPayload["type"] | null) => void;
missingDragPayloadLoggedRef: MutableRefObject<boolean>;
onEditHost: (host: HostConfig) => void;
};
/** Props shared by every row; pass with `row` into {@link HostListRow}. */
export type HostListRowBridgeProps = Omit<HostListRowProps, "row">;
export function HostListRow({
row,
activeHost,
suppressHostClickAliasRef,
setContextMenu,
setHostContextMenu,
setHoveredHostAlias,
setActiveHost,
setDragOverPaneIndex,
toggleFavoriteForHost,
connectToHostInNewPane,
setDragPayload,
setDraggingKind,
missingDragPayloadLoggedRef,
onEditHost,
}: HostListRowProps) {
const metaUser = row.displayUser.trim() || "—";
const alias = row.host.host.trim();
const hostName = row.host.hostName.trim();
const showHostName = hostName.length > 0 && hostName !== alias;
const metaLine = [metaUser, ...(showHostName ? [hostName] : []), `port ${row.host.port}`].join(" · ");
return (
<div
className="host-row"
onContextMenu={(event) => {
event.preventDefault();
setContextMenu((prev) => ({ ...prev, visible: false }));
setHostContextMenu({
x: event.clientX,
y: event.clientY,
host: row.host,
});
}}
>
<div
className={`host-sidebar-row-wrap${
activeHost === row.host.host ? " host-sidebar-row-wrap--selected" : ""
}`}
data-host-power={row.connected ? "up" : "down"}
data-host-favorite={row.metadata.favorite ? "true" : "false"}
>
<div className="proxmux-sidebar-item-shell">
<button
type="button"
className={`proxmux-sidebar-favorite-btn${row.metadata.favorite ? " is-active" : ""}`}
aria-label={`Toggle favorite for ${row.host.host}`}
onClick={(event) => {
event.stopPropagation();
void toggleFavoriteForHost(row.host.host);
}}
>
★
</button>
<div
role="button"
tabIndex={0}
aria-label={`SSH host ${row.host.host}`}
className="host-item host-sidebar-row-main proxmux-sidebar-row proxmux-sidebar-row--guest"
onClick={() => {
if (suppressHostClickAliasRef.current) {
const suppressedAlias = suppressHostClickAliasRef.current;
suppressHostClickAliasRef.current = null;
if (suppressedAlias === row.host.host) {
return;
}
}
setActiveHost(row.host.host);
}}
onMouseEnter={() => {
if (row.connected) {
setHoveredHostAlias(row.host.host);
}
}}
onMouseLeave={() => {
if (row.connected) {
setHoveredHostAlias((prev) => (prev === row.host.host ? null : prev));
}
}}
onDoubleClick={() => {
void connectToHostInNewPane(row.host);
}}
onKeyDown={(event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
if (activeHost !== row.host.host) {
setActiveHost(row.host.host);
}
void connectToHostInNewPane(row.host);
}
}}
draggable
onDragStart={(event) => {
suppressHostClickAliasRef.current = row.host.host;
setDragPayload(event, { type: "machine", hostAlias: row.host.host });
setDraggingKind("machine");
missingDragPayloadLoggedRef.current = false;
}}
onDragEnd={() => {
setDraggingKind(null);
setDragOverPaneIndex(null);
missingDragPayloadLoggedRef.current = false;
}}
>
<span className="proxmux-sidebar-row-main">{row.host.host}</span>
<span className="proxmux-sidebar-row-meta">{metaLine}</span>
</div>
<div className="proxmux-sidebar-actions" onMouseDown={(e) => e.stopPropagation()}>
<button
type="button"
className="proxmux-action-btn host-sidebar-overflow-btn"
aria-label={`Open host settings for ${row.host.host}`}
title={`Open host settings for ${row.host.host}`}
onClick={(event) => {
event.stopPropagation();
onEditHost(row.host);
}}
>
⋮
</button>
</div>
</div>
</div>
</div>
);
}