diff --git a/e2e/specs/workflows/workflow-builder-layout.spec.ts b/e2e/specs/workflows/workflow-builder-layout.spec.ts new file mode 100644 index 000000000..e1547f7aa --- /dev/null +++ b/e2e/specs/workflows/workflow-builder-layout.spec.ts @@ -0,0 +1,29 @@ +import { test, expect, createWorkflow, WorkflowBuilder } from '@e2e' + +// The builder is a full-screen overlay; on narrow screens the node list +// becomes a drawer and node types are added by tap (touch has no drag-and-drop). + +const SIZES = [ + { name: 'phone', width: 375, height: 812 }, + { name: 'tablet', width: 768, height: 1024 }, +] + +test.describe('workflow builder layout', () => { + for (const size of SIZES) { + test(`the builder fits a ${size.name}: every action stays on screen and Nodes adds a step by tap @workflows`, async ({ agent, adminApi, page }) => { + await createWorkflow(adminApi, agent.id) + await page.setViewportSize({ width: size.width, height: size.height }) + const builder = new WorkflowBuilder(page) + await builder.open(agent.id) + + for (const action of ['Close', 'Publish', 'Save'] as const) { + await expect(builder.action(action)).toBeInViewport({ ratio: 1 }) + } + expect(await page.evaluate(() => document.documentElement.scrollWidth - window.innerWidth)).toBeLessThanOrEqual(0) + + await expect(builder.nodeTypes).toBeHidden() + await builder.addNodeByTap('Message') + await expect(builder.node('Message')).toBeInViewport() + }) + } +}) diff --git a/e2e/src/api/workflows.ts b/e2e/src/api/workflows.ts index 1deb4cbcb..1a983e7eb 100644 --- a/e2e/src/api/workflows.ts +++ b/e2e/src/api/workflows.ts @@ -12,8 +12,14 @@ export interface WorkflowGraph { * connects, so embed the widget after this. */ export async function publishWorkflow(api: ApiClient, agentId: string, graph: WorkflowGraph): Promise { + const workflowId = await createWorkflow(api, agentId) + await api.put(`/workflow/${workflowId}/nodes`, { data: { nodes: graph.nodes, connections: graph.connections ?? [] } }) + await api.put(`/workflow/${workflowId}`, { data: { status: 'published' } }) + return workflowId +} + +/** Creates an empty draft workflow for `agentId`. */ +export async function createWorkflow(api: ApiClient, agentId: string): Promise { const workflow = await api.post<{ id: string }>('/workflow', { data: { name: unique('E2E flow'), agent_id: agentId } }) - await api.put(`/workflow/${workflow.id}/nodes`, { data: { nodes: graph.nodes, connections: graph.connections ?? [] } }) - await api.put(`/workflow/${workflow.id}`, { data: { status: 'published' } }) return workflow.id } diff --git a/e2e/src/index.ts b/e2e/src/index.ts index 56c0ac0b2..60a099e1e 100644 --- a/e2e/src/index.ts +++ b/e2e/src/index.ts @@ -15,7 +15,7 @@ export { putBackOnSale, routeTicketsToJira, shopifyOrderNow, storefrontAction, uninstallShopify, useShopForAgent, } from './api/integrations' export type { FakeShopifyOrder } from './api/integrations' -export { publishWorkflow, type WorkflowGraph } from './api/workflows' +export { createWorkflow, publishWorkflow, type WorkflowGraph } from './api/workflows' export { askHelpCenter, createArticle, enableHelpCenter, helpCenterChat, setArticleStatus, setHelpCenterChat, turnOnAskAi, type Article, type HelpCenterChat, } from './api/help-center' @@ -71,6 +71,7 @@ export { SetupWizard } from './pages/setup-wizard.page' export { TicketsPage } from './pages/tickets.page' export { WidgetAllowedDomainsPage } from './pages/widget-allowed-domains.page' export { WidgetInstallPage } from './pages/widget-install.page' +export { WorkflowBuilder } from './pages/workflow-builder.page' export { unique } from './support/ids' export { step } from './support/step' export { allowClipboard, clipboardText } from './support/clipboard' diff --git a/e2e/src/pages/workflow-builder.page.ts b/e2e/src/pages/workflow-builder.page.ts new file mode 100644 index 000000000..acfb6d8db --- /dev/null +++ b/e2e/src/pages/workflow-builder.page.ts @@ -0,0 +1,79 @@ +import { expect, type Locator, type Page } from '@playwright/test' +import { step } from '../support/step' + +/** The agent editor's Workflow Builder tab and the full-screen builder it opens. */ +export class WorkflowBuilder { + readonly page: Page + + constructor(page: Page) { + this.page = page + } + + async open(agentId: string): Promise { + await step('Open the workflow builder', async () => { + await this.page.goto(`/ai-agents?agent=${agentId}&tab=workflow-builder`) + await this.page.getByRole('button', { name: 'Open Builder' }).click() + await expect(this.page.getByRole('button', { name: 'Save', exact: true })).toBeVisible() + }) + } + + /** A node on the canvas, by its name. */ + node(name: string): Locator { + // Vue Flow's nodes have no role or accessible name of their own + return this.page.locator('.vue-flow__node').filter({ hasText: name }) + } + + async selectNode(name: string): Promise { + await this.node(name).click() + await expect(this.page.getByRole('textbox', { name: 'Node Name' })).toHaveValue(name) + } + + /** The handover node's team picker. */ + get team(): Locator { + return this.page.getByRole('combobox', { name: 'Team' }) + } + + async chooseTeam(workflowId: string, teamName: string): Promise { + await step(`Hand the node over to ${teamName}`, async () => { + await this.team.selectOption({ label: teamName }) + const groupId = await this.team.inputValue() + // The panel writes the node to the builder's local copy on a short delay, + // and Save sends that copy: wait for it, or Save can beat the change + await this.page.waitForFunction( + ([key, id]) => (localStorage.getItem(key) ?? '').includes(id), + [`workflow_info_${workflowId}`, groupId], + ) + }) + } + + async save(): Promise { + await step('Save the workflow', async () => { + await this.page.getByRole('button', { name: 'Save', exact: true }).click() + await expect(this.page.getByText('Workflow saved successfully')).toBeVisible() + }) + } + + /** The builder's header: name, status and the Nodes, Close, Publish and Save actions. */ + get header(): Locator { + return this.page.locator('.builder-header') + } + + /** A header action by its name; on phones the label is hidden and the name stays. */ + action(name: 'Node types' | 'Close' | 'Publish' | 'Unpublish' | 'Save'): Locator { + return this.header.getByRole('button', { name, exact: true }) + } + + /** The node type list: a sidebar on wide screens, a drawer on narrow ones. */ + get nodeTypes(): Locator { + return this.page.locator('#workflow-node-types') + } + + /** Narrow screens: open the drawer and tap a node type to add it. */ + async addNodeByTap(label: string): Promise { + await step(`Add a ${label} node from the drawer`, async () => { + await this.action('Node types').click() + await this.nodeTypes.getByText(label, { exact: true }).click() + await expect(this.nodeTypes).toBeHidden() + }) + } +} diff --git a/frontend/src/components/workflow/NodeTypeIcon.vue b/frontend/src/components/workflow/NodeTypeIcon.vue new file mode 100644 index 000000000..3acc5ad14 --- /dev/null +++ b/frontend/src/components/workflow/NodeTypeIcon.vue @@ -0,0 +1,64 @@ + + + + + diff --git a/frontend/src/components/workflow/WorkflowBuilder.vue b/frontend/src/components/workflow/WorkflowBuilder.vue index 048bed558..4bd43719d 100644 --- a/frontend/src/components/workflow/WorkflowBuilder.vue +++ b/frontend/src/components/workflow/WorkflowBuilder.vue @@ -26,13 +26,16 @@ import { workflowService } from '../../services/workflow' import type { WorkflowResponse } from '@/types/workflow' import { WorkflowStatus, ExitCondition } from '@/types/workflow' import PropertiesPanel from './PropertiesPanel.vue' +import NodeTypeIcon from './NodeTypeIcon.vue' import { workflowCacheStorage } from '@/utils/storage' import { useWorkflowValidation, type NodeTypeInfo } from '@/composables/useWorkflowValidation' import { useWorkflowManagement } from '@/composables/useWorkflowManagement' +import { useBreakpoint } from '@/composables/useBreakpoint' // Import Vue Flow styles import '@vue-flow/core/dist/style.css' import '@vue-flow/core/dist/theme-default.css' +import '@vue-flow/controls/dist/style.css' const props = defineProps<{ workflow: WorkflowResponse @@ -43,7 +46,7 @@ const emit = defineEmits<{ }>() // Vue Flow setup -const { onConnect, addNodes, removeNodes, addEdges, getNodes, getEdges, vueFlowRef } = useVueFlow({ +const { onConnect, addNodes, removeNodes, addEdges, getNodes, getEdges, vueFlowRef, screenToFlowCoordinate } = useVueFlow({ id: 'workflow-builder', nodes: [], edges: [], @@ -184,6 +187,14 @@ const selectedNode = ref(null) const workflowStatus = ref(props.workflow.status) const publishLoading = ref(false) +// Narrow screens: the node list becomes a drawer and nodes are added by tap, +// since touch browsers don't fire HTML5 drag-and-drop. +const { isMobile: isCompactLayout } = useBreakpoint() +const showNodeDrawer = ref(false) +watch(isCompactLayout, (compact) => { + if (!compact) showNodeDrawer.value = false +}) + // Variables state for PropertiesPanel const availableVariables = ref { const vueFlowBounds = vueFlowRef.value?.getBoundingClientRect() if (!vueFlowBounds) return - const position = { + createNodeAt(type, { x: event.clientX - vueFlowBounds.left, y: event.clientY - vueFlowBounds.top - } + }) +} + +// Tap a node type in the drawer: add it at the centre of the visible canvas +const handleNodeTypeTap = (type: string) => { + if (!isCompactLayout.value) return + const vueFlowBounds = vueFlowRef.value?.getBoundingClientRect() + if (!vueFlowBounds) return + + createNodeAt(type, screenToFlowCoordinate({ + x: vueFlowBounds.left + vueFlowBounds.width / 2, + y: vueFlowBounds.top + vueFlowBounds.height / 3 + })) + showNodeDrawer.value = false +} +const createNodeAt = (type: string, position: { x: number, y: number }) => { const nodeType = availableNodeTypes.find(t => t.type === type) const uniqueName = generateUniqueNodeName(nodeType?.label || 'Node') @@ -730,18 +756,33 @@ onUnmounted(() => {
- + -
- -