Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

fix(web): make inline items work in the data selector's friendly view (#15971)

Ahmad Tash313ebfa9b46b
diff --git a/brain/knowledge/flows-execution/flows.md b/brain/knowledge/flows-execution/flows.md
index 947dceca158..27deae675d0 100644
--- a/brain/knowledge/flows-execution/flows.md
+++ b/brain/knowledge/flows-execution/flows.md
@@ -35,6 +35,7 @@ Flows are the core automation primitive: a versioned directed graph of trigger +
- `createdBy` (automated source) is distinct from `ownerId` (current owning user).
- List filtering: `folderId` uses the string sentinel `"NULL"` for uncategorized; `folderIds` (array) loads all foldered flows in one request.
- Builder is Zustand-sliced (flow/run/canvas/step-form/piece-selector state). Canvas supports vertical (default) and horizontal orientations, and PNG export via a hand-rolled clone-and-rasterize pipeline.
+- **Inline items (an array prop with dynamic values on, e.g. Google Sheets "Insert Multiple Rows") only work through the data selector's zipped tree.** Focusing that input sets `isFocusInsideListMapperModeInput`, and only `traverseStep` with zipping on emits `flattenNestedKeys(step_1['output'], ['name'])`, the column-wide list the engine's `arrayZipperProcessor` spreads into one row per item. The Friendly view's builders (`utils-schema.ts`) emit per-item `[0]` paths, which the zipper reads as a single row, so from #12919 until the fix a Friendly pick silently wrote only the first item. In that mode Friendly View shows a step in the zipped shape only when its output contains a list of objects (`dataSelectorUtils.shouldShowStepAsFlatList`); every other step keeps its Friendly shape with plain paths, which repeat one value on every row, because zipping a plain object hands the engine one-item lists that fill only the first row. A new Friendly branch must sit below that check. The flag is one shared value, so `useIsFocusInsideListMapperModeInput` derives it from whether focus is inside *any* inline-items input (the `listMapperModeInputCssClass` marker), never "inside my container": per-instance checks let the last listener overwrite the others, so with two inline arrays the first one never switched the mode on. It is recomputed on each `focusin` and again when an inline input unmounts, because removing one without moving focus fires no event (Safari and Firefox for macOS don't focus clicked buttons) and used to leave the zipped tree on every later field until a reload.
- **`Popover.Trigger asChild` always composes its own open-toggle onto the child's click, even when `open`/`onOpenChange` is externally controlled — a `preventDefault()`-shaped guard is the only thing that stops it.** Radix wires `onClick={composeEventHandlers(props.onClick, context.onOpenToggle)}` on the trigger, and `composeEventHandlers` skips the second handler only if `event.defaultPrevented`. `ApStepCanvasNode` wraps *every* step (trigger and action) in `<PieceSelector openSelectorOnClick={false}>` (`flow-canvas/nodes/step-node/index.tsx`), but that prop only guards the app's own `onClick` — it was `handleStepClick`'s incidental `e.preventDefault()` that actually suppressed Radix's toggle for ordinary steps. PR #14405 ("close trigger piece selector on outside/repeat click") removed that `preventDefault()` and made `pieces-selector/index.tsx`'s `onOpenChange` unconditionally honor `open` for any step id — fixing a real empty-trigger close/repeat-click race, but with nothing scoping the new open-branch to the empty trigger specifically. Regression window: 2026-07-28 (#14405) to 2026-08-11 — any plain click on a *configured* step's body reopened its own piece selector, not just the empty trigger (case 1) or an explicit Replace (case 2, which sets the state directly from the context menu and never touches this trigger). Fix: gate the `onOpenChange` open-branch on `isForEmptyTrigger || openSelectorOnClick` instead of honoring every toggle — Radix's own attempt to open is simply ignored (state doesn't change, so the controlled `open` prop stays false) when neither condition holds. Confirmed both the break and the fix by reproducing the exact `Popover.Root`/`Trigger asChild` wiring against the real installed `radix-ui` package in a throwaway vitest — not just static reading. The general lesson (Radix always attempts the toggle; controlled mode only means *you* decide whether to honor it) applies to every controlled Radix `Trigger` in this codebase, not just this one.
- **Rolling a release back past a `LATEST_FLOW_SCHEMA_VERSION` bump fails silently, not loudly.** `flowMigrations.apply` matches a row on exact equality (`flowVersion.schemaVersion === migration.targetSchemaVersion`), so a row stamped `'27'` running on code that only knows up to `'26'` matches no migration, is returned unchanged, and is not even rewritten — no error, no page, nothing in the log. The row survives; what does not survive is whatever the new migration wrote into it, because the old code has no idea how to read it. So a release that bumps the schema version is a one-way door for every flow read while it was live, and the only way back is `backupFiles[<old version>]`, which nothing reads on its own (`flowVersionBackupService.get()` has no callers). Ship a schema-version bump in a release of its own, with nothing in it you might want to revert for another reason. **And when the migration depends on a server-side change, put the two in different releases, server code first.** A rollback then lands on a server that still understands what the migration wrote: ship both together and undoing that release leaves every rewritten row unreadable, ship the migration one release later and the same rollback is safe.
- **Anything drawn in canvas coordinates must measure the canvas element, never infer its offset from app chrome.** The note and step drag previews are `position: absolute` inside the canvas and used to subtract `#project-sidebar`'s width plus a hardcoded 60px header; when the chat-first rail (#15005) replaced that sidebar the id vanished, the width read 0, and Add note silently stopped working — the preview drew a sidebar-width right of the cursor, so the placing click always missed it. Take the origin from xyflow's `useStore((s) => s.domNode)?.getBoundingClientRect()`. `position: fixed` is no way out: an ancestor carries `will-change: transform`, which makes it the containing block.
diff --git a/packages/web/src/app/builder/data-selector/index.tsx b/packages/web/src/app/builder/data-selector/index.tsx
index 7fb5d5e86de..0ff880255da 100644
--- a/packages/web/src/app/builder/data-selector/index.tsx
+++ b/packages/web/src/app/builder/data-selector/index.tsx
@@ -69,24 +69,43 @@ function buildAdvancedStructure(
isFocusInsideListMapperModeInput: boolean,
targetStepName: string,
): DataSelectorTreeNode[] {
- return steps.map((step) => {
- try {
- return dataSelectorUtils.traverseStep(
- step,
- sampleData,
- isFocusInsideListMapperModeInput,
- targetStepName,
- );
- } catch {
- return {
- key: `error-${step.name}`,
- data: {
- type: 'chunk' as const,
- displayName: `Error loading ${step.name}`,
- },
- };
- }
- });
+ return steps.map((step) =>
+ traverseStepOrErrorNode({
+ step,
+ sampleData,
+ zipArraysOfProperties: isFocusInsideListMapperModeInput,
+ targetStepName,
+ }),
+ );
+}
+
+function traverseStepOrErrorNode({
+ step,
+ sampleData,
+ zipArraysOfProperties,
+ targetStepName,
+}: {
+ step: StepInfo;
+ sampleData: Record<string, unknown>;
+ zipArraysOfProperties: boolean;
+ targetStepName: string;
+}): DataSelectorTreeNode {
+ try {
+ return dataSelectorUtils.traverseStep(
+ step,
+ sampleData,
+ zipArraysOfProperties,
+ targetStepName,
+ );
+ } catch {
+ return {
+ key: `error-${step.name}`,
+ data: {
+ type: 'chunk' as const,
+ displayName: `Error loading ${step.name}`,
+ },
+ };
+ }
}
type DataSelectorProps = {
@@ -215,6 +234,20 @@ const DataSelector = ({ parentHeight, parentWidth }: DataSelectorProps) => {
const displayName = `${step.dfsIndex + 1}. ${step.displayName}`;
const stepData = sampleData[step.name];
+ if (
+ dataSelectorUtils.shouldShowStepAsFlatList({
+ isFocusInsideListMapperModeInput,
+ stepOutput: stepData,
+ })
+ ) {
+ return traverseStepOrErrorNode({
+ step,
+ sampleData,
+ zipArraysOfProperties: true,
+ targetStepName: selectedStepName,
+ });
+ }
+
if (
typeof stepData === 'string' ||
typeof stepData === 'number' ||
@@ -283,22 +316,12 @@ const DataSelector = ({ parentHeight, parentWidth }: DataSelectorProps) => {
sampleData: stepData,
});
}
- try {
- return dataSelectorUtils.traverseStep(
- step,
- sampleData,
- isFocusInsideListMapperModeInput,
- selectedStepName,
- );
- } catch {
- return {
- key: `error-${step.name}`,
- data: {
- type: 'chunk' as const,
- displayName: `Error loading ${step.name}`,
- },
- };
- }
+ return traverseStepOrErrorNode({
+ step,
+ sampleData,
+ zipArraysOfProperties: false,
+ targetStepName: selectedStepName,
+ });
}),
[
steps,
diff --git a/packages/web/src/app/builder/data-selector/utils.ts b/packages/web/src/app/builder/data-selector/utils.ts
index a85812d97b6..e807050598d 100644
--- a/packages/web/src/app/builder/data-selector/utils.ts
+++ b/packages/web/src/app/builder/data-selector/utils.ts
@@ -478,6 +478,26 @@ function flattenVisibleRows({
});
}
+function shouldShowStepAsFlatList({
+ isFocusInsideListMapperModeInput,
+ stepOutput,
+}: {
+ isFocusInsideListMapperModeInput: boolean;
+ stepOutput: unknown;
+}): boolean {
+ return isFocusInsideListMapperModeInput && containsListOfObjects(stepOutput);
+}
+
+function containsListOfObjects(value: unknown): boolean {
+ if (Array.isArray(value)) {
+ return value.some((item) => isObject(item) || containsListOfObjects(item));
+ }
+ if (isObject(value)) {
+ return Object.values(value).some(containsListOfObjects);
+ }
+ return false;
+}
+
export const dataSelectorUtils = {
isTestStepNode: (
node: DataSelectorTreeNode,
@@ -486,6 +506,7 @@ export const dataSelectorUtils = {
traverseStep,
filterBy,
flattenVisibleRows,
+ shouldShowStepAsFlatList,
};
export type DataSelectorRow = {
diff --git a/packages/web/src/app/builder/flow-canvas/hooks.tsx b/packages/web/src/app/builder/flow-canvas/hooks.tsx
index 7820fe57db5..b01c7c3548e 100644
--- a/packages/web/src/app/builder/flow-canvas/hooks.tsx
+++ b/packages/web/src/app/builder/flow-canvas/hooks.tsx
@@ -219,11 +219,9 @@ export const useSwitchToDraft = () => {
};
const useIsFocusInsideListMapperModeInput = ({
- containerRef,
setIsFocusInsideListMapperModeInput,
isFocusInsideListMapperModeInput,
}: {
- containerRef: React.RefObject<HTMLDivElement | null>;
setIsFocusInsideListMapperModeInput: (
isFocusInsideListMapperModeInput: boolean,
) => void;
@@ -232,15 +230,11 @@ const useIsFocusInsideListMapperModeInput = ({
useEffect(() => {
const focusInListener = () => {
const focusedElement = document.activeElement;
- const isFocusedInside = !!containerRef.current?.contains(focusedElement);
const isFocusedInsideDataSelector =
- !isNil(document.activeElement) &&
- document.activeElement instanceof HTMLElement &&
- textMentionUtils.isDataSelectorOrChildOfDataSelector(
- document.activeElement,
- );
+ focusedElement instanceof HTMLElement &&
+ textMentionUtils.isDataSelectorOrChildOfDataSelector(focusedElement);
setIsFocusInsideListMapperModeInput(
- isFocusedInside ||
+ isActiveElementInsideListMapperModeInput() ||
(isFocusedInsideDataSelector && isFocusInsideListMapperModeInput),
);
};
@@ -249,6 +243,13 @@ const useIsFocusInsideListMapperModeInput = ({
document.removeEventListener('focusin', focusInListener);
};
}, [setIsFocusInsideListMapperModeInput, isFocusInsideListMapperModeInput]);
+ useEffect(
+ () => () =>
+ setIsFocusInsideListMapperModeInput(
+ isActiveElementInsideListMapperModeInput(),
+ ),
+ [setIsFocusInsideListMapperModeInput],
+ );
};
export const useFocusOnStep = () => {
const [currentRun, selectStep, userManuallySelectedStepDuringRun] =
@@ -312,6 +313,14 @@ export const useResizeCanvas = (
}, [setViewport, getViewport]);
};
+function isActiveElementInsideListMapperModeInput(): boolean {
+ const focusedElement = document.activeElement;
+ return (
+ focusedElement instanceof HTMLElement &&
+ textMentionUtils.isInsideListMapperModeInput(focusedElement)
+ );
+}
+
export const flowCanvasHooks = {
useSetSocketListener,
useShowBuilderIsSavingWarningBeforeLeaving,
diff --git a/packages/web/src/app/builder/piece-properties/array-property-in-inline-item-mode.tsx b/packages/web/src/app/builder/piece-properties/array-property-in-inline-item-mode.tsx
index bbef2491903..137a5b4a579 100644
--- a/packages/web/src/app/builder/piece-properties/array-property-in-inline-item-mode.tsx
+++ b/packages/web/src/app/builder/piece-properties/array-property-in-inline-item-mode.tsx
@@ -1,6 +1,6 @@
import { isNil } from '@activepieces/core-utils';
import { ArraySubProps } from '@activepieces/pieces-framework';
-import React, { useEffect, useRef } from 'react';
+import React, { useEffect } from 'react';
import { useFormContext } from 'react-hook-form';
import { cn, GAP_SIZE_FOR_STEP_SETTINGS } from '@/lib/utils';
@@ -10,6 +10,7 @@ import { flowCanvasHooks } from '../flow-canvas/hooks';
import { GenericPropertiesForm } from './generic-properties-form';
import { TextInputWithMentions } from './text-input-with-mentions';
+import { textMentionUtils } from './text-input-with-mentions/text-input-utils';
type BaseArrayPropertyProps = {
inputName: string;
@@ -28,7 +29,6 @@ type ArrayPiecePropertyInInlineItemModeProps = BaseArrayPropertyProps &
const ArrayPiecePropertyInInlineItemMode = React.memo(
(props: ArrayPiecePropertyInInlineItemModeProps) => {
- const containerRef = useRef<HTMLDivElement>(null);
const [
isFocusInsideListMapperModeInput,
setIsFocusInsideListMapperModeInput,
@@ -38,13 +38,17 @@ const ArrayPiecePropertyInInlineItemMode = React.memo(
]);
const { inputName, disabled } = props;
flowCanvasHooks.useIsFocusInsideListMapperModeInput({
- containerRef,
setIsFocusInsideListMapperModeInput,
isFocusInsideListMapperModeInput,
});
useFixInlineArrayPropertyValue(inputName, props);
return (
- <div className="w-full" ref={containerRef}>
+ <div
+ className={cn(
+ 'w-full',
+ textMentionUtils.listMapperModeInputCssClassSelector,
+ )}
+ >
{props.arrayProperties ? (
<div
className={cn(
diff --git a/packages/web/src/app/builder/piece-properties/text-input-with-mentions/text-input-utils.ts b/packages/web/src/app/builder/piece-properties/text-input-with-mentions/text-input-utils.ts
index 644d53d8eb8..e67ed4e8162 100644
--- a/packages/web/src/app/builder/piece-properties/text-input-with-mentions/text-input-utils.ts
+++ b/packages/web/src/app/builder/piece-properties/text-input-with-mentions/text-input-utils.ts
@@ -550,6 +550,9 @@ const isDataSelectorOrChildOfDataSelector = (element: HTMLElement) => {
!isNil(element.closest(`.${dataSelectorCssClassSelector}`))
);
};
+const listMapperModeInputCssClassSelector = 'ap-list-mapper-mode-input';
+const isInsideListMapperModeInput = (element: HTMLElement) =>
+ !isNil(element.closest(`.${listMapperModeInputCssClassSelector}`));
export const textMentionUtils = {
convertTextToTipTapJsonContent,
convertTiptapJsonToText: ({ content }: JSONContent) => {
@@ -566,4 +569,6 @@ export const textMentionUtils = {
inputWithMentionsCssClass,
dataSelectorCssClassSelector,
isDataSelectorOrChildOfDataSelector,
+ listMapperModeInputCssClassSelector,
+ isInsideListMapperModeInput,
};
diff --git a/packages/web/test/app/builder/data-selector/utils.test.ts b/packages/web/test/app/builder/data-selector/utils.test.ts
index c69f1d8db00..359d499fc4b 100644
--- a/packages/web/test/app/builder/data-selector/utils.test.ts
+++ b/packages/web/test/app/builder/data-selector/utils.test.ts
@@ -121,3 +121,47 @@ describe('dataSelectorUtils.filterBy — searchable value of containers', () =>
).toHaveLength(1);
});
});
+
+describe('dataSelectorUtils.shouldShowStepAsFlatList — inline items (list-mapper mode)', () => {
+ it('flattens a step whose output is a list of objects', () => {
+ expect(
+ dataSelectorUtils.shouldShowStepAsFlatList({
+ isFocusInsideListMapperModeInput: true,
+ stepOutput: [{ name: 'first' }, { name: 'second' }],
+ }),
+ ).toBe(true);
+ });
+
+ it('flattens a step whose output has a list of objects nested inside', () => {
+ expect(
+ dataSelectorUtils.shouldShowStepAsFlatList({
+ isFocusInsideListMapperModeInput: true,
+ stepOutput: { total: 2, results: [{ id: 1 }, { id: 2 }] },
+ }),
+ ).toBe(true);
+ });
+
+ it('keeps steps without a list of objects in their friendly shape', () => {
+ expect(
+ dataSelectorUtils.shouldShowStepAsFlatList({
+ isFocusInsideListMapperModeInput: true,
+ stepOutput: { customer: { id: 7 }, tags: ['a', 'b'] },
+ }),
+ ).toBe(false);
+ expect(
+ dataSelectorUtils.shouldShowStepAsFlatList({
+ isFocusInsideListMapperModeInput: true,
+ stepOutput: 'hello',
+ }),
+ ).toBe(false);
+ });
+
+ it('never flattens outside list-mapper mode', () => {
+ expect(
+ dataSelectorUtils.shouldShowStepAsFlatList({
+ isFocusInsideListMapperModeInput: false,
+ stepOutput: [{ name: 'first' }, { name: 'second' }],
+ }),
+ ).toBe(false);
+ });
+});
diff --git a/packages/web/test/app/builder/flow-canvas/hooks.test.tsx b/packages/web/test/app/builder/flow-canvas/hooks.test.tsx
index fca02239fbe..1c0e4b22428 100644
--- a/packages/web/test/app/builder/flow-canvas/hooks.test.tsx
+++ b/packages/web/test/app/builder/flow-canvas/hooks.test.tsx
@@ -1,4 +1,5 @@
// @vitest-environment jsdom
+/* eslint-disable testing-library/no-unnecessary-act */
import {
EmptyTrigger,
FlowOperationRequest,
@@ -18,7 +19,7 @@ import {
WebsocketClientEvent,
} from '@activepieces/shared';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
-import { act } from 'react';
+import { act, useCallback, useState } from 'react';
import { createRoot, type Root } from 'react-dom/client';
import { io } from 'socket.io-client';
import { Toaster, toast } from 'sonner';
@@ -31,6 +32,7 @@ import {
} from '@/app/builder/builder-hooks';
import { flowCanvasHooks } from '@/app/builder/flow-canvas/hooks';
import { useFlowLock } from '@/app/builder/flow-canvas/widgets/use-flow-lock';
+import { textMentionUtils } from '@/app/builder/piece-properties/text-input-with-mentions/text-input-utils';
import { editorSession } from '@/lib/editor-session';
declare global {
@@ -627,6 +629,60 @@ describe('useRefreshDraftOnReconnectAndReturn', () => {
}
});
+let listMapperContainer: HTMLDivElement | null = null;
+let listMapperRoot: Root | null = null;
+let latestFlag = false;
+
+describe('useIsFocusInsideListMapperModeInput', () => {
+ afterEach(() => {
+ act(() => listMapperRoot?.unmount());
+ listMapperContainer?.remove();
+ listMapperContainer = null;
+ listMapperRoot = null;
+ latestFlag = false;
+ });
+
+ it('turns list-mapper mode on inside an inline-items input and off in another field', () => {
+ renderHarness({ inlineItems: ['inline item'] });
+
+ focusField('inline item');
+ expect(latestFlag).toBe(true);
+
+ focusField('other field');
+ expect(latestFlag).toBe(false);
+ });
+
+ it('turns list-mapper mode off when the focused inline-items input unmounts without a focus change', () => {
+ renderHarness({ inlineItems: ['inline item'] });
+ focusField('inline item');
+ expect(latestFlag).toBe(true);
+
+ renderHarness({ inlineItems: [] });
+
+ expect(latestFlag).toBe(false);
+ });
+
+ it('turns list-mapper mode on for whichever of two inline-items inputs is focused', () => {
+ renderHarness({ inlineItems: ['first array', 'second array'] });
+
+ focusField('first array');
+ expect(latestFlag).toBe(true);
+
+ focusField('second array');
+ expect(latestFlag).toBe(true);
+ });
+
+ it('keeps list-mapper mode on when another inline-items input unmounts while one is focused', () => {
+ renderHarness({ inlineItems: ['first array', 'second array'] });
+ focusField('second array');
+ expect(latestFlag).toBe(true);
+
+ renderHarness({ inlineItems: ['second array'] });
+
+ expect(latestFlag).toBe(true);
+ });
+});
+
function shownToasts() {
return document.querySelectorAll('[data-sonner-toast]');
}
@@ -809,4 +865,62 @@ function flowWithDraftVersion({
};
}
+function InlineItemsInput({
+ label,
+ isFocusInsideListMapperModeInput,
+ setIsFocusInsideListMapperModeInput,
+}: {
+ label: string;
+ isFocusInsideListMapperModeInput: boolean;
+ setIsFocusInsideListMapperModeInput: (value: boolean) => void;
+}) {
+ flowCanvasHooks.useIsFocusInsideListMapperModeInput({
+ setIsFocusInsideListMapperModeInput,
+ isFocusInsideListMapperModeInput,
+ });
+ return (
+ <div className={textMentionUtils.listMapperModeInputCssClassSelector}>
+ <input aria-label={label} />
+ </div>
+ );
+}
+
+function Harness({ inlineItems }: { inlineItems: string[] }) {
+ const [flag, setFlag] = useState(false);
+ const recordFlag = useCallback((value: boolean) => {
+ latestFlag = value;
+ setFlag(value);
+ }, []);
+ return (
+ <div>
+ {inlineItems.map((label) => (
+ <InlineItemsInput
+ key={label}
+ label={label}
+ isFocusInsideListMapperModeInput={flag}
+ setIsFocusInsideListMapperModeInput={recordFlag}
+ />
+ ))}
+ <input aria-label="other field" />
+ </div>
+ );
+}
+
+function renderHarness({ inlineItems }: { inlineItems: string[] }) {
+ if (!listMapperContainer) {
+ listMapperContainer = document.createElement('div');
+ document.body.appendChild(listMapperContainer);
+ listMapperRoot = createRoot(listMapperContainer);
+ }
+ act(() => listMapperRoot?.render(<Harness inlineItems={inlineItems} />));
+}
+
+function focusField(label: string) {
+ act(() => {
+ listMapperContainer
+ ?.querySelector<HTMLInputElement>(`[aria-label="${label}"]`)
+ ?.focus();
+ });
+}
+
type LockHolder = { userId: string; userDisplayName: string };