add output preview for grouped components
This commit is contained in:
parent
b97ec2436c
commit
c2382b97db
5 changed files with 78 additions and 50 deletions
|
|
@ -18,10 +18,7 @@ const SwitchOutputView: React.FC<SwitchOutputViewProps> = ({
|
||||||
nodeId,
|
nodeId,
|
||||||
outputName,
|
outputName,
|
||||||
}) => {
|
}) => {
|
||||||
const nodes = useFlowStore((state) => state.nodes);
|
|
||||||
const flowPool = useFlowStore((state) => state.flowPool);
|
const flowPool = useFlowStore((state) => state.flowPool);
|
||||||
const node = nodes.find((node) => node?.id === nodeId);
|
|
||||||
|
|
||||||
const flowPoolNode = (flowPool[nodeId] ?? [])[
|
const flowPoolNode = (flowPool[nodeId] ?? [])[
|
||||||
(flowPool[nodeId]?.length ?? 1) - 1
|
(flowPool[nodeId]?.length ?? 1) - 1
|
||||||
];
|
];
|
||||||
|
|
@ -46,7 +43,7 @@ const SwitchOutputView: React.FC<SwitchOutputViewProps> = ({
|
||||||
></ErrorOutput>
|
></ErrorOutput>
|
||||||
</Case>
|
</Case>
|
||||||
|
|
||||||
<Case condition={node && resultType === "text"}>
|
<Case condition={resultType === "text"}>
|
||||||
<TextOutputView left={false} value={resultMessage} />
|
<TextOutputView left={false} value={resultMessage} />
|
||||||
</Case>
|
</Case>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import useFlowStore from "../../../../stores/flowStore";
|
||||||
import useFlowsManagerStore from "../../../../stores/flowsManagerStore";
|
import useFlowsManagerStore from "../../../../stores/flowsManagerStore";
|
||||||
import { useShortcutsStore } from "../../../../stores/shortcuts";
|
import { useShortcutsStore } from "../../../../stores/shortcuts";
|
||||||
import { useTypesStore } from "../../../../stores/typesStore";
|
import { useTypesStore } from "../../../../stores/typesStore";
|
||||||
import { APIClassType } from "../../../../types/api";
|
import { APIClassType, VertexDataTypeAPI } from "../../../../types/api";
|
||||||
import { ParameterComponentType } from "../../../../types/components";
|
import { ParameterComponentType } from "../../../../types/components";
|
||||||
import { isErrorLog } from "../../../../types/utils/typeCheckingUtils";
|
import { isErrorLog } from "../../../../types/utils/typeCheckingUtils";
|
||||||
import {
|
import {
|
||||||
|
|
@ -34,6 +34,7 @@ import {
|
||||||
import {
|
import {
|
||||||
convertObjToArray,
|
convertObjToArray,
|
||||||
convertValuesToNumbers,
|
convertValuesToNumbers,
|
||||||
|
getGroupOutputNodeId,
|
||||||
hasDuplicateKeys,
|
hasDuplicateKeys,
|
||||||
scapedJSONStringfy,
|
scapedJSONStringfy,
|
||||||
} from "../../../../utils/reactflowUtils";
|
} from "../../../../utils/reactflowUtils";
|
||||||
|
|
@ -41,6 +42,9 @@ import {
|
||||||
classNames,
|
classNames,
|
||||||
cn,
|
cn,
|
||||||
isThereModal,
|
isThereModal,
|
||||||
|
logHasMessage,
|
||||||
|
logTypeIsError,
|
||||||
|
logTypeIsUnknown,
|
||||||
} from "../../../../utils/utils";
|
} from "../../../../utils/utils";
|
||||||
import useFetchDataOnMount from "../../../hooks/use-fetch-data-on-mount";
|
import useFetchDataOnMount from "../../../hooks/use-fetch-data-on-mount";
|
||||||
import useHandleOnNewValue from "../../../hooks/use-handle-new-value";
|
import useHandleOnNewValue from "../../../hooks/use-handle-new-value";
|
||||||
|
|
@ -84,45 +88,29 @@ export default function ParameterComponent({
|
||||||
const [openOutputModal, setOpenOutputModal] = useState(false);
|
const [openOutputModal, setOpenOutputModal] = useState(false);
|
||||||
const flowPool = useFlowStore((state) => state.flowPool);
|
const flowPool = useFlowStore((state) => state.flowPool);
|
||||||
|
|
||||||
const logHasMessage = (data: any) => {
|
let flowPoolId = data.id;
|
||||||
if (!outputName) return;
|
let internalOutputName = outputName;
|
||||||
const logs = data?.logs[outputName];
|
|
||||||
if (Array.isArray(logs) && logs.length > 1) {
|
|
||||||
return logs.some((log) => log.message);
|
|
||||||
} else {
|
|
||||||
return logs?.message;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const logTypeIsUnknown = (data: any) => {
|
if(data.node?.flow && outputProxy){
|
||||||
if (!outputName) return;
|
const realOutput = getGroupOutputNodeId(data.node.flow, outputProxy.name, outputProxy.id)
|
||||||
const logs = data?.logs[outputName];
|
if(realOutput){
|
||||||
if (Array.isArray(logs) && logs.length > 1) {
|
flowPoolId = realOutput.id;
|
||||||
return logs.some((log) => log.type === "unknown");
|
internalOutputName = realOutput.outputName;
|
||||||
} else {
|
|
||||||
return logs?.type === "unknown";
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
const logTypeIsError = (data: any) => {
|
const flowPoolNode = (flowPool[flowPoolId] ?? [])[
|
||||||
if (!outputName) return;
|
(flowPool[flowPoolId]?.length ?? 1) - 1
|
||||||
const logs = data?.logs[outputName];
|
|
||||||
if (Array.isArray(logs) && logs.length > 1) {
|
|
||||||
return logs.some((log) => isErrorLog(log));
|
|
||||||
} else {
|
|
||||||
return isErrorLog(logs);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const flowPoolNode = (flowPool[data.id] ?? [])[
|
|
||||||
(flowPool[data.id]?.length ?? 1) - 1
|
|
||||||
];
|
];
|
||||||
const displayOutputPreview =
|
|
||||||
!!flowPool[data.id] &&
|
|
||||||
logHasMessage(flowPool[data.id][flowPool[data.id].length - 1]?.data);
|
|
||||||
|
|
||||||
const unknownOutput = logTypeIsUnknown(flowPoolNode?.data);
|
const displayOutputPreview = !!flowPool[flowPoolId] && logHasMessage(flowPoolNode?.data,internalOutputName);
|
||||||
const errorOutput = logTypeIsError(flowPoolNode?.data);
|
|
||||||
|
const unknownOutput = logTypeIsUnknown(flowPoolNode?.data,internalOutputName);
|
||||||
|
const errorOutput = logTypeIsError(flowPoolNode?.data,internalOutputName);
|
||||||
|
|
||||||
|
if (outputProxy) {
|
||||||
|
console.log(logHasMessage(flowPoolNode?.data,internalOutputName))
|
||||||
|
}
|
||||||
|
|
||||||
const preventDefault = true;
|
const preventDefault = true;
|
||||||
|
|
||||||
|
|
@ -276,7 +264,7 @@ export default function ParameterComponent({
|
||||||
className={
|
className={
|
||||||
"relative mt-1 flex w-full flex-wrap items-center justify-between bg-muted px-5 py-2" +
|
"relative mt-1 flex w-full flex-wrap items-center justify-between bg-muted px-5 py-2" +
|
||||||
((name === "code" && type === "code") ||
|
((name === "code" && type === "code") ||
|
||||||
(name.includes("code") && proxy)
|
(name.includes("code") && proxy)
|
||||||
? " hidden"
|
? " hidden"
|
||||||
: "")
|
: "")
|
||||||
}
|
}
|
||||||
|
|
@ -416,7 +404,7 @@ export default function ParameterComponent({
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
value={
|
value={
|
||||||
!data.node!.template[name]?.value ||
|
!data.node!.template[name]?.value ||
|
||||||
data.node!.template[name]?.value === ""
|
data.node!.template[name]?.value === ""
|
||||||
? [""]
|
? [""]
|
||||||
: data.node!.template[name]?.value
|
: data.node!.template[name]?.value
|
||||||
}
|
}
|
||||||
|
|
@ -631,7 +619,7 @@ export default function ParameterComponent({
|
||||||
editNode={false}
|
editNode={false}
|
||||||
value={
|
value={
|
||||||
!data.node!.template[name]?.value ||
|
!data.node!.template[name]?.value ||
|
||||||
data.node!.template[name]?.value?.toString() === "{}"
|
data.node!.template[name]?.value?.toString() === "{}"
|
||||||
? {}
|
? {}
|
||||||
: data.node!.template[name]?.value
|
: data.node!.template[name]?.value
|
||||||
}
|
}
|
||||||
|
|
@ -648,7 +636,7 @@ export default function ParameterComponent({
|
||||||
editNode={false}
|
editNode={false}
|
||||||
value={
|
value={
|
||||||
data.node!.template[name]?.value?.length === 0 ||
|
data.node!.template[name]?.value?.length === 0 ||
|
||||||
!data.node!.template[name]?.value
|
!data.node!.template[name]?.value
|
||||||
? [{ "": "" }]
|
? [{ "": "" }]
|
||||||
: convertObjToArray(data.node!.template[name]?.value, type!)
|
: convertObjToArray(data.node!.template[name]?.value, type!)
|
||||||
}
|
}
|
||||||
|
|
@ -670,9 +658,9 @@ export default function ParameterComponent({
|
||||||
{openOutputModal && (
|
{openOutputModal && (
|
||||||
<OutputModal
|
<OutputModal
|
||||||
open={openOutputModal}
|
open={openOutputModal}
|
||||||
nodeId={data.id}
|
nodeId={flowPoolId}
|
||||||
setOpen={setOpenOutputModal}
|
setOpen={setOpenOutputModal}
|
||||||
outputName={outputName}
|
outputName={internalOutputName}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|
|
||||||
|
|
@ -195,7 +195,7 @@ export type LogType = {
|
||||||
// it has results, artifacts, timedelta, duration
|
// it has results, artifacts, timedelta, duration
|
||||||
export type VertexDataTypeAPI = {
|
export type VertexDataTypeAPI = {
|
||||||
results: { [key: string]: string };
|
results: { [key: string]: string };
|
||||||
logs: { [key: string]: LogType | LogType[] };
|
logs: { [key: string]: LogType };
|
||||||
messages: ChatOutputType[] | ChatInputType[];
|
messages: ChatOutputType[] | ChatInputType[];
|
||||||
inactive?: boolean;
|
inactive?: boolean;
|
||||||
timedelta?: number;
|
timedelta?: number;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { cloneDeep } from "lodash";
|
import { cloneDeep, get } from "lodash";
|
||||||
import {
|
import {
|
||||||
Connection,
|
Connection,
|
||||||
Edge,
|
Edge,
|
||||||
|
|
@ -1490,3 +1490,15 @@ export function updateGroupRecursion(groupNode: NodeType, edges: Edge[]) {
|
||||||
updateEdgesIds(flowEdges, idsMap);
|
updateEdgesIds(flowEdges, idsMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getGroupOutputNodeId(flow:FlowType,p_name:string,p_node_id:string){
|
||||||
|
let node:NodeType|undefined = flow.data?.nodes.find((n) => n.id === p_node_id);
|
||||||
|
if(!node) return;
|
||||||
|
if(node.data.node?.flow){
|
||||||
|
let output = node.data.node.outputs?.find((o) => o.name === p_name);
|
||||||
|
if(output && output.proxy){
|
||||||
|
return getGroupOutputNodeId(node.data.node.flow,output.proxy.name,output.proxy.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {id: node.id, outputName: p_name};
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import clsx, { ClassValue } from "clsx";
|
||||||
import { twMerge } from "tailwind-merge";
|
import { twMerge } from "tailwind-merge";
|
||||||
import TableAutoCellRender from "../components/tableComponent/components/tableAutoCellRender";
|
import TableAutoCellRender from "../components/tableComponent/components/tableAutoCellRender";
|
||||||
import { MESSAGES_TABLE_ORDER, MODAL_CLASSES } from "../constants/constants";
|
import { MESSAGES_TABLE_ORDER, MODAL_CLASSES } from "../constants/constants";
|
||||||
import { APIDataType, InputFieldType } from "../types/api";
|
import { APIDataType, InputFieldType, VertexDataTypeAPI } from "../types/api";
|
||||||
import {
|
import {
|
||||||
groupedObjType,
|
groupedObjType,
|
||||||
nodeGroupedObjType,
|
nodeGroupedObjType,
|
||||||
|
|
@ -11,6 +11,7 @@ import {
|
||||||
} from "../types/components";
|
} from "../types/components";
|
||||||
import { NodeType } from "../types/flow";
|
import { NodeType } from "../types/flow";
|
||||||
import { FlowState } from "../types/tabs";
|
import { FlowState } from "../types/tabs";
|
||||||
|
import { isErrorLog } from "../types/utils/typeCheckingUtils";
|
||||||
|
|
||||||
export function classNames(...classes: Array<string>): string {
|
export function classNames(...classes: Array<string>): string {
|
||||||
return classes.filter(Boolean).join(" ");
|
return classes.filter(Boolean).join(" ");
|
||||||
|
|
@ -423,3 +424,33 @@ export function messagesSorter(a: any, b: any) {
|
||||||
|
|
||||||
return orderA - orderB;
|
return orderA - orderB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const logHasMessage = (data: VertexDataTypeAPI,outputName:string|undefined) => {
|
||||||
|
if (!outputName) return;
|
||||||
|
const logs = data?.logs[outputName];
|
||||||
|
if (Array.isArray(logs) && logs.length > 1) {
|
||||||
|
return logs.some((log) => log.message);
|
||||||
|
} else {
|
||||||
|
return logs?.message;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const logTypeIsUnknown = (data: VertexDataTypeAPI,outputName:string|undefined) => {
|
||||||
|
if (!outputName) return;
|
||||||
|
const logs = data?.logs[outputName];
|
||||||
|
if (Array.isArray(logs) && logs.length > 1) {
|
||||||
|
return logs.some((log) => log.type === "unknown");
|
||||||
|
} else {
|
||||||
|
return logs?.type === "unknown";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const logTypeIsError = (data: VertexDataTypeAPI,outputName:string|undefined) => {
|
||||||
|
if (!outputName) return;
|
||||||
|
const logs = data?.logs[outputName];
|
||||||
|
if (Array.isArray(logs) && logs.length > 1) {
|
||||||
|
return logs.some((log) => isErrorLog(log));
|
||||||
|
} else {
|
||||||
|
return isErrorLog(logs);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue