From b5c6b06b3cc47e20395d73160b6bf1050076d886 Mon Sep 17 00:00:00 2001 From: Igor Carvalho Date: Thu, 20 Jul 2023 17:58:48 -0300 Subject: [PATCH] refactor[components]: Add types to functions that didnt have it --- .../components/AccordionComponent/index.tsx | 2 +- .../components/CrashErrorComponent/index.tsx | 2 +- .../EditFlowSettingsComponent/index.tsx | 2 +- .../src/components/RadialProgress/index.tsx | 2 +- .../ReactTooltipComponent/index.tsx | 2 +- .../components/SanitizedHTMLWrapper/index.tsx | 2 +- .../components/ShadTooltipComponent/index.tsx | 2 +- .../src/components/TooltipComponent/index.tsx | 2 +- .../src/components/cardComponent/index.tsx | 2 +- .../chatComponent/buildTrigger/index.tsx | 2 +- .../chatComponent/chatTrigger/index.tsx | 5 ++-- .../src/components/chatComponent/index.tsx | 2 +- .../components/codeAreaComponent/index.tsx | 2 +- .../components/dropdownComponent/index.tsx | 2 +- .../src/components/floatComponent/index.tsx | 2 +- .../components/menuBar/index.tsx | 3 ++- .../src/components/headerComponent/index.tsx | 2 +- .../src/components/inputComponent/index.tsx | 2 +- .../components/inputFileComponent/index.tsx | 2 +- .../components/inputListComponent/index.tsx | 2 +- .../src/components/intComponent/index.tsx | 2 +- .../src/components/loadingComponent/index.tsx | 2 +- .../src/components/promptComponent/index.tsx | 2 +- .../components/textAreaComponent/index.tsx | 2 +- .../src/components/toggleComponent/index.tsx | 2 +- .../components/toggleShadComponent/index.tsx | 2 +- src/frontend/src/types/components/index.ts | 24 +++++++++++++++++-- 27 files changed, 51 insertions(+), 29 deletions(-) diff --git a/src/frontend/src/components/AccordionComponent/index.tsx b/src/frontend/src/components/AccordionComponent/index.tsx index 7212e6a1b..3f6597d2a 100644 --- a/src/frontend/src/components/AccordionComponent/index.tsx +++ b/src/frontend/src/components/AccordionComponent/index.tsx @@ -12,7 +12,7 @@ export default function AccordionComponent({ children, open = [], keyValue, -}: AccordionComponentType) { +}: AccordionComponentType): JSX.Element { const [value, setValue] = useState( open.length === 0 ? "" : getOpenAccordion() ); diff --git a/src/frontend/src/components/CrashErrorComponent/index.tsx b/src/frontend/src/components/CrashErrorComponent/index.tsx index fd7d22c36..b435cca0b 100644 --- a/src/frontend/src/components/CrashErrorComponent/index.tsx +++ b/src/frontend/src/components/CrashErrorComponent/index.tsx @@ -1,4 +1,4 @@ -export default function CrashErrorComponent({ error, resetErrorBoundary }) { +export default function CrashErrorComponent({ error, resetErrorBoundary }): JSX.Element { return (
diff --git a/src/frontend/src/components/EditFlowSettingsComponent/index.tsx b/src/frontend/src/components/EditFlowSettingsComponent/index.tsx index 6c1b77b6c..77dfc2422 100644 --- a/src/frontend/src/components/EditFlowSettingsComponent/index.tsx +++ b/src/frontend/src/components/EditFlowSettingsComponent/index.tsx @@ -13,7 +13,7 @@ export const EditFlowSettings: React.FC = ({ setName, setDescription, updateFlow, -}) => { +}): JSX.Element => { const [isMaxLength, setIsMaxLength] = useState(false); const handleNameChange = (event: ChangeEvent) => { diff --git a/src/frontend/src/components/RadialProgress/index.tsx b/src/frontend/src/components/RadialProgress/index.tsx index f277a9c80..f5160c40b 100644 --- a/src/frontend/src/components/RadialProgress/index.tsx +++ b/src/frontend/src/components/RadialProgress/index.tsx @@ -3,7 +3,7 @@ import { RadialProgressType } from "../../types/components"; export default function RadialProgressComponent({ value, color, -}: RadialProgressType) { +}: RadialProgressType): JSX.Element { const style = { "--value": value * 100, "--size": "1.5rem", diff --git a/src/frontend/src/components/ReactTooltipComponent/index.tsx b/src/frontend/src/components/ReactTooltipComponent/index.tsx index 9b4120ee2..9103ae21c 100644 --- a/src/frontend/src/components/ReactTooltipComponent/index.tsx +++ b/src/frontend/src/components/ReactTooltipComponent/index.tsx @@ -16,7 +16,7 @@ const TooltipReact: FC = ({ className, clickable, delayShow, -}) => { +}: TooltipProps): JSX.Element => { return (
{React.cloneElement(children as React.ReactElement, { diff --git a/src/frontend/src/components/SanitizedHTMLWrapper/index.tsx b/src/frontend/src/components/SanitizedHTMLWrapper/index.tsx index e76105c00..248f210a4 100644 --- a/src/frontend/src/components/SanitizedHTMLWrapper/index.tsx +++ b/src/frontend/src/components/SanitizedHTMLWrapper/index.tsx @@ -5,7 +5,7 @@ const SanitizedHTMLWrapper = ({ content, onClick, suppressWarning = false, -}) => { +}): JSX.Element => { const sanitizedHTML = DOMPurify.sanitize(content); return ( diff --git a/src/frontend/src/components/ShadTooltipComponent/index.tsx b/src/frontend/src/components/ShadTooltipComponent/index.tsx index 89f301e60..62d5bc2e4 100644 --- a/src/frontend/src/components/ShadTooltipComponent/index.tsx +++ b/src/frontend/src/components/ShadTooltipComponent/index.tsx @@ -8,7 +8,7 @@ export default function ShadTooltip({ children, styleClasses, delayDuration = 500, -}: ShadToolTipType) { +}: ShadToolTipType): JSX.Element { return ( {children} diff --git a/src/frontend/src/components/TooltipComponent/index.tsx b/src/frontend/src/components/TooltipComponent/index.tsx index 91fa006ec..5f105873d 100644 --- a/src/frontend/src/components/TooltipComponent/index.tsx +++ b/src/frontend/src/components/TooltipComponent/index.tsx @@ -5,7 +5,7 @@ export default function Tooltip({ children, title, placement, -}: TooltipComponentType) { +}: TooltipComponentType): JSX.Element { return ( {children} diff --git a/src/frontend/src/components/cardComponent/index.tsx b/src/frontend/src/components/cardComponent/index.tsx index 12c409047..3a1388f53 100644 --- a/src/frontend/src/components/cardComponent/index.tsx +++ b/src/frontend/src/components/cardComponent/index.tsx @@ -21,7 +21,7 @@ export const CardComponent = ({ id: string; onDelete?: () => void; button?: JSX.Element; -}) => { +}): JSX.Element => { const { removeFlow } = useContext(TabsContext); return ( diff --git a/src/frontend/src/components/chatComponent/buildTrigger/index.tsx b/src/frontend/src/components/chatComponent/buildTrigger/index.tsx index 4eb69546e..b82a65db0 100644 --- a/src/frontend/src/components/chatComponent/buildTrigger/index.tsx +++ b/src/frontend/src/components/chatComponent/buildTrigger/index.tsx @@ -21,7 +21,7 @@ export default function BuildTrigger({ flow: FlowType; setIsBuilt: any; isBuilt: boolean; -}) { +}): JSX.Element { const { updateSSEData, isBuilding, setIsBuilding, sseData } = useSSE(); const { reactFlowInstance } = useContext(typesContext); const { setTabsState } = useContext(TabsContext); diff --git a/src/frontend/src/components/chatComponent/chatTrigger/index.tsx b/src/frontend/src/components/chatComponent/chatTrigger/index.tsx index a92a8e0cd..2be327904 100644 --- a/src/frontend/src/components/chatComponent/chatTrigger/index.tsx +++ b/src/frontend/src/components/chatComponent/chatTrigger/index.tsx @@ -9,11 +9,12 @@ import { } from "../../../constants/constants"; import { alertContext } from "../../../contexts/alertContext"; import IconComponent from "../../genericIconComponent"; +import { chatTriggerPropType } from "../../../types/components"; -export default function ChatTrigger({ open, setOpen, isBuilt, canOpen }) { +export default function ChatTrigger({ open, setOpen, isBuilt, canOpen }: chatTriggerPropType): JSX.Element { const { setErrorData } = useContext(alertContext); - function handleClick() { + function handleClick(): void { if (isBuilt) { if (canOpen) { setOpen(true); diff --git a/src/frontend/src/components/chatComponent/index.tsx b/src/frontend/src/components/chatComponent/index.tsx index 58c058866..044bf64c0 100644 --- a/src/frontend/src/components/chatComponent/index.tsx +++ b/src/frontend/src/components/chatComponent/index.tsx @@ -10,7 +10,7 @@ import { getBuildStatus } from "../../controllers/API"; import FormModal from "../../modals/formModal"; import { NodeType } from "../../types/flow"; -export default function Chat({ flow }: ChatType) { +export default function Chat({ flow }: ChatType): JSX.Element { const [open, setOpen] = useState(false); const [isBuilt, setIsBuilt] = useState(false); const [canOpen, setCanOpen] = useState(false); diff --git a/src/frontend/src/components/codeAreaComponent/index.tsx b/src/frontend/src/components/codeAreaComponent/index.tsx index 4f0fc3b17..1e3797ec9 100644 --- a/src/frontend/src/components/codeAreaComponent/index.tsx +++ b/src/frontend/src/components/codeAreaComponent/index.tsx @@ -12,7 +12,7 @@ export default function CodeAreaComponent({ editNode = false, nodeClass, setNodeClass, -}: TextAreaComponentType) { +}: TextAreaComponentType): JSX.Element { const [myValue, setMyValue] = useState( typeof value == "string" ? value : JSON.stringify(value) ); diff --git a/src/frontend/src/components/dropdownComponent/index.tsx b/src/frontend/src/components/dropdownComponent/index.tsx index 9b614c7ae..bb7b75c05 100644 --- a/src/frontend/src/components/dropdownComponent/index.tsx +++ b/src/frontend/src/components/dropdownComponent/index.tsx @@ -12,7 +12,7 @@ export default function Dropdown({ editNode = false, numberOfOptions = 0, apiModal = false, -}: DropDownComponentType) { +}: DropDownComponentType): JSX.Element { const { closePopUp } = useContext(PopUpContext); let [internalValue, setInternalValue] = useState( diff --git a/src/frontend/src/components/floatComponent/index.tsx b/src/frontend/src/components/floatComponent/index.tsx index 66b97db1a..fcee0d1a5 100644 --- a/src/frontend/src/components/floatComponent/index.tsx +++ b/src/frontend/src/components/floatComponent/index.tsx @@ -9,7 +9,7 @@ export default function FloatComponent({ disableCopyPaste = false, disabled, editNode = false, -}: FloatComponentType) { +}: FloatComponentType): JSX.Element { const [myValue, setMyValue] = useState(value ?? ""); const { setDisableCopyPaste } = useContext(TabsContext); const { closePopUp } = useContext(PopUpContext); diff --git a/src/frontend/src/components/headerComponent/components/menuBar/index.tsx b/src/frontend/src/components/headerComponent/components/menuBar/index.tsx index 84777c5fe..6e5560bbd 100644 --- a/src/frontend/src/components/headerComponent/components/menuBar/index.tsx +++ b/src/frontend/src/components/headerComponent/components/menuBar/index.tsx @@ -15,8 +15,9 @@ import { undoRedoContext } from "../../../../contexts/undoRedoContext"; import FlowSettingsModal from "../../../../modals/flowSettingsModal"; import IconComponent from "../../../genericIconComponent"; import { Button } from "../../../ui/button"; +import { menuBarPropsType } from "../../../../types/components"; -export const MenuBar = ({ flows, tabId }) => { +export const MenuBar = ({ flows, tabId }: menuBarPropsType): JSX.Element => { const { updateFlow, setTabId, addFlow } = useContext(TabsContext); const { setErrorData } = useContext(alertContext); const { openPopUp } = useContext(PopUpContext); diff --git a/src/frontend/src/components/headerComponent/index.tsx b/src/frontend/src/components/headerComponent/index.tsx index 67f738821..ef067cd5c 100644 --- a/src/frontend/src/components/headerComponent/index.tsx +++ b/src/frontend/src/components/headerComponent/index.tsx @@ -14,7 +14,7 @@ import { Button } from "../ui/button"; import { Separator } from "../ui/separator"; import MenuBar from "./components/menuBar"; -export default function Header() { +export default function Header(): JSX.Element { const { flows, addFlow, tabId } = useContext(TabsContext); const { openPopUp } = useContext(PopUpContext); const { templates } = useContext(typesContext); diff --git a/src/frontend/src/components/inputComponent/index.tsx b/src/frontend/src/components/inputComponent/index.tsx index 1e6ca32ef..c976f1906 100644 --- a/src/frontend/src/components/inputComponent/index.tsx +++ b/src/frontend/src/components/inputComponent/index.tsx @@ -11,7 +11,7 @@ export default function InputComponent({ disabled, password, editNode = false, -}: InputComponentType) { +}: InputComponentType): JSX.Element { const [myValue, setMyValue] = useState(value ?? ""); const [pwdVisible, setPwdVisible] = useState(false); const { setDisableCopyPaste } = useContext(TabsContext); diff --git a/src/frontend/src/components/inputFileComponent/index.tsx b/src/frontend/src/components/inputFileComponent/index.tsx index 3f77734f3..4de6e3dbe 100644 --- a/src/frontend/src/components/inputFileComponent/index.tsx +++ b/src/frontend/src/components/inputFileComponent/index.tsx @@ -13,7 +13,7 @@ export default function InputFileComponent({ fileTypes, onFileChange, editNode = false, -}: FileComponentType) { +}: FileComponentType): JSX.Element { const [myValue, setMyValue] = useState(value); const [loading, setLoading] = useState(false); const { setErrorData } = useContext(alertContext); diff --git a/src/frontend/src/components/inputListComponent/index.tsx b/src/frontend/src/components/inputListComponent/index.tsx index 086473acc..853fd95d1 100644 --- a/src/frontend/src/components/inputListComponent/index.tsx +++ b/src/frontend/src/components/inputListComponent/index.tsx @@ -11,7 +11,7 @@ export default function InputListComponent({ disabled, editNode = false, onAddInput, -}: InputListComponentType) { +}: InputListComponentType): JSX.Element { const [inputList, setInputList] = useState(value ?? [""]); const { closePopUp } = useContext(PopUpContext); diff --git a/src/frontend/src/components/intComponent/index.tsx b/src/frontend/src/components/intComponent/index.tsx index ae47d856a..c3fc98c9c 100644 --- a/src/frontend/src/components/intComponent/index.tsx +++ b/src/frontend/src/components/intComponent/index.tsx @@ -9,7 +9,7 @@ export default function IntComponent({ disableCopyPaste = false, disabled, editNode = false, -}: FloatComponentType) { +}: FloatComponentType): JSX.Element { const [myValue, setMyValue] = useState(value ?? ""); const { setDisableCopyPaste } = useContext(TabsContext); const min = 0; diff --git a/src/frontend/src/components/loadingComponent/index.tsx b/src/frontend/src/components/loadingComponent/index.tsx index a1e406710..406dad793 100644 --- a/src/frontend/src/components/loadingComponent/index.tsx +++ b/src/frontend/src/components/loadingComponent/index.tsx @@ -1,6 +1,6 @@ import { LoadingComponentProps } from "../../types/components"; -export default function LoadingComponent({ remSize }: LoadingComponentProps) { +export default function LoadingComponent({ remSize }: LoadingComponentProps): JSX.Element { return (
{ diff --git a/src/frontend/src/components/toggleShadComponent/index.tsx b/src/frontend/src/components/toggleShadComponent/index.tsx index c06d42430..2af4696f4 100644 --- a/src/frontend/src/components/toggleShadComponent/index.tsx +++ b/src/frontend/src/components/toggleShadComponent/index.tsx @@ -6,7 +6,7 @@ export default function ToggleShadComponent({ setEnabled, disabled, size, -}: ToggleComponentType) { +}: ToggleComponentType): JSX.Element { let scaleX, scaleY; switch (size) { case "small": diff --git a/src/frontend/src/types/components/index.ts b/src/frontend/src/types/components/index.ts index 4e02e1403..81cfbcb15 100644 --- a/src/frontend/src/types/components/index.ts +++ b/src/frontend/src/types/components/index.ts @@ -1,6 +1,6 @@ import { ReactElement, ReactNode } from "react"; import { APIClassType } from "../api"; -import { NodeDataType } from "../flow/index"; +import { FlowStyleType, NodeDataType } from "../flow/index"; import { typesContextType } from "../typesContext"; export type InputComponentType = { @@ -430,5 +430,25 @@ export type nodeToolbarType = { value: void; }; deleteNode: (idx: string) => void; - openPopUp: (element: any) => void; + openPopUp: (element) => JSX.Element; }; + +export type chatTriggerPropType = { + open: boolean; + isBuilt: boolean; + canOpen: boolean; + setOpen: (can: boolean) => void; +} + +export type headerFlowsType = { + data: object; + description: string; + id: string; + name: string; + style?: FlowStyleType; +} + +export type menuBarPropsType = { + flows: Array; + tabId: string; +}