Types made as a context
This commit is contained in:
parent
549ccdf658
commit
a7bd874e16
4 changed files with 139 additions and 93 deletions
|
|
@ -7,9 +7,12 @@ import {
|
||||||
snakeToNormalCase,
|
snakeToNormalCase,
|
||||||
} from "../../utils";
|
} from "../../utils";
|
||||||
import ParameterComponent from "./components/parameterComponent";
|
import ParameterComponent from "./components/parameterComponent";
|
||||||
|
import { typesContext } from "../../contexts/typesContext";
|
||||||
|
import { useContext } from "react";
|
||||||
|
|
||||||
export default function GenericNode({ data }) {
|
export default function GenericNode({ data }) {
|
||||||
const Icon = nodeIcons[data.type];
|
const Icon = nodeIcons[data.type];
|
||||||
|
const {types} = useContext(typesContext);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="prompt-node relative bg-white w-96 rounded-lg solid border flex flex-col justify-center">
|
<div className="prompt-node relative bg-white w-96 rounded-lg solid border flex flex-col justify-center">
|
||||||
|
|
@ -46,7 +49,7 @@ export default function GenericNode({ data }) {
|
||||||
|
|
||||||
data={data}
|
data={data}
|
||||||
color={
|
color={
|
||||||
nodeColors[data.types[data.node.template[t].type]] ??
|
nodeColors[types[data.node.template[t].type]] ??
|
||||||
"black"
|
"black"
|
||||||
}
|
}
|
||||||
title={
|
title={
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,16 @@
|
||||||
import { AlertProvider } from "./alertContext";
|
import { AlertProvider } from "./alertContext";
|
||||||
import { LocationProvider } from "./locationContext";
|
import { LocationProvider } from "./locationContext";
|
||||||
import PopUpProvider from "./popUpContext";
|
import PopUpProvider from "./popUpContext";
|
||||||
|
import { TypesProvider } from "./typesContext";
|
||||||
|
|
||||||
export default function ContextWrapper({ children }) {
|
export default function ContextWrapper({ children }) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<LocationProvider>
|
<LocationProvider>
|
||||||
<PopUpProvider>
|
<PopUpProvider>
|
||||||
<AlertProvider>{children}</AlertProvider>
|
<TypesProvider>
|
||||||
|
<AlertProvider>{children}</AlertProvider>
|
||||||
|
</TypesProvider>
|
||||||
</PopUpProvider>
|
</PopUpProvider>
|
||||||
</LocationProvider>
|
</LocationProvider>
|
||||||
</>
|
</>
|
||||||
|
|
|
||||||
23
space_flow/src/contexts/typesContext.tsx
Normal file
23
space_flow/src/contexts/typesContext.tsx
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { createContext, useState } from "react";
|
||||||
|
|
||||||
|
type typesContextType=
|
||||||
|
{
|
||||||
|
types: {};
|
||||||
|
setTypes:(newState:{})=>void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const initialValue= {
|
||||||
|
types: {},
|
||||||
|
setTypes:()=>{},
|
||||||
|
}
|
||||||
|
|
||||||
|
export const typesContext = createContext<typesContextType>(initialValue);
|
||||||
|
|
||||||
|
export function TypesProvider({children}){
|
||||||
|
const [types, setTypes] = useState({});
|
||||||
|
return (
|
||||||
|
<typesContext.Provider value={{ types, setTypes}}>
|
||||||
|
{children}
|
||||||
|
</typesContext.Provider>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -1,20 +1,18 @@
|
||||||
import { Bars2Icon, ComputerDesktopIcon } from "@heroicons/react/24/outline";
|
import { Bars2Icon, ComputerDesktopIcon } from "@heroicons/react/24/outline";
|
||||||
import DisclosureComponent from "../DisclosureComponent";
|
import DisclosureComponent from "../DisclosureComponent";
|
||||||
import { nodeColors, nodeIcons, nodeNames, toFirstUpperCase } from "../../../../utils";
|
import {
|
||||||
import { useEffect, useState } from "react";
|
nodeColors,
|
||||||
|
nodeIcons,
|
||||||
|
nodeNames,
|
||||||
|
toFirstUpperCase,
|
||||||
|
} from "../../../../utils";
|
||||||
|
import { useContext, useEffect, useState } from "react";
|
||||||
import { getAll } from "../../../../controllers/NodesServices";
|
import { getAll } from "../../../../controllers/NodesServices";
|
||||||
|
import { typesContext } from "../../../../contexts/typesContext";
|
||||||
|
|
||||||
export default function ExtraSidebar() {
|
export default function ExtraSidebar() {
|
||||||
const [data, setData] = useState({});
|
const [data, setData] = useState({});
|
||||||
|
const { setTypes } = useContext(typesContext);
|
||||||
const types = Object.keys(data).reduce((acc, curr) => {
|
|
||||||
Object.keys(data[curr]).forEach((c) => {
|
|
||||||
acc[c] = curr;
|
|
||||||
data[curr][c].base_classes?.forEach((b) => {acc[b] = curr;})
|
|
||||||
});
|
|
||||||
// console.log(acc);
|
|
||||||
return acc;
|
|
||||||
}, {str: 'advanced', bool: 'advanced', chatOutput: 'chat', chatInput: 'chat'});
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getAll().then((d) => {
|
getAll().then((d) => {
|
||||||
|
|
@ -23,6 +21,31 @@ export default function ExtraSidebar() {
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if(data){
|
||||||
|
setTypes(
|
||||||
|
Object.keys(data).reduce(
|
||||||
|
(acc, curr) => {
|
||||||
|
Object.keys(data[curr]).forEach((c) => {
|
||||||
|
acc[c] = curr;
|
||||||
|
data[curr][c].base_classes?.forEach((b) => {
|
||||||
|
acc[b] = curr;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// console.log(acc);
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
str: "advanced",
|
||||||
|
bool: "advanced",
|
||||||
|
chatOutput: "chat",
|
||||||
|
chatInput: "chat",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, [data, setTypes])
|
||||||
|
|
||||||
function onDragStart(event: React.DragEvent<any>, data) {
|
function onDragStart(event: React.DragEvent<any>, data) {
|
||||||
event.dataTransfer.effectAllowed = "move";
|
event.dataTransfer.effectAllowed = "move";
|
||||||
event.dataTransfer.setData("json", JSON.stringify(data));
|
event.dataTransfer.setData("json", JSON.stringify(data));
|
||||||
|
|
@ -46,7 +69,6 @@ export default function ExtraSidebar() {
|
||||||
onDragStart(event, {
|
onDragStart(event, {
|
||||||
type: d,
|
type: d,
|
||||||
name: t,
|
name: t,
|
||||||
types: types,
|
|
||||||
node: data[d][t],
|
node: data[d][t],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -62,94 +84,89 @@ export default function ExtraSidebar() {
|
||||||
</DisclosureComponent>
|
</DisclosureComponent>
|
||||||
))}
|
))}
|
||||||
<DisclosureComponent
|
<DisclosureComponent
|
||||||
button={{ title: nodeNames['chat'], Icon: nodeIcons['chat'] }}
|
button={{ title: nodeNames["chat"], Icon: nodeIcons["chat"] }}
|
||||||
>
|
>
|
||||||
<div className="p-2 flex flex-col gap-2">
|
<div className="p-2 flex flex-col gap-2">
|
||||||
<div>
|
<div>
|
||||||
<div
|
<div
|
||||||
draggable
|
draggable
|
||||||
className={" cursor-grab border-l-8 rounded-l-md"}
|
className={" cursor-grab border-l-8 rounded-l-md"}
|
||||||
style={{ borderLeftColor: nodeColors['chat'] }}
|
style={{ borderLeftColor: nodeColors["chat"] }}
|
||||||
onDragStart={(event) =>
|
onDragStart={(event) =>
|
||||||
onDragStart(event, {
|
onDragStart(event, {
|
||||||
type: 'chat',
|
type: "chat",
|
||||||
name: 'chatInput',
|
name: "chatInput",
|
||||||
types,
|
})
|
||||||
})
|
}
|
||||||
}
|
>
|
||||||
>
|
<div className="flex w-full justify-between text-sm px-4 py-3 items-center border-dashed border-gray-400 border-l-0 rounded-md rounded-l-none border-2">
|
||||||
<div className="flex w-full justify-between text-sm px-4 py-3 items-center border-dashed border-gray-400 border-l-0 rounded-md rounded-l-none border-2">
|
<span className="text-black w-36 truncate">Chat Input</span>
|
||||||
<span className="text-black w-36 truncate">Chat Input</span>
|
<Bars2Icon className="w-6 h-6 text-gray-400" />
|
||||||
<Bars2Icon className="w-6 h-6 text-gray-400" />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
</div>
|
||||||
<div
|
<div>
|
||||||
draggable
|
<div
|
||||||
className={" cursor-grab border-l-8 rounded-l-md"}
|
draggable
|
||||||
style={{ borderLeftColor: nodeColors['chat'] }}
|
className={" cursor-grab border-l-8 rounded-l-md"}
|
||||||
onDragStart={(event) =>
|
style={{ borderLeftColor: nodeColors["chat"] }}
|
||||||
onDragStart(event, {
|
onDragStart={(event) =>
|
||||||
type: 'chat',
|
onDragStart(event, {
|
||||||
name: 'chatOutput',
|
type: "chat",
|
||||||
types,
|
name: "chatOutput",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<div className="flex w-full justify-between text-sm px-4 py-3 items-center border-dashed border-gray-400 border-l-0 rounded-md rounded-l-none border-2">
|
<div className="flex w-full justify-between text-sm px-4 py-3 items-center border-dashed border-gray-400 border-l-0 rounded-md rounded-l-none border-2">
|
||||||
<span className="text-black w-36 truncate">Chat Output</span>
|
<span className="text-black w-36 truncate">Chat Output</span>
|
||||||
<Bars2Icon className="w-6 h-6 text-gray-400" />
|
<Bars2Icon className="w-6 h-6 text-gray-400" />
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</DisclosureComponent>
|
</div>
|
||||||
|
</DisclosureComponent>
|
||||||
<DisclosureComponent
|
<DisclosureComponent
|
||||||
button={{ title: nodeNames['advanced'], Icon: nodeIcons['advanced'] }}
|
button={{ title: nodeNames["advanced"], Icon: nodeIcons["advanced"] }}
|
||||||
>
|
>
|
||||||
<div className="p-2 flex flex-col gap-2">
|
<div className="p-2 flex flex-col gap-2">
|
||||||
<div>
|
<div>
|
||||||
<div
|
<div
|
||||||
draggable
|
draggable
|
||||||
className={" cursor-grab border-l-8 rounded-l-md"}
|
className={" cursor-grab border-l-8 rounded-l-md"}
|
||||||
style={{ borderLeftColor: nodeColors['advanced'] }}
|
style={{ borderLeftColor: nodeColors["advanced"] }}
|
||||||
onDragStart={(event) =>
|
onDragStart={(event) =>
|
||||||
onDragStart(event, {
|
onDragStart(event, {
|
||||||
type: 'advanced',
|
type: "advanced",
|
||||||
name: 'str',
|
name: "str",
|
||||||
types,
|
})
|
||||||
})
|
}
|
||||||
}
|
>
|
||||||
>
|
<div className="flex w-full justify-between text-sm px-4 py-3 items-center border-dashed border-gray-400 border-l-0 rounded-md rounded-l-none border-2">
|
||||||
<div className="flex w-full justify-between text-sm px-4 py-3 items-center border-dashed border-gray-400 border-l-0 rounded-md rounded-l-none border-2">
|
<span className="text-black w-36 truncate">String</span>
|
||||||
<span className="text-black w-36 truncate">String</span>
|
<Bars2Icon className="w-6 h-6 text-gray-400" />
|
||||||
<Bars2Icon className="w-6 h-6 text-gray-400" />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
</div>
|
||||||
<div
|
<div>
|
||||||
draggable
|
<div
|
||||||
className={" cursor-grab border-l-8 rounded-l-md"}
|
draggable
|
||||||
style={{ borderLeftColor: nodeColors['advanced'] }}
|
className={" cursor-grab border-l-8 rounded-l-md"}
|
||||||
onDragStart={(event) =>
|
style={{ borderLeftColor: nodeColors["advanced"] }}
|
||||||
onDragStart(event, {
|
onDragStart={(event) =>
|
||||||
type: 'advanced',
|
onDragStart(event, {
|
||||||
name: 'bool',
|
type: "advanced",
|
||||||
types,
|
name: "bool",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<div className="flex w-full justify-between text-sm px-4 py-3 items-center border-dashed border-gray-400 border-l-0 rounded-md rounded-l-none border-2">
|
<div className="flex w-full justify-between text-sm px-4 py-3 items-center border-dashed border-gray-400 border-l-0 rounded-md rounded-l-none border-2">
|
||||||
<span className="text-black w-36 truncate">Boolean</span>
|
<span className="text-black w-36 truncate">Boolean</span>
|
||||||
<Bars2Icon className="w-6 h-6 text-gray-400" />
|
<Bars2Icon className="w-6 h-6 text-gray-400" />
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</DisclosureComponent>
|
</div>
|
||||||
|
</DisclosureComponent>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue