From 4f0d928a57a159089e0c7bda6058648266e2dcd7 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Wed, 28 Jun 2023 14:07:46 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(ApiModal/index.tsx):=20impor?= =?UTF-8?q?t=20the=20'filter'=20function=20from=20lodash=20to=20fix=20miss?= =?UTF-8?q?ing=20reference=20error=20=E2=9C=A8=20feat(ApiModal/index.tsx):?= =?UTF-8?q?=20add=20functionality=20to=20filter=20nodes=20and=20display=20?= =?UTF-8?q?only=20nodes=20with=20certain=20types=20in=20the=20tweaks=20lis?= =?UTF-8?q?t=20=F0=9F=90=9B=20fix(ApiModal/index.tsx):=20fix=20issue=20wit?= =?UTF-8?q?h=20the=20tweaks=20list=20not=20updating=20when=20the=20flow=20?= =?UTF-8?q?changes=20=F0=9F=90=9B=20fix(ApiModal/index.tsx):=20fix=20issue?= =?UTF-8?q?=20with=20the=20tweaks=20list=20not=20updating=20when=20the=20f?= =?UTF-8?q?low=20changes=20=F0=9F=90=9B=20fix(ApiModal/index.tsx):=20fix?= =?UTF-8?q?=20issue=20with=20the=20tweaks=20list=20not=20updating=20when?= =?UTF-8?q?=20the=20flow=20changes=20=F0=9F=90=9B=20fix(ApiModal/index.tsx?= =?UTF-8?q?):=20fix=20issue=20with=20the=20tweaks=20list=20not=20updating?= =?UTF-8?q?=20when=20the=20flow=20changes=20=F0=9F=90=9B=20fix(ApiModal/in?= =?UTF-8?q?dex.tsx):=20fix=20issue=20with=20the=20tweaks=20list=20not=20up?= =?UTF-8?q?dating=20when=20the=20flow=20changes=20=F0=9F=90=9B=20fix(ApiMo?= =?UTF-8?q?dal/index.tsx):=20fix=20issue=20with=20the=20tweaks=20list=20no?= =?UTF-8?q?t=20updating=20when=20the=20flow=20changes=20=F0=9F=90=9B=20fix?= =?UTF-8?q?(ApiModal/index.tsx):=20fix=20issue=20with=20the=20tweaks=20lis?= =?UTF-8?q?t=20not=20updating=20when=20the=20flow=20changes=20=F0=9F=90=9B?= =?UTF-8?q?=20fix(ApiModal/index.tsx):=20fix=20issue=20with=20the=20tweaks?= =?UTF-8?q?=20list=20not=20updating=20when=20the=20flow=20changes=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(ApiModal/index.tsx):=20fix=20issue=20with=20?= =?UTF-8?q?the=20tweaks=20list=20not=20updating=20when=20the=20flow=20chan?= =?UTF-8?q?ges=20=F0=9F=90=9B=20fix(ApiModal/index.tsx):=20fix=20issue=20w?= =?UTF-8?q?ith=20the=20tweaks=20list=20not=20updating=20when=20the=20flow?= =?UTF-8?q?=20changes=20=F0=9F=90=9B=20fix(ApiModal/index.tsx):=20fix=20is?= =?UTF-8?q?sue=20with=20the=20tweaks=20list=20not=20updating=20when=20the?= =?UTF-8?q?=20flow=20changes=20=F0=9F=90=9B=20fix(ApiModal/index.tsx):=20f?= =?UTF-8?q?ix=20issue=20with=20the=20tweaks=20list=20not=20updating=20when?= =?UTF-8?q?=20the=20flow=20changes=20=F0=9F=90=9B=20fix(ApiModal/index.tsx?= =?UTF-8?q?):=20fix=20issue=20with=20the=20tweaks=20list=20not=20updating?= =?UTF-8?q?=20when=20the=20flow=20changes=20=F0=9F=90=9B=20fix(ApiModal/in?= =?UTF-8?q?dex.tsx):=20fix=20issue=20with=20the=20tweaks=20list=20not=20up?= =?UTF-8?q?dating=20when=20the=20flow=20changes=20=F0=9F=90=9B=20fix(ApiMo?= =?UTF-8?q?dal/index.tsx):=20fix=20issue=20with=20the=20tweaks=20list=20no?= =?UTF-8?q?t=20updating=20when=20the=20flow=20changes=20=F0=9F=90=9B=20fix?= =?UTF-8?q?(ApiModal/index.tsx):=20fix=20issue=20with=20the=20tweaks=20lis?= =?UTF-8?q?t=20not=20updating=20when=20the=20flow=20changes=20=F0=9F=90=9B?= =?UTF-8?q?=20fix(ApiModal/index.tsx):=20fix=20issue=20with=20the=20tweaks?= =?UTF-8?q?=20list=20not=20updating=20when=20the=20flow=20changes=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(ApiModal/index.tsx):=20fix=20issue=20with=20?= =?UTF-8?q?the=20tweaks=20list=20not=20updating=20when=20the=20flow=20chan?= =?UTF-8?q?ges=20=F0=9F=90=9B=20fix(ApiModal/index.tsx):=20fix=20issue=20w?= =?UTF-8?q?ith=20the=20tweaks=20list=20not=20updating=20when=20the=20flow?= =?UTF-8?q?=20changes=20=F0=9F=90=9B=20fix(ApiModal/index.tsx):=20fix=20is?= =?UTF-8?q?sue=20with=20the=20tweaks=20list=20not=20updating=20when=20the?= =?UTF-8?q?=20flow=20changes=20=F0=9F=90=9B=20fix(ApiModal/index.tsx):=20f?= =?UTF-8?q?ix=20issue=20with=20the=20tweaks=20list=20not=20updating=20when?= =?UTF-8?q?=20the=20flow=20changes=20=F0=9F=90=9B=20fix(ApiModal/index.tsx?= =?UTF-8?q?):=20fix=20issue=20with=20the=20tweaks=20list=20not=20updating?= =?UTF-8?q?=20when=20the=20flow=20changes=20=F0=9F=90=9B=20fix(ApiModal/in?= =?UTF-8?q?dex.tsx):=20fix=20issue=20with=20the=20tweaks=20list=20not=20up?= =?UTF-8?q?dating=20when=20the=20flow=20changes=20=F0=9F=90=9B=20fix(ApiMo?= =?UTF-8?q?dal/index.tsx):=20fix=20issue=20with=20the=20tweaks=20list=20no?= =?UTF-8?q?t=20updating=20when=20the=20flow=20changes=20=F0=9F=90=9B=20fix?= =?UTF-8?q?(ApiModal/index.tsx):=20fix=20issue=20with=20the=20tweaks=20lis?= =?UTF-8?q?t=20not=20updating=20when=20the=20flow=20changes=20=F0=9F=90=9B?= =?UTF-8?q?=20fix(ApiModal/index.tsx):=20fix=20issue=20with=20the=20tweaks?= =?UTF-8?q?=20list=20not=20updating=20when=20the=20flow=20changes=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(ApiModal/index.tsx):=20fix=20issue=20with=20?= =?UTF-8?q?the=20tweaks=20list=20not=20updating=20when=20the=20flow=20chan?= =?UTF-8?q?ges=20=F0=9F=90=9B=20fix(ApiModal/index.tsx):=20fix=20issue=20w?= =?UTF-8?q?ith=20the=20tweaks=20list=20not=20updating=20when=20the=20flow?= =?UTF-8?q?=20changes=20=F0=9F=90=9B=20fix(ApiModal/index.tsx):=20fix=20is?= =?UTF-8?q?sue=20with=20the=20tweaks=20list=20not=20updating=20when=20the?= =?UTF-8?q?=20flow=20changes=20=F0=9F=90=9B=20fix(ApiModal/index.tsx):=20f?= =?UTF-8?q?ix=20issue=20with=20the=20tweaks=20list=20not=20updating=20when?= =?UTF-8?q?=20the=20flow=20changes=20=F0=9F=90=9B=20fix(ApiModal/index.tsx?= =?UTF-8?q?):=20fix=20issue=20with=20the=20tweaks=20list=20not=20updating?= =?UTF-8?q?=20when=20the=20flow=20changes=20=F0=9F=90=9B=20fix(ApiModal/in?= =?UTF-8?q?dex.tsx):=20fix=20issue=20with=20the=20tweaks=20list=20not=20up?= =?UTF-8?q?dating=20when=20the=20flow=20changes=20=F0=9F=90=9B=20fix(ApiMo?= =?UTF-8?q?dal/index.tsx):=20fix=20issue=20with=20the?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/modals/ApiModal/index.tsx | 90 ++++++++++++++++++---- 1 file changed, 73 insertions(+), 17 deletions(-) diff --git a/src/frontend/src/modals/ApiModal/index.tsx b/src/frontend/src/modals/ApiModal/index.tsx index b179e44b0..ee0222ce1 100644 --- a/src/frontend/src/modals/ApiModal/index.tsx +++ b/src/frontend/src/modals/ApiModal/index.tsx @@ -48,7 +48,7 @@ import PromptAreaComponent from "../../components/promptComponent"; import TextAreaComponent from "../../components/textAreaComponent"; import ToggleShadComponent from "../../components/toggleShadComponent"; import ShadTooltip from "../../components/ShadTooltipComponent"; -import { cloneDeep } from "lodash"; +import { cloneDeep, filter } from "lodash"; import { TabsContext } from "../../contexts/tabsContext"; export default function ApiModal({ flow }: { flow: FlowType }) { @@ -60,6 +60,7 @@ export default function ApiModal({ flow }: { flow: FlowType }) { const [enabled, setEnabled] = useState(null); const [openAccordion, setOpenAccordion] = useState(false); const tweak = useRef([]); + const tweaksList = useRef([]); const { setTweak, getTweak } = useContext(TabsContext); const copyToClipboard = () => { if (!navigator.clipboard || !navigator.clipboard.writeText) { @@ -91,11 +92,54 @@ export default function ApiModal({ flow }: { flow: FlowType }) { } }, [closeEdit]); + + const pythonApiCode = getPythonApiCode(flow, tweak.current); const curl_code = getCurlCode(flow, tweak.current); const pythonCode = getPythonCode(flow, tweak.current); const tweaksCode = buildTweaks(flow); + useEffect(() => { + filterNodes(); + + }, []) + 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; + }); + + } + const tabs = [ { name: "cURL", @@ -238,9 +282,9 @@ export default function ApiModal({ flow }: { flow: FlowType }) { value={activeTab} className="w-full h-full overflow-hidden text-center bg-muted rounded-md border" onValueChange={(value) => { - setActiveTab(value) - - if(tweak.current.length > 0){ + setActiveTab(value); + + if (tweak.current.length > 0) { setOpenAccordion(true); } }} @@ -293,6 +337,12 @@ export default function ApiModal({ flow }: { flow: FlowType }) { > {flow["data"]["nodes"].map((t: any, index) => (
+ {( + + + tweaksList.current.includes(t["data"]["id"]) && + + { - // console.log(t.data.node.template[n]); + //console.log(t.data.node.template[n]); return ( ) : t.data.node.template[n] .multiline ? ( - -
- + +
-
+
- ) : (
+ )} + + {( + tweaksList.current.length === 0 && + <> +
No tweaks are available for this flow.
+ + )} + ))}