diff --git a/src/frontend/src/modals/ApiModal/index.tsx b/src/frontend/src/modals/ApiModal/index.tsx index 5c4d534e8..52b0b03f6 100644 --- a/src/frontend/src/modals/ApiModal/index.tsx +++ b/src/frontend/src/modals/ApiModal/index.tsx @@ -2,7 +2,14 @@ import "ace-builds/src-noconflict/ext-language_tools"; import "ace-builds/src-noconflict/mode-python"; import "ace-builds/src-noconflict/theme-github"; import "ace-builds/src-noconflict/theme-twilight"; -import { ReactNode, useContext, useEffect, useRef, useState } from "react"; +import { + ReactNode, + forwardRef, + useContext, + useEffect, + useRef, + useState, +} from "react"; // import "ace-builds/webpack-resolver"; import { Check, Clipboard, Code2 } from "lucide-react"; import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; @@ -19,7 +26,6 @@ import IntComponent from "../../components/intComponent"; import PromptAreaComponent from "../../components/promptComponent"; import TextAreaComponent from "../../components/textAreaComponent"; import ToggleShadComponent from "../../components/toggleShadComponent"; -import { DialogTitle } from "../../components/ui/dialog"; import { Table, TableBody, @@ -45,651 +51,673 @@ import { FlowType } from "../../types/flow/index"; import { buildTweaks, classNames } from "../../utils"; import BaseModal from "../baseModal"; -export default function ApiModal({ - flow, - children, -}: { - flow: FlowType; - children: ReactNode; -}) { - const [activeTab, setActiveTab] = useState("0"); - const [isCopied, setIsCopied] = useState(false); - const [openAccordion, setOpenAccordion] = useState([]); - const tweak = useRef([]); - const tweaksList = useRef([]); - const { setTweak, getTweak, tabsState } = useContext(TabsContext); - const copyToClipboard = () => { - if (!navigator.clipboard || !navigator.clipboard.writeText) { - return; - } - - navigator.clipboard.writeText(tabs[activeTab].code).then(() => { - setIsCopied(true); - - setTimeout(() => { - setIsCopied(false); - }, 2000); - }); - }; - const pythonApiCode = getPythonApiCode(flow, tweak.current, tabsState); - const curl_code = getCurlCode(flow, tweak.current, tabsState); - const pythonCode = getPythonCode(flow, tweak.current, tabsState); - const tweaksCode = buildTweaks(flow); - const tabs = [ +const ApiModal = forwardRef( + ( { - name: "cURL", - mode: "bash", - image: "https://curl.se/logo/curl-symbol-transparent.png", - code: curl_code, + flow, + children, + }: { + flow: FlowType; + children: ReactNode; }, - { - name: "Python API", - mode: "python", - image: - "https://images.squarespace-cdn.com/content/v1/5df3d8c5d2be5962e4f87890/1628015119369-OY4TV3XJJ53ECO0W2OLQ/Python+API+Training+Logo.png?format=1000w", - code: pythonApiCode, - }, - { - name: "Python Code", - mode: "python", - image: "https://cdn-icons-png.flaticon.com/512/5968/5968350.png", - code: pythonCode, - }, - ]; - - useEffect(() => { - filterNodes(); - }, []); - - if (Object.keys(tweaksCode).length > 0) { - tabs.push({ - name: "Tweaks", - mode: "python", - image: "https://cdn-icons-png.flaticon.com/512/5968/5968350.png", - code: pythonCode, - }); - } - - function filterNodes() { - let arrNodesWithValues = []; - - flow["data"]["nodes"].forEach((t) => { - Object.keys(t["data"]["node"]["template"]) - .filter( - (n) => - n.charAt(0) !== "_" && - t.data.node.template[n].show && - (t.data.node.template[n].type === "str" || - t.data.node.template[n].type === "bool" || - t.data.node.template[n].type === "float" || - t.data.node.template[n].type === "code" || - t.data.node.template[n].type === "prompt" || - t.data.node.template[n].type === "file" || - t.data.node.template[n].type === "int") - ) - .map((n, i) => { - arrNodesWithValues.push(t["id"]); - }); - }); - - tweaksList.current = arrNodesWithValues.filter((value, index, self) => { - return self.indexOf(value) === index; - }); - } - - function buildTweakObject(tw, changes, template) { - if (template.type === "float") { - changes = parseFloat(changes); - } - if (template.type === "int") { - changes = parseInt(changes); - } - if (template.list === true && Array.isArray(changes)) { - changes = changes?.filter((x) => x !== ""); - } - - const existingTweak = tweak.current.find((element) => - element.hasOwnProperty(tw) - ); - - if (existingTweak) { - existingTweak[tw][template["name"]] = changes; - - if (existingTweak[tw][template["name"]] == template.value) { - tweak.current.forEach((element) => { - if (element[tw] && Object.keys(element[tw])?.length === 0) { - tweak.current = tweak.current.filter((obj) => { - const prop = obj[Object.keys(obj)[0]].prop; - return prop !== undefined && prop !== null && prop !== ""; - }); - } - }); + ref + ) => { + const [activeTab, setActiveTab] = useState("0"); + const [isCopied, setIsCopied] = useState(false); + const [openAccordion, setOpenAccordion] = useState([]); + const tweak = useRef([]); + const tweaksList = useRef([]); + const { setTweak, getTweak, tabsState } = useContext(TabsContext); + const copyToClipboard = () => { + if (!navigator.clipboard || !navigator.clipboard.writeText) { + return; } - } else { - const newTweak = { - [tw]: { - [template["name"]]: changes, - }, - }; - tweak.current.push(newTweak); - } - const pythonApiCode = getPythonApiCode(flow, tweak.current); - const curl_code = getCurlCode(flow, tweak.current); - const pythonCode = getPythonCode(flow, tweak.current); + navigator.clipboard.writeText(tabs[activeTab].code).then(() => { + setIsCopied(true); - tabs[0].code = curl_code; - tabs[1].code = pythonApiCode; - tabs[2].code = pythonCode; - - setTweak(tweak.current); - } - - function buildContent(value) { - const htmlContent = ( -
- {value != null && value != "" ? value : "None"} -
- ); - return htmlContent; - } - - function getValue(value, node, template) { - let returnValue = value ?? ""; - - if (getTweak.length > 0) { - for (const obj of getTweak) { - Object.keys(obj).forEach((key) => { - const value = obj[key]; - if (key == node["id"]) { - Object.keys(value).forEach((key) => { - if (key == template["name"]) { - returnValue = value[key]; - } - }); - } - }); - } - } else { - return value ?? ""; - } - return returnValue; - } - - function openAccordions() { - let accordionsToOpen = []; - tweak.current.forEach((el) => { - Object.keys(el).forEach((key) => { - if (Object.keys(el[key]).length > 0) { - accordionsToOpen.push(key); - setOpenAccordion(accordionsToOpen); - } + setTimeout(() => { + setIsCopied(false); + }, 2000); }); - }); - } + }; + const pythonApiCode = getPythonApiCode(flow, tweak.current, tabsState); + const curl_code = getCurlCode(flow, tweak.current, tabsState); + const pythonCode = getPythonCode(flow, tweak.current, tabsState); + const tweaksCode = buildTweaks(flow); + const tabs = [ + { + name: "cURL", + mode: "bash", + image: "https://curl.se/logo/curl-symbol-transparent.png", + code: curl_code, + }, + { + name: "Python API", + mode: "python", + image: + "https://images.squarespace-cdn.com/content/v1/5df3d8c5d2be5962e4f87890/1628015119369-OY4TV3XJJ53ECO0W2OLQ/Python+API+Training+Logo.png?format=1000w", + code: pythonApiCode, + }, + { + name: "Python Code", + mode: "python", + image: "https://cdn-icons-png.flaticon.com/512/5968/5968350.png", + code: pythonCode, + }, + ]; - return ( - - {children} - - + useEffect(() => { + filterNodes(); + }, []); + + if (Object.keys(tweaksCode).length > 0) { + tabs.push({ + name: "Tweaks", + mode: "python", + image: "https://cdn-icons-png.flaticon.com/512/5968/5968350.png", + code: pythonCode, + }); + } + + function filterNodes() { + let arrNodesWithValues = []; + + flow["data"]["nodes"].forEach((t) => { + Object.keys(t["data"]["node"]["template"]) + .filter( + (n) => + n.charAt(0) !== "_" && + t.data.node.template[n].show && + (t.data.node.template[n].type === "str" || + t.data.node.template[n].type === "bool" || + t.data.node.template[n].type === "float" || + t.data.node.template[n].type === "code" || + t.data.node.template[n].type === "prompt" || + t.data.node.template[n].type === "file" || + t.data.node.template[n].type === "int") + ) + .map((n, i) => { + arrNodesWithValues.push(t["id"]); + }); + }); + + tweaksList.current = arrNodesWithValues.filter((value, index, self) => { + return self.indexOf(value) === index; + }); + } + + function buildTweakObject(tw, changes, template) { + if (template.type === "float") { + changes = parseFloat(changes); + } + if (template.type === "int") { + changes = parseInt(changes); + } + if (template.list === true && Array.isArray(changes)) { + changes = changes?.filter((x) => x !== ""); + } + + const existingTweak = tweak.current.find((element) => + element.hasOwnProperty(tw) + ); + + if (existingTweak) { + existingTweak[tw][template["name"]] = changes; + + if (existingTweak[tw][template["name"]] == template.value) { + tweak.current.forEach((element) => { + if (element[tw] && Object.keys(element[tw])?.length === 0) { + tweak.current = tweak.current.filter((obj) => { + const prop = obj[Object.keys(obj)[0]].prop; + return prop !== undefined && prop !== null && prop !== ""; + }); + } + }); + } + } else { + const newTweak = { + [tw]: { + [template["name"]]: changes, + }, + }; + tweak.current.push(newTweak); + } + + const pythonApiCode = getPythonApiCode(flow, tweak.current); + const curl_code = getCurlCode(flow, tweak.current); + const pythonCode = getPythonCode(flow, tweak.current); + + tabs[0].code = curl_code; + tabs[1].code = pythonApiCode; + tabs[2].code = pythonCode; + + setTweak(tweak.current); + } + + function buildContent(value) { + const htmlContent = ( +
+ {value != null && value != "" ? value : "None"} +
+ ); + return htmlContent; + } + + function getValue(value, node, template) { + let returnValue = value ?? ""; + + if (getTweak.length > 0) { + for (const obj of getTweak) { + Object.keys(obj).forEach((key) => { + const value = obj[key]; + if (key == node["id"]) { + Object.keys(value).forEach((key) => { + if (key == template["name"]) { + returnValue = value[key]; + } + }); + } + }); + } + } else { + return value ?? ""; + } + return returnValue; + } + + function openAccordions() { + let accordionsToOpen = []; + tweak.current.forEach((el) => { + Object.keys(el).forEach((key) => { + if (Object.keys(el[key]).length > 0) { + accordionsToOpen.push(key); + setOpenAccordion(accordionsToOpen); + } + }); + }); + } + + return ( + + {children} + Code
-
- - { - setActiveTab(value); - if (value === "3") { - openAccordions(); - } - }} - > -
- - {tabs.map((tab, index) => ( - - {tab.name} - - ))} - - {Number(activeTab) < 3 && ( -
- -
- )} -
+ + + { + setActiveTab(value); + if (value === "3") { + openAccordions(); + } + }} + > +
+ + {tabs.map((tab, index) => ( + + {tab.name} + + ))} + + {Number(activeTab) < 3 && ( +
+ +
+ )} +
- {tabs.map((tab, index) => ( - - {index < 3 ? ( - - {tab.code} - - ) : index === 3 ? ( - <> -
-
- {flow["data"]["nodes"].map((t: any, index) => ( -
- {tweaksList.current.includes(t["data"]["id"]) && ( - -
- - - - - PARAM - - - VALUE - - - - - {Object.keys(t["data"]["node"]["template"]) - .filter( - (n) => - n.charAt(0) !== "_" && - t.data.node.template[n].show && - (t.data.node.template[n].type === - "str" || - t.data.node.template[n].type === - "bool" || - t.data.node.template[n].type === - "float" || - t.data.node.template[n].type === - "code" || - t.data.node.template[n].type === - "prompt" || - t.data.node.template[n].type === - "file" || - t.data.node.template[n].type === - "int") + {tabs.map((tab, index) => ( + + {index < 3 ? ( + + {tab.code} + + ) : index === 3 ? ( + <> +
+
+ {flow["data"]["nodes"].map((t: any, index) => ( +
+ {tweaksList.current.includes(t["data"]["id"]) && ( + +
+
+ + + + PARAM + + + VALUE + + + + + {Object.keys( + t["data"]["node"]["template"] ) - .map((n, i) => { - //console.log(t.data.node.template[n]); + .filter( + (n) => + n.charAt(0) !== "_" && + t.data.node.template[n].show && + (t.data.node.template[n].type === + "str" || + t.data.node.template[n].type === + "bool" || + t.data.node.template[n].type === + "float" || + t.data.node.template[n].type === + "code" || + t.data.node.template[n].type === + "prompt" || + t.data.node.template[n].type === + "file" || + t.data.node.template[n].type === + "int") + ) + .map((n, i) => { + //console.log(t.data.node.template[n]); - return ( - - - {n} - - -
- {t.data.node.template[n] - .type === "str" && - !t.data.node.template[n] - .options ? ( -
- {t.data.node.template[n] - .list ? ( - {}} - onAddInput={(k) => { - buildTweakObject( - t["data"]["id"], - k, + return ( + + + {n} + + +
+ {t.data.node.template[n] + .type === "str" && + !t.data.node.template[n] + .options ? ( +
+ {t.data.node.template[n] + .list ? ( + - ) : t.data.node.template[n] - .multiline ? ( - {}} + onAddInput={(k) => { + buildTweakObject( + t["data"]["id"], + k, + t.data.node + .template[n] + ); + }} + /> + ) : t.data.node.template[ + n + ].multiline ? ( + +
+ { + buildTweakObject( + t["data"][ + "id" + ], + k, + t.data.node + .template[n] + ); + }} + /> +
+
+ ) : ( + { + buildTweakObject( + t["data"]["id"], + k, + t.data.node + .template[n] + ); + }} + /> + )} +
+ ) : t.data.node.template[n] + .type === "bool" ? ( +
+ {" "} + { + t.data.node.template[ + n + ].value = e; + buildTweakObject( + t["data"]["id"], + e, + t.data.node + .template[n] + ); + }} + size="small" + disabled={false} + /> +
+ ) : t.data.node.template[n] + .type === "file" ? ( + +
+ {}} + fileTypes={ + t.data.node + .template[n] + .fileTypes + } + suffixes={ + t.data.node + .template[n] + .suffixes + } + onFileChange={( + k: any + ) => {}} + > +
+
+ ) : t.data.node.template[n] + .type === "float" ? ( +
+ -
- { + buildTweakObject( + t["data"]["id"], + k, + t.data.node + .template[n] + ); + }} + /> +
+ ) : t.data.node.template[n] + .type === "str" && + t.data.node.template[n] + .options ? ( +
+ { + buildTweakObject( + t["data"]["id"], + k, + t.data.node + .template[n] + ); + }} + value={getValue( + t.data.node.template[ + n + ].value, + t.data, + t.data.node.template[ + n + ] + )} + > +
+ ) : t.data.node.template[n] + .type === "int" ? ( +
+ { + buildTweakObject( + t["data"]["id"], + k, + t.data.node + .template[n] + ); + }} + /> +
+ ) : t.data.node.template[n] + .type === "prompt" ? ( + +
+ { + buildTweakObject( + t["data"]["id"], + k, t.data.node .template[n] - .value, - t.data, + ); + }} + /> +
+
+ ) : t.data.node.template[n] + .type === "code" ? ( + +
+ { + buildTweakObject( + t["data"]["id"], + k, t.data.node .template[n] - )} - onChange={(k) => { - buildTweakObject( - t["data"]["id"], - k, - t.data.node - .template[n] - ); - }} - /> -
-
- ) : ( - { - buildTweakObject( - t["data"]["id"], - k, - t.data.node - .template[n] - ); - }} - /> - )} -
- ) : t.data.node.template[n] - .type === "bool" ? ( -
- {" "} - { - t.data.node.template[ - n - ].value = e; - buildTweakObject( - t["data"]["id"], - e, - t.data.node.template[ - n - ] - ); - }} - size="small" - disabled={false} - /> -
- ) : t.data.node.template[n] - .type === "file" ? ( - -
- {}} - fileTypes={ - t.data.node.template[ - n - ].fileTypes - } - suffixes={ - t.data.node.template[ - n - ].suffixes - } - onFileChange={( - k: any - ) => {}} - > -
-
- ) : t.data.node.template[n] - .type === "float" ? ( -
- { - buildTweakObject( - t["data"]["id"], - k, - t.data.node.template[ - n - ] - ); - }} - /> -
- ) : t.data.node.template[n] - .type === "str" && - t.data.node.template[n] - .options ? ( -
- { - buildTweakObject( - t["data"]["id"], - k, - t.data.node.template[ - n - ] - ); - }} - value={getValue( - t.data.node.template[n] - .value, - t.data, - t.data.node.template[n] - )} - > -
- ) : t.data.node.template[n] - .type === "int" ? ( -
- { - buildTweakObject( - t["data"]["id"], - k, - t.data.node.template[ - n - ] - ); - }} - /> -
- ) : t.data.node.template[n] - .type === "prompt" ? ( - -
- { - buildTweakObject( - t["data"]["id"], - k, - t.data.node - .template[n] - ); - }} - /> -
-
- ) : t.data.node.template[n] - .type === "code" ? ( - -
- { - buildTweakObject( - t["data"]["id"], - k, - t.data.node - .template[n] - ); - }} - /> -
-
- ) : t.data.node.template[n] - .type === "Any" ? ( - "-" - ) : ( -
- )} -
-
-
- ); - })} - -
-
-
- )} + ); + }} + /> +
+ + ) : t.data.node.template[n] + .type === "Any" ? ( + "-" + ) : ( +
+ )} +
+ + + ); + })} + + +
+ + )} - {tweaksList.current.length === 0 && ( - <> -
- No tweaks are available for this flow. -
- - )} - - ))} + {tweaksList.current.length === 0 && ( + <> +
+ No tweaks are available for this flow. +
+ + )} + + ))} + - - - ) : null} -
- ))} -
-
-
- ); -} + + ) : null} + + ))} + + + + ); + } +); + +export default ApiModal; diff --git a/src/frontend/src/modals/EditNodeModal/index.tsx b/src/frontend/src/modals/EditNodeModal/index.tsx index 0e5ab9efc..52e0e3a2c 100644 --- a/src/frontend/src/modals/EditNodeModal/index.tsx +++ b/src/frontend/src/modals/EditNodeModal/index.tsx @@ -12,7 +12,6 @@ import TextAreaComponent from "../../components/textAreaComponent"; import ToggleShadComponent from "../../components/toggleShadComponent"; import { Badge } from "../../components/ui/badge"; import { Button } from "../../components/ui/button"; -import { DialogTitle } from "../../components/ui/dialog"; import { Table, TableBody, @@ -93,10 +92,8 @@ export default function EditNodeModal({ {children} - - {data.type} - ID: {data.id} - + {data.type} + ID: {data.id}
diff --git a/src/frontend/src/modals/codeAreaModal/index.tsx b/src/frontend/src/modals/codeAreaModal/index.tsx index 44208ebd4..f8af1cc6f 100644 --- a/src/frontend/src/modals/codeAreaModal/index.tsx +++ b/src/frontend/src/modals/codeAreaModal/index.tsx @@ -1,4 +1,3 @@ -import { DialogTitle } from "@radix-ui/react-dialog"; import "ace-builds/src-noconflict/ace"; import "ace-builds/src-noconflict/ext-language_tools"; import "ace-builds/src-noconflict/mode-python"; @@ -77,14 +76,12 @@ export default function CodeAreaModal({ {children} - - Edit Code - + Edit Code +
diff --git a/src/frontend/src/modals/exportModal/index.tsx b/src/frontend/src/modals/exportModal/index.tsx index 2355082cf..0a709d3fa 100644 --- a/src/frontend/src/modals/exportModal/index.tsx +++ b/src/frontend/src/modals/exportModal/index.tsx @@ -3,7 +3,6 @@ import { ReactNode, forwardRef, useContext, useState } from "react"; import EditFlowSettings from "../../components/EditFlowSettingsComponent"; import { Button } from "../../components/ui/button"; import { Checkbox } from "../../components/ui/checkbox"; -import { DialogTitle } from "../../components/ui/dialog"; import { EXPORT_DIALOG_SUBTITLE } from "../../constants"; import { PopUpContext } from "../../contexts/popUpContext"; import { TabsContext } from "../../contexts/tabsContext"; @@ -23,14 +22,12 @@ const ExportModal = forwardRef((props: { children: ReactNode }, ref) => { {props.children} - - Export - + Export + - - {myModalTitle} - + {myModalTitle} +
)} diff --git a/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx index 83c204c03..a86cf1eb0 100644 --- a/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx @@ -96,7 +96,7 @@ const NodeToolbarComponent = (props) => { - +