AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(frontend/builder): offset tutorial connection popover so handles stay draggable (#13480)
Abhimanyu Yadavd62a60a8670c
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/tutorial/steps/connections.test.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/tutorial/steps/connections.test.tsnew file mode 100644index 0000000000..fa23dd2271--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/tutorial/steps/connections.test.ts@@ -0,0 +1,79 @@+import { describe, it, expect } from "vitest";+import {+ connectionHandleOffset,+ CONNECTION_STEP_OFFSET,+ createConnectionSteps,+} from "./connections";++describe("connectionHandleOffset", () => {+ it("shifts left placements further left along x", () => {+ expect(+ connectionHandleOffset({ placement: "left", x: 100, y: 50 }),+ ).toEqual({ x: 100 - CONNECTION_STEP_OFFSET });+ });++ it("shifts right placements further right along x", () => {+ expect(+ connectionHandleOffset({ placement: "right", x: 100, y: 50 }),+ ).toEqual({ x: 100 + CONNECTION_STEP_OFFSET });+ });++ it("shifts top placements further up along y", () => {+ expect(connectionHandleOffset({ placement: "top", x: 100, y: 50 })).toEqual(+ {+ y: 50 - CONNECTION_STEP_OFFSET,+ },+ );+ });++ it("shifts bottom placements further down along y", () => {+ expect(+ connectionHandleOffset({ placement: "bottom", x: 100, y: 50 }),+ ).toEqual({ y: 50 + CONNECTION_STEP_OFFSET });+ });++ it("respects the base side of aligned placements like left-start", () => {+ expect(+ connectionHandleOffset({ placement: "left-start", x: 100, y: 50 }),+ ).toEqual({ x: 100 - CONNECTION_STEP_OFFSET });+ });++ it("returns no offset for unknown placements", () => {+ expect(+ connectionHandleOffset({ placement: "center", x: 100, y: 50 }),+ ).toEqual({});+ });+});++describe("createConnectionSteps floating offset", () => {+ const tour = { next: () => {}, back: () => {}, show: () => {} };++ it("attaches the connection offset middleware to the connect steps", () => {+ const steps = createConnectionSteps(tour) as Array<{+ id?: string;+ floatingUIOptions?: {+ middleware?: Array<{+ name: string;+ fn: (state: { placement: string; x: number; y: number }) => {+ x?: number;+ y?: number;+ };+ }>;+ };+ }>;++ const output = steps.find((s) => s.id === "connect-blocks-output");+ const input = steps.find((s) => s.id === "connect-blocks-input");++ const middleware = output?.floatingUIOptions?.middleware?.[0];+ expect(middleware?.name).toBe("connectionHandleOffset");+ expect(input?.floatingUIOptions?.middleware?.[0]?.name).toBe(+ "connectionHandleOffset",+ );++ // Invoking the middleware fn exercises the wiring to connectionHandleOffset.+ expect(middleware?.fn({ placement: "left", x: 200, y: 30 })).toEqual({+ x: 200 - CONNECTION_STEP_OFFSET,+ });+ });+});diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/tutorial/steps/connections.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/tutorial/steps/connections.tsindex 7d0ebc9116..af010b0be0 100644--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/tutorial/steps/connections.ts+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/tutorial/steps/connections.ts@@ -44,6 +44,42 @@ const hasAnyEdge = (): boolean => {return useEdgeStore.getState().edges.length > 0;};+// Shepherd 14 positions the popover via @floating-ui/dom (absolute left/top),+// so CSS margins don't move it. Use a floating-ui offset middleware to push the+// popover away from the handle, leaving room to grab and drag the connection.+export const CONNECTION_STEP_OFFSET = 72;++export const connectionHandleOffset = ({+ placement,+ x,+ y,+}: {+ placement: string;+ x: number;+ y: number;+}): { x?: number; y?: number } => {+ const side = placement.split("-")[0];+ if (side === "left") return { x: x - CONNECTION_STEP_OFFSET };+ if (side === "right") return { x: x + CONNECTION_STEP_OFFSET };+ if (side === "top") return { y: y - CONNECTION_STEP_OFFSET };+ if (side === "bottom") return { y: y + CONNECTION_STEP_OFFSET };+ return {};+};++const connectionFloatingOptions: StepOptions["floatingUIOptions"] = {+ middleware: [+ {+ name: "connectionHandleOffset",+ fn: (state) =>+ connectionHandleOffset({+ placement: state.placement,+ x: state.x,+ y: state.y,+ }),+ },+ ],+};+export const createConnectionSteps = (tour: any): StepOptions[] => {let isConnecting = false;@@ -87,6 +123,7 @@ export const createConnectionSteps = (tour: any): StepOptions[] => {element: TUTORIAL_SELECTORS.FIRST_CALCULATOR_RESULT_OUTPUT_HANDLER,on: "left",},+ floatingUIOptions: connectionFloatingOptions,when: {show: () => {@@ -174,6 +211,7 @@ export const createConnectionSteps = (tour: any): StepOptions[] => {element: TUTORIAL_SELECTORS.SECOND_CALCULATOR_NUMBER_A_INPUT_HANDLER,on: "right",},+ floatingUIOptions: connectionFloatingOptions,when: {show: () => {const inputSelector =