-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathServerActionMenu.tsx
More file actions
183 lines (167 loc) · 6.04 KB
/
Copy pathServerActionMenu.tsx
File metadata and controls
183 lines (167 loc) · 6.04 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/**
* ServerActionMenu - Overflow menu for server actions
*
* Actions:
* - Configure: Edit server inputs
* - Refresh: Quick reconnect with existing credentials
* - Reconnect: Logout + re-authenticate (OAuth only)
* - View Logs: Open log viewer
* - View Definition: View server definition JSON
* - Uninstall: Remove server
*/
import { useState, useRef, useEffect } from 'react';
import { MoreVertical, Settings, RefreshCw, RotateCcw, FileText, Code, Trash2 } from 'lucide-react';
export interface ServerActionMenuProps {
serverId: string;
serverName: string;
hasInputs: boolean;
isOAuth: boolean;
isEnabled: boolean;
isConnected: boolean;
onConfigure: () => void;
onRefresh: () => void;
onReconnect: () => void;
onViewLogs: () => void;
onViewDefinition: () => void;
onUninstall: () => void;
}
export function ServerActionMenu({
serverId,
serverName: _serverName,
hasInputs,
isOAuth,
isEnabled,
isConnected: _isConnected,
onConfigure,
onRefresh,
onReconnect,
onViewLogs,
onViewDefinition,
onUninstall,
}: ServerActionMenuProps) {
const [isOpen, setIsOpen] = useState(false);
const menuRef = useRef<HTMLDivElement>(null);
const buttonRef = useRef<HTMLButtonElement>(null);
// Close menu when clicking outside
useEffect(() => {
function handleClickOutside(event: MouseEvent) {
if (
menuRef.current &&
!menuRef.current.contains(event.target as Node) &&
buttonRef.current &&
!buttonRef.current.contains(event.target as Node)
) {
setIsOpen(false);
}
}
if (isOpen) {
document.addEventListener('mousedown', handleClickOutside);
return () => document.removeEventListener('mousedown', handleClickOutside);
}
}, [isOpen]);
// Close menu on escape
useEffect(() => {
function handleEscape(event: KeyboardEvent) {
if (event.key === 'Escape') {
setIsOpen(false);
}
}
if (isOpen) {
document.addEventListener('keydown', handleEscape);
return () => document.removeEventListener('keydown', handleEscape);
}
}, [isOpen]);
const handleAction = (action: () => void) => {
setIsOpen(false);
action();
};
return (
<div className="relative">
<button
ref={buttonRef}
onClick={() => setIsOpen(!isOpen)}
className="p-2 text-sm rounded-lg bg-[rgb(var(--surface-hover))] border border-[rgb(var(--border))] text-[rgb(var(--foreground))]/70 hover:bg-[rgb(var(--surface-elevated))] hover:text-[rgb(var(--foreground))] transition-colors"
title="More actions"
aria-label="More actions"
aria-expanded={isOpen}
aria-haspopup="menu"
data-testid={`action-menu-${serverId}`}
>
<MoreVertical className="h-4 w-4" />
</button>
{isOpen && (
<div
ref={menuRef}
className="absolute right-0 mt-1 w-48 py-1 bg-[rgb(var(--surface-elevated))] border border-[rgb(var(--border))] rounded-lg shadow-lg z-50 animate-in fade-in slide-in-from-top-1 duration-150"
role="menu"
>
{/* Configure - visible if server has inputs */}
{hasInputs && (
<button
onClick={() => handleAction(onConfigure)}
className="w-full flex items-center gap-2 px-3 py-2 text-sm text-[rgb(var(--foreground))] hover:bg-[rgb(var(--surface-hover))] transition-colors"
role="menuitem"
>
<Settings className="h-4 w-4 text-[rgb(var(--muted))]" />
Configure
</button>
)}
{/* Refresh - visible when enabled (quick reconnect with existing creds) */}
{isEnabled && (
<button
onClick={() => handleAction(onRefresh)}
className="w-full flex items-center gap-2 px-3 py-2 text-sm text-[rgb(var(--foreground))] hover:bg-[rgb(var(--surface-hover))] transition-colors"
role="menuitem"
>
<RefreshCw className="h-4 w-4 text-[rgb(var(--muted))]" />
Refresh
</button>
)}
{/* Reconnect - OAuth only (logout + re-auth) */}
{isOAuth && isEnabled && (
<button
onClick={() => handleAction(onReconnect)}
className="w-full flex items-center gap-2 px-3 py-2 text-sm text-[rgb(var(--warning))] hover:bg-[rgb(var(--surface-hover))] transition-colors"
role="menuitem"
>
<RotateCcw className="h-4 w-4" />
Reconnect
</button>
)}
{/* View Logs - always visible */}
<button
onClick={() => handleAction(onViewLogs)}
className="w-full flex items-center gap-2 px-3 py-2 text-sm text-[rgb(var(--foreground))] hover:bg-[rgb(var(--surface-hover))] transition-colors"
role="menuitem"
data-testid={`view-logs-${serverId}`}
>
<FileText className="h-4 w-4 text-[rgb(var(--muted))]" />
View Logs
</button>
{/* View Definition - always visible */}
<button
onClick={() => handleAction(onViewDefinition)}
className="w-full flex items-center gap-2 px-3 py-2 text-sm text-[rgb(var(--foreground))] hover:bg-[rgb(var(--surface-hover))] transition-colors"
role="menuitem"
data-testid={`view-definition-${serverId}`}
>
<Code className="h-4 w-4 text-[rgb(var(--muted))]" />
View Definition
</button>
{/* Separator */}
<div className="my-1 border-t border-[rgb(var(--border-subtle))]" />
{/* Uninstall - always visible, destructive */}
<button
onClick={() => handleAction(onUninstall)}
className="w-full flex items-center gap-2 px-3 py-2 text-sm text-[rgb(var(--error))] hover:bg-[rgb(var(--error))]/10 transition-colors"
role="menuitem"
data-testid={`uninstall-menu-${serverId}`}
>
<Trash2 className="h-4 w-4" />
Uninstall
</button>
</div>
)}
</div>
);
}