Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,15 @@ export function DataSourcePopover({
<button
key={`${item.value}-${index}`}
type="button"
className="flex items-center gap-2 w-full rounded-md px-2 py-1.5 text-left text-xs font-mono text-muted-foreground hover:bg-accent hover:text-foreground transition-colors cursor-pointer"
className="hover:bg-accent flex w-full cursor-pointer flex-col items-start gap-0.5 rounded-md px-2 py-1.5 text-left transition-colors"
onClick={() => onSelect(item.value)}
>
{item.value}
<span className="text-foreground w-full truncate text-xs">
{item.label || item.value}
</span>
<span className="text-muted-foreground w-full truncate font-mono text-[10px]">
{item.value}
</span>
</button>
))}
</div>
Expand Down
57 changes: 44 additions & 13 deletions apps/platform/src/features/flow-editor/hooks/use-flow-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,33 +287,64 @@ export function useFlowNodes(apiNodes: ResolvedNode[] = []) {
})
contextMenu = cNew
} else if (source) {
const edges = source.edges.filter((e) => e.target === ref)
for (let i = 0; i < edges.length; i++) {
const edge = edges[i]
if (edge.source === '0') {
continue
const currentApiNodes = apiNodesArg || apiOriginRef.current
const nodeName = (
node: { title?: string; data?: { title?: string } },
fallback: string,
) => node.title || node.data?.title || fallback

const directParents = source.edges.filter((e) => e.target === ref)
if (directParents.length === 1 && directParents[0].source !== '0') {
const parentNode = source.nodes.find(
(n) => n.id === directParents[0].source,
)
const parentApiNode = currentApiNodes?.find(
(n) => n.id === parentNode?.nodeId,
)
for (const outputType of parentApiNode?.outputTypes ?? []) {
contextMenu.push({
label: `${t('ui.text.input', 'Input')} ${outputType.key}`,
value: `$input.${outputType.key}`,
isEditable: outputType.isEditable ?? false,
})
}
}

const ancestors: string[] = []
const seenNodes = new Set<string>([ref])
const queue = [ref]

while (queue.length > 0) {
const current = queue.shift()!
for (const edge of source.edges) {
if (edge.target !== current || seenNodes.has(edge.source)) {
continue
}
seenNodes.add(edge.source)
queue.push(edge.source)
if (edge.source !== '0') {
ancestors.push(edge.source)
}
}
const sourceNode = source.nodes.find((n) => n.id === edge.source)
}

for (const ancestorID of ancestors) {
const sourceNode = source.nodes.find((n) => n.id === ancestorID)
if (!sourceNode) {
continue
}
const currentApiNodes = apiNodesArg || apiOriginRef.current
const apiNode = currentApiNodes?.find(
(n) => n.id === sourceNode.nodeId,
)

if (apiNode === undefined) {
continue
}
const sourceContextMenu = sourceNode.data?.contextMenu
if (sourceContextMenu && sourceContextMenu.length > 0) {
contextMenu = contextMenu.concat(sourceContextMenu)
}

const outputs = apiNode.outputTypes ?? []
for (let j = 0; j < outputs.length; j++) {
const outputType = outputs[j]
contextMenu.push({
label: `${t(sourceNode.data?.title || apiNode.name)} ${outputType.key}`,
label: `${t(nodeName(sourceNode, apiNode.name))} ${outputType.key}`,
value: `$${apiNode.id}_${sourceNode.id}.${outputType.key}`,
isEditable: outputType.isEditable ?? false,
})
Expand Down