dingo4dev commented on code in PR #62882:
URL: https://github.com/apache/airflow/pull/62882#discussion_r2978965167
##########
airflow-core/src/airflow/ui/src/pages/Variables/ManageVariable/VariableForm.tsx:
##########
@@ -16,14 +16,95 @@
* specific language governing permissions and limitations
* under the License.
*/
-import { Box, Button, Field, HStack, Input, Spacer, Text, Textarea } from
"@chakra-ui/react";
-import { Controller, useForm } from "react-hook-form";
+import { Box, Button, Field, HStack, IconButton, Input, Spacer, Text, Textarea
} from "@chakra-ui/react";
+import { useEffect, useRef, useState } from "react";
+import { type ControllerFieldState, type ControllerRenderProps, Controller,
useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
-import { FiSave } from "react-icons/fi";
+import { FiCode, FiSave } from "react-icons/fi";
import { ErrorAlert } from "src/components/ErrorAlert";
import { TeamSelector } from "src/components/TeamSelector.tsx";
import { useConfig } from "src/queries/useConfig.tsx";
+import { isJsonString, minifyJson, prettifyJson } from "src/utils";
+
+type ValueFieldProps = {
+ readonly field: ControllerRenderProps<VariableBody, "value">;
+ readonly fieldState: ControllerFieldState;
+};
+
+const ValueField = ({ field, fieldState }: ValueFieldProps) => {
+ const { t: translate } = useTranslation(["admin"]);
+ const [displayValue, setDisplayValue] = useState(field.value);
+ const fieldValueRef = useRef(field.value);
+
+ useEffect(() => {
+ if (fieldValueRef.current !== field.value) {
+ fieldValueRef.current = field.value;
+ setDisplayValue(field.value);
+ }
+ }, [field.value]);
+
+ const showJsonWarning =
+ displayValue.startsWith("{") || displayValue.startsWith("[") ?
!isJsonString(displayValue) : false;
+
Review Comment:
Added memo to computing the display value.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]