diff --git a/apps/yaak-proxy/components/FlowList.tsx b/apps/yaak-proxy/components/FlowList.tsx index df6a8af35..ae44b0f85 100644 --- a/apps/yaak-proxy/components/FlowList.tsx +++ b/apps/yaak-proxy/components/FlowList.tsx @@ -633,8 +633,8 @@ function useColumnDragView( const ghost = snapshotColumn(event.id, event.x, root, header, list); const style = document.createElement("style"); document.head.append(style); - const width = cells[from]?.getBoundingClientRect().width ?? 0; - drag.current = { ghost, ids, from, width, to: null, style }; + const widths = cells.map((c) => c.getBoundingClientRect().width); + drag.current = { ghost, ids, widths, from, to: null, style }; style.textContent = columnDragCss(drag.current); } } @@ -656,16 +656,16 @@ function useColumnDragView( interface ColumnDragView { ghost: ColumnGhost | null; - /** The columns shown, the dragged one's place among them and its width, and its target */ + /** The columns shown and their widths, the dragged one's place among them, and its target */ ids: ColumnId[]; + widths: number[]; from: number; - width: number; to: number | null; style: HTMLStyleElement; } /** The rules for a drag: the column hidden, and those it passes slid aside */ -function columnDragCss({ ids, from, width, to }: ColumnDragView): string { +function columnDragCss({ ids, widths, from, to }: ColumnDragView): string { // A row's cell is the box in its grid: the column's child, or inside the `contents` span a // tooltip wraps it in, as a box that is only its contents can't move const cells = (is: string) => @@ -679,10 +679,23 @@ function columnDragCss({ ids, from, width, to }: ColumnDragView): string { ]; const dragged = ids[from]; if (dragged != null) rules.push(`${column(dragged)} { visibility: hidden; }`); - columnShifts(ids.length, from, width, to).forEach((dx, i) => { + const shifts = columnShifts(ids.length, from, widths[from] ?? 0, to); + shifts.forEach((dx, i) => { const id = ids[i]; if (dx !== 0 && id != null) rules.push(`${column(id)} { transform: translateX(${dx}px); }`); }); + // A failed flow's reason spans Type and Size together; while they part, it keeps to Type's + // width, so it doesn't slide over the column past Size. + const type = ids.indexOf("type"); + if (type !== -1 && ids[type + 1] === "size") { + const size = type + 1; + if (from === size || shifts[type] !== shifts[size]) { + const is = '[data-flow-rows] [data-column="type"]'; + rules.push( + `${is} > .col-span-2, ${is} > .contents > .col-span-2 { width: ${widths[type] ?? 0}px; }`, + ); + } + } return rules.join("\n"); } diff --git a/apps/yaak-proxy/components/FlowListHeader.tsx b/apps/yaak-proxy/components/FlowListHeader.tsx index 837eec069..7eccf9856 100644 --- a/apps/yaak-proxy/components/FlowListHeader.tsx +++ b/apps/yaak-proxy/components/FlowListHeader.tsx @@ -382,6 +382,8 @@ function useColumnDrag({ from: number; /** The labels' edges when the drag began, from the header's left, as the columns slide */ cells: { left: number; right: number }[]; + /** The columns shown when it began, which the edges and `from` describe */ + shown: string; /** The pointer, across the window */ x: number; /** The boundary it would move to, null where it would stay */ @@ -418,7 +420,8 @@ function useColumnDrag({ ); const id = e.active.id as ColumnId; const x = pointer.current; - state.current = { id, from, cells, x, to: null, ghostX: x, frame: 0 }; + const shown = shownKey(latest.current.columns); + state.current = { id, from, cells, shown, x, to: null, ghostX: x, frame: 0 }; latest.current.onColumnDrag({ type: "start", id, x }); target(state.current); @@ -460,6 +463,13 @@ function useColumnDrag({ stop(false); }, [stop]); + // Columns shown or hidden under a drag, as App is when the first flow with an app arrives, + // leave its edges and target describing columns that are gone; it is put back instead. + const shown = shownKey(columns); + useEffect(() => { + if (state.current != null && state.current.shown !== shown) cancel(); + }, [shown, cancel]); + // The pointer from a press on the header until its release, read before dnd-kit sees it. // dnd-kit starts a drag on the move that crosses `DRAG_DISTANCE` and reports moves and the // release only once it has rendered the drag, so a release right after a move would drop @@ -522,3 +532,8 @@ function useColumnDrag({ dndHandlers: { onDragStart, onDragEnd: drop, onDragCancel: cancel }, }; } + +/** Which columns show, in order, to tell when that changes */ +function shownKey(columns: Column[]): string { + return columns.map((c) => c.id).join(" "); +}