diff --git a/airflow-core/newsfragments/64281.significant.rst b/airflow-core/newsfragments/64281.significant.rst new file mode 100644 index 0000000000000..9e91de9db5e82 --- /dev/null +++ b/airflow-core/newsfragments/64281.significant.rst @@ -0,0 +1 @@ +Rework Monaco Editor style to match Chakra UI color palette. diff --git a/airflow-core/src/airflow/ui/src/components/JsonEditor.tsx b/airflow-core/src/airflow/ui/src/components/JsonEditor.tsx index 3b9cc6f4e01a4..806b73b7d2625 100644 --- a/airflow-core/src/airflow/ui/src/components/JsonEditor.tsx +++ b/airflow-core/src/airflow/ui/src/components/JsonEditor.tsx @@ -19,7 +19,7 @@ import Editor, { type EditorProps } from "@monaco-editor/react"; import { useRef } from "react"; -import { useColorMode } from "src/context/colorMode"; +import { useMonacoTheme } from "src/context/colorMode"; type JsonEditorProps = { readonly editable?: boolean; @@ -39,7 +39,7 @@ export const JsonEditor = ({ value, ...rest }: JsonEditorProps) => { - const { colorMode } = useColorMode(); + const { beforeMount, theme } = useMonacoTheme(); const onBlurRef = useRef(onBlur); onBlurRef.current = onBlur; @@ -55,8 +55,6 @@ export const JsonEditor = ({ scrollBeyondLastLine: false, }; - const theme = colorMode === "dark" ? "vs-dark" : "vs-light"; - const handleChange = (val: string | undefined) => { onChange?.(val ?? ""); }; @@ -72,6 +70,7 @@ export const JsonEditor = ({ {...rest} > { const contentFormatted = JSON.stringify(content, undefined, 2); - const { colorMode } = useColorMode(); + const { beforeMount, theme } = useMonacoTheme(); const lineCount = contentFormatted.split("\n").length; - const expandedHeight = Math.min(Math.max(lineCount * 19 + 10, MIN_HEIGHT), MAX_HEIGHT); - const [editorHeight, setEditorHeight] = useState(collapsed ? MIN_HEIGHT : expandedHeight); - const [isReady, setIsReady] = useState(!collapsed); - const theme = colorMode === "dark" ? "vs-dark" : "vs-light"; + const height = `${Math.min(Math.max(lineCount * 19 + 10, 40), 300)}px`; const handleMount: OnMount = useCallback( (editorInstance) => { - editorInstance.onDidContentSizeChange(() => { - const contentHeight = editorInstance.getContentHeight(); - - setEditorHeight(Math.min(Math.max(contentHeight, MIN_HEIGHT), MAX_HEIGHT)); - }); - if (collapsed) { - const action = editorInstance.getAction("editor.foldAll"); - - if (action) { - void action.run().then(() => { - setIsReady(true); - }); - } else { - setIsReady(true); - } + void editorInstance.getAction("editor.foldAll")?.run(); } }, [collapsed], @@ -66,16 +46,15 @@ const RenderedJsonField = ({ collapsed = false, content, enableClipboard = true, return (