-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathshell.tsx
More file actions
396 lines (365 loc) · 15 KB
/
Copy pathshell.tsx
File metadata and controls
396 lines (365 loc) · 15 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
import { Link, Outlet, useLocation } from "@tanstack/react-router";
import { useEffect, useRef, useState } from "react";
import { useAtomRefresh, useAtomValue } from "@effect/atom-react";
import * as AsyncResult from "effect/unstable/reactivity/AsyncResult";
import type { Integration } from "@executor-js/sdk/shared";
import {
integrationsAtom,
integrationsOptimisticAtom,
toolsAllAtom,
} from "@executor-js/react/api/atoms";
import { Button } from "@executor-js/react/components/button";
import { integrationPresetIconUrl } from "@executor-js/react/components/integration-favicon";
import { IntegrationIconWithAccount } from "@executor-js/react/components/integration-icon-with-account";
import { CommandPalette } from "@executor-js/react/components/command-palette";
import { useClientPlugins, useIntegrationPlugins } from "@executor-js/sdk/client";
import { SidebarUpdateCard } from "@executor-js/react/components/update-card";
import { Wordmark } from "@executor-js/react/components/wordmark";
import { ServerConnectionMenu } from "./server-connection-menu";
// ── Env ─────────────────────────────────────────────────────────────────
type AppMetaEnv = {
readonly VITE_APP_VERSION: string;
readonly VITE_GITHUB_URL: string;
};
const { VITE_APP_VERSION, VITE_GITHUB_URL } = (
import.meta as ImportMeta & {
readonly env: AppMetaEnv;
}
).env;
// ── NavItem ──────────────────────────────────────────────────────────────
function NavItem(props: { to: string; label: string; active: boolean; onNavigate?: () => void }) {
return (
<Link
to={props.to}
onClick={props.onNavigate}
className={[
"flex items-center gap-2.5 rounded-md px-2.5 py-1.5 text-sm transition-colors",
props.active
? "bg-sidebar-active text-foreground font-medium"
: "text-sidebar-foreground hover:bg-sidebar-active/60 hover:text-foreground",
].join(" ")}
>
{props.label}
</Link>
);
}
// ── PluginNav ────────────────────────────────────────────────────────────
//
// Renders one nav link per plugin page that opted in via
// `pages[].nav.label`. The catch-all `/plugins/$pluginId/$` route is the
// mount point; the splat is the page's relative path with the leading
// slash stripped.
function PluginNav(props: { pathname: string; onNavigate?: () => void }) {
const plugins = useClientPlugins();
const entries = plugins.flatMap((plugin) =>
(plugin.pages ?? [])
.filter((page) => page.nav)
.map((page) => {
const splat = page.path.replace(/^\//, "");
const href = `/plugins/${plugin.id}${splat ? `/${splat}` : "/"}`;
return {
key: `${plugin.id}:${page.path}`,
pluginId: plugin.id,
splat,
href,
label: page.nav!.label,
};
}),
);
if (entries.length === 0) return null;
return (
<>
{entries.map((entry) => (
<Link
key={entry.key}
to="/{-$orgSlug}/plugins/$pluginId/$"
params={{ pluginId: entry.pluginId, _splat: entry.splat }}
onClick={props.onNavigate}
className={[
"flex items-center gap-2.5 rounded-md px-2.5 py-1.5 text-sm transition-colors",
props.pathname === entry.href || props.pathname.startsWith(`${entry.href}/`)
? "bg-sidebar-active text-foreground font-medium"
: "text-sidebar-foreground hover:bg-sidebar-active/60 hover:text-foreground",
].join(" ")}
>
{entry.label}
</Link>
))}
</>
);
}
// ── IntegrationList ───────────────────────────────────────────────────────────
function IntegrationList(props: { pathname: string; onNavigate?: () => void }) {
const integrations = useAtomValue(integrationsOptimisticAtom);
const integrationPlugins = useIntegrationPlugins();
return AsyncResult.match(integrations, {
onInitial: () => <div className="px-2.5 py-2 text-xs text-muted-foreground">Loading…</div>,
onFailure: () => (
<div className="px-2.5 py-2 text-xs text-muted-foreground">No integrations yet</div>
),
onSuccess: ({ value }: { readonly value: readonly Integration[] }) =>
value.length === 0 ? (
<div className="px-2.5 py-2 text-sm leading-relaxed text-muted-foreground">
No integrations yet
</div>
) : (
<div className="flex flex-col gap-px">
{value.map((integration: Integration) => {
const slug = String(integration.slug);
const name = integration.name || slug;
const detailPath = `/integrations/${slug}`;
const active =
props.pathname === detailPath || props.pathname.startsWith(`${detailPath}/`);
return (
<Link
key={slug}
to="/{-$orgSlug}/integrations/$namespace"
params={{ namespace: slug }}
onClick={props.onNavigate}
className={[
"group flex items-center gap-2 rounded-md px-2.5 py-1.5 text-xs transition-colors",
active
? "bg-sidebar-active text-foreground font-medium"
: "text-sidebar-foreground hover:bg-sidebar-active/60 hover:text-foreground",
].join(" ")}
>
<IntegrationIconWithAccount
icon={integrationPresetIconUrl(
{ id: slug, kind: integration.kind },
integrationPlugins,
)}
sourceId={slug}
size="sm"
/>
<span className="flex-1 truncate">{name}</span>
</Link>
);
})}
</div>
),
});
}
// ── SidebarContent ───────────────────────────────────────────────────────
function SidebarContent(props: {
pathname: string;
onNavigate?: () => void;
showBrand?: boolean;
onOpenCommands: () => void;
}) {
const isHome = props.pathname === "/";
const isSecrets = props.pathname === "/secrets";
const isPolicies = props.pathname === "/policies";
const isToolkits = props.pathname === "/toolkits" || props.pathname.startsWith("/toolkits/");
return (
<>
{props.showBrand !== false && (
<div className="desktop-macos-titlebar flex h-12 shrink-0 items-center gap-2 border-b border-sidebar-border px-4">
<Link to="/{-$orgSlug}" className="desktop-macos-no-drag flex shrink-0 items-center">
<Wordmark />
</Link>
<div className="desktop-macos-no-drag ml-auto flex min-w-0 flex-1 justify-end pl-3">
<ServerConnectionMenu variant="header" />
</div>
</div>
)}
<nav className="flex flex-1 flex-col overflow-y-auto p-2">
<NavItem
to="/{-$orgSlug}"
label="Integrations"
active={isHome}
onNavigate={props.onNavigate}
/>
<NavItem
to="/{-$orgSlug}/secrets"
label="Secrets"
active={isSecrets}
onNavigate={props.onNavigate}
/>
<NavItem
to="/{-$orgSlug}/policies"
label="Policies"
active={isPolicies}
onNavigate={props.onNavigate}
/>
<NavItem
to="/{-$orgSlug}/toolkits"
label="Toolkits"
active={isToolkits}
onNavigate={props.onNavigate}
/>
<PluginNav pathname={props.pathname} onNavigate={props.onNavigate} />
{/* Sources list */}
<div className="mt-5 mb-1 px-2.5 text-xs font-medium uppercase tracking-widest text-muted-foreground">
<span>Integrations</span>
</div>
<IntegrationList pathname={props.pathname} onNavigate={props.onNavigate} />
</nav>
<SidebarUpdateCard />
{/* Footer */}
<div className="shrink-0 border-t border-sidebar-border px-4 py-2.5">
<div className="flex flex-col gap-1.5 text-xs leading-none">
{/* oxlint-disable-next-line react/forbid-elements */}
<button
type="button"
onClick={props.onOpenCommands}
className="flex items-center justify-between text-left text-muted-foreground transition-colors hover:text-foreground"
>
<span>Commands</span>
<span className="font-mono text-[11px]">⌘K</span>
</button>
<a
href="https://executor.sh/docs"
target="_blank"
rel="noreferrer"
className="text-muted-foreground transition-colors hover:text-foreground"
>
Docs
</a>
<a
href={`${VITE_GITHUB_URL}/issues`}
target="_blank"
rel="noreferrer"
className="text-muted-foreground transition-colors hover:text-foreground"
>
Feedback / bug?
</a>
<a
href={VITE_GITHUB_URL}
target="_blank"
rel="noreferrer"
className="text-muted-foreground transition-colors hover:text-foreground"
>
Star on GitHub
</a>
<span className="mt-0.5 text-xs text-muted-foreground tabular-nums">
v{VITE_APP_VERSION}
</span>
</div>
</div>
</>
);
}
// ── Shell ─────────────────────────────────────────────────────────────────
export function Shell() {
const location = useLocation();
const pathname = location.pathname;
const refreshSources = useAtomRefresh(integrationsAtom);
const refreshTools = useAtomRefresh(toolsAllAtom);
const lastPathname = useRef(pathname);
const [mobileSidebarOpen, setMobileSidebarOpen] = useState(false);
const [commandPaletteOpen, setCommandPaletteOpen] = useState(false);
if (lastPathname.current !== pathname) {
lastPathname.current = pathname;
if (mobileSidebarOpen) setMobileSidebarOpen(false);
}
// Lock scroll when mobile sidebar open
useEffect(() => {
if (!mobileSidebarOpen) return;
const prev = document.body.style.overflow;
document.body.style.overflow = "hidden";
return () => {
document.body.style.overflow = prev;
};
}, [mobileSidebarOpen]);
useEffect(() => {
if (!import.meta.hot) {
return;
}
const refreshBackendData = () => {
refreshSources();
refreshTools();
};
import.meta.hot.on("executor:backend-updated", refreshBackendData);
return () => {
import.meta.hot?.off("executor:backend-updated", refreshBackendData);
};
}, [refreshSources, refreshTools]);
return (
<div className="flex h-screen overflow-hidden">
<CommandPalette open={commandPaletteOpen} onOpenChange={setCommandPaletteOpen} />
{/* Desktop sidebar */}
<aside className="desktop-macos-sidebar hidden w-52 shrink-0 border-r border-sidebar-border bg-sidebar md:flex md:flex-col lg:w-56">
<SidebarContent pathname={pathname} onOpenCommands={() => setCommandPaletteOpen(true)} />
</aside>
{/* Mobile sidebar overlay */}
{mobileSidebarOpen && (
<div className="fixed inset-0 z-50 flex md:hidden">
{/* oxlint-disable-next-line react/forbid-elements */}
<button
type="button"
aria-label="Close navigation"
className="absolute inset-0 bg-black/45 backdrop-blur-[1px]"
onClick={() => setMobileSidebarOpen(false)}
/>
<div className="relative flex h-full w-[84vw] max-w-xs flex-col border-r border-sidebar-border bg-sidebar shadow-2xl">
<div className="desktop-macos-titlebar flex h-12 shrink-0 items-center justify-between border-b border-sidebar-border px-4">
<Link to="/{-$orgSlug}" className="desktop-macos-no-drag flex items-center">
<Wordmark />
</Link>
<Button
variant="ghost"
size="icon-sm"
aria-label="Close navigation"
onClick={() => setMobileSidebarOpen(false)}
className="desktop-macos-no-drag text-sidebar-foreground hover:bg-sidebar-active hover:text-foreground"
>
<svg viewBox="0 0 16 16" className="size-3.5">
<path
d="M3 3l10 10M13 3L3 13"
stroke="currentColor"
strokeWidth="1.4"
strokeLinecap="round"
/>
</svg>
</Button>
</div>
<SidebarContent
pathname={pathname}
onNavigate={() => setMobileSidebarOpen(false)}
showBrand={false}
onOpenCommands={() => {
setMobileSidebarOpen(false);
setCommandPaletteOpen(true);
}}
/>
</div>
</div>
)}
{/* Main content */}
<main className="relative flex min-h-0 flex-1 flex-col min-w-0 overflow-hidden">
{/* Desktop (macOS frameless) draggable title-bar strip. Gives the main
area the same native window drag + double-click-to-zoom as the
sidebar header; hidden everywhere else via CSS. Overlays the top of
the main area (behind page content) so page headers stay flush with
the top and their borders line up with the sidebar header. */}
<div className="desktop-macos-main-titlebar" />
{/* Mobile top bar. The desktop-macos-titlebar offset keeps the
far-left hamburger clear of the native traffic lights when the macOS
window is forced below the md breakpoint (issue #1125). */}
<div className="desktop-macos-titlebar flex h-12 shrink-0 items-center justify-between border-b border-border bg-background px-4 md:hidden">
<Button
variant="outline"
size="icon-sm"
aria-label="Open navigation"
onClick={() => setMobileSidebarOpen(true)}
className="desktop-macos-no-drag bg-card hover:bg-accent/50"
>
<svg viewBox="0 0 16 16" className="size-4">
<path
d="M2 4h12M2 8h12M2 12h12"
stroke="currentColor"
strokeWidth="1.2"
strokeLinecap="round"
/>
</svg>
</Button>
<Link to="/{-$orgSlug}" className="desktop-macos-no-drag flex items-center">
<Wordmark />
</Link>
<div className="w-8 shrink-0" />
</div>
<Outlet />
</main>
</div>
);
}