Generated output parameters and disable one of them if the other is in use

This commit is contained in:
Lucas Oliveira 2023-03-31 09:04:24 -03:00
commit 876a691004
2 changed files with 117 additions and 107 deletions

View file

@ -46,12 +46,14 @@ export default function ParameterComponent({
const { reactFlowInstance } = useContext(typesContext); const { reactFlowInstance } = useContext(typesContext);
let disabled = let disabled =
reactFlowInstance?.getEdges().some((e) => e.targetHandle === id) ?? false; reactFlowInstance?.getEdges().some((e) => e.targetHandle === id) ?? false;
let disabledSource =
reactFlowInstance?.getEdges().some((e) => e.sourceHandle !== id && e.source === data.id) ?? false;
const { save } = useContext(TabsContext); const { save } = useContext(TabsContext);
return ( return (
<div <div
ref={ref} ref={ref}
className="w-full flex flex-wrap justify-between items-center bg-gray-50 dark:bg-gray-800 dark:text-white mt-1 px-5 py-2" className={"w-full flex flex-wrap justify-between items-center dark:text-white mt-1 px-5 py-2 " + (!left ? (disabledSource ? "bg-gray-100 dark:bg-gray-700 text-gray-500": "bg-gray-50 dark:bg-gray-800") : "bg-gray-50 dark:bg-gray-800")}
> >
<> <>
<div className="text-sm truncate"> <div className="text-sm truncate">
@ -76,8 +78,8 @@ export default function ParameterComponent({
isValidConnection(connection, reactFlowInstance) isValidConnection(connection, reactFlowInstance)
} }
className={classNames( className={classNames(
left ? "-ml-0.5 " : "-mr-0.5 ", left ? "-ml-0.5 " : ("-mr-0.5 " + (disabledSource ? "pointer-events-none border-gray-400 " : "")),
"w-3 h-3 rounded-full border-2 bg-white dark:bg-gray-800" "w-3 h-3 rounded-full border-2 bg-white dark:bg-gray-800",
)} )}
style={{ style={{
borderColor: color, borderColor: color,

View file

@ -100,18 +100,26 @@ export default function GenericNode({
)} )}
</div> </div>
))} ))}
{data.node.base_classes.map((c, idx) => (
<div key={idx}>
{idx === 0 ? (
<div className="px-5 py-2 mt-2 dark:text-white text-center"> <div className="px-5 py-2 mt-2 dark:text-white text-center">
Output: Outputs:
</div> </div>
) : (
<></>
)}
<ParameterComponent <ParameterComponent
data={data} data={data}
color={nodeColors[types[data.type]] ?? nodeColors.unknown} color={nodeColors[types[c]] ?? nodeColors.unknown}
title={data.type} title={c}
tooltipTitle={`Type: ${data.node.base_classes.join(" | ")}`} tooltipTitle={`Type: ${c}`}
id={[data.type, data.id, ...data.node.base_classes].join("|")} id={[data.type, data.id, c].join("|")}
type={"str"} type={c}
left={false} left={false}
/> />
</div>
))}
</> </>
</div> </div>
</div> </div>