Refactor IOInputField component and update dependencies
This commit is contained in:
parent
42e433c6e2
commit
1fb907bf4f
4 changed files with 100 additions and 58 deletions
|
|
@ -1,36 +1,54 @@
|
||||||
|
import { cloneDeep } from "lodash";
|
||||||
|
import useFlowStore from "../../stores/flowStore";
|
||||||
import { IOInputProps } from "../../types/components";
|
import { IOInputProps } from "../../types/components";
|
||||||
import IOFileInput from "../IOInputs/FileInput";
|
|
||||||
import { Textarea } from "../ui/textarea";
|
import { Textarea } from "../ui/textarea";
|
||||||
|
|
||||||
export default function IOInputField({
|
export default function IOInputField({
|
||||||
inputType,
|
inputType,
|
||||||
field,
|
inputId,
|
||||||
updateValue,
|
|
||||||
}: IOInputProps): JSX.Element | undefined {
|
}: IOInputProps): JSX.Element | undefined {
|
||||||
|
const nodes = useFlowStore((state) => state.nodes);
|
||||||
|
const setNode = useFlowStore((state) => state.setNode);
|
||||||
|
const node = nodes.find((node) => node.id === inputId);
|
||||||
function handleInputType() {
|
function handleInputType() {
|
||||||
|
if (!node) return "no node found";
|
||||||
switch (inputType) {
|
switch (inputType) {
|
||||||
case "TextInput":
|
case "TextInput":
|
||||||
return (
|
return (
|
||||||
<Textarea
|
<Textarea
|
||||||
className="custom-scroll"
|
className="h-full w-full custom-scroll"
|
||||||
placeholder={"Enter text..."}
|
placeholder={"Enter text..."}
|
||||||
value={field.value}
|
value={node.data.node!.template["value"].value}
|
||||||
onChange={updateValue}
|
onChange={(e) => {
|
||||||
|
e.target.value;
|
||||||
|
if (node) {
|
||||||
|
let newNode = cloneDeep(node);
|
||||||
|
newNode.data.node!.template["value"].value = e.target.value;
|
||||||
|
setNode(node.id, newNode);
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case "fileLoader":
|
case "fileLoader":
|
||||||
return <IOFileInput field={field} updateValue={updateValue} />;
|
// return <IOFileInput />;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return (
|
return (
|
||||||
<Textarea
|
<Textarea
|
||||||
className="custom-scroll"
|
className="h-full w-full custom-scroll"
|
||||||
placeholder={"Enter text..."}
|
placeholder={"Enter text..."}
|
||||||
value={field.value}
|
value={node.data.node!.template["value"]}
|
||||||
onChange={updateValue}
|
onChange={(e) => {
|
||||||
|
e.target.value;
|
||||||
|
if (node) {
|
||||||
|
let newNode = cloneDeep(node);
|
||||||
|
newNode.data.node!.template["value"].value = e.target.value;
|
||||||
|
setNode(node.id, newNode);
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return <div className="h-full">{handleInputType()}</div>;
|
return <div className="h-full w-full">{handleInputType()}</div>;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import { cloneDeep } from "lodash";
|
|
||||||
import { ReactNode, useState } from "react";
|
import { ReactNode, useState } from "react";
|
||||||
import useFlowStore from "../../stores/flowStore";
|
import useFlowStore from "../../stores/flowStore";
|
||||||
import { NodeType } from "../../types/flow";
|
import { NodeType } from "../../types/flow";
|
||||||
|
|
@ -20,32 +19,47 @@ export default function IOView(): JSX.Element {
|
||||||
const [selectedCategory, setSelectedCategory] = useState<string>(
|
const [selectedCategory, setSelectedCategory] = useState<string>(
|
||||||
categories[0]
|
categories[0]
|
||||||
);
|
);
|
||||||
|
const [showChat, setShowChat] = useState<boolean>(false);
|
||||||
//TODO: show output options for view
|
//TODO: show output options for view
|
||||||
const [selectedView, setSelectedView] = useState<string>("Chat");
|
const [selectedView, setSelectedView] = useState<{
|
||||||
|
type: string;
|
||||||
|
id?: string;
|
||||||
|
}>(handleInitialView());
|
||||||
|
|
||||||
|
function handleInitialView() {
|
||||||
|
if (outputs.map((output) => output.type).includes("ChatOutput")) {
|
||||||
|
return { type: "ChatOutput" };
|
||||||
|
}
|
||||||
|
return { type: "" };
|
||||||
|
}
|
||||||
|
|
||||||
function getCategories() {
|
function getCategories() {
|
||||||
const categories: string[] = [];
|
const categories: string[] = [];
|
||||||
if (inputs.length > 0) categories.push("Inputs");
|
if (inputs.length > 0) categories.push("Inputs");
|
||||||
if (outputs.filter((output) => output.type !== "ChatOutput").length > 0)
|
if (outputs.filter((output) => output.type !== "ChatOutput").length > 0)
|
||||||
categories.push("Outputs");
|
categories.push("Outputs");
|
||||||
if (outputs.map((output) => output.type).includes("ChatOutput"))
|
|
||||||
categories.push("Chat");
|
|
||||||
return categories;
|
return categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSelectChange(type?: string): ReactNode {
|
function handleSelectChange(): ReactNode {
|
||||||
if (selectedCategory === "Chat") return <NewChatView />;
|
const { type, id } = selectedView;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "Chat":
|
case "ChatOutput":
|
||||||
return <NewChatView />;
|
return <NewChatView />;
|
||||||
break;
|
break;
|
||||||
// case "TextInput":
|
case "TextInput":
|
||||||
// break;
|
console.log("rodoussss");
|
||||||
|
return <IOInputField inputId={id!} inputType={type} />;
|
||||||
default:
|
default:
|
||||||
//create empty view output screen
|
//create empty view output screen
|
||||||
return <div>no view selected</div>;
|
return <div>no view selected</div>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function UpdateAccordion() {
|
||||||
|
return selectedCategory === "Inputs" ? inputs : outputs;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="form-modal-iv-box">
|
<div className="form-modal-iv-box">
|
||||||
<div className="mr-6 flex h-full w-2/6 flex-col justify-start overflow-auto scrollbar-hide">
|
<div className="mr-6 flex h-full w-2/6 flex-col justify-start overflow-auto scrollbar-hide">
|
||||||
|
|
@ -53,7 +67,6 @@ export default function IOView(): JSX.Element {
|
||||||
{categories.map((category, index) => {
|
{categories.map((category, index) => {
|
||||||
return (
|
return (
|
||||||
//hide chat button if chat is alredy on the view
|
//hide chat button if chat is alredy on the view
|
||||||
!(selectedView === category && category === "Chat") && (
|
|
||||||
<button
|
<button
|
||||||
onClick={() => setSelectedCategory(category)}
|
onClick={() => setSelectedCategory(category)}
|
||||||
className={classNames(
|
className={classNames(
|
||||||
|
|
@ -72,9 +85,25 @@ export default function IOView(): JSX.Element {
|
||||||
{category}
|
{category}
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
)
|
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
{selectedView.type !== "ChatOutput" && (
|
||||||
|
<button
|
||||||
|
onClick={() => setSelectedView({ type: "ChatOutput" })}
|
||||||
|
className={
|
||||||
|
"cursor flex items-center rounded-md rounded-b-none px-1 hover:bg-muted-foreground"
|
||||||
|
}
|
||||||
|
key={"chat"}
|
||||||
|
>
|
||||||
|
<IconComponent
|
||||||
|
name="Variable"
|
||||||
|
className=" file-component-variable"
|
||||||
|
/>
|
||||||
|
<span className="file-component-variables-span text-md">
|
||||||
|
Chat
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
{inputs
|
{inputs
|
||||||
.filter((input) => input.type !== "ChatInput")
|
.filter((input) => input.type !== "ChatInput")
|
||||||
|
|
@ -89,11 +118,17 @@ export default function IOView(): JSX.Element {
|
||||||
{input.id}
|
{input.id}
|
||||||
</Badge>
|
</Badge>
|
||||||
<div
|
<div
|
||||||
className="-mb-1"
|
className="-mb-1 pr-4"
|
||||||
onClick={(event) => {
|
onClick={(event) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
setSelectedView({ type: input.type, id: input.id });
|
||||||
}}
|
}}
|
||||||
></div>
|
>
|
||||||
|
<IconComponent
|
||||||
|
className="h-4 w-4"
|
||||||
|
name="ScreenShare"
|
||||||
|
></IconComponent>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
key={index}
|
key={index}
|
||||||
|
|
@ -101,19 +136,7 @@ export default function IOView(): JSX.Element {
|
||||||
>
|
>
|
||||||
<div className="file-component-tab-column">
|
<div className="file-component-tab-column">
|
||||||
{node && (
|
{node && (
|
||||||
<IOInputField
|
<IOInputField inputType={input.type} inputId={input.id} />
|
||||||
field={node.data.node!.template["value"]}
|
|
||||||
inputType={input.type}
|
|
||||||
updateValue={(e) => {
|
|
||||||
e.target.value;
|
|
||||||
if (node) {
|
|
||||||
let newNode = cloneDeep(node);
|
|
||||||
newNode.data.node!.template["value"].value =
|
|
||||||
e.target.value;
|
|
||||||
setNode(node.id, newNode);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</AccordionComponent>
|
</AccordionComponent>
|
||||||
|
|
@ -121,7 +144,7 @@ export default function IOView(): JSX.Element {
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
{handleSelectChange(selectedView)}
|
{handleSelectChange()}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -649,8 +649,7 @@ export type dropdownButtonPropsType = {
|
||||||
|
|
||||||
export type IOInputProps = {
|
export type IOInputProps = {
|
||||||
inputType: string;
|
inputType: string;
|
||||||
field: TemplateVariableType;
|
inputId: string;
|
||||||
updateValue: (e: any) => void;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type IOFileInputProps = {
|
export type IOFileInputProps = {
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,7 @@ import {
|
||||||
Save,
|
Save,
|
||||||
SaveAll,
|
SaveAll,
|
||||||
Scissors,
|
Scissors,
|
||||||
|
ScreenShare,
|
||||||
Search,
|
Search,
|
||||||
Settings2,
|
Settings2,
|
||||||
Share,
|
Share,
|
||||||
|
|
@ -388,4 +389,5 @@ export const nodeIconsLucide: iconsType = {
|
||||||
TerminalIcon,
|
TerminalIcon,
|
||||||
Repeat,
|
Repeat,
|
||||||
io: ArrowDownUp,
|
io: ArrowDownUp,
|
||||||
|
ScreenShare,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue