feat(web): show and move a task's workflow step from the kanban preview (#3329)
Co-authored-by: nova28 <17953305+nova28@users.noreply.github.com> Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com> Co-authored-by: Carlos Florencio <carlosmflorencio@gmail.com>
This commit is contained in:
@@ -48,6 +48,8 @@ type MinimalWorkflowStepperProps = {
|
||||
workflowId?: string | null;
|
||||
movingToStepId: string | null;
|
||||
onMove: (stepId: string) => Promise<boolean>;
|
||||
/** Notified whenever the disclosure surface opens or closes. */
|
||||
onDisclosureOpenChange?: (open: boolean) => void;
|
||||
};
|
||||
|
||||
export function MinimalWorkflowStepper({
|
||||
@@ -58,6 +60,7 @@ export function MinimalWorkflowStepper({
|
||||
workflowId,
|
||||
movingToStepId,
|
||||
onMove,
|
||||
onDisclosureOpenChange,
|
||||
}: MinimalWorkflowStepperProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
@@ -95,6 +98,7 @@ export function MinimalWorkflowStepper({
|
||||
workflowId={workflowId}
|
||||
movingToStepId={movingToStepId}
|
||||
onMove={onMove}
|
||||
onDisclosureOpenChange={onDisclosureOpenChange}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -308,6 +312,7 @@ function CompactWorkflowStepDisclosure({
|
||||
workflowId,
|
||||
movingToStepId,
|
||||
onMove,
|
||||
onDisclosureOpenChange,
|
||||
}: {
|
||||
sortedSteps: Step[];
|
||||
current: Step;
|
||||
@@ -317,10 +322,20 @@ function CompactWorkflowStepDisclosure({
|
||||
workflowId: string;
|
||||
movingToStepId: string | null;
|
||||
onMove: (stepId: string) => Promise<boolean>;
|
||||
onDisclosureOpenChange?: (open: boolean) => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const usesTouchDrawer = useTouchDrawer();
|
||||
const controls = useCompactWorkflowDisclosure();
|
||||
useEffect(() => {
|
||||
onDisclosureOpenChange?.(controls.open);
|
||||
}, [controls.open, onDisclosureOpenChange]);
|
||||
useEffect(
|
||||
() => () => {
|
||||
onDisclosureOpenChange?.(false);
|
||||
},
|
||||
[onDisclosureOpenChange],
|
||||
);
|
||||
const trigger = (
|
||||
<CompactWorkflowTrigger
|
||||
current={current}
|
||||
@@ -376,6 +391,7 @@ function CompactWorkflowStepDisclosure({
|
||||
className="w-72 max-w-[calc(100vw-1rem)] p-2"
|
||||
onOpenAutoFocus={controls.handleOpenAutoFocus}
|
||||
onCloseAutoFocus={controls.handleCloseAutoFocus}
|
||||
onEscapeKeyDown={(event) => event.stopPropagation()}
|
||||
onMouseEnter={controls.openDisclosure}
|
||||
onMouseLeave={controls.scheduleClose}
|
||||
onFocusCapture={controls.handleContentFocus}
|
||||
@@ -423,8 +439,8 @@ function MinimalStepContents({
|
||||
aria-current={currentIndex >= 0 ? "step" : undefined}
|
||||
className="flex min-w-0 items-center gap-1.5 text-xs"
|
||||
>
|
||||
<StepCircleIndicator isCurrent isCompleted={false} />
|
||||
<span className="truncate text-xs font-medium leading-none text-foreground">
|
||||
<StepCircleIndicator isCurrent={currentIndex >= 0} isCompleted={false} />
|
||||
<span className="min-w-0 truncate text-xs font-medium leading-none text-foreground">
|
||||
{current.name}
|
||||
</span>
|
||||
</div>
|
||||
@@ -531,6 +547,8 @@ export function canMoveToStep(params: {
|
||||
return params.isAdjacent || !!params.allowManualMove;
|
||||
}
|
||||
|
||||
export type StepMarkerState = "current" | "completed" | "upcoming";
|
||||
|
||||
export function StepCircleIndicator({
|
||||
isCurrent,
|
||||
isCompleted,
|
||||
@@ -538,9 +556,15 @@ export function StepCircleIndicator({
|
||||
isCurrent: boolean;
|
||||
isCompleted: boolean;
|
||||
}) {
|
||||
let state: StepMarkerState = "upcoming";
|
||||
if (isCurrent) state = "current";
|
||||
else if (isCompleted) state = "completed";
|
||||
if (isCurrent) {
|
||||
return (
|
||||
<span className="relative flex items-center justify-center shrink-0">
|
||||
<span
|
||||
data-marker-state={state}
|
||||
className="relative flex items-center justify-center shrink-0"
|
||||
>
|
||||
<span className="absolute h-3.5 w-3.5 rounded-full border-2 border-primary/40" />
|
||||
<span className="h-2 w-2 rounded-full bg-primary" />
|
||||
</span>
|
||||
@@ -548,13 +572,16 @@ export function StepCircleIndicator({
|
||||
}
|
||||
if (isCompleted) {
|
||||
return (
|
||||
<span className="relative flex items-center justify-center shrink-0">
|
||||
<span
|
||||
data-marker-state={state}
|
||||
className="relative flex items-center justify-center shrink-0"
|
||||
>
|
||||
<span className="h-2 w-2 rounded-full bg-muted-foreground/60" />
|
||||
</span>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<span className="relative flex items-center justify-center shrink-0">
|
||||
<span data-marker-state={state} className="relative flex items-center justify-center shrink-0">
|
||||
<span className="h-2 w-2 rounded-full border border-muted-foreground/40" />
|
||||
</span>
|
||||
);
|
||||
|
||||
@@ -112,6 +112,8 @@ const MOVE_A_TEST_ID = "workflow-step-disclosure-move-a";
|
||||
const MOVE_C_TEST_ID = "workflow-step-disclosure-move-c";
|
||||
const MOVE_D_TEST_ID = "workflow-step-disclosure-move-d";
|
||||
const TRIGGER_LABEL = "Step 2 of 4: Work";
|
||||
const SPEC_TEST_ID = "workflow-step-Spec";
|
||||
const ARIA_CURRENT = "aria-current";
|
||||
|
||||
describe("WorkflowStepper", () => {
|
||||
it("renders every step when there is room (not collapsed)", () => {
|
||||
@@ -121,11 +123,25 @@ describe("WorkflowStepper", () => {
|
||||
expect(screen.getByTestId("workflow-stepper")).toBeTruthy();
|
||||
expect(screen.queryByTestId("workflow-stepper-minimal")).toBeNull();
|
||||
// All steps render under the persistent outer container.
|
||||
expect(screen.getByTestId("workflow-step-Spec")).toBeTruthy();
|
||||
expect(screen.getByTestId(SPEC_TEST_ID)).toBeTruthy();
|
||||
expect(screen.getByTestId("workflow-step-Work")).toBeTruthy();
|
||||
expect(screen.getByTestId("workflow-step-Review")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("orders steps sharing a position by ascending id, not insertion order", () => {
|
||||
collapsedMock.mockReturnValue(false);
|
||||
const TIEBREAK_STEPS: WorkflowStepperStep[] = [
|
||||
{ id: "z", name: "ZStep", color: "#111", position: 0 },
|
||||
{ id: "a", name: "AStep", color: "#222", position: 0 },
|
||||
];
|
||||
const { container } = render(<WorkflowStepper steps={TIEBREAK_STEPS} currentStepId={null} />);
|
||||
|
||||
const aIndex = container.innerHTML.indexOf("AStep");
|
||||
const zIndex = container.innerHTML.indexOf("ZStep");
|
||||
expect(aIndex).toBeGreaterThan(-1);
|
||||
expect(aIndex).toBeLessThan(zIndex);
|
||||
});
|
||||
|
||||
it("collapses to only the current step when space runs out", () => {
|
||||
collapsedMock.mockReturnValue(true);
|
||||
render(<WorkflowStepper steps={STEPS} currentStepId="b" />);
|
||||
@@ -136,8 +152,8 @@ describe("WorkflowStepper", () => {
|
||||
|
||||
// Current step keeps its test id + aria-current in either variant.
|
||||
const current = screen.getByTestId("workflow-step-Work");
|
||||
expect(current.getAttribute("aria-current")).toBe("step");
|
||||
expect(screen.queryByTestId("workflow-step-Spec")).toBeNull();
|
||||
expect(current.getAttribute(ARIA_CURRENT)).toBe("step");
|
||||
expect(screen.queryByTestId(SPEC_TEST_ID)).toBeNull();
|
||||
expect(screen.queryByTestId("workflow-step-Review")).toBeNull();
|
||||
|
||||
// Position indicator reflects the current step out of the total.
|
||||
@@ -164,7 +180,7 @@ describe("WorkflowStepper compact disclosure", () => {
|
||||
|
||||
expect(screen.getByTestId(DISCLOSURE_TEST_ID)).toBeTruthy();
|
||||
expect(screen.getByTestId("workflow-step-disclosure-row-a")).toBeTruthy();
|
||||
expect(screen.getByTestId("workflow-step-disclosure-row-b").getAttribute("aria-current")).toBe(
|
||||
expect(screen.getByTestId("workflow-step-disclosure-row-b").getAttribute(ARIA_CURRENT)).toBe(
|
||||
"step",
|
||||
);
|
||||
expect(screen.getByTestId("workflow-step-disclosure-row-c")).toBeTruthy();
|
||||
@@ -248,10 +264,27 @@ describe("WorkflowStepper fallback states", () => {
|
||||
render(<WorkflowStepper steps={STEPS} currentStepId={null} />);
|
||||
|
||||
// Fallback step isn't the real current step, so it must not claim aria-current.
|
||||
expect(screen.getByTestId("workflow-step-Spec").getAttribute("aria-current")).toBeNull();
|
||||
const fallbackStep = screen.getByTestId(SPEC_TEST_ID);
|
||||
expect(fallbackStep.getAttribute(ARIA_CURRENT)).toBeNull();
|
||||
// aria-current alone is a false negative here: it was already conditioned
|
||||
// correctly before the fix. The marker itself must also not read "current".
|
||||
expect(
|
||||
fallbackStep.querySelector("[data-marker-state]")?.getAttribute("data-marker-state"),
|
||||
).toBe("upcoming");
|
||||
expect(screen.getByText("1/3")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("marks the marker current when collapsed on a resolved current step", () => {
|
||||
collapsedMock.mockReturnValue(true);
|
||||
render(<WorkflowStepper steps={STEPS} currentStepId="a" />);
|
||||
|
||||
const currentStep = screen.getByTestId(SPEC_TEST_ID);
|
||||
expect(currentStep.getAttribute(ARIA_CURRENT)).toBe("step");
|
||||
expect(
|
||||
currentStep.querySelector("[data-marker-state]")?.getAttribute("data-marker-state"),
|
||||
).toBe("current");
|
||||
});
|
||||
|
||||
it("shows the archived badge instead of a step when collapsed and archived", () => {
|
||||
collapsedMock.mockReturnValue(true);
|
||||
render(
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
"use client";
|
||||
|
||||
import { memo, useCallback, useMemo, useRef, useState } from "react";
|
||||
import { memo, useMemo, useRef } from "react";
|
||||
import { cn } from "@kandev/ui/lib/utils";
|
||||
import { HoverCard, HoverCardContent, HoverCardTrigger } from "@kandev/ui/hover-card";
|
||||
import { Button } from "@kandev/ui/button";
|
||||
import { IconArrowRight } from "@tabler/icons-react";
|
||||
import { moveTask } from "@/lib/api";
|
||||
import { StepCapabilityIcons } from "@/components/step-capability-icons";
|
||||
import { useAppStore } from "@/components/state-provider";
|
||||
import { useContextFilesStore } from "@/lib/state/context-files-store";
|
||||
import { useLayoutStore } from "@/lib/state/layout-store";
|
||||
import { useDockviewStore } from "@/lib/state/dockview-store";
|
||||
import { useToolbarCollapsed } from "@/hooks/use-toolbar-collapsed";
|
||||
import {
|
||||
usePresentationToken,
|
||||
useWorkflowStepMove,
|
||||
} from "@/hooks/domains/kanban/use-workflow-step-move";
|
||||
import { sortWorkflowStepsByPosition } from "@/lib/kanban/workflow-step-order";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
MinimalWorkflowStepper,
|
||||
@@ -23,38 +23,6 @@ import {
|
||||
|
||||
type Step = WorkflowStepperStep;
|
||||
|
||||
const PLAN_CONTEXT_PATH = "plan:context";
|
||||
|
||||
/** Returns a callback that disables plan mode for the active session of a task. */
|
||||
function useDisablePlanMode() {
|
||||
const activeSessionId = useAppStore((s) => s.tasks.activeSessionId);
|
||||
const planModeEnabled = useAppStore((s) =>
|
||||
activeSessionId ? (s.chatInput.planModeBySessionId[activeSessionId] ?? false) : false,
|
||||
);
|
||||
const setPlanMode = useAppStore((s) => s.setPlanMode);
|
||||
const setActiveDocument = useAppStore((s) => s.setActiveDocument);
|
||||
const closeDocument = useLayoutStore((s) => s.closeDocument);
|
||||
const removeContextFile = useContextFilesStore((s) => s.removeFile);
|
||||
const applyBuiltInPreset = useDockviewStore((s) => s.applyBuiltInPreset);
|
||||
|
||||
return useCallback(() => {
|
||||
if (!activeSessionId || !planModeEnabled) return;
|
||||
applyBuiltInPreset("default");
|
||||
closeDocument(activeSessionId);
|
||||
setActiveDocument(activeSessionId, null);
|
||||
setPlanMode(activeSessionId, false);
|
||||
removeContextFile(activeSessionId, PLAN_CONTEXT_PATH);
|
||||
}, [
|
||||
activeSessionId,
|
||||
planModeEnabled,
|
||||
setPlanMode,
|
||||
setActiveDocument,
|
||||
closeDocument,
|
||||
removeContextFile,
|
||||
applyBuiltInPreset,
|
||||
]);
|
||||
}
|
||||
|
||||
type WorkflowStepperProps = {
|
||||
steps: Step[];
|
||||
currentStepId: string | null;
|
||||
@@ -75,45 +43,26 @@ const WorkflowStepper = memo(function WorkflowStepper({
|
||||
onMoveError,
|
||||
}: WorkflowStepperProps) {
|
||||
const { t } = useTranslation();
|
||||
const [movingToStepId, setMovingToStepId] = useState<string | null>(null);
|
||||
const disablePlanMode = useDisablePlanMode();
|
||||
// Only the in-flight step's own button is disabled, so every other step stays
|
||||
// clickable and two moves can overlap. This counter marks which one is the
|
||||
// latest; a slower predecessor must not own the banner or the loading state.
|
||||
const moveRequestRef = useRef(0);
|
||||
// The task route's continuous presentation of this task: a navigation away
|
||||
// and back changes taskId and back, which must invalidate a request left
|
||||
// over from the earlier presentation the same way a preview close-and-reopen
|
||||
// does for the kanban preview header.
|
||||
const presentationToken = usePresentationToken(taskId ?? null);
|
||||
const { movingToStepId, handleMove } = useWorkflowStepMove({
|
||||
taskId,
|
||||
workflowId,
|
||||
presentationToken,
|
||||
onMoveStart,
|
||||
onMoveError,
|
||||
});
|
||||
|
||||
const sortedSteps = useMemo(() => [...steps].sort((a, b) => a.position - b.position), [steps]);
|
||||
const sortedSteps = useMemo(() => sortWorkflowStepsByPosition(steps), [steps]);
|
||||
|
||||
const currentIndex = useMemo(
|
||||
() => sortedSteps.findIndex((s) => s.id === currentStepId),
|
||||
[sortedSteps, currentStepId],
|
||||
);
|
||||
|
||||
const handleMove = useCallback(
|
||||
async (stepId: string): Promise<boolean> => {
|
||||
if (!taskId || !workflowId) return false;
|
||||
onMoveStart?.();
|
||||
disablePlanMode();
|
||||
const requestId = ++moveRequestRef.current;
|
||||
setMovingToStepId(stepId);
|
||||
try {
|
||||
await moveTask(taskId, {
|
||||
workflow_id: workflowId,
|
||||
workflow_step_id: stepId,
|
||||
position: 0,
|
||||
});
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.error("[WorkflowStepper] Failed to move task:", err);
|
||||
if (requestId === moveRequestRef.current) onMoveError?.(err);
|
||||
return false;
|
||||
} finally {
|
||||
if (requestId === moveRequestRef.current) setMovingToStepId(null);
|
||||
}
|
||||
},
|
||||
[taskId, workflowId, disablePlanMode, onMoveStart, onMoveError],
|
||||
);
|
||||
|
||||
// Collapse to a minimal view when the full stepper can't fit (w-full keeps the measurement track-driven).
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const isCollapsed = useToolbarCollapsed(containerRef);
|
||||
|
||||
Reference in New Issue
Block a user