Skip to content

Commit

Permalink
Fix closing and tab order issues for variables dialog (#16367)
Browse files Browse the repository at this point in the history
  • Loading branch information
desertaxle authored Dec 12, 2024
1 parent a0f3219 commit 8f33592
Show file tree
Hide file tree
Showing 5 changed files with 356 additions and 343 deletions.
4 changes: 2 additions & 2 deletions ui-v2/biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
},
"files": {
"ignoreUnknown": false,
"ignore": ["src/api/prefect.ts"]
"ignore": ["src/api/prefect.ts", "src/routeTree.gen.ts"]
},
"formatter": {
"enabled": true,
"indentStyle": "tab"
},
"organizeImports": {
"enabled": true,
"ignore": ["src/api/prefect.ts"]
"ignore": ["src/api/prefect.ts", "src/routeTree.gen.ts"]
},
"linter": {
"enabled": false,
Expand Down
22 changes: 16 additions & 6 deletions ui-v2/src/components/ui/json-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import React, { useRef, useEffect } from "react";

import { cn } from "@/lib/utils";
import { json } from "@codemirror/lang-json";
import { EditorView, useCodeMirror } from "@uiw/react-codemirror";
import {
type BasicSetupOptions,
EditorView,
useCodeMirror,
} from "@uiw/react-codemirror";

const extensions = [json(), EditorView.lineWrapping];

Expand All @@ -20,6 +24,16 @@ export const JsonInput = React.forwardRef<HTMLDivElement, JsonInputProps>(
forwardedRef,
) => {
const editor = useRef<HTMLDivElement | null>(null);
// Setting `basicSetup` messes up the tab order. We only change the basic setup
// if the input is disabled, so we leave it undefined to maintain the tab order.
let basicSetup: BasicSetupOptions | undefined;
if (disabled) {
basicSetup = {
highlightActiveLine: false,
foldGutter: false,
highlightActiveLineGutter: false,
};
}
const { setContainer } = useCodeMirror({
container: editor.current,
extensions,
Expand All @@ -28,11 +42,7 @@ export const JsonInput = React.forwardRef<HTMLDivElement, JsonInputProps>(
onBlur,
indentWithTab: false,
editable: !disabled,
basicSetup: {
highlightActiveLine: !disabled,
foldGutter: !disabled,
highlightActiveLineGutter: !disabled,
},
basicSetup,
});

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const VariableDialog = ({
toast({
title: "Variable updated",
});
onOpenChange(false);
},
onError: (error) => {
const message =
Expand All @@ -115,6 +116,7 @@ export const VariableDialog = ({
toast({
title: "Variable created",
});
onOpenChange(false);
},
onError: (error) => {
const message =
Expand Down
Loading

0 comments on commit 8f33592

Please sign in to comment.