From 6c1f55f41d4fed83896274084cc8c61c4ea247bb Mon Sep 17 00:00:00 2001 From: Brent Bovenzi Date: Tue, 6 May 2025 15:27:23 -0400 Subject: [PATCH] Add basic json check to variable value --- .../Variables/ManageVariable/VariableForm.tsx | 42 +++++++++++++++---- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/airflow-core/src/airflow/ui/src/pages/Variables/ManageVariable/VariableForm.tsx b/airflow-core/src/airflow/ui/src/pages/Variables/ManageVariable/VariableForm.tsx index 8ae39c58210b5..2b7c65e760e90 100644 --- a/airflow-core/src/airflow/ui/src/pages/Variables/ManageVariable/VariableForm.tsx +++ b/airflow-core/src/airflow/ui/src/pages/Variables/ManageVariable/VariableForm.tsx @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { Box, Field, HStack, Input, Spacer, Textarea } from "@chakra-ui/react"; +import { Box, Field, HStack, Input, Spacer, Textarea, Text } from "@chakra-ui/react"; import { Controller, useForm } from "react-hook-form"; import { FiSave } from "react-icons/fi"; @@ -29,6 +29,16 @@ export type VariableBody = { value: string; }; +const isJsonString = (string: string) => { + try { + JSON.parse(string); + } catch { + return false; + } + + return true; +}; + type VariableFormProps = { readonly error: unknown; readonly initialVariable: VariableBody; @@ -80,14 +90,28 @@ const VariableForm = ({ error, initialVariable, isPending, manageMutate, setErro ( - - - Value - -