From e40628a069b0dedb6ece560d19677aa6dd30b261 Mon Sep 17 00:00:00 2001 From: Igor Carvalho Date: Mon, 24 Jul 2023 16:15:29 -0300 Subject: [PATCH] refactor: Remove any types --- .../src/CustomNodes/GenericNode/index.tsx | 2 +- .../components/AccordionComponent/index.tsx | 4 +-- .../EditFlowSettingsComponent/index.tsx | 2 +- .../components/SanitizedHTMLWrapper/index.tsx | 3 ++- .../chatComponent/buildTrigger/index.tsx | 8 +++--- .../components/inputFileComponent/index.tsx | 4 +-- .../src/pages/CommunityPage/index.tsx | 2 +- .../components/PageComponent/index.tsx | 2 +- .../extraSidebarComponent/index.tsx | 10 +++---- .../components/nodeToolbarComponent/index.tsx | 3 ++- src/frontend/src/types/api/index.ts | 2 +- src/frontend/src/types/components/index.ts | 26 ++++++++++++++++--- src/frontend/src/types/flow/index.ts | 2 +- src/frontend/tsconfig.json | 2 +- 14 files changed, 48 insertions(+), 24 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/index.tsx b/src/frontend/src/CustomNodes/GenericNode/index.tsx index e3925fda9..bb4541e61 100644 --- a/src/frontend/src/CustomNodes/GenericNode/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/index.tsx @@ -111,7 +111,7 @@ export default function GenericNode({ {validationStatus.params ? validationStatus.params .split("\n") - .map((line, index) =>
{line}
) + .map((line: string, index: number) =>
{line}
) : ""} ) diff --git a/src/frontend/src/components/AccordionComponent/index.tsx b/src/frontend/src/components/AccordionComponent/index.tsx index 3f6597d2a..e7cd92081 100644 --- a/src/frontend/src/components/AccordionComponent/index.tsx +++ b/src/frontend/src/components/AccordionComponent/index.tsx @@ -17,7 +17,7 @@ export default function AccordionComponent({ open.length === 0 ? "" : getOpenAccordion() ); - function getOpenAccordion() { + function getOpenAccordion(): string { let value = ""; open.forEach((el) => { if (el == trigger) { @@ -28,7 +28,7 @@ export default function AccordionComponent({ return value; } - function handleClick() { + function handleClick(): void { value === "" ? setValue(keyValue) : setValue(""); } diff --git a/src/frontend/src/components/EditFlowSettingsComponent/index.tsx b/src/frontend/src/components/EditFlowSettingsComponent/index.tsx index 77dfc2422..5d4392d25 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 => { +}: InputProps): JSX.Element => { const [isMaxLength, setIsMaxLength] = useState(false); const handleNameChange = (event: ChangeEvent) => { diff --git a/src/frontend/src/components/SanitizedHTMLWrapper/index.tsx b/src/frontend/src/components/SanitizedHTMLWrapper/index.tsx index 248f210a4..db26ad918 100644 --- a/src/frontend/src/components/SanitizedHTMLWrapper/index.tsx +++ b/src/frontend/src/components/SanitizedHTMLWrapper/index.tsx @@ -1,11 +1,12 @@ import DOMPurify from "dompurify"; +import { SanitizedHTMLWrapperType } from "../../types/components"; const SanitizedHTMLWrapper = ({ className, content, onClick, suppressWarning = false, -}): JSX.Element => { +}: SanitizedHTMLWrapperType): JSX.Element => { const sanitizedHTML = DOMPurify.sanitize(content); return ( diff --git a/src/frontend/src/components/chatComponent/buildTrigger/index.tsx b/src/frontend/src/components/chatComponent/buildTrigger/index.tsx index b82a65db0..3e59c88f0 100644 --- a/src/frontend/src/components/chatComponent/buildTrigger/index.tsx +++ b/src/frontend/src/components/chatComponent/buildTrigger/index.tsx @@ -11,6 +11,7 @@ import { TabsContext } from "../../../contexts/tabsContext"; import { validateNodes } from "../../../utils/reactflowUtils"; import RadialProgressComponent from "../../RadialProgress"; import IconComponent from "../../genericIconComponent"; +import { parsedDataType } from "../../../types/components"; export default function BuildTrigger({ open, @@ -30,7 +31,7 @@ export default function BuildTrigger({ const eventClick = isBuilding ? "pointer-events-none" : ""; const [progress, setProgress] = useState(0); - async function handleBuild(flow: FlowType) { + async function handleBuild(flow: FlowType): Promise { try { if (isBuilding) { return; @@ -69,7 +70,7 @@ export default function BuildTrigger({ const response = await postBuildInit(flow); const { flowId } = response.data; // Step 2: Use the session ID to establish an SSE connection using EventSource - let validationResults = []; + let validationResults: boolean[] = []; let finished = false; const apiUrl = `/api/v1/build/stream/${flowId}`; const eventSource = new EventSource(apiUrl); @@ -124,10 +125,11 @@ export default function BuildTrigger({ return validationResults.every((result) => result); } - function processStreamResult(parsedData) { + function processStreamResult(parsedData: parsedDataType) { // Process each chunk of data here // Parse the chunk and update the context try { + console.log(parsedData) updateSSEData({ [parsedData.id]: parsedData }); } catch (err) { console.log("Error parsing stream data: ", err); diff --git a/src/frontend/src/components/inputFileComponent/index.tsx b/src/frontend/src/components/inputFileComponent/index.tsx index 4de6e3dbe..3d2e71c2b 100644 --- a/src/frontend/src/components/inputFileComponent/index.tsx +++ b/src/frontend/src/components/inputFileComponent/index.tsx @@ -41,7 +41,7 @@ export default function InputFileComponent({ setMyValue(value); }, [value]); - const handleButtonClick = () => { + const handleButtonClick = (): void => { // Create a file input element const input = document.createElement("input"); input.type = "file"; @@ -49,7 +49,7 @@ export default function InputFileComponent({ input.style.display = "none"; // Hidden from view input.multiple = false; // Allow only one file selection - input.onchange = (e: Event) => { + input.onchange = (e: Event): void => { setLoading(true); // Get the selected file diff --git a/src/frontend/src/pages/CommunityPage/index.tsx b/src/frontend/src/pages/CommunityPage/index.tsx index 2c9ae8a29..128df5032 100644 --- a/src/frontend/src/pages/CommunityPage/index.tsx +++ b/src/frontend/src/pages/CommunityPage/index.tsx @@ -21,7 +21,7 @@ export default function CommunityPage(): JSX.Element { const [examples, setExamples] = useState([]); // Show community examples on screen - function handleExamples() { + function handleExamples(): void { setLoadingExamples(true); getExamples() .then((result) => { diff --git a/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx index 5505ef101..a70ce81ce 100644 --- a/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx @@ -93,7 +93,7 @@ export default function Page({ flow }: { flow: FlowType }): JSX.Element { event.preventDefault(); } }; - const handleMouseMove = (event) => { + const handleMouseMove = (event: MouseEvent) => { setPosition({ x: event.clientX, y: event.clientY }); }; diff --git a/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx index 877e2dae9..3ed61c462 100644 --- a/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx @@ -30,7 +30,7 @@ export default function ExtraSidebar(): JSX.Element { function onDragStart( event: React.DragEvent, data: { type: string; node?: APIClassType } - ) { + ): void { //start drag event var crt = event.currentTarget.cloneNode(true); crt.style.position = "absolute"; @@ -65,7 +65,7 @@ export default function ExtraSidebar(): JSX.Element {