From 60032d614626a8d416411f54ab6f9c0c78ca3182 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 29 Jun 2023 19:36:22 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(AccordionComponent):=20fix?= =?UTF-8?q?=20formatting=20and=20add=20missing=20semicolons=20to=20improve?= =?UTF-8?q?=20code=20readability=20and=20maintainability=20=F0=9F=90=9B=20?= =?UTF-8?q?fix(codeAreaComponent):=20fix=20formatting=20and=20add=20missin?= =?UTF-8?q?g=20semicolons=20to=20improve=20code=20readability=20and=20main?= =?UTF-8?q?tainability=20=F0=9F=90=9B=20fix(dropdownComponent):=20fix=20fo?= =?UTF-8?q?rmatting=20and=20add=20missing=20semicolons=20to=20improve=20co?= =?UTF-8?q?de=20readability=20and=20maintainability=20=F0=9F=90=9B=20fix(f?= =?UTF-8?q?loatComponent):=20fix=20formatting=20and=20add=20missing=20semi?= =?UTF-8?q?colons=20to=20improve=20code=20readability=20and=20maintainabil?= =?UTF-8?q?ity=20=F0=9F=90=9B=20fix(inputFileComponent):=20fix=20formattin?= =?UTF-8?q?g=20and=20add=20missing=20semicolons=20to=20improve=20code=20re?= =?UTF-8?q?adability=20and=20maintainability=20=F0=9F=90=9B=20fix(inputLis?= =?UTF-8?q?tComponent):=20fix=20formatting=20and=20add=20missing=20semicol?= =?UTF-8?q?ons=20to=20improve=20code=20readability=20and=20maintainability?= =?UTF-8?q?=20=F0=9F=90=9B=20fix(intComponent):=20fix=20formatting=20and?= =?UTF-8?q?=20add=20missing=20semicolons=20to=20improve=20code=20readabili?= =?UTF-8?q?ty=20and=20maintainability=20=F0=9F=90=9B=20fix(promptComponent?= =?UTF-8?q?):=20fix=20formatting=20and=20add=20missing=20semicolons=20to?= =?UTF-8?q?=20improve=20code=20readability=20and=20maintainability=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(textAreaComponent):=20fix=20formatting=20and?= =?UTF-8?q?=20add=20missing=20semicolons=20to=20improve=20code=20readabili?= =?UTF-8?q?ty=20and=20maintainability=20=F0=9F=90=9B=20fix(ui/accordion.ts?= =?UTF-8?q?x):=20fix=20formatting=20and=20add=20missing=20semicolons=20to?= =?UTF-8?q?=20improve=20code=20readability=20and=20maintainability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The changes were made to fix formatting issues and add missing semicolons in the code. This improves code readability and maintainability, making it easier for developers to understand and work with the code. 🐛 fix(constants.tsx): fix formatting and indentation issues in the buildTweakObject function 🐛 fix(popUpContext.tsx): remove unnecessary empty line 🐛 fix(tabsContext.tsx): remove unnecessary empty line 🐛 fix(ApiModal/index.tsx): fix formatting and indentation issues 🐛 fix(codeAreaModal/index.tsx): fix formatting and indentation issues 🐛 fix(types/components/index.ts): remove unnecessary empty line The changes in constants.tsx fix formatting and indentation issues in the buildTweakObject function to improve code readability. The changes in popUpContext.tsx, tabsContext.tsx, ApiModal/index.tsx, codeAreaModal/index.tsx, and types/components/index.ts fix formatting and indentation issues to ensure consistent code style. --- .../components/AccordionComponent/index.tsx | 14 +++++----- .../components/codeAreaComponent/index.tsx | 7 +++-- .../components/dropdownComponent/index.tsx | 12 ++++----- .../src/components/floatComponent/index.tsx | 3 ++- .../components/inputFileComponent/index.tsx | 3 ++- .../components/inputListComponent/index.tsx | 7 ++--- .../src/components/intComponent/index.tsx | 3 ++- .../src/components/promptComponent/index.tsx | 3 ++- .../components/textAreaComponent/index.tsx | 3 ++- src/frontend/src/components/ui/accordion.tsx | 27 +++++++++---------- src/frontend/src/constants.tsx | 27 +++++++++++-------- src/frontend/src/contexts/popUpContext.tsx | 6 ++--- src/frontend/src/contexts/tabsContext.tsx | 2 +- src/frontend/src/modals/ApiModal/index.tsx | 19 +++++++------ .../src/modals/codeAreaModal/index.tsx | 2 +- src/frontend/src/types/components/index.ts | 3 +-- 16 files changed, 76 insertions(+), 65 deletions(-) diff --git a/src/frontend/src/components/AccordionComponent/index.tsx b/src/frontend/src/components/AccordionComponent/index.tsx index 825a2c19d..f03a2ad5f 100644 --- a/src/frontend/src/components/AccordionComponent/index.tsx +++ b/src/frontend/src/components/AccordionComponent/index.tsx @@ -17,15 +17,17 @@ export default function AccordionComponent({ children, open = [], }: AccordionComponentType) { - const [value, setValue] = useState(open.length == 0 ? "" : getOpenAccordion()); + const [value, setValue] = useState( + open.length == 0 ? "" : getOpenAccordion() + ); - function getOpenAccordion(){ + function getOpenAccordion() { let value = ""; - open.forEach(el => { - if(el == trigger){ + open.forEach((el) => { + if (el == trigger) { value = trigger; - } - }) + } + }); return value; } diff --git a/src/frontend/src/components/codeAreaComponent/index.tsx b/src/frontend/src/components/codeAreaComponent/index.tsx index ff786ea99..b42f1489b 100644 --- a/src/frontend/src/components/codeAreaComponent/index.tsx +++ b/src/frontend/src/components/codeAreaComponent/index.tsx @@ -12,7 +12,9 @@ export default function CodeAreaComponent({ disabled, editNode = false, }: TextAreaComponentType) { - const [myValue, setMyValue] = useState(typeof value == "string" ? value : JSON.stringify(value)); + const [myValue, setMyValue] = useState( + typeof value == "string" ? value : JSON.stringify(value) + ); const { openPopUp } = useContext(PopUpContext); useEffect(() => { if (disabled) { @@ -47,7 +49,8 @@ export default function CodeAreaComponent({ className={ editNode ? "truncate cursor-pointer placeholder:text-center text-gray-500 block w-full pt-0.5 pb-0.5 form-input dark:bg-gray-900 dark:text-gray-300 dark:border-gray-600 rounded-md border-gray-300 border-1 shadow-sm sm:text-sm" + - INPUT_STYLE + (disabled ? " bg-gray-200 " : "") + INPUT_STYLE + + (disabled ? " bg-gray-200 " : "") : "truncate block w-full text-gray-500 px-3 py-2 rounded-md border border-gray-300 dark:border-gray-700 shadow-sm sm:text-sm" + INPUT_STYLE + (disabled ? " bg-gray-200" : "") diff --git a/src/frontend/src/components/dropdownComponent/index.tsx b/src/frontend/src/components/dropdownComponent/index.tsx index d1292525d..fab9cad93 100644 --- a/src/frontend/src/components/dropdownComponent/index.tsx +++ b/src/frontend/src/components/dropdownComponent/index.tsx @@ -13,7 +13,7 @@ export default function Dropdown({ onSelect, editNode = false, numberOfOptions = 0, - apiModal = false + apiModal = false, }: DropDownComponentType) { const { closePopUp } = useContext(PopUpContext); @@ -67,14 +67,12 @@ export default function Dropdown({ leaveTo="opacity-0" > {options.map((option, id) => ( , @@ -17,8 +16,8 @@ const AccordionItem = React.forwardRef< className={cn("border-b", className)} {...props} /> -)) -AccordionItem.displayName = "AccordionItem" +)); +AccordionItem.displayName = "AccordionItem"; const AccordionTrigger = React.forwardRef< React.ElementRef, @@ -37,8 +36,8 @@ const AccordionTrigger = React.forwardRef< -)) -AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName +)); +AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName; const AccordionContent = React.forwardRef< React.ElementRef, @@ -54,7 +53,7 @@ const AccordionContent = React.forwardRef< >
{children}
-)) -AccordionContent.displayName = AccordionPrimitive.Content.displayName +)); +AccordionContent.displayName = AccordionPrimitive.Content.displayName; -export { Accordion, AccordionItem, AccordionTrigger, AccordionContent } +export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }; diff --git a/src/frontend/src/constants.tsx b/src/frontend/src/constants.tsx index b4a275d17..49eb583b7 100644 --- a/src/frontend/src/constants.tsx +++ b/src/frontend/src/constants.tsx @@ -71,7 +71,9 @@ FLOW_ID = "${flowId}" # You can tweak the flow by adding a tweaks dictionary # e.g {"OpenAI-XXXXX": {"model_name": "gpt-4"}} TWEAKS = ${ - tweak && tweak.length > 0 ? buildTweakObject(tweak): JSON.stringify(tweaks, null, 2) + tweak && tweak.length > 0 + ? buildTweakObject(tweak) + : JSON.stringify(tweaks, null, 2) } def run_flow(message: str, flow_id: str, tweaks: dict = None) -> dict: @@ -111,7 +113,9 @@ export const getCurlCode = (flow: FlowType, tweak?): string => { }/api/v1/process/${flowId} \\ -H 'Content-Type: application/json' \\ -d '{"inputs": {"input": message}, "tweaks": ${ - tweak && tweak.length > 0 ? buildTweakObject(tweak) : JSON.stringify(tweaks, null, 2) + tweak && tweak.length > 0 + ? buildTweakObject(tweak) + : JSON.stringify(tweaks, null, 2) }}'`; }; /** @@ -124,25 +128,26 @@ export const getPythonCode = (flow: FlowType, tweak?): string => { const tweaks = buildTweaks(flow); return `from langflow import load_flow_from_json TWEAKS = ${ - tweak && tweak.length > 0 ? buildTweakObject(tweak) : JSON.stringify(tweaks, null, 2) + tweak && tweak.length > 0 + ? buildTweakObject(tweak) + : JSON.stringify(tweaks, null, 2) } flow = load_flow_from_json("${flowName}.json", tweaks=TWEAKS) # Now you can use it like any chain flow("Hey, have you heard of LangFlow?")`; }; -function buildTweakObject(tweak){ - tweak.forEach(el => { - Object.keys(el).forEach(key => { +function buildTweakObject(tweak) { + tweak.forEach((el) => { + Object.keys(el).forEach((key) => { for (let kp in el[key]) { - try{ + try { el[key][kp] = JSON.parse(el[key][kp]); - } - catch{} + } catch {} } - }) + }); }); - + const tweakString = JSON.stringify(tweak, null, 2); return tweakString; } diff --git a/src/frontend/src/contexts/popUpContext.tsx b/src/frontend/src/contexts/popUpContext.tsx index a59eb0f9f..d46f51f00 100644 --- a/src/frontend/src/contexts/popUpContext.tsx +++ b/src/frontend/src/contexts/popUpContext.tsx @@ -13,7 +13,6 @@ interface PopUpProviderProps { children: React.ReactNode; } - const PopUpProvider = ({ children }: PopUpProviderProps) => { const [popUpElements, setPopUpElements] = useState([]); @@ -27,9 +26,10 @@ const PopUpProvider = ({ children }: PopUpProviderProps) => { const [closeEdit, setCloseEdit] = useState(""); - return ( - + {children} {popUpElements[0]} diff --git a/src/frontend/src/contexts/tabsContext.tsx b/src/frontend/src/contexts/tabsContext.tsx index 5ce455273..3b20ded95 100644 --- a/src/frontend/src/contexts/tabsContext.tsx +++ b/src/frontend/src/contexts/tabsContext.tsx @@ -648,7 +648,7 @@ export function TabsProvider({ children }: { children: ReactNode }) { setTabsState, paste, getTweak, - setTweak + setTweak, }} > {children} diff --git a/src/frontend/src/modals/ApiModal/index.tsx b/src/frontend/src/modals/ApiModal/index.tsx index 545a26d01..5acd42ec0 100644 --- a/src/frontend/src/modals/ApiModal/index.tsx +++ b/src/frontend/src/modals/ApiModal/index.tsx @@ -104,11 +104,10 @@ export default function ApiModal({ flow }: { flow: FlowType }) { useEffect(() => { if (closeEdit !== "") { tweak.current = getTweak; - if(tweak.current.length > 0){ + if (tweak.current.length > 0) { setActiveTab("3"); openAccordions(); - } - else{ + } else { startTweaks(); } } else { @@ -250,14 +249,14 @@ export default function ApiModal({ flow }: { flow: FlowType }) { 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); - } - }); + tweak.current.forEach((el) => { + Object.keys(el).forEach((key) => { + if (Object.keys(el[key]).length > 0) { + accordionsToOpen.push(key); + setOpenAccordion(accordionsToOpen); + } }); + }); } return ( diff --git a/src/frontend/src/modals/codeAreaModal/index.tsx b/src/frontend/src/modals/codeAreaModal/index.tsx index ec6d3d07c..bc814a9ab 100644 --- a/src/frontend/src/modals/codeAreaModal/index.tsx +++ b/src/frontend/src/modals/codeAreaModal/index.tsx @@ -34,7 +34,7 @@ export default function CodeAreaModal({ const [code, setCode] = useState(value); const { dark } = useContext(darkContext); const { setErrorData, setSuccessData } = useContext(alertContext); - const { closePopUp,setCloseEdit } = useContext(PopUpContext); + const { closePopUp, setCloseEdit } = useContext(PopUpContext); const ref = useRef(); function setModalOpen(x: boolean) { setOpen(x); diff --git a/src/frontend/src/types/components/index.ts b/src/frontend/src/types/components/index.ts index 4437f48e3..598f2af41 100644 --- a/src/frontend/src/types/components/index.ts +++ b/src/frontend/src/types/components/index.ts @@ -44,7 +44,6 @@ export type InputListComponentType = { disabled: boolean; editNode?: boolean; onAddInput?: (value?: string[]) => void; - }; export type TextAreaComponentType = { @@ -114,7 +113,7 @@ export type RadialProgressType = { color?: string; }; -export type AccordionComponentType = { +export type AccordionComponentType = { children?: ReactElement; open?: string[]; trigger?: string;