From b71171f53eb56105b663fbff929c3876d5381b3e Mon Sep 17 00:00:00 2001 From: Maina Wycliffe Date: Tue, 24 Oct 2023 09:24:45 +0300 Subject: [PATCH 1/2] fix: default code editor to undefined instead of empty object Closes #1400 --- .../Forms/Formik/FormikCodeEditor.tsx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/components/Forms/Formik/FormikCodeEditor.tsx b/src/components/Forms/Formik/FormikCodeEditor.tsx index 7995b3994..55cebbb49 100644 --- a/src/components/Forms/Formik/FormikCodeEditor.tsx +++ b/src/components/Forms/Formik/FormikCodeEditor.tsx @@ -55,9 +55,9 @@ export function FormikCodeEditor({ const debouncedValues = useDebounce(codeEditorValue, 300); useEffect(() => { - if (debouncedValues) { - try { - if (format === "yaml" || format === "json") { + try { + if (format === "yaml" || format === "json") { + if (debouncedValues) { setFieldValue( fieldName, format === "yaml" @@ -65,11 +65,13 @@ export function FormikCodeEditor({ : JSON.parse(debouncedValues) ); } else { - setFieldValue(fieldName, debouncedValues); + setFieldValue(fieldName, undefined); } - } catch (e) { - // do nothing, we don't want to set the values if the user is typing + } else { + setFieldValue(fieldName, debouncedValues); } + } catch (e) { + // do nothing, we don't want to set the values if the user is typing } }, [debouncedValues, fieldName, format, setFieldValue]); @@ -106,8 +108,9 @@ export function FormikCodeEditor({ if (v) { setCodeEditorValue(v); } else { - // if the value is empty, we want to reset the form - setFieldValue(fieldName, {}); + setCodeEditorValue(undefined); + // if the value is empty, we want to set to undefined + setFieldValue(fieldName, undefined); } }} value={value} From e9de6a80ddecefbcd07b29940d43fa5b8b7d079d Mon Sep 17 00:00:00 2001 From: Maina Wycliffe Date: Tue, 24 Oct 2023 09:26:07 +0300 Subject: [PATCH 2/2] refactor: remove console log and sort imports --- src/components/Forms/Formik/FormikCodeEditor.tsx | 2 +- src/components/Forms/Formik/FormikSelectDropdown.tsx | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/Forms/Formik/FormikCodeEditor.tsx b/src/components/Forms/Formik/FormikCodeEditor.tsx index 55cebbb49..08fe75955 100644 --- a/src/components/Forms/Formik/FormikCodeEditor.tsx +++ b/src/components/Forms/Formik/FormikCodeEditor.tsx @@ -2,8 +2,8 @@ import { useField, useFormikContext } from "formik"; import { isEmpty } from "lodash"; import dynamic from "next/dynamic"; import { useEffect, useMemo, useState } from "react"; -import useDebounce from "../../../hooks/useDebounce"; import YAML from "yaml"; +import useDebounce from "../../../hooks/useDebounce"; const CodeEditor = dynamic( () => import("../../CodeEditor").then((m) => m.CodeEditor), diff --git a/src/components/Forms/Formik/FormikSelectDropdown.tsx b/src/components/Forms/Formik/FormikSelectDropdown.tsx index 2edc79d79..a0916d90a 100644 --- a/src/components/Forms/Formik/FormikSelectDropdown.tsx +++ b/src/components/Forms/Formik/FormikSelectDropdown.tsx @@ -70,7 +70,6 @@ export default function FormikSelectDropdown({ options={options} value={value} onChange={(value: any) => { - console.log({ value: value }); field.onChange({ target: { name: field.name,