Skip to content

ui: add scenario reorder buttons for condition agent#5720

Open
TianHougege wants to merge 1 commit intoFlowiseAI:mainfrom
TianHougege:feat/condition-agent-scenario-reorder
Open

ui: add scenario reorder buttons for condition agent#5720
TianHougege wants to merge 1 commit intoFlowiseAI:mainfrom
TianHougege:feat/condition-agent-scenario-reorder

Conversation

@TianHougege
Copy link
Copy Markdown

What

Add lightweight Up/Down controls to reorder Condition Agent scenarios.

Why

Up/Down buttons keep the behavior simple and predictable (no extra drag-and-drop deps).

Notes

  • Reorder is gated to Condition Agent scenarios only (by stable inputParam.name), so other array inputs are unaffected.
  • Uses UI-only stable keys (itemKeys) during reorder to avoid input/focus mismatch caused by key={index}.
  • Updates output anchors on reorder; does not auto-rewire edges (minimal & safe).

Demo

Kapture.2026-02-08.at.13.07.51.mp4

Closes #5699

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @TianHougege, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the usability of the 'Condition Agent' component by adding intuitive reordering capabilities for its scenarios. By providing simple Up/Down controls, users can now easily adjust the sequence of their conditional logic. The implementation is robust, focusing on stability during UI updates and ensuring the feature is applied precisely where needed without unintended side effects on other array-based inputs.

Highlights

  • Scenario Reordering: Introduced 'Up' and 'Down' buttons to allow users to reorder scenarios specifically within the 'Condition Agent' UI component, enhancing user experience for managing complex conditional logic.
  • Targeted Implementation: The reordering functionality is carefully scoped to only apply to 'Condition Agent' scenarios, identified by stable input parameter names, ensuring other array inputs remain unaffected.
  • Stable UI Keys: Implemented UI-only stable keys (UUIDs) for array items during reordering. This prevents input/focus mismatches and other rendering issues that can occur when using array indices as keys.
  • Output Anchor Updates: The system now updates output anchors when scenarios are reordered. Importantly, it does not automatically rewire existing edges, maintaining a minimal and safe approach to changes.
Changelog
  • packages/ui/src/ui-component/array/ArrayRenderer.jsx
    • Added imports for IconArrowUp and IconArrowDown from @tabler/icons-react to support the new reorder buttons.
    • Implemented state management for itemKeys to provide stable, UI-only identifiers for array items, crucial for correct rendering during reordering.
    • Introduced logic to conditionally enable reordering (enableReorder) based on whether the component is a 'Condition Agent' node and the specific scenario field name.
    • Developed swapInArray utility and moveItem function to handle the actual reordering of array items, itemKeys, and itemParameters.
    • Created handleMoveUp and handleMoveDown functions to trigger the reordering logic for individual items.
    • Modified the useEffect hook to initialize itemKeys with unique UUIDs when the component mounts or data changes, ensuring stable keys from the start.
    • Updated updateOutputAnchors to use the new isConditionAgentNode flag for more precise condition checking.
    • Adjusted handleAddItem and handleRemoveItem to correctly manage the itemKeys array alongside the arrayItems and itemParameters.
    • Changed the key prop for rendered array items from index to itemKeys[index] ?? index to leverage the new stable keys.
    • Added a new Box component containing 'Move up' and 'Move down' IconButtons, which are conditionally displayed when reordering is enabled.
    • Modified the rendering of itemParameters[index] to (itemParameters[index] || []) to safely handle cases where itemParameters[index] might be undefined.
Activity
  • The pull request introduces new UI functionality to reorder scenarios within the Condition Agent.
  • A demo video has been provided by the author to visually demonstrate the new feature.
  • The changes address and close issue Drag and Drop Scenario Reordering for Condition Agent node #5699, indicating a resolution to a previously identified need or bug.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces reordering functionality for Condition Agent scenarios using simple up/down buttons. The implementation correctly uses stable keys to prevent rendering issues during reordering, which is a great approach. My review includes a couple of suggestions to improve the code's design and maintainability. Specifically, I recommend refactoring some duplicated code into a helper function and suggest a more flexible, prop-based approach to enable the reorder feature, which would make the ArrayRenderer component more reusable.

Comment on lines +24 to +31
const isConditionAgentNode = data?.name === 'conditionAgentV2' || data?.name === 'conditionAgentAgentflow'

// Whitelist scenario field names across variants (keep this minimal)
// Include both legacy and UI field name for compatibility
const scenarioFieldNames = new Set(['conditionAgentScenarios', 'ConditionAgentScenarios'])

const isScenarioField = scenarioFieldNames.has(inputParam?.name)
const enableReorder = !isDocStore && isConditionAgentNode && isScenarioField
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Hardcoding node names (conditionAgentV2, conditionAgentAgentflow) and input parameter names (conditionAgentScenarios, ConditionAgentScenarios) makes the ArrayRenderer component less reusable and tightly coupled to specific nodes. A more flexible approach would be to control this behavior via a prop on the inputParam object, for example reorderable: true. This would decouple ArrayRenderer and make it a more generic component that can be used for any array input that needs reordering capabilities.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TianHougege can we make this change? Adding reorderable to ConditionAgents.ts so in the inputParam will have it and just have enableReorder to be

const enableReorder = !isDocStore && !disabled && !!inputParam?.reorderable

This allows us to be more dynamic and not have specific hardcoded nodes to be reorderable
we can also remove

const isConditionAgentNode = data?.name === 'conditionAgentV2' || data?.name === 'conditionAgentAgentflow'
const scenarioFieldNames = new Set(['conditionAgentScenarios', 'ConditionAgentScenarios'])
const isScenarioField = scenarioFieldNames.has(inputParam?.name)

as those won't be necessary anymore.

Comment on lines +34 to +38
const swapInArray = (arr, i, j) => {
const next = [...arr]
;[next[i], next[j]] = [next[j], next[i]]
return next
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To avoid duplicating the key generation logic found in useEffect (lines 130-141) and handleAddItem (lines 221-229), you can extract it into a single createKey helper function here. This function can then be reused in both places, improving code reuse and maintainability.

    const swapInArray = (arr, i, j) => {
        const next = [...arr]
        ;[next[i], next[j]] = [next[j], next[i]]
        return next
    }

    const createKey = () => {
        try {
            return crypto.randomUUID()
        } catch (e) {
            return 'key-' + Date.now() + '-' + Math.random()
        }
    }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this change as well?

@HenryHengZJ HenryHengZJ added the ui Issues or features related to ui label Feb 26, 2026
Copy link
Copy Markdown
Contributor

@jchui-wd jchui-wd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @TianHougege, thanks for making this change, I have a few suggestions I have listed out.

There's also a small visual bug if you can have time to take a look. Pressing 'up' button is also affecting the 'up' button above it.

VisualBug.mp4

@HenryHengZJ any thoughts on this? Long-term, drag and drop might be the more standard UI pattern, but this approach works well and is also more accessible for keyboard users.

Comment on lines +24 to +31
const isConditionAgentNode = data?.name === 'conditionAgentV2' || data?.name === 'conditionAgentAgentflow'

// Whitelist scenario field names across variants (keep this minimal)
// Include both legacy and UI field name for compatibility
const scenarioFieldNames = new Set(['conditionAgentScenarios', 'ConditionAgentScenarios'])

const isScenarioField = scenarioFieldNames.has(inputParam?.name)
const enableReorder = !isDocStore && isConditionAgentNode && isScenarioField
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TianHougege can we make this change? Adding reorderable to ConditionAgents.ts so in the inputParam will have it and just have enableReorder to be

const enableReorder = !isDocStore && !disabled && !!inputParam?.reorderable

This allows us to be more dynamic and not have specific hardcoded nodes to be reorderable
we can also remove

const isConditionAgentNode = data?.name === 'conditionAgentV2' || data?.name === 'conditionAgentAgentflow'
const scenarioFieldNames = new Set(['conditionAgentScenarios', 'ConditionAgentScenarios'])
const isScenarioField = scenarioFieldNames.has(inputParam?.name)

as those won't be necessary anymore.

if (isDocStore || !reactFlowInstance) return

if (data.name !== 'conditionAgentflow' && data.name !== 'conditionAgentAgentflow') return
if (!isConditionAgentNode) return
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can probably revert this back once reorderable is implemented.

Also I think conditionAgentV2 isn't used anywhere else in the project so probably a typo.

Comment on lines +34 to +38
const swapInArray = (arr, i, j) => {
const next = [...arr]
;[next[i], next[j]] = [next[j], next[i]]
return next
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this change as well?


//scenario array swap function
const moveItem = (fromIndex, toIndex) => {
if (!enableReorder) return
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are a lot of redundant guards here, below is enough.

const moveItem = (fromIndex, toIndex) => {
    const nextItems = swapInArray(arrayItems, fromIndex, toIndex)
    const nextKeys = swapInArray(itemKeys, fromIndex, toIndex)
    const canSwapParams = itemParameters.length === arrayItems.length
    const nextParams = canSwapParams ? swapInArray(itemParameters, fromIndex, toIndex) : itemParameters

    setArrayItems(nextItems)
    if (canSwapParams) setItemParameters(nextParams)
    setItemKeys(nextKeys)

    data.inputs[inputParam.name] = nextItems
    updateOutputAnchors(nextItems, 'REORDER')
}

moveItem is only called by handleMoveUp and handleMoveDown, which already enforce bounds. The buttons only render when enableReorder is true and are disabled when disabled is true. All 6 guards duplicate checks that are already enforced by the callers and JSX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ui Issues or features related to ui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Drag and Drop Scenario Reordering for Condition Agent node

3 participants