Skip to content

Commit 3d33ee5

Browse files
committed
Update the connector type on drag
1 parent 6804022 commit 3d33ee5

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

apps/webapp/app/components/navigation/SideMenu.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,17 @@ export function SideMenu({
232232

233233
const canReorder = orderedDashboards.length >= 2;
234234

235+
// Track layout during drag for real-time tree connector updates
236+
const [dragLayout, setDragLayout] = useState<Layout | null>(null);
237+
238+
const handleDashboardDrag = useCallback((layout: Layout) => {
239+
setDragLayout(layout);
240+
}, []);
241+
235242
// Handle drag stop - extract new order from layout y-positions
236243
const handleDashboardDragStop = useCallback(
237244
(layout: Layout) => {
245+
setDragLayout(null);
238246
const sorted = [...layout].sort((a, b) => a.y - b.y);
239247
const newOrder = sorted.map((item) => item.i);
240248
if (JSON.stringify(newOrder) === JSON.stringify(dashboardOrder)) return;
@@ -253,6 +261,18 @@ export function SideMenu({
253261
[dashboardOrder, organization.id, user.isImpersonating, dashboardOrderFetcher]
254262
);
255263

264+
// Compute which dashboard is visually last (during drag or at rest)
265+
const getIsLastDashboard = useCallback(
266+
(friendlyId: string, index: number) => {
267+
if (dragLayout) {
268+
const maxY = Math.max(...dragLayout.map((l) => l.y));
269+
return dragLayout.find((l) => l.i === friendlyId)?.y === maxY;
270+
}
271+
return index === orderedDashboards.length - 1;
272+
},
273+
[dragLayout, orderedDashboards.length]
274+
);
275+
256276
const persistSideMenuPreferences = useCallback(
257277
(data: {
258278
isCollapsed?: boolean;
@@ -594,12 +614,13 @@ export function SideMenu({
594614
}}
595615
resizeConfig={{ enabled: false }}
596616
dragConfig={{ enabled: !isCollapsed, handle: ".sidebar-drag-handle" }}
617+
onDrag={handleDashboardDrag}
597618
onDragStop={handleDashboardDragStop}
598619
className="sidebar-reorder-grid"
599620
autoSize
600621
>
601622
{orderedDashboards.map((dashboard, index) => {
602-
const isLast = index === orderedDashboards.length - 1;
623+
const isLast = getIsLastDashboard(dashboard.friendlyId, index);
603624
return (
604625
<div key={dashboard.friendlyId}>
605626
<SideMenuItem
@@ -608,8 +629,8 @@ export function SideMenu({
608629
isCollapsed
609630
? LineChartIcon
610631
: isLast
611-
? TreeConnectorEnd
612-
: TreeConnectorBranch
632+
? TreeConnectorEnd
633+
: TreeConnectorBranch
613634
}
614635
activeIconColor={isCollapsed ? "text-customDashboards" : undefined}
615636
inactiveIconColor={isCollapsed ? "text-customDashboards" : undefined}

0 commit comments

Comments
 (0)