From f38692c9df41acd24cd26a394fb6d06f89a18cdd Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 29 Sep 2023 10:05:19 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(genericModal/index.tsx):=20s?= =?UTF-8?q?et=20field=5Fname=20to=20the=20first=20key=20of=20custom=5Ffiel?= =?UTF-8?q?ds=20object=20if=20it=20is=20an=20empty=20string=20=F0=9F=90=9B?= =?UTF-8?q?=20fix(genericModal/index.tsx):=20update=20template=20value=20b?= =?UTF-8?q?ased=20on=20field=5Fname=20instead=20of=20hardcoding=20"templat?= =?UTF-8?q?e"=20=E2=9C=A8=20feat(api/index.ts):=20add=20CustomFieldsType?= =?UTF-8?q?=20to=20represent=20custom=20fields=20in=20APIClassType?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/modals/genericModal/index.tsx | 11 +++++++++-- src/frontend/src/types/api/index.ts | 14 +++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/frontend/src/modals/genericModal/index.tsx b/src/frontend/src/modals/genericModal/index.tsx index e82b40fbb..c3f091ce0 100644 --- a/src/frontend/src/modals/genericModal/index.tsx +++ b/src/frontend/src/modals/genericModal/index.tsx @@ -109,6 +109,13 @@ export default function GenericModal({ postValidatePrompt(field_name, inputValue, nodeClass!) .then((apiReturn) => { + // if field_name is an empty string, then we need to set it + // to the first key of the custom_fields object + if (field_name === "") { + field_name = Object.keys( + apiReturn.data?.frontend_node?.custom_fields ?? {} + )[0]; + } if (apiReturn.data) { let inputVariables = apiReturn.data.input_variables ?? []; if (inputVariables && inputVariables.length === 0) { @@ -124,7 +131,7 @@ export default function GenericModal({ setNodeClass!(apiReturn.data?.frontend_node); setModalOpen(closeModal); setValue(inputValue); - apiReturn.data.frontend_node["template"]["template"]["value"] = + apiReturn.data.frontend_node["template"][field_name]["value"] = inputValue; } else { setIsEdit(false); @@ -138,7 +145,7 @@ export default function GenericModal({ setNodeClass!(apiReturn.data?.frontend_node); setModalOpen(closeModal); setValue(inputValue); - apiReturn.data.frontend_node["template"]["template"]["value"] = + apiReturn.data.frontend_node["template"][field_name]["value"] = inputValue; } } else { diff --git a/src/frontend/src/types/api/index.ts b/src/frontend/src/types/api/index.ts index ad867d12d..42ec05ead 100644 --- a/src/frontend/src/types/api/index.ts +++ b/src/frontend/src/types/api/index.ts @@ -7,6 +7,11 @@ export type APITemplateType = { variable: TemplateVariableType; [key: string]: TemplateVariableType; }; + +export type CustomFieldsType = { + [key: string]: Array; +}; + export type APIClassType = { base_classes: Array; description: string; @@ -14,10 +19,17 @@ export type APIClassType = { display_name: string; input_types?: Array; output_types?: Array; + custom_fields?: CustomFieldsType; beta?: boolean; documentation: string; error?: string; - [key: string]: Array | string | APITemplateType | boolean | undefined; + [key: string]: + | Array + | string + | APITemplateType + | CustomFieldsType + | boolean + | undefined; }; export type TemplateVariableType = {