Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-8941: merge project workflow entry points into one flow panel (#10285)
Jiayuan Zhang7cae26303b69
diff --git a/packages/views/locales/en/issues.json b/packages/views/locales/en/issues.jsonindex 6e1bd4fe01..833bc7b2d5 100644--- a/packages/views/locales/en/issues.json+++ b/packages/views/locales/en/issues.json@@ -1781,16 +1781,13 @@"name_placeholder": "Status name","add": "Add"},- "menu": {- "view_flow": "View full flow",- "switch": "Switch workflow"- },"flow": {"title": "{{workflow}} workflow","scope_own": "Only this project uses this workflow.","no_handoff_here": "No handoff","scope_shared_one": "{{count}} project uses this workflow. Its handoffs apply to every project using it.",- "scope_shared_other": "{{count}} projects use this workflow. Its handoffs apply to all of them."+ "scope_shared_other": "{{count}} projects use this workflow. Its handoffs apply to all of them.",+ "switch": "Switch workflow"},"templates": {"delivery": {diff --git a/packages/views/locales/es/issues.json b/packages/views/locales/es/issues.jsonindex d39d77a6cb..d72d8f76c5 100644--- a/packages/views/locales/es/issues.json+++ b/packages/views/locales/es/issues.json@@ -1774,16 +1774,13 @@"name_placeholder": "Nombre del estado","add": "Añadir"},- "menu": {- "view_flow": "Ver el flujo completo",- "switch": "Cambiar de flujo de trabajo"- },"flow": {"title": "Flujo de trabajo {{workflow}}","scope_own": "Solo este proyecto usa este flujo de trabajo.","no_handoff_here": "Sin traspaso","scope_shared_one": "{{count}} proyecto usa este flujo de trabajo. Sus traspasos se aplican a todos los proyectos que lo usan.",- "scope_shared_other": "{{count}} proyectos usan este flujo de trabajo. Sus traspasos se aplican a todos ellos."+ "scope_shared_other": "{{count}} proyectos usan este flujo de trabajo. Sus traspasos se aplican a todos ellos.",+ "switch": "Cambiar de flujo de trabajo"},"templates": {"delivery": {diff --git a/packages/views/locales/fr/issues.json b/packages/views/locales/fr/issues.jsonindex 06512a6d32..54ff09a499 100644--- a/packages/views/locales/fr/issues.json+++ b/packages/views/locales/fr/issues.json@@ -1781,16 +1781,13 @@"name_placeholder": "Nom de l’état","add": "Ajouter"},- "menu": {- "view_flow": "Voir tout le flux",- "switch": "Changer de workflow"- },"flow": {"title": "Workflow {{workflow}}","scope_own": "Seul ce projet utilise ce workflow.","no_handoff_here": "Pas de relais","scope_shared_one": "{{count}} projet utilise ce workflow. Ses transferts s’appliquent à chaque projet qui l’utilise.",- "scope_shared_other": "{{count}} projets utilisent ce workflow. Ses transferts s’appliquent à tous."+ "scope_shared_other": "{{count}} projets utilisent ce workflow. Ses transferts s’appliquent à tous.",+ "switch": "Changer de workflow"},"templates": {"delivery": {diff --git a/packages/views/locales/ja/issues.json b/packages/views/locales/ja/issues.jsonindex 8f8f5d6bc8..f36d939ba0 100644--- a/packages/views/locales/ja/issues.json+++ b/packages/views/locales/ja/issues.json@@ -1713,15 +1713,12 @@"name_placeholder": "ステータス名","add": "追加"},- "menu": {- "view_flow": "フロー全体を見る",- "switch": "ワークフローを切り替え"- },"flow": {"title": "ワークフロー「{{workflow}}」","scope_own": "このワークフローを使用しているのはこのプロジェクトだけです。","no_handoff_here": "引き継ぎなし",- "scope_shared_other": "{{count}} 件のプロジェクトがこのワークフローを使用しています。引き継ぎはそのすべてに適用されます。"+ "scope_shared_other": "{{count}} 件のプロジェクトがこのワークフローを使用しています。引き継ぎはそのすべてに適用されます。",+ "switch": "ワークフローを切り替え"},"templates": {"delivery": {diff --git a/packages/views/locales/ko/issues.json b/packages/views/locales/ko/issues.jsonindex 19b5e16a93..ee843564ba 100644--- a/packages/views/locales/ko/issues.json+++ b/packages/views/locales/ko/issues.json@@ -1713,15 +1713,12 @@"name_placeholder": "상태 이름","add": "추가"},- "menu": {- "view_flow": "전체 흐름 보기",- "switch": "워크플로 전환"- },"flow": {"title": "“{{workflow}}” 워크플로","scope_own": "이 워크플로는 이 프로젝트만 사용합니다.","no_handoff_here": "인계 없음",- "scope_shared_other": "프로젝트 {{count}}개가 이 워크플로를 사용합니다. 인계는 모두에 적용됩니다."+ "scope_shared_other": "프로젝트 {{count}}개가 이 워크플로를 사용합니다. 인계는 모두에 적용됩니다.",+ "switch": "워크플로 전환"},"templates": {"delivery": {diff --git a/packages/views/locales/ru/issues.json b/packages/views/locales/ru/issues.jsonindex 625a44b57f..cefe32f6a7 100644--- a/packages/views/locales/ru/issues.json+++ b/packages/views/locales/ru/issues.json@@ -1916,10 +1916,6 @@"name_placeholder": "Название статуса","add": "Добавить"},- "menu": {- "view_flow": "Посмотреть весь процесс",- "switch": "Сменить рабочий процесс"- },"flow": {"title": "Рабочий процесс «{{workflow}}»","scope_own": "Этот рабочий процесс используется только в данном проекте.",@@ -1927,7 +1923,8 @@"scope_shared_one": "Этот рабочий процесс используется в {{count}} проекте. Его передачи применяются ко всем проектам, использующим этот процесс.","scope_shared_other": "Этот рабочий процесс используется в {{count}} проекта. Его передачи применяются ко всем этим проектам.","scope_shared_few": "Этот рабочий процесс используется в {{count}} проектах. Его передачи применяются ко всем этим проектам.",- "scope_shared_many": "Этот рабочий процесс используется в {{count}} проектах. Его передачи применяются ко всем этим проектам."+ "scope_shared_many": "Этот рабочий процесс используется в {{count}} проектах. Его передачи применяются ко всем этим проектам.",+ "switch": "Сменить рабочий процесс"},"templates": {"delivery": {diff --git a/packages/views/locales/zh-Hans/issues.json b/packages/views/locales/zh-Hans/issues.jsonindex 92bd6ea8ca..b2f69f1adb 100644--- a/packages/views/locales/zh-Hans/issues.json+++ b/packages/views/locales/zh-Hans/issues.json@@ -1713,15 +1713,12 @@"name_placeholder": "状态名称","add": "添加"},- "menu": {- "view_flow": "查看完整流程",- "switch": "切换工作流"- },"flow": {"title": "「{{workflow}}」工作流","scope_own": "只有这个项目使用这个工作流。","no_handoff_here": "不交接",- "scope_shared_other": "{{count}} 个项目使用这个工作流,它的交接对这些项目都生效。"+ "scope_shared_other": "{{count}} 个项目使用这个工作流,它的交接对这些项目都生效。",+ "switch": "切换工作流"},"templates": {"delivery": {diff --git a/packages/views/locales/zh-Hant/issues.json b/packages/views/locales/zh-Hant/issues.jsonindex c13f0a3e21..0adb0f8ba5 100644--- a/packages/views/locales/zh-Hant/issues.json+++ b/packages/views/locales/zh-Hant/issues.json@@ -1713,15 +1713,12 @@"name_placeholder": "狀態名稱","add": "新增"},- "menu": {- "view_flow": "檢視完整流程",- "switch": "切換工作流"- },"flow": {"title": "「{{workflow}}」工作流","scope_own": "只有這個專案使用這個工作流。","no_handoff_here": "不交接",- "scope_shared_other": "{{count}} 個專案使用這個工作流,它的交接對這些專案都生效。"+ "scope_shared_other": "{{count}} 個專案使用這個工作流,它的交接對這些專案都生效。",+ "switch": "切換工作流"},"templates": {"delivery": {diff --git a/packages/views/projects/components/project-detail.test.tsx b/packages/views/projects/components/project-detail.test.tsxindex 6fe7b3213b..4118486d0e 100644--- a/packages/views/projects/components/project-detail.test.tsx+++ b/packages/views/projects/components/project-detail.test.tsx@@ -28,8 +28,9 @@ vi.mock("@multica/ui/lib/clipboard", () => ({copyText: mocks.copyText,}));-vi.mock("../../workflows/project-workflow-menu", () => ({- ProjectWorkflowMenuHost: ({ children }: { children: (submenu: null) => React.ReactNode }) => children(null),+vi.mock("../../workflows/project-workflow-sheet", () => ({+ ProjectWorkflowMenuItem: () => null,+ ProjectWorkflowSheet: () => null,}));vi.mock("../../workflows/project-workflow-row", () => ({ ProjectWorkflowControl: () => null }));diff --git a/packages/views/projects/components/project-detail.tsx b/packages/views/projects/components/project-detail.tsxindex 9f532a40f3..03ac79227c 100644--- a/packages/views/projects/components/project-detail.tsx+++ b/packages/views/projects/components/project-detail.tsx@@ -35,7 +35,7 @@ import { ProjectStartDatePicker } from "./project-start-date-picker";import { ProjectDueDatePicker } from "./project-due-date-picker";import { ProjectAccessControl } from "./project-access";import { ProjectWorkflowControl } from "../../workflows/project-workflow-row";-import { ProjectWorkflowMenuHost } from "../../workflows/project-workflow-menu";+import { ProjectWorkflowMenuItem, ProjectWorkflowSheet } from "../../workflows/project-workflow-sheet";import { IssueSurface } from "../../issues/surface/issue-surface";import { Skeleton } from "@multica/ui/components/ui/skeleton";import { Button, buttonVariants } from "@multica/ui/components/ui/button";@@ -104,11 +104,11 @@ function PropRow({}// The project's workflow (MUL-7420).-function ProjectWorkflowPropRow({ project }: { project: Project }) {+function ProjectWorkflowPropRow({ project, onOpen }: { project: Project; onOpen: () => void }) {const { t } = useT("issues");return (<PropRow label={t(($) => $.workflows.project.label)}>- <ProjectWorkflowControl project={project} />+ <ProjectWorkflowControl project={project} onOpen={onOpen} /></PropRow>);}@@ -196,6 +196,12 @@ export function ProjectDetail({ projectId }: { projectId: string }) {} = useAnimatedRightSidebarState(desktopSidebarInitialOpen);const [mobileSidebarOpen, setMobileSidebarOpen] = useState(false);const sidebarOpen = isMobile ? mobileSidebarOpen : desktopSidebarOpen;+ const [workflowSheetOpen, setWorkflowSheetOpen] = useState(false);+ // The flow panel is its own modal sheet; it can't stack over the mobile sidebar sheet.+ const openWorkflowSheet = useCallback(() => {+ setMobileSidebarOpen(false);+ setWorkflowSheetOpen(true);+ }, []);useEffect(() => {if (isMobile) {@@ -463,7 +469,7 @@ export function ProjectDetail({ projectId }: { projectId: string }) {<PropRow label={t(($) => $.detail.prop_due_date)}><ProjectDueDatePicker dueDate={project.due_date} onUpdate={handleUpdateField} /></PropRow>- <ProjectWorkflowPropRow project={project} />+ <ProjectWorkflowPropRow project={project} onOpen={openWorkflowSheet} /></div>}</div>@@ -534,84 +540,75 @@ export function ProjectDetail({ projectId }: { projectId: string }) {scope={issueScope}modes={["board", "list", "table", "swimlane", "gantt"]}renderHeader={({ controller }) => (- <ProjectWorkflowMenuHost project={project}>- {(workflowSubmenu) => (- <IssueViewHeader- controller={controller}- base={{ kind: "project", project }}- baseMenu={+ <IssueViewHeader+ controller={controller}+ base={{ kind: "project", project }}+ baseMenu={+ <>+ <DropdownMenuItem+ onClick={() =>+ useModalStore+ .getState()+ .open("project-rename", { projectId: project.id, title: project.title })+ }+ >+ <Pencil className="h-3.5 w-3.5" />+ {t(($) => $.detail.rename_action)}+ </DropdownMenuItem>+ <DropdownMenuItem onClick={() => {+ void copyText(router.getShareableUrl(currentPath(router))).then((ok) => {+ if (ok) toast.success(t(($) => $.detail.toast_link_copied));+ });+ }}>+ <Link2 className="h-3.5 w-3.5" />+ {t(($) => $.detail.copy_link)}+ </DropdownMenuItem>+ <DropdownMenuItem onClick={() => {+ if (isPinned) {+ deletePinMut.mutate({ itemType: "project", itemId: projectId });+ } else {+ createPin.mutate({ item_type: "project", item_id: projectId });+ }+ }}>+ {isPinned ? <PinOff className="h-3.5 w-3.5" /> : <Pin className="h-3.5 w-3.5" />}+ {isPinned ? t(($) => $.detail.unpin_tooltip) : t(($) => $.detail.pin_tooltip)}+ </DropdownMenuItem>+ <ProjectWorkflowMenuItem project={project} onOpen={() => setWorkflowSheetOpen(true)} />+ {canDelete && (<>+ <DropdownMenuSeparator /><DropdownMenuItem- onClick={() =>- useModalStore- .getState()- .open("project-rename", { projectId: project.id, title: project.title })- }+ variant="destructive"+ disabled={deleting}+ aria-busy={deleting}+ onClick={() => setDeleteDialogOpen(true)}>- <Pencil className="h-3.5 w-3.5" />- {t(($) => $.detail.rename_action)}+ {deleting ? <Spinner className="size-3.5" aria-hidden="true" /> : <Trash2 className="h-3.5 w-3.5" />}+ {t(($) => $.detail.delete_action)}</DropdownMenuItem>- <DropdownMenuItem onClick={() => {- void copyText(router.getShareableUrl(currentPath(router))).then((ok) => {- if (ok) toast.success(t(($) => $.detail.toast_link_copied));- });- }}>- <Link2 className="h-3.5 w-3.5" />- {t(($) => $.detail.copy_link)}- </DropdownMenuItem>- <DropdownMenuItem onClick={() => {- if (isPinned) {- deletePinMut.mutate({ itemType: "project", itemId: projectId });- } else {- createPin.mutate({ item_type: "project", item_id: projectId });- }- }}>- {isPinned ? <PinOff className="h-3.5 w-3.5" /> : <Pin className="h-3.5 w-3.5" />}- {isPinned ? t(($) => $.detail.unpin_tooltip) : t(($) => $.detail.pin_tooltip)}- </DropdownMenuItem>- {workflowSubmenu && (- <>- <DropdownMenuSeparator />- {workflowSubmenu}- </>- )}- {canDelete && (- <>- <DropdownMenuSeparator />- <DropdownMenuItem- variant="destructive"- disabled={deleting}- aria-busy={deleting}- onClick={() => setDeleteDialogOpen(true)}- >- {deleting ? <Spinner className="size-3.5" aria-hidden="true" /> : <Trash2 className="h-3.5 w-3.5" />}- {t(($) => $.detail.delete_action)}- </DropdownMenuItem>- </>- )}</>- }- trailing={- <Tooltip>- <TooltipTrigger- render={- <Button- variant={sidebarOpen ? "secondary" : "ghost"}- size="icon-sm"- className={sidebarOpen ? "" : "text-muted-foreground"}- aria-label={t(($) => $.detail.sidebar_tooltip)}- onClick={handleToggleSidebar}- >- <PanelRight />- </Button>- }- />- <TooltipContent side="bottom">{t(($) => $.detail.sidebar_tooltip)}</TooltipContent>- </Tooltip>- }- />- )}- </ProjectWorkflowMenuHost>+ )}+ </>+ }+ trailing={+ <Tooltip>+ <TooltipTrigger+ render={+ <Button+ variant={sidebarOpen ? "secondary" : "ghost"}+ size="icon-sm"+ className={sidebarOpen ? "" : "text-muted-foreground"}+ aria-label={t(($) => $.detail.sidebar_tooltip)}+ onClick={handleToggleSidebar}+ >+ <PanelRight />+ </Button>+ }+ />+ <TooltipContent side="bottom">{t(($) => $.detail.sidebar_tooltip)}</TooltipContent>+ </Tooltip>+ }+ />)}/></div>@@ -644,6 +641,8 @@ export function ProjectDetail({ projectId }: { projectId: string }) {)}</ResizablePanelGroup>+ <ProjectWorkflowSheet project={project} open={workflowSheetOpen} onOpenChange={setWorkflowSheetOpen} />+{/* Delete confirmation */}{canDelete && (<AlertDialogdiff --git a/packages/views/workflows/project-workflow-row.test.tsx b/packages/views/workflows/project-workflow-row.test.tsxindex 8a7c7e848a..60753080ea 100644--- a/packages/views/workflows/project-workflow-row.test.tsx+++ b/packages/views/workflows/project-workflow-row.test.tsx@@ -1,4 +1,4 @@-import { cleanup, screen } from "@testing-library/react";+import { cleanup, fireEvent, screen } from "@testing-library/react";import { afterEach, describe, expect, it, vi } from "vitest";import type { IssueWorkflow, Project } from "@multica/core/types";import { renderWithI18n } from "../test/i18n";@@ -20,7 +20,6 @@ const releaseWorkflow = {vi.mock("@tanstack/react-query", () => ({ useQuery: () => ({ data: [] }) }));vi.mock("@multica/core/api", () => ({ api: {}, clientErrorMessage: () => null }));vi.mock("@multica/core/hooks", () => ({ useWorkspaceId: () => "workspace-1" }));-vi.mock("@multica/core/paths", () => ({ useWorkspacePaths: () => ({ settings: () => "/settings" }) }));vi.mock("@multica/core/projects/queries", () => ({ projectListOptions: () => ({}) }));vi.mock("@multica/core/issue-workflows", () => ({useIssueWorkflows: () => ({ workflows: [releaseWorkflow] }),@@ -28,8 +27,6 @@ vi.mock("@multica/core/issue-workflows", () => ({handoffStepCount: () => 3,useSetProjectWorkflow: () => ({ isPending: false, mutateAsync: vi.fn() }),}));-vi.mock("../navigation", () => ({ useNavigation: () => ({ push: vi.fn() }) }));-vi.mock("./permissions", () => ({ useWorkflowPermissions: () => ({ canManageProject: true }) }));vi.mock("./workflow-mapping-dialog", () => ({ WorkflowMappingDialog: () => null }));afterEach(cleanup);@@ -40,10 +37,20 @@ describe("ProjectWorkflowControl", () => {// MUL-8119: in the narrow project sidebar the handoff count used to keep its// width and squeeze the workflow name down to a single glyph.it("gives the whole row to the workflow name and moves the handoff count to the title", () => {- renderWithI18n(<ProjectWorkflowControl project={project} />);+ renderWithI18n(<ProjectWorkflowControl project={project} onOpen={vi.fn()} />);const trigger = screen.getByRole("button", { name: /版本发布/ });expect(trigger.getAttribute("title")).toBe("版本发布 · 3 handoff steps");expect(trigger.textContent).toBe("版本发布");});++ // MUL-8941: the row opens the flow panel instead of a second switch list.+ it("opens the flow panel when clicked", () => {+ const onOpen = vi.fn();+ renderWithI18n(<ProjectWorkflowControl project={project} onOpen={onOpen} />);++ fireEvent.click(screen.getByRole("button", { name: /版本发布/ }));++ expect(onOpen).toHaveBeenCalledOnce();+ });});diff --git a/packages/views/workflows/project-workflow-row.tsx b/packages/views/workflows/project-workflow-row.tsxindex f72d0cba1e..314616a246 100644--- a/packages/views/workflows/project-workflow-row.tsx+++ b/packages/views/workflows/project-workflow-row.tsx@@ -2,27 +2,16 @@import { useState, type ReactNode } from "react";import { useQuery } from "@tanstack/react-query";-import { Check, ChevronDown, Settings, Workflow } from "@multica/ui/icons";+import { Check, Workflow } from "@multica/ui/icons";import { toast } from "sonner";import { api, clientErrorMessage } from "@multica/core/api";import { useWorkspaceId } from "@multica/core/hooks";import { handoffStepCount, resolveProjectWorkflow, useIssueWorkflows, useSetProjectWorkflow } from "@multica/core/issue-workflows";-import { useWorkspacePaths } from "@multica/core/paths";import { projectListOptions } from "@multica/core/projects/queries";import type { IssueWorkflow, IssueWorkflowMappingPlan, Project } from "@multica/core/types";-import {- DropdownMenu,- DropdownMenuContent,- DropdownMenuGroup,- DropdownMenuItem,- DropdownMenuLabel,- DropdownMenuSeparator,- DropdownMenuTrigger,-} from "@multica/ui/components/ui/dropdown-menu";-import { useNavigation } from "../navigation";+import { DropdownMenuItem } from "@multica/ui/components/ui/dropdown-menu";import { useT } from "../i18n";import { WorkflowMappingDialog } from "./workflow-mapping-dialog";-import { useWorkflowPermissions } from "./permissions";interface PendingSwitch {workflowId: string | null;@@ -154,66 +143,34 @@ export function WorkflowChoiceItems({}/**- * The project's Workflow property (MUL-7420). Admins and the project lead- * switch it; everyone else sees which one it uses.+ * The project's Workflow property (MUL-7420). It opens the project's flow+ * panel for everyone; switching lives there (MUL-8941).*/-export function ProjectWorkflowControl({ project }: { project: Project }) {+export function ProjectWorkflowControl({ project, onOpen }: { project: Project; onOpen: () => void }) {const { t } = useT("issues");const wsId = useWorkspaceId();- const navigation = useNavigation();- const paths = useWorkspacePaths();const { workflows } = useIssueWorkflows(wsId);- const { canManageProject } = useWorkflowPermissions(project);- const { choose, busy, dialog } = useProjectWorkflowSwitch(project);const current = resolveProjectWorkflow(workflows, project);const name = current?.name ?? t(($) => $.workflows.default_name);const handoffs = current ? handoffStepCount(current) : 0;const handoffLabel = handoffs > 0 ? t(($) => $.workflows.settings.handoffs, { count: handoffs }) : null;- if (!canManageProject) {- return (- <span title={name} className="-ml-1 inline-flex min-w-0 items-center gap-1.5 px-1 py-0.5 text-caption">- <Workflow aria-hidden className="size-3.5 shrink-0 text-muted-foreground" />- <span className="truncate font-medium">{name}</span>- </span>- );- }-return (- <>- <DropdownMenu>- <DropdownMenuTrigger- disabled={busy}- render={- <button- type="button"- title={handoffLabel ? `${name} · ${handoffLabel}` : name}- className="-ml-1 inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-md px-1 py-0.5 text-caption transition-colors hover:bg-accent data-popup-open:bg-accent"- >- <Workflow aria-hidden className="size-3.5 shrink-0 text-muted-foreground" />- {/* Only the name competes for the narrow sidebar row (MUL-8119):- a sibling summary, however it is weighted, still takes width- from the name. The handoff count lives in the title and the- picker items instead. */}- <span className="min-w-0 truncate font-medium">{name}</span>- <ChevronDown aria-hidden className="size-3 shrink-0 text-muted-foreground" />- </button>- }- />- <DropdownMenuContent align="start" className="w-80">- <DropdownMenuGroup>- <DropdownMenuLabel>{t(($) => $.workflows.project.picker_title)}</DropdownMenuLabel>- <WorkflowChoiceItems project={project} onChoose={(w) => void choose(w)} />- </DropdownMenuGroup>- <DropdownMenuSeparator />- <DropdownMenuItem onClick={() => navigation.push(`${paths.settings()}?tab=workflows`)}>- <Settings aria-hidden className="size-3.5" />- {t(($) => $.workflows.project.manage)}- </DropdownMenuItem>- </DropdownMenuContent>- </DropdownMenu>- {dialog}- </>+ <button+ type="button"+ disabled={!current}+ onClick={onOpen}+ aria-haspopup="dialog"+ title={handoffLabel ? `${name} · ${handoffLabel}` : name}+ className="-ml-1 inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-md px-1 py-0.5 text-caption transition-colors hover:bg-accent disabled:pointer-events-none"+ >+ <Workflow aria-hidden className="size-3.5 shrink-0 text-muted-foreground" />+ {/* Only the name competes for the narrow sidebar row (MUL-8119):+ a sibling summary, however it is weighted, still takes width+ from the name. The handoff count lives in the title and the+ picker items instead. */}+ <span className="min-w-0 truncate font-medium">{name}</span>+ </button>);}diff --git a/packages/views/workflows/project-workflow-sheet.test.tsx b/packages/views/workflows/project-workflow-sheet.test.tsxnew file mode 100644index 0000000000..9e1618cd04--- /dev/null+++ b/packages/views/workflows/project-workflow-sheet.test.tsx@@ -0,0 +1,86 @@+import { cleanup, fireEvent, screen } from "@testing-library/react";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import type { IssueWorkflow, Project } from "@multica/core/types";+import { renderWithI18n } from "../test/i18n";+import { ProjectWorkflowSheet } from "./project-workflow-sheet";++const mocks = vi.hoisted(() => ({+ push: vi.fn(),+ permissions: { canCreateWorkflow: true, canEditWorkflow: false, canManageProject: true },+}));++const releaseWorkflow = {+ id: "wf-release",+ workspace_id: "workspace-1",+ name: "Release",+ description: "",+ is_default: false,+ owner_id: null,+ steps: [{ status_key: "todo" }, { status_key: "in_review" }],+ project_ids: ["project-1"],+ created_at: "",+ updated_at: "",+} as unknown as IssueWorkflow;++vi.mock("@tanstack/react-query", () => ({ useQuery: () => ({ data: [] }) }));+vi.mock("@multica/core/api", () => ({ api: {}, clientErrorMessage: () => null }));+vi.mock("@multica/core/hooks", () => ({ useWorkspaceId: () => "workspace-1" }));+vi.mock("@multica/core/paths", () => ({ useWorkspacePaths: () => ({ settings: () => "/settings" }) }));+vi.mock("@multica/core/projects/queries", () => ({ projectListOptions: () => ({}) }));+vi.mock("@multica/core/issue-statuses/hooks", () => ({+ useIssueStatuses: () => ({ categoryOf: () => "unstarted", colorOf: () => undefined, iconOf: () => undefined }),+}));+vi.mock("@multica/core/issue-workflows", () => ({+ useIssueWorkflows: () => ({ workflows: [releaseWorkflow] }),+ resolveProjectWorkflow: () => releaseWorkflow,+ statusAcceptsHandoff: () => true,+ handoffStepCount: () => 0,+ useSetProjectWorkflow: () => ({ isPending: false, mutateAsync: vi.fn() }),+}));+vi.mock("../navigation", () => ({ useNavigation: () => ({ push: mocks.push }) }));+vi.mock("./permissions", () => ({ useWorkflowPermissions: () => mocks.permissions }));+vi.mock("./workflow-mapping-dialog", () => ({ WorkflowMappingDialog: () => null }));+vi.mock("./handoff-form", () => ({ WorkflowHandoffForm: () => null }));+vi.mock("./step-handler", () => ({ useStepHandlerLabel: () => () => null, stepHandlerActor: () => null }));+vi.mock("../common/actor-avatar", () => ({ ActorAvatar: () => null }));+vi.mock("../issues/components/status-icon", () => ({ StatusIcon: () => null }));+vi.mock("../issues/utils/status-label", () => ({ useStatusLabel: () => (key: string) => key }));++const project = { id: "project-1", title: "Launch", workflow_id: "wf-release" } as Project;++beforeEach(() => {+ mocks.push.mockReset();+ mocks.permissions = { canCreateWorkflow: true, canEditWorkflow: false, canManageProject: true };+});+afterEach(cleanup);++describe("ProjectWorkflowSheet", () => {+ it("offers switching and managing once, in the panel header", () => {+ renderWithI18n(<ProjectWorkflowSheet project={project} open onOpenChange={vi.fn()} />);++ expect(screen.getByText("Release workflow")).toBeInTheDocument();+ expect(screen.getAllByRole("button", { name: /Switch workflow/ })).toHaveLength(1);+ expect(screen.getAllByRole("button", { name: /Manage workflows/ })).toHaveLength(1);+ expect(screen.getByRole("button", { name: /todo/ })).toBeInTheDocument();+ expect(screen.getByRole("button", { name: /in_review/ })).toBeInTheDocument();+ });++ it("shows members who can't switch the flow without the switch control", () => {+ mocks.permissions = { canCreateWorkflow: true, canEditWorkflow: false, canManageProject: false };+ renderWithI18n(<ProjectWorkflowSheet project={project} open onOpenChange={vi.fn()} />);++ expect(screen.getByText("Release workflow")).toBeInTheDocument();+ expect(screen.queryByRole("button", { name: /Switch workflow/ })).not.toBeInTheDocument();+ expect(screen.getByRole("button", { name: /todo/ })).toBeInTheDocument();+ });++ it("closes the panel before going to workflow settings", () => {+ const onOpenChange = vi.fn();+ renderWithI18n(<ProjectWorkflowSheet project={project} open onOpenChange={onOpenChange} />);++ fireEvent.click(screen.getByRole("button", { name: /Manage workflows/ }));++ expect(onOpenChange).toHaveBeenCalledWith(false);+ expect(mocks.push).toHaveBeenCalledWith("/settings?tab=workflows");+ });+});diff --git a/packages/views/workflows/project-workflow-menu.tsx b/packages/views/workflows/project-workflow-sheet.tsxsimilarity index 69%rename from packages/views/workflows/project-workflow-menu.tsxrename to packages/views/workflows/project-workflow-sheet.tsxindex 1207c61253..f0413d2465 100644--- a/packages/views/workflows/project-workflow-menu.tsx+++ b/packages/views/workflows/project-workflow-sheet.tsx@@ -1,8 +1,8 @@"use client";-import { useState, type ReactNode } from "react";+import { useState } from "react";import { useQuery } from "@tanstack/react-query";-import { ChevronRight, ListTree, Settings, Workflow } from "@multica/ui/icons";+import { ChevronDown, ChevronRight, Settings, Workflow } from "@multica/ui/icons";import { useWorkspaceId } from "@multica/core/hooks";import { useIssueStatuses } from "@multica/core/issue-statuses/hooks";import {@@ -13,14 +13,15 @@ import {import { useWorkspacePaths } from "@multica/core/paths";import { projectListOptions } from "@multica/core/projects/queries";import type { IssueWorkflow, Project } from "@multica/core/types";+import { Button } from "@multica/ui/components/ui/button";import {+ DropdownMenu,+ DropdownMenuContent,DropdownMenuGroup,DropdownMenuItem,DropdownMenuLabel,DropdownMenuSeparator,- DropdownMenuSub,- DropdownMenuSubContent,- DropdownMenuSubTrigger,+ DropdownMenuTrigger,} from "@multica/ui/components/ui/dropdown-menu";import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from "@multica/ui/components/ui/sheet";import { cn } from "@multica/ui/lib/utils";@@ -35,103 +36,56 @@ import { useProjectWorkflowSwitch, WorkflowChoiceItems } from "./project-workfloimport { stepHandlerActor, useStepHandlerLabel } from "./step-handler";/**- * The project's "Workflow" submenu (MUL-7420), shown in the project title's- * menu: open the full flow or switch workflows; workflows themselves are made- * in settings.- *- * The flow sheet and the switch dialog must outlive the menu that opens them,- * so this host owns both and hands the submenu to `children` to place.+ * The project title menu's one Workflow item (MUL-7420, MUL-8941): it opens+ * the project's flow panel, where everything else about the workflow lives.*/-export function ProjectWorkflowMenuHost({- project,- children,-}: {- project: Project;- children: (submenu: ReactNode) => ReactNode;-}) {+export function ProjectWorkflowMenuItem({ project, onOpen }: { project: Project; onOpen: () => void }) {const { t } = useT("issues");const wsId = useWorkspaceId();- const navigation = useNavigation();- const paths = useWorkspacePaths();const { workflows } = useIssueWorkflows(wsId);- const { canManageProject, canCreateWorkflow } = useWorkflowPermissions(project);- const { choose, busy, dialog } = useProjectWorkflowSwitch(project);- const [flowOpen, setFlowOpen] = useState(false);const workflow = resolveProjectWorkflow(workflows, project);-- const submenu = workflow ? (- <DropdownMenuSub>- <DropdownMenuSubTrigger disabled={busy}>- <Workflow className="size-3.5" />- <span className="flex-1">{t(($) => $.workflows.project.label)}</span>- <span className="ml-3 max-w-32 truncate text-caption font-medium text-muted-foreground">- {workflow.name}- </span>- </DropdownMenuSubTrigger>- <DropdownMenuSubContent className="w-64">- <DropdownMenuItem onClick={() => setFlowOpen(true)}>- <ListTree className="size-3.5" />- {t(($) => $.workflows.menu.view_flow)}- </DropdownMenuItem>- {canManageProject && (- <DropdownMenuSub>- <DropdownMenuSubTrigger>- <Workflow className="size-3.5" />- {t(($) => $.workflows.menu.switch)}- </DropdownMenuSubTrigger>- <DropdownMenuSubContent className="w-80">- <DropdownMenuGroup>- <DropdownMenuLabel>{t(($) => $.workflows.project.picker_title)}</DropdownMenuLabel>- <WorkflowChoiceItems project={project} onChoose={(w) => void choose(w)} />- </DropdownMenuGroup>- </DropdownMenuSubContent>- </DropdownMenuSub>- )}- {canCreateWorkflow && (- <>- <DropdownMenuSeparator />- <DropdownMenuItem onClick={() => navigation.push(`${paths.settings()}?tab=workflows`)}>- <Settings className="size-3.5" />- {t(($) => $.workflows.project.manage)}- </DropdownMenuItem>- </>- )}- </DropdownMenuSubContent>- </DropdownMenuSub>- ) : null;+ if (!workflow) return null;return (<>- {children(submenu)}- {dialog}- {workflow && (- <WorkflowFlowSheet open={flowOpen} onOpenChange={setFlowOpen} project={project} workflow={workflow} />- )}+ <DropdownMenuSeparator />+ <DropdownMenuItem onClick={onOpen}>+ <Workflow className="size-3.5" />+ <span className="flex-1">{t(($) => $.workflows.project.label)}</span>+ <span className="ml-3 max-w-32 truncate text-caption font-medium text-muted-foreground">{workflow.name}</span>+ </DropdownMenuItem></>);}/*** The project's whole flow in one panel (MUL-7420): every column, who it- * hands to, and the same handoff form the column header opens. Handoffs- * belong to the workflow, so only its owner and admins edit them here.+ * hands to, and the same handoff form the column header opens. Switching+ * workflows and the way to settings live in its header, so the project page+ * offers each exactly once (MUL-8941). Handoffs belong to the workflow, so+ * only its owner and admins edit them here.*/-export function WorkflowFlowSheet({+export function ProjectWorkflowSheet({open,onOpenChange,project,- workflow,}: {open: boolean;onOpenChange: (open: boolean) => void;project: Project;- workflow: IssueWorkflow;}) {const { t } = useT("issues");const wsId = useWorkspaceId();+ const navigation = useNavigation();+ const paths = useWorkspacePaths();+ const { workflows } = useIssueWorkflows(wsId);const { data: projects = [] } = useQuery(projectListOptions(wsId));- const { canEditWorkflow, canManageProject } = useWorkflowPermissions(project, workflow);+ const workflow = resolveProjectWorkflow(workflows, project);+ const { canCreateWorkflow, canEditWorkflow, canManageProject } = useWorkflowPermissions(project, workflow);+ const { choose, busy, dialog } = useProjectWorkflowSwitch(project);const [expanded, setExpanded] = useState<string | null>(null);+ if (!workflow) return null;+const usedBy = workflow.is_default? projects.filter((p) => !p.workflow_id).length: workflow.project_ids.length;@@ -147,6 +101,44 @@ export function WorkflowFlowSheet({: t(($) => $.workflows.flow.scope_own)}</SheetDescription></SheetHeader>+ {(canManageProject || canCreateWorkflow) && (+ <div className="flex flex-wrap items-center gap-2">+ {canManageProject && (+ <DropdownMenu>+ <DropdownMenuTrigger+ disabled={busy}+ render={+ <Button variant="outline" size="xs">+ <Workflow aria-hidden />+ {t(($) => $.workflows.flow.switch)}+ <ChevronDown aria-hidden className="size-3 text-muted-foreground" />+ </Button>+ }+ />+ <DropdownMenuContent align="start" className="w-80">+ <DropdownMenuGroup>+ <DropdownMenuLabel>{t(($) => $.workflows.project.picker_title)}</DropdownMenuLabel>+ <WorkflowChoiceItems project={project} onChoose={(w) => void choose(w)} />+ </DropdownMenuGroup>+ </DropdownMenuContent>+ </DropdownMenu>+ )}+ {canCreateWorkflow && (+ <Button+ variant="ghost"+ size="xs"+ className="text-muted-foreground"+ onClick={() => {+ onOpenChange(false);+ navigation.push(`${paths.settings()}?tab=workflows`);+ }}+ >+ <Settings aria-hidden />+ {t(($) => $.workflows.project.manage)}+ </Button>+ )}+ </div>+ )}<ol className="space-y-1.5">{workflow.steps.map((step) => (<FlowRow@@ -161,6 +153,7 @@ export function WorkflowFlowSheet({/>))}</ol>+ {dialog}</SheetContent></Sheet>);