From 9edf4c84e4eafdff625959ba66ea8e81b056dc1e Mon Sep 17 00:00:00 2001 From: cristhianzl Date: Tue, 28 May 2024 12:15:22 -0300 Subject: [PATCH] Refactor: Revamp utils Folder Structure --- .../components/parameterComponent/index.tsx | 4 --- .../src/customNodes/helpers/count-handles.ts | 26 +++++++++++++++++++ .../helpers/get-class-from-build-status.ts | 25 ++++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 src/frontend/src/customNodes/helpers/count-handles.ts create mode 100644 src/frontend/src/customNodes/helpers/get-class-from-build-status.ts diff --git a/src/frontend/src/customNodes/genericNode/components/parameterComponent/index.tsx b/src/frontend/src/customNodes/genericNode/components/parameterComponent/index.tsx index c87c97741..fce391191 100644 --- a/src/frontend/src/customNodes/genericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/customNodes/genericNode/components/parameterComponent/index.tsx @@ -22,7 +22,6 @@ import { TOOLTIP_EMPTY, } from "../../../../constants/constants"; import { Case } from "../../../../shared/components/caseComponent"; -import useAlertStore from "../../../../stores/alertStore"; import useFlowStore from "../../../../stores/flowStore"; import useFlowsManagerStore from "../../../../stores/flowsManagerStore"; import { useTypesStore } from "../../../../stores/typesStore"; @@ -66,7 +65,6 @@ export default function ParameterComponent({ const ref = useRef(null); const refHtml = useRef(null); const infoHtml = useRef(null); - const setErrorData = useAlertStore((state) => state.setErrorData); const currentFlow = useFlowsManagerStore((state) => state.currentFlow); const nodes = useFlowStore((state) => state.nodes); const edges = useFlowStore((state) => state.edges); @@ -173,8 +171,6 @@ export default function ParameterComponent({ renderTooltips(); }, [tooltipTitle, flow]); - console.log(left === true && type === "dict"); - return !showNode ? ( left && LANGFLOW_SUPPORTED_TYPES.has(type ?? "") && !optionalHandle ? ( <> diff --git a/src/frontend/src/customNodes/helpers/count-handles.ts b/src/frontend/src/customNodes/helpers/count-handles.ts new file mode 100644 index 000000000..ebfbfe01b --- /dev/null +++ b/src/frontend/src/customNodes/helpers/count-handles.ts @@ -0,0 +1,26 @@ +import { NodeDataType } from "../../types/flow"; + +export function countHandlesFn(data: NodeDataType): number { + let count = Object.keys(data.node!.template) + .filter((templateField) => templateField.charAt(0) !== "_") + .map((templateCamp) => { + const { template } = data.node!; + if (template[templateCamp].input_types) return true; + if (!template[templateCamp].show) return false; + switch (template[templateCamp].type) { + case "str": + case "bool": + case "float": + case "code": + case "prompt": + case "file": + case "int": + return false; + default: + return true; + } + }) + .reduce((total, value) => total + (value ? 1 : 0), 0); + + return count; +} diff --git a/src/frontend/src/customNodes/helpers/get-class-from-build-status.ts b/src/frontend/src/customNodes/helpers/get-class-from-build-status.ts new file mode 100644 index 000000000..710e91d15 --- /dev/null +++ b/src/frontend/src/customNodes/helpers/get-class-from-build-status.ts @@ -0,0 +1,25 @@ +import { BuildStatus } from "../../constants/enums"; +import { VertexBuildTypeAPI } from "../../types/api"; + +export const getSpecificClassFromBuildStatus = ( + buildStatus: BuildStatus | undefined, + validationStatus: VertexBuildTypeAPI | null, + isDark: boolean, +) => { + let isInvalid = validationStatus && !validationStatus.valid; + + if (buildStatus === BuildStatus.INACTIVE) { + // INACTIVE should have its own class + return "inactive-status"; + } + if ( + (buildStatus === BuildStatus.BUILT && isInvalid) || + buildStatus === BuildStatus.ERROR + ) { + return isDark ? "built-invalid-status-dark" : "built-invalid-status"; + } else if (buildStatus === BuildStatus.BUILDING) { + return "building-status"; + } else { + return ""; + } +};