Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

feat: sort variables in the selector by x axis for most recent order (#19243)

GeorgeCaoJb979a8a707f1
diff --git a/web/app/components/workflow/nodes/_base/components/variable/utils.ts b/web/app/components/workflow/nodes/_base/components/variable/utils.ts
index d56c636f550..f804cf6902c 100644
--- a/web/app/components/workflow/nodes/_base/components/variable/utils.ts
+++ b/web/app/components/workflow/nodes/_base/components/variable/utils.ts
@@ -577,8 +577,20 @@ export const toNodeOutputVars = (
chatVarList: conversationVariables,
},
}
+ // Sort nodes in reverse chronological order (most recent first)
+ const sortedNodes = [...nodes].sort((a, b) => {
+ if (a.data.type === BlockEnum.Start) return 1
+ if (b.data.type === BlockEnum.Start) return -1
+ if (a.data.type === 'env') return 1
+ if (b.data.type === 'env') return -1
+ if (a.data.type === 'conversation') return 1
+ if (b.data.type === 'conversation') return -1
+ // sort nodes by x position
+ return (b.position?.x || 0) - (a.position?.x || 0)
+ })
+
const res = [
- ...nodes.filter(node => SUPPORT_OUTPUT_VARS_NODE.includes(node?.data?.type)),
+ ...sortedNodes.filter(node => SUPPORT_OUTPUT_VARS_NODE.includes(node?.data?.type)),
...(environmentVariables.length > 0 ? [ENV_NODE] : []),
...((isChatMode && conversationVariables.length > 0) ? [CHAT_VAR_NODE] : []),
].map((node) => {