From fb733d32076bd66cb44b01aa730717fa9780cf3e Mon Sep 17 00:00:00 2001 From: Igor Carvalho Date: Mon, 7 Aug 2023 13:30:08 -0300 Subject: [PATCH] Resolve api modal type errors --- src/frontend/src/modals/ApiModal/index.tsx | 14 +++++++------- src/frontend/src/types/components/index.ts | 12 +++++++++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/frontend/src/modals/ApiModal/index.tsx b/src/frontend/src/modals/ApiModal/index.tsx index 51611ac83..429c77b18 100644 --- a/src/frontend/src/modals/ApiModal/index.tsx +++ b/src/frontend/src/modals/ApiModal/index.tsx @@ -25,7 +25,7 @@ import { getWidgetCode, } from "../../utils/utils"; import BaseModal from "../baseModal"; -import { tweakType } from "../../types/components"; +import { tweakType, uniqueTweakType } from "../../types/components"; import { APITemplateType, TemplateVariableType } from "../../types/api"; const ApiModal = forwardRef( @@ -207,11 +207,11 @@ const ApiModal = forwardRef( return self.indexOf(value) === index; }); } - function buildTweakObject(tw: string | string[], changes: string | string[] | boolean, template: TemplateVariableType) { - if (template.type === "float") { + function buildTweakObject(tw: string, changes: string | string[] | boolean | number, template: TemplateVariableType) { + if (typeof changes === "string" && template.type === "float") { changes = parseFloat(changes); } - if (template.type === "int") { + if (typeof changes === "string" && template.type === "int") { changes = parseInt(changes); } if (template.list === true && Array.isArray(changes)) { @@ -223,7 +223,7 @@ const ApiModal = forwardRef( ); if (existingTweak) { - existingTweak[tw][template["name"]] = changes; + existingTweak[tw][template["name"]] = changes as string; if (existingTweak[tw][template["name"]] == template.value) { tweak.current.forEach((element) => { @@ -240,7 +240,7 @@ const ApiModal = forwardRef( [tw]: { [template["name"]]: changes, }, - }; + } as uniqueTweakType; tweak.current.push(newTweak); } @@ -266,7 +266,7 @@ const ApiModal = forwardRef( return htmlContent; } - function getValue(value: string, node: NodeType, template: APITemplateType) { + function getValue(value: string, node: NodeType, template: TemplateVariableType) { let returnValue = value ?? ""; if (getTweak.length > 0) { diff --git a/src/frontend/src/types/components/index.ts b/src/frontend/src/types/components/index.ts index 273427ca8..e0ef84bde 100644 --- a/src/frontend/src/types/components/index.ts +++ b/src/frontend/src/types/components/index.ts @@ -223,6 +223,12 @@ export type tweakType = Array<{ } & FlowStyleType; }>; +export type uniqueTweakType = { + [key: string]: { + [char: string]: string; + } & FlowStyleType; +} + export type apiModalTweakType = { current: Array<{ [key: string]: { @@ -425,11 +431,11 @@ export type codeTabsPropsType = { getValue?: ( value: string, node: NodeType, - template: APITemplateType + template: TemplateVariableType ) => string; buildTweakObject?: ( - tw: string | string[], - changes: string | string[] | boolean, + tw: string, + changes: string | string[] | boolean | number, template: TemplateVariableType ) => string | void; };