refactor: Remove any types

This commit is contained in:
Igor Carvalho 2023-07-24 16:15:29 -03:00
commit e40628a069
14 changed files with 48 additions and 24 deletions

View file

@ -111,7 +111,7 @@ export default function GenericNode({
{validationStatus.params {validationStatus.params
? validationStatus.params ? validationStatus.params
.split("\n") .split("\n")
.map((line, index) => <div key={index}>{line}</div>) .map((line: string, index: number) => <div key={index}>{line}</div>)
: ""} : ""}
</div> </div>
) )

View file

@ -17,7 +17,7 @@ export default function AccordionComponent({
open.length === 0 ? "" : getOpenAccordion() open.length === 0 ? "" : getOpenAccordion()
); );
function getOpenAccordion() { function getOpenAccordion(): string {
let value = ""; let value = "";
open.forEach((el) => { open.forEach((el) => {
if (el == trigger) { if (el == trigger) {
@ -28,7 +28,7 @@ export default function AccordionComponent({
return value; return value;
} }
function handleClick() { function handleClick(): void {
value === "" ? setValue(keyValue) : setValue(""); value === "" ? setValue(keyValue) : setValue("");
} }

View file

@ -13,7 +13,7 @@ export const EditFlowSettings: React.FC<InputProps> = ({
setName, setName,
setDescription, setDescription,
updateFlow, updateFlow,
}): JSX.Element => { }: InputProps): JSX.Element => {
const [isMaxLength, setIsMaxLength] = useState(false); const [isMaxLength, setIsMaxLength] = useState(false);
const handleNameChange = (event: ChangeEvent<HTMLInputElement>) => { const handleNameChange = (event: ChangeEvent<HTMLInputElement>) => {

View file

@ -1,11 +1,12 @@
import DOMPurify from "dompurify"; import DOMPurify from "dompurify";
import { SanitizedHTMLWrapperType } from "../../types/components";
const SanitizedHTMLWrapper = ({ const SanitizedHTMLWrapper = ({
className, className,
content, content,
onClick, onClick,
suppressWarning = false, suppressWarning = false,
}): JSX.Element => { }: SanitizedHTMLWrapperType): JSX.Element => {
const sanitizedHTML = DOMPurify.sanitize(content); const sanitizedHTML = DOMPurify.sanitize(content);
return ( return (

View file

@ -11,6 +11,7 @@ import { TabsContext } from "../../../contexts/tabsContext";
import { validateNodes } from "../../../utils/reactflowUtils"; import { validateNodes } from "../../../utils/reactflowUtils";
import RadialProgressComponent from "../../RadialProgress"; import RadialProgressComponent from "../../RadialProgress";
import IconComponent from "../../genericIconComponent"; import IconComponent from "../../genericIconComponent";
import { parsedDataType } from "../../../types/components";
export default function BuildTrigger({ export default function BuildTrigger({
open, open,
@ -30,7 +31,7 @@ export default function BuildTrigger({
const eventClick = isBuilding ? "pointer-events-none" : ""; const eventClick = isBuilding ? "pointer-events-none" : "";
const [progress, setProgress] = useState(0); const [progress, setProgress] = useState(0);
async function handleBuild(flow: FlowType) { async function handleBuild(flow: FlowType): Promise<void> {
try { try {
if (isBuilding) { if (isBuilding) {
return; return;
@ -69,7 +70,7 @@ export default function BuildTrigger({
const response = await postBuildInit(flow); const response = await postBuildInit(flow);
const { flowId } = response.data; const { flowId } = response.data;
// Step 2: Use the session ID to establish an SSE connection using EventSource // Step 2: Use the session ID to establish an SSE connection using EventSource
let validationResults = []; let validationResults: boolean[] = [];
let finished = false; let finished = false;
const apiUrl = `/api/v1/build/stream/${flowId}`; const apiUrl = `/api/v1/build/stream/${flowId}`;
const eventSource = new EventSource(apiUrl); const eventSource = new EventSource(apiUrl);
@ -124,10 +125,11 @@ export default function BuildTrigger({
return validationResults.every((result) => result); return validationResults.every((result) => result);
} }
function processStreamResult(parsedData) { function processStreamResult(parsedData: parsedDataType) {
// Process each chunk of data here // Process each chunk of data here
// Parse the chunk and update the context // Parse the chunk and update the context
try { try {
console.log(parsedData)
updateSSEData({ [parsedData.id]: parsedData }); updateSSEData({ [parsedData.id]: parsedData });
} catch (err) { } catch (err) {
console.log("Error parsing stream data: ", err); console.log("Error parsing stream data: ", err);

View file

@ -41,7 +41,7 @@ export default function InputFileComponent({
setMyValue(value); setMyValue(value);
}, [value]); }, [value]);
const handleButtonClick = () => { const handleButtonClick = (): void => {
// Create a file input element // Create a file input element
const input = document.createElement("input"); const input = document.createElement("input");
input.type = "file"; input.type = "file";
@ -49,7 +49,7 @@ export default function InputFileComponent({
input.style.display = "none"; // Hidden from view input.style.display = "none"; // Hidden from view
input.multiple = false; // Allow only one file selection input.multiple = false; // Allow only one file selection
input.onchange = (e: Event) => { input.onchange = (e: Event): void => {
setLoading(true); setLoading(true);
// Get the selected file // Get the selected file

View file

@ -21,7 +21,7 @@ export default function CommunityPage(): JSX.Element {
const [examples, setExamples] = useState<FlowType[]>([]); const [examples, setExamples] = useState<FlowType[]>([]);
// Show community examples on screen // Show community examples on screen
function handleExamples() { function handleExamples(): void {
setLoadingExamples(true); setLoadingExamples(true);
getExamples() getExamples()
.then((result) => { .then((result) => {

View file

@ -93,7 +93,7 @@ export default function Page({ flow }: { flow: FlowType }): JSX.Element {
event.preventDefault(); event.preventDefault();
} }
}; };
const handleMouseMove = (event) => { const handleMouseMove = (event: MouseEvent) => {
setPosition({ x: event.clientX, y: event.clientY }); setPosition({ x: event.clientX, y: event.clientY });
}; };

View file

@ -30,7 +30,7 @@ export default function ExtraSidebar(): JSX.Element {
function onDragStart( function onDragStart(
event: React.DragEvent<any>, event: React.DragEvent<any>,
data: { type: string; node?: APIClassType } data: { type: string; node?: APIClassType }
) { ): void {
//start drag event //start drag event
var crt = event.currentTarget.cloneNode(true); var crt = event.currentTarget.cloneNode(true);
crt.style.position = "absolute"; crt.style.position = "absolute";
@ -65,7 +65,7 @@ export default function ExtraSidebar(): JSX.Element {
<ShadTooltip content="Import" side="top"> <ShadTooltip content="Import" side="top">
<button <button
className="extra-side-bar-buttons" className="extra-side-bar-buttons"
onClick={() => { onClick={(): void => {
uploadFlow(); uploadFlow();
}} }}
> >
@ -76,7 +76,7 @@ export default function ExtraSidebar(): JSX.Element {
<ShadTooltip content="Export" side="top"> <ShadTooltip content="Export" side="top">
<button <button
className={classNames("extra-side-bar-buttons")} className={classNames("extra-side-bar-buttons")}
onClick={(event) => { onClick={(event): void => {
openPopUp(<ExportModal />); openPopUp(<ExportModal />);
}} }}
> >
@ -86,7 +86,7 @@ export default function ExtraSidebar(): JSX.Element {
<ShadTooltip content="Code" side="top"> <ShadTooltip content="Code" side="top">
<button <button
className={classNames("extra-side-bar-buttons")} className={classNames("extra-side-bar-buttons")}
onClick={(event) => { onClick={(event): void => {
openPopUp(<ApiModal flow={flows.find((f) => f.id === tabId)} />); openPopUp(<ApiModal flow={flows.find((f) => f.id === tabId)} />);
}} }}
> >
@ -97,7 +97,7 @@ export default function ExtraSidebar(): JSX.Element {
<ShadTooltip content="Save" side="top"> <ShadTooltip content="Save" side="top">
<button <button
className="extra-side-bar-buttons" className="extra-side-bar-buttons"
onClick={(event) => { onClick={(event): void => {
saveFlow(flows.find((f) => f.id === tabId)); saveFlow(flows.find((f) => f.id === tabId));
setSuccessData({ title: "Changes saved successfully" }); setSuccessData({ title: "Changes saved successfully" });
}} }}

View file

@ -5,8 +5,9 @@ import IconComponent from "../../../../components/genericIconComponent";
import { TabsContext } from "../../../../contexts/tabsContext"; import { TabsContext } from "../../../../contexts/tabsContext";
import EditNodeModal from "../../../../modals/EditNodeModal"; import EditNodeModal from "../../../../modals/EditNodeModal";
import { classNames } from "../../../../utils/utils"; import { classNames } from "../../../../utils/utils";
import { nodeToolbarPropsType } from "../../../../types/components";
const NodeToolbarComponent = (props): JSX.Element => { const NodeToolbarComponent = (props: nodeToolbarPropsType): JSX.Element => {
const [nodeLength, setNodeLength] = useState( const [nodeLength, setNodeLength] = useState(
Object.keys(props.data.node.template).filter( Object.keys(props.data.node.template).filter(
(t) => (t) =>

View file

@ -35,7 +35,7 @@ export type sendAllProps = {
name: string; name: string;
description: string; description: string;
viewport: Viewport; viewport: Viewport;
inputs: any; inputs: { text: string; };
chatHistory: { message: string | object; isSend: boolean }[]; chatHistory: { message: string | object; isSend: boolean }[];
}; };

View file

@ -1,4 +1,4 @@
import { ReactElement, ReactNode } from "react"; import { ReactElement, ReactNode, RefObject } from "react";
import { APIClassType } from "../api"; import { APIClassType } from "../api";
import { FlowStyleType, NodeDataType } from "../flow/index"; import { FlowStyleType, NodeDataType } from "../flow/index";
import { typesContextType } from "../typesContext"; import { typesContextType } from "../typesContext";
@ -84,7 +84,7 @@ export type DisclosureComponentType = {
openDisc: boolean; openDisc: boolean;
button: { button: {
title: string; title: string;
Icon: any; Icon: React.Component;
buttons?: { buttons?: {
Icon: ReactElement; Icon: ReactElement;
title: string; title: string;
@ -431,7 +431,7 @@ export type nodeToolbarType = {
value: void; value: void;
}; };
deleteNode: (idx: string) => void; deleteNode: (idx: string) => void;
openPopUp: (element) => JSX.Element; openPopUp: (element: JSX.Element) => JSX.Element;
}; };
export type chatTriggerPropType = { export type chatTriggerPropType = {
@ -488,3 +488,23 @@ export type fileCardPropsType = {
content: string; content: string;
fileType: string; fileType: string;
}; };
export type nodeToolbarPropsType = {
data: NodeDataType;
deleteNode: (idx: string) => void;
openPopUp: (element: JSX.Element) => void;
}
export type parsedDataType = {
id: string;
params: string;
progress: number;
valid: boolean;
};
export type SanitizedHTMLWrapperType = {
className: string;
content: string;
onClick: () => void;
suppressWarning: boolean;
};

View file

@ -18,7 +18,7 @@ export type NodeDataType = {
type: string; type: string;
node?: APIClassType; node?: APIClassType;
id: string; id: string;
value: any; value: null;
}; };
// FlowStyleType is the type of the style object that is used to style the // FlowStyleType is the type of the style object that is used to style the
// Flow card with an emoji and a color. // Flow card with an emoji and a color.

View file

@ -15,7 +15,7 @@
"isolatedModules": true, "isolatedModules": true,
"noEmit": true, "noEmit": true,
"jsx": "react-jsx", "jsx": "react-jsx",
"noImplicitAny": true "noImplicitAny": false
}, },
"include": ["src"] "include": ["src"]
} }