feat(frontend): refactor OutputComponent to use external dropdown menu component
This commit is contained in:
parent
3f43958f08
commit
77cb85b7f2
1 changed files with 33 additions and 20 deletions
|
|
@ -16,6 +16,8 @@ import {
|
||||||
specialCharsRegex,
|
specialCharsRegex,
|
||||||
} from "../constants/constants";
|
} from "../constants/constants";
|
||||||
import { downloadFlowsFromDatabase } from "../controllers/API";
|
import { downloadFlowsFromDatabase } from "../controllers/API";
|
||||||
|
import getFieldTitle from "../customNodes/utils/get-field-title";
|
||||||
|
import { DESCRIPTIONS } from "../flow_constants";
|
||||||
import {
|
import {
|
||||||
APIClassType,
|
APIClassType,
|
||||||
APIKindType,
|
APIKindType,
|
||||||
|
|
@ -37,8 +39,6 @@ import {
|
||||||
updateEdgesHandleIdsType,
|
updateEdgesHandleIdsType,
|
||||||
} from "../types/utils/reactflowUtils";
|
} from "../types/utils/reactflowUtils";
|
||||||
import { createRandomKey, toTitleCase } from "./utils";
|
import { createRandomKey, toTitleCase } from "./utils";
|
||||||
import { DESCRIPTIONS } from "../flow_constants";
|
|
||||||
import getFieldTitle from "../customNodes/utils/get-field-title";
|
|
||||||
const uid = new ShortUniqueId({ length: 5 });
|
const uid = new ShortUniqueId({ length: 5 });
|
||||||
|
|
||||||
export function checkChatInput(nodes: Node[]) {
|
export function checkChatInput(nodes: Node[]) {
|
||||||
|
|
@ -413,25 +413,38 @@ export function updateEdgesHandleIds({
|
||||||
export function updateNewOutput({ nodes, edges }: updateEdgesHandleIdsType) {
|
export function updateNewOutput({ nodes, edges }: updateEdgesHandleIdsType) {
|
||||||
let newEdges = cloneDeep(edges);
|
let newEdges = cloneDeep(edges);
|
||||||
let newNodes = cloneDeep(nodes);
|
let newNodes = cloneDeep(nodes);
|
||||||
newNodes.forEach((node) => {
|
newEdges.forEach((edge) => {
|
||||||
if (
|
if (edge.sourceHandle && edge.targetHandle) {
|
||||||
!node.data.node?.outputs &&
|
let newSourceHandle: sourceHandleType = scapeJSONParse(edge.sourceHandle);
|
||||||
(node.data.node?.base_classes ?? []).length > 0
|
let newTargetHandle: targetHandleType = scapeJSONParse(edge.targetHandle);
|
||||||
) {
|
let intersection;
|
||||||
const selected = node.data.node?.base_classes[0]!;
|
if (newTargetHandle.inputTypes && newTargetHandle.inputTypes.length > 0) {
|
||||||
node.data.node!.outputs = [
|
//conjuction subtraction
|
||||||
{ types: node.data.node!.base_classes, selected: selected },
|
intersection = newSourceHandle.baseClasses.filter((type) =>
|
||||||
];
|
newTargetHandle.inputTypes!.includes(type),
|
||||||
newEdges.forEach((edge) => {
|
);
|
||||||
if (edge.source === node.id && edge.sourceHandle) {
|
} else {
|
||||||
let newSourceHandle: sourceHandleType = scapeJSONParse(
|
intersection = newSourceHandle.baseClasses.filter(
|
||||||
edge.sourceHandle,
|
(type) => type === newTargetHandle.type,
|
||||||
);
|
);
|
||||||
newSourceHandle.baseClasses = [selected];
|
}
|
||||||
edge.sourceHandle = scapedJSONStringfy(newSourceHandle);
|
const selected = intersection[0];
|
||||||
edge.data.sourceHandle = newSourceHandle;
|
newSourceHandle.baseClasses = [selected];
|
||||||
|
const id = newSourceHandle.id;
|
||||||
|
const sourceNodeIndex = newNodes.findIndex((node) => node.id === id);
|
||||||
|
if (sourceNodeIndex > -1) {
|
||||||
|
const sourceNode = newNodes[sourceNodeIndex];
|
||||||
|
if (
|
||||||
|
!sourceNode.data.node?.outputs ||
|
||||||
|
sourceNode.data.node!.outputs!.length === 0
|
||||||
|
) {
|
||||||
|
sourceNode.data.node!.outputs = [
|
||||||
|
{ types: sourceNode.data.node!.base_classes, selected: selected },
|
||||||
|
];
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
edge.sourceHandle = scapedJSONStringfy(newSourceHandle);
|
||||||
|
edge.data.sourceHandle = newSourceHandle;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue