-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathlayout.tsx
More file actions
300 lines (285 loc) · 11.1 KB
/
Copy pathlayout.tsx
File metadata and controls
300 lines (285 loc) · 11.1 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
import {
CatchBoundary,
createFileRoute,
Outlet,
useLocation,
useMatchRoute,
useNavigate,
} from "@tanstack/react-router";
import { useMemo, useState } from "react";
import { CommandPaletteHost } from "renderer/commandPalette";
import { Redirect } from "renderer/components/Redirect";
import { useIsV2CloudEnabled } from "renderer/hooks/useIsV2CloudEnabled";
import { useQuickCreateWorkspace } from "renderer/hooks/useQuickCreateWorkspace";
import { useHotkey } from "renderer/hotkeys";
import { electronTrpc } from "renderer/lib/electron-trpc";
import { DashboardSidebar } from "renderer/routes/_authenticated/_dashboard/components/DashboardSidebar";
import { DashboardSidebarPortsProvider } from "renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/providers/DashboardSidebarPortsProvider";
import { useDevSeedV2Sidebar } from "renderer/routes/_authenticated/hooks/useDevSeedV2Sidebar";
import { useHostWorkspaces } from "renderer/routes/_authenticated/providers/HostWorkspacesProvider";
import { ResizablePanel } from "renderer/screens/main/components/ResizablePanel";
import { WorkspaceSidebar } from "renderer/screens/main/components/WorkspaceSidebar";
import { DeleteWorkspaceDialog } from "renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/components";
import { useDeleteWorkspaceIntent } from "renderer/stores/delete-workspace-intent";
import { usePortsDisplayMode } from "renderer/stores/inline-workspace-ports";
import { useOpenNewWorkspaceModal } from "renderer/stores/new-workspace-modal";
import {
COLLAPSED_WORKSPACE_SIDEBAR_WIDTH,
DEFAULT_WORKSPACE_SIDEBAR_WIDTH,
MAX_WORKSPACE_SIDEBAR_WIDTH,
useWorkspaceSidebarStore,
} from "renderer/stores/workspace-sidebar-state";
import { AddRepositoryModals } from "./components/AddRepositoryModals";
import { CrossVersionMismatchState } from "./components/CrossVersionMismatchState";
import { DashboardContentError } from "./components/DashboardContentError";
import { TopBar } from "./components/TopBar";
export const Route = createFileRoute("/_authenticated/_dashboard")({
component: DashboardLayout,
});
/** v1 only — v2 deletes go through the globally-mounted DeleteWorkspaceMount
* (see delete-workspace-intent store). */
type DeleteTarget = {
workspaceId: string;
workspaceName: string;
workspaceType: "worktree" | "branch";
};
function DashboardLayout() {
const navigate = useNavigate();
const location = useLocation();
const openNewWorkspaceModal = useOpenNewWorkspaceModal();
const isV2CloudEnabled = useIsV2CloudEnabled();
const portsDisplayMode = usePortsDisplayMode();
const { workspaces: hostWorkspaces } = useHostWorkspaces();
const quickCreateWorkspace = useQuickCreateWorkspace();
useDevSeedV2Sidebar();
// Get current workspace from route to pre-select project in new workspace modal
const matchRoute = useMatchRoute();
const currentWorkspaceMatch = matchRoute({
to: "/workspace/$workspaceId",
fuzzy: true,
});
const currentWorkspaceId =
currentWorkspaceMatch !== false ? currentWorkspaceMatch.workspaceId : null;
const v2WorkspaceMatch = matchRoute({
to: "/v2-workspace/$workspaceId",
fuzzy: true,
});
const currentV2WorkspaceId =
v2WorkspaceMatch !== false ? v2WorkspaceMatch.workspaceId : null;
const onV1WorkspaceRoute = currentWorkspaceMatch !== false;
const onV2WorkspaceRoute = v2WorkspaceMatch !== false;
const onNewWorkspaceRoute = matchRoute({ to: "/new-workspace" }) !== false;
const onDashboardViewRoute =
matchRoute({ to: "/automations", fuzzy: true }) !== false ||
matchRoute({ to: "/tasks", fuzzy: true }) !== false ||
matchRoute({ to: "/pull-requests", fuzzy: true }) !== false ||
matchRoute({ to: "/usage", fuzzy: true }) !== false ||
matchRoute({ to: "/plugins", fuzzy: true }) !== false ||
matchRoute({ to: "/pages", fuzzy: true }) !== false ||
matchRoute({ to: "/memory", fuzzy: true }) !== false ||
matchRoute({ to: "/v2-workspaces", fuzzy: true }) !== false;
const versionMismatch =
(isV2CloudEnabled && onV1WorkspaceRoute) ||
(!isV2CloudEnabled && onV2WorkspaceRoute);
const { data: currentWorkspace } = electronTrpc.workspaces.get.useQuery(
{ id: currentWorkspaceId ?? "" },
{ enabled: !!currentWorkspaceId },
);
const currentV2Workspace = useMemo(
() =>
currentV2WorkspaceId != null
? (hostWorkspaces.find(
(workspace) => workspace.id === currentV2WorkspaceId,
) ?? null)
: null,
[hostWorkspaces, currentV2WorkspaceId],
);
const {
isOpen: isWorkspaceSidebarOpen,
toggleCollapsed: toggleWorkspaceSidebarCollapsed,
setOpen: setWorkspaceSidebarOpen,
width: workspaceSidebarWidth,
setWidth: setWorkspaceSidebarWidth,
isResizing: isWorkspaceSidebarResizing,
setIsResizing: setWorkspaceSidebarIsResizing,
isCollapsed: isWorkspaceSidebarCollapsed,
} = useWorkspaceSidebarStore();
// Global hotkeys for dashboard
useHotkey("OPEN_SETTINGS", () => navigate({ to: "/settings/account" }));
useHotkey("SHOW_HOTKEYS", () => navigate({ to: "/settings/keyboard" }));
useHotkey("TOGGLE_WORKSPACE_SIDEBAR", () => {
if (!isWorkspaceSidebarOpen) {
setWorkspaceSidebarOpen(true);
} else {
toggleWorkspaceSidebarCollapsed();
}
});
useHotkey("NEW_WORKSPACE", () =>
openNewWorkspaceModal(
currentWorkspace?.projectId ?? currentV2Workspace?.projectId ?? undefined,
),
);
useHotkey(
"QUICK_CREATE_WORKSPACE",
() => quickCreateWorkspace(currentV2Workspace?.projectId ?? null),
{ enabled: isV2CloudEnabled },
);
const [deleteTarget, setDeleteTarget] = useState<DeleteTarget | null>(null);
useHotkey(
"CLOSE_WORKSPACE",
() => {
if (currentWorkspaceId && currentWorkspace) {
setDeleteTarget({
workspaceId: currentWorkspaceId,
workspaceName: currentWorkspace.name,
workspaceType: currentWorkspace.type,
});
return;
}
if (
currentV2WorkspaceId &&
currentV2Workspace &&
currentV2Workspace.type !== "main"
) {
useDeleteWorkspaceIntent.getState().request({
workspaceId: currentV2WorkspaceId,
workspaceName: currentV2Workspace.name || currentV2Workspace.branch,
});
}
},
{
enabled:
(!!currentWorkspaceId && !!currentWorkspace) ||
(!!currentV2WorkspaceId &&
!!currentV2Workspace &&
currentV2Workspace.type !== "main"),
},
);
// Collapsed rail on the v2 workspace route: the rail's headroom strip
// continues the pane tab bar, so the panel must not draw its own
// full-height border — the sidebar's inner border (which stops below the
// strip) is the only divider.
const railContinuesTabBar =
isV2CloudEnabled &&
onV2WorkspaceRoute &&
!versionMismatch &&
isWorkspaceSidebarOpen &&
isWorkspaceSidebarCollapsed();
const sidebarPanel = isWorkspaceSidebarOpen && (
<ResizablePanel
width={workspaceSidebarWidth}
onWidthChange={setWorkspaceSidebarWidth}
isResizing={isWorkspaceSidebarResizing}
onResizingChange={setWorkspaceSidebarIsResizing}
minWidth={COLLAPSED_WORKSPACE_SIDEBAR_WIDTH}
maxWidth={MAX_WORKSPACE_SIDEBAR_WIDTH}
handleSide="right"
clampWidth={false}
className={railContinuesTabBar ? "border-r-0" : undefined}
onDoubleClickHandle={() =>
setWorkspaceSidebarWidth(DEFAULT_WORKSPACE_SIDEBAR_WIDTH)
}
>
{isV2CloudEnabled ? (
<DashboardSidebar isCollapsed={isWorkspaceSidebarCollapsed()} />
) : (
<WorkspaceSidebar
isCollapsed={isWorkspaceSidebarCollapsed()}
activeProjectId={currentWorkspace?.projectId ?? null}
activeProjectName={currentWorkspace?.project?.name ?? null}
/>
)}
</ResizablePanel>
);
// Only lift the sidebar out of the TopBar column when v2 + expanded.
// Collapsed/closed sidebars stay inside so the TopBar runs full-width.
const sidebarOutsideColumn =
isV2CloudEnabled &&
isWorkspaceSidebarOpen &&
!isWorkspaceSidebarCollapsed();
// On the v2 workspace route with an open sidebar the TopBar row is merged
// into the pane tab bar (which provides the drag region and hosts the
// right-sidebar toggle). Expanded sidebars host the traffic-light pad in
// their header; collapsed rails host it via their headroom spacer plus the
// tab bar's leading inset. Only a fully closed sidebar keeps the TopBar,
// whose inset then keeps content clear of the macOS traffic lights. The
// new-workspace page brings its own drag strip, and the dashboard views
// (automations/tasks/workspaces) carry drag fillers in their own headers,
// so they hide the TopBar whenever the expanded sidebar sits outside the
// column — otherwise it renders as an empty strip above their headers.
const hideTopBar =
(onV2WorkspaceRoute &&
!versionMismatch &&
isV2CloudEnabled &&
isWorkspaceSidebarOpen) ||
((onNewWorkspaceRoute || onDashboardViewRoute) && sidebarOutsideColumn);
return (
// The single ports-data provider for both layout modes. It lives up here
// (not in the sidebar) because in topbar mode the pill renders inside
// subtrees that remount on workspace navigation (TopBar / the workspace
// tab bar) — the data must survive those remounts or the pill blinks out
// for the first empty-data frames. The inline chip in the sidebar reads
// the same context; polling stays off when nothing renders ports (v1, or
// a collapsed/closed sidebar in inline mode).
<DashboardSidebarPortsProvider
enabled={
isV2CloudEnabled &&
(portsDisplayMode === "topbar" ||
(isWorkspaceSidebarOpen && !isWorkspaceSidebarCollapsed()))
}
>
<div className="flex h-full w-full overflow-hidden">
<CommandPaletteHost />
{sidebarOutsideColumn && sidebarPanel}
<div className="flex flex-1 flex-col min-w-0 min-h-0">
{!hideTopBar && <TopBar />}
<div className="flex flex-1 min-h-0 min-w-0 overflow-hidden">
{!sidebarOutsideColumn && sidebarPanel}
<div className="relative flex flex-1 min-h-0 min-w-0">
{versionMismatch ? (
// A v2 user on a stale v1 workspace route has nothing to go
// back to, so send them somewhere actionable instead of a
// dead-end "pick a workspace" screen. v1 users keep the
// static state — /new-workspace is a v2-only surface.
isV2CloudEnabled ? (
<Redirect to="/new-workspace" replace />
) : (
<CrossVersionMismatchState />
)
) : (
// Contain content-route crashes to this pane: without a
// boundary they bubble to the root and unmount the whole
// app, which reads as Superset restarting itself
// (SUPER-1814). Resets on navigation.
<CatchBoundary
// Full href, not just pathname: a same-path search/hash
// change (filter, tab) must also clear a stuck error pane.
getResetKey={() => location.href}
errorComponent={DashboardContentError}
>
<Outlet />
</CatchBoundary>
)}
</div>
</div>
</div>
<div
id="workspace-right-sidebar-slot"
className="flex h-full shrink-0"
/>
<AddRepositoryModals />
{deleteTarget && (
<DeleteWorkspaceDialog
workspaceId={deleteTarget.workspaceId}
workspaceName={deleteTarget.workspaceName}
workspaceType={deleteTarget.workspaceType}
open={true}
onOpenChange={(open) => {
if (!open) setDeleteTarget(null);
}}
/>
)}
</div>
</DashboardSidebarPortsProvider>
);
}