Add logHasMessage and logTypeIsUnknown functions
This commit is contained in:
parent
c73eb44842
commit
3c9948e2c3
1 changed files with 31 additions and 18 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import { cloneDeep } from "lodash";
|
import { cloneDeep } from "lodash";
|
||||||
import { ReactNode, useEffect, useRef, useState } from "react";
|
import { ReactNode, useEffect, useRef, useState } from "react";
|
||||||
|
import { useHotkeys } from "react-hotkeys-hook";
|
||||||
import { Handle, Position, useUpdateNodeInternals } from "reactflow";
|
import { Handle, Position, useUpdateNodeInternals } from "reactflow";
|
||||||
import CodeAreaComponent from "../../../../components/codeAreaComponent";
|
import CodeAreaComponent from "../../../../components/codeAreaComponent";
|
||||||
import DictComponent from "../../../../components/dictComponent";
|
import DictComponent from "../../../../components/dictComponent";
|
||||||
|
|
@ -17,10 +18,7 @@ import TextAreaComponent from "../../../../components/textAreaComponent";
|
||||||
import ToggleShadComponent from "../../../../components/toggleShadComponent";
|
import ToggleShadComponent from "../../../../components/toggleShadComponent";
|
||||||
import { Button } from "../../../../components/ui/button";
|
import { Button } from "../../../../components/ui/button";
|
||||||
import { RefreshButton } from "../../../../components/ui/refreshButton";
|
import { RefreshButton } from "../../../../components/ui/refreshButton";
|
||||||
import {
|
import { LANGFLOW_SUPPORTED_TYPES } from "../../../../constants/constants";
|
||||||
LANGFLOW_SUPPORTED_TYPES,
|
|
||||||
TOOLTIP_EMPTY,
|
|
||||||
} from "../../../../constants/constants";
|
|
||||||
import { Case } from "../../../../shared/components/caseComponent";
|
import { Case } from "../../../../shared/components/caseComponent";
|
||||||
import useFlowStore from "../../../../stores/flowStore";
|
import useFlowStore from "../../../../stores/flowStore";
|
||||||
import useFlowsManagerStore from "../../../../stores/flowsManagerStore";
|
import useFlowsManagerStore from "../../../../stores/flowsManagerStore";
|
||||||
|
|
@ -51,10 +49,8 @@ import useHandleNodeClass from "../../../hooks/use-handle-node-class";
|
||||||
import useHandleRefreshButtonPress from "../../../hooks/use-handle-refresh-buttons";
|
import useHandleRefreshButtonPress from "../../../hooks/use-handle-refresh-buttons";
|
||||||
import HandleTooltips from "../HandleTooltipComponent";
|
import HandleTooltips from "../HandleTooltipComponent";
|
||||||
import OutputComponent from "../OutputComponent";
|
import OutputComponent from "../OutputComponent";
|
||||||
import TooltipRenderComponent from "../tooltipRenderComponent";
|
|
||||||
import { TEXT_FIELD_TYPES } from "./constants";
|
|
||||||
import OutputModal from "../outputModal";
|
import OutputModal from "../outputModal";
|
||||||
import { useHotkeys } from "react-hotkeys-hook";
|
import { TEXT_FIELD_TYPES } from "./constants";
|
||||||
|
|
||||||
export default function ParameterComponent({
|
export default function ParameterComponent({
|
||||||
left,
|
left,
|
||||||
|
|
@ -93,23 +89,40 @@ 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 displayOutputPreview =
|
const logHasMessage = (data: any) => {
|
||||||
!!flowPool[data.id] &&
|
if (!outputName) return;
|
||||||
flowPool[data.id][flowPool[data.id].length - 1]?.valid &&
|
const logs = data?.logs[outputName];
|
||||||
flowPool[data.id][flowPool[data.id].length - 1]?.data?.logs[0]?.message;
|
if (Array.isArray(logs) && logs.length > 1) {
|
||||||
|
return logs.some((log) => log.message);
|
||||||
|
} else {
|
||||||
|
return logs?.message;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const logTypeIsUnknown = (data: any) => {
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const flowPoolNode = (flowPool[data.id] ?? [])[
|
const flowPoolNode = (flowPool[data.id] ?? [])[
|
||||||
(flowPool[data.id]?.length ?? 1) - 1
|
(flowPool[data.id]?.length ?? 1) - 1
|
||||||
];
|
];
|
||||||
|
const displayOutputPreview =
|
||||||
|
!!flowPool[data.id] &&
|
||||||
|
flowPool[data.id][flowPool[data.id].length - 1]?.valid &&
|
||||||
|
logHasMessage(flowPool[data.id][flowPool[data.id].length - 1]?.data);
|
||||||
|
|
||||||
let hasOutputs;
|
let hasOutputs;
|
||||||
if (flowPoolNode?.data?.logs && outputName) {
|
if (flowPoolNode?.data?.logs && outputName) {
|
||||||
hasOutputs = flowPoolNode?.data?.logs[outputName] ?? null;
|
hasOutputs = flowPoolNode?.data?.logs[outputName] ?? null;
|
||||||
}
|
}
|
||||||
const unknownOutput = !!(
|
|
||||||
flowPool[data.id] &&
|
const unknownOutput = logTypeIsUnknown(flowPoolNode?.data);
|
||||||
flowPool[data.id][flowPool[data.id].length - 1]?.data?.logs[0]?.type ===
|
|
||||||
"unknown"
|
|
||||||
);
|
|
||||||
|
|
||||||
const preventDefault = true;
|
const preventDefault = true;
|
||||||
|
|
||||||
|
|
@ -165,7 +178,7 @@ export default function ParameterComponent({
|
||||||
|
|
||||||
const handleOnNewValue = async (
|
const handleOnNewValue = async (
|
||||||
newValue: string | string[] | boolean | Object[],
|
newValue: string | string[] | boolean | Object[],
|
||||||
skipSnapshot: boolean | undefined = false,
|
skipSnapshot: boolean | undefined = false
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
handleOnNewValueHook(newValue, skipSnapshot);
|
handleOnNewValueHook(newValue, skipSnapshot);
|
||||||
};
|
};
|
||||||
|
|
@ -278,7 +291,7 @@ export default function ParameterComponent({
|
||||||
className={classNames(
|
className={classNames(
|
||||||
left ? "my-12 -ml-0.5 " : " my-12 -mr-0.5 ",
|
left ? "my-12 -ml-0.5 " : " my-12 -mr-0.5 ",
|
||||||
"h-3 w-3 rounded-full border-2 bg-background",
|
"h-3 w-3 rounded-full border-2 bg-background",
|
||||||
!showNode ? "mt-0" : "",
|
!showNode ? "mt-0" : ""
|
||||||
)}
|
)}
|
||||||
style={{
|
style={{
|
||||||
borderColor: color ?? nodeColors.unknown,
|
borderColor: color ?? nodeColors.unknown,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue