From 42e433c6e2a048591692f9aed6290a7e87307529 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Tue, 30 Jan 2024 14:35:51 -0300 Subject: [PATCH] fix(IOview/index.tsx): import classNames function from utils/utils to fix compilation error feat(IOview/index.tsx): add support for dynamic categories based on available inputs and outputs feat(IOview/index.tsx): add functionality to select and display different views based on selected category fix(flowStore.ts): fix logic for determining if flow has inputs or outputs --- src/frontend/src/components/IOview/index.tsx | 69 +++++++++++++++----- src/frontend/src/stores/flowStore.ts | 4 +- 2 files changed, 54 insertions(+), 19 deletions(-) diff --git a/src/frontend/src/components/IOview/index.tsx b/src/frontend/src/components/IOview/index.tsx index 520a4a3e8..a0ee0a988 100644 --- a/src/frontend/src/components/IOview/index.tsx +++ b/src/frontend/src/components/IOview/index.tsx @@ -2,7 +2,7 @@ import { cloneDeep } from "lodash"; import { ReactNode, useState } from "react"; import useFlowStore from "../../stores/flowStore"; import { NodeType } from "../../types/flow"; -import { extractTypeFromLongId } from "../../utils/utils"; +import { classNames } from "../../utils/utils"; import AccordionComponent from "../AccordionComponent"; import IOInputField from "../IOInputField"; import IconComponent from "../genericIconComponent"; @@ -16,30 +16,65 @@ export default function IOView(): JSX.Element { const outputIds = outputs.map((obj) => obj.id); const nodes = useFlowStore((state) => state.nodes); const setNode = useFlowStore((state) => state.setNode); - const options = inputIds.concat(outputIds); - //TODO: show output options for view - const [selectedView, setSelectedView] = useState( - handleSelectChange(options[0]) + const categories = getCategories(); + const [selectedCategory, setSelectedCategory] = useState( + categories[0] ); - // if (outputTypes.includes("ChatOutput")) { - // return ; - // } - function handleSelectChange(selected: string) { - const type = extractTypeFromLongId(selected); - return ; + //TODO: show output options for view + const [selectedView, setSelectedView] = useState("Chat"); + + function getCategories() { + const categories: string[] = []; + if (inputs.length > 0) categories.push("Inputs"); + if (outputs.filter((output) => output.type !== "ChatOutput").length > 0) + categories.push("Outputs"); + if (outputs.map((output) => output.type).includes("ChatOutput")) + categories.push("Chat"); + return categories; + } + + function handleSelectChange(type?: string): ReactNode { + if (selectedCategory === "Chat") return ; switch (type) { - case "ChatOutput": + case "Chat": return ; break; + // case "TextInput": + // break; + default: + //create empty view output screen + return
no view selected
; } } - console.log(inputs); return (
-
- - Inputs +
+ {categories.map((category, index) => { + return ( + //hide chat button if chat is alredy on the view + !(selectedView === category && category === "Chat") && ( + + ) + ); + })}
{inputs .filter((input) => input.type !== "ChatInput") @@ -86,7 +121,7 @@ export default function IOView(): JSX.Element { ); })}
- {selectedView} + {handleSelectChange(selectedView)}
); } diff --git a/src/frontend/src/stores/flowStore.ts b/src/frontend/src/stores/flowStore.ts index 4e8ef5068..447f68713 100644 --- a/src/frontend/src/stores/flowStore.ts +++ b/src/frontend/src/stores/flowStore.ts @@ -82,7 +82,7 @@ const useFlowStore = create((set, get) => ({ flowState: undefined, inputs, outputs, - hasIO: inputs.length > 0 && outputs.length > 0, + hasIO: inputs.length > 0 || outputs.length > 0, flowPool, }); get().reactFlowInstance!.setViewport(viewport); @@ -124,7 +124,7 @@ const useFlowStore = create((set, get) => ({ flowState: undefined, inputs, outputs, - hasIO: inputs.length > 0 && outputs.length > 0, + hasIO: inputs.length > 0 || outputs.length > 0, }); const flowsManager = useFlowsManagerStore.getState();