diff --git a/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx index 2e9d2f23d..0eb3876f1 100644 --- a/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx @@ -1,86 +1,93 @@ import { Bars2Icon } from "@heroicons/react/24/outline"; import DisclosureComponent from "../DisclosureComponent"; -import { - nodeColors, - nodeIcons, - nodeNames, -} from "../../../../utils"; +import { nodeColors, nodeIcons, nodeNames } from "../../../../utils"; import { useContext, useEffect, useState } from "react"; import { getAll } from "../../../../controllers/API"; import { typesContext } from "../../../../contexts/typesContext"; -import { APIClassType, APIKindType, APIObjectType } from "../../../../types/api"; +import { + APIClassType, + APIKindType, + APIObjectType, +} from "../../../../types/api"; export default function ExtraSidebar() { - const [data, setData] = useState({}); - const { setTypes} = useContext(typesContext); + const [data, setData] = useState({}); + const { setTypes } = useContext(typesContext); - useEffect(() => { - async function getTypes():Promise{ - - // Make an asynchronous API call to retrieve all data. - let result = await getAll(); - - // Update the state of the component with the retrieved data. - setData(result.data); - - // Set the types by reducing over the keys of the result data and updating the accumulator. - setTypes( - Object.keys(result.data).reduce( - (acc, curr) => { - Object.keys(result.data[curr]).forEach((c:keyof APIKindType) => { - acc[c] = curr; - // Add the base classes to the accumulator as well. - result.data[curr][c].base_classes?.forEach((b) => { - acc[b] = curr; - }); - }); - return acc; - },{} - ) - ); - } - // Call the getTypes function. - getTypes(); - }, [setTypes]); + useEffect(() => { + async function getTypes(): Promise { + // Make an asynchronous API call to retrieve all data. + let result = await getAll(); + // Update the state of the component with the retrieved data. + setData(result.data); - function onDragStart(event: React.DragEvent, data:{type:string,node?:APIClassType}) { - //start drag event - event.dataTransfer.effectAllowed = "move"; - event.dataTransfer.setData("json", JSON.stringify(data)); - } + // Set the types by reducing over the keys of the result data and updating the accumulator. + setTypes( + Object.keys(result.data).reduce((acc, curr) => { + Object.keys(result.data[curr]).forEach((c: keyof APIKindType) => { + acc[c] = curr; + // Add the base classes to the accumulator as well. + result.data[curr][c].base_classes?.forEach((b) => { + acc[b] = curr; + }); + }); + return acc; + }, {}) + ); + } + // Call the getTypes function. + getTypes(); + }, [setTypes]); - return ( -
- {Object.keys(data).map((d:keyof APIObjectType, i) => ( - -
- {Object.keys(data[d]).map((t: string, k) => ( -
-
- onDragStart(event, { - type: t, - node: data[d][t], - }) - } - > -
- {t} - -
-
-
- ))} -
-
- ))} -
- ); + function onDragStart( + event: React.DragEvent, + data: { type: string; node?: APIClassType } + ) { + //start drag event + event.dataTransfer.effectAllowed = "move"; + event.dataTransfer.setData("json", JSON.stringify(data)); + } + + return ( +
+ {Object.keys(data).map((d: keyof APIObjectType, i) => ( + +
+ {Object.keys(data[d]).map((t: string, k) => ( +
+
+ onDragStart(event, { + type: t, + node: data[d][t], + }) + } + > +
+ + {t} + + +
+
+
+ ))} + {Object.keys(data[d]).length===0 &&
Coming soon
} +
+
+ ))} +
+ ); }