MCPcopy Create free account
hub / github.com/bytebase/bytebase / FolderForm

Function FolderForm

frontend/src/react/components/sql-editor/FolderForm.tsx:31–188  ·  view source on GitHub ↗
({ folder, onFolderChange }: Props)

Source from the content-addressed store, hash-verified

29}
30
31export function FolderForm({ folder, onFolderChange }: Props) {
32 const { t } = useTranslation();
33
34 const { folderTree, folderContext } = useSheetContextByView("my");
35 const rootPath = folderContext.rootPath;
36
37 const [folderPath, setFolderPath] = useState(folder);
38 const [showPopover, setShowPopover] = useState(false);
39
40 const containerRef = useRef<HTMLDivElement>(null);
41 const inputRef = useRef<HTMLInputElement>(null);
42
43 // Close the popover on a mousedown outside the input AND outside the
44 // overlay layer (where the portalled popup lives). Base UI's PopoverTrigger
45 // toggles on click, which means a second click on the input would close the
46 // popover even though the user wants to keep typing — so we bypass Trigger
47 // entirely and manage open state ourselves.
48 useEffect(() => {
49 if (!showPopover) return;
50 const overlayRoot = document.getElementById(LAYER_ROOT_ID.overlay);
51 const handler = (e: MouseEvent) => {
52 const target = e.target as Node;
53 if (containerRef.current?.contains(target)) return;
54 if (overlayRoot?.contains(target)) return;
55 setShowPopover(false);
56 };
57 document.addEventListener("mousedown", handler);
58 return () => document.removeEventListener("mousedown", handler);
59 }, [showPopover]);
60
61 // Sync incoming folder prop → local state
62 useEffect(() => {
63 setFolderPath(folder);
64 }, [folder]);
65
66 // Emit changes upward whenever folderPath changes
67 useEffect(() => {
68 onFolderChange(folderPath);
69 }, [folderPath, onFolderChange]);
70
71 const formattedFolderPath = (() => {
72 let val = folderPath.replace(rootPath, "");
73 if (val[0] === "/") {
74 val = val.slice(1);
75 }
76 return val.split("/").join(" / ");
77 })();
78
79 const handleInput = (raw: string) => {
80 let changedVal = raw;
81 if (changedVal.endsWith(" /")) {
82 changedVal = changedVal.slice(0, -2);
83 }
84 if (changedVal.endsWith(".")) {
85 changedVal = changedVal.slice(0, -1);
86 }
87 const rawPath = changedVal
88 .split("/")

Callers

nothing calls this directly

Calls 5

useSheetContextByViewFunction · 0.90
cnFunction · 0.90
handleUserClickFunction · 0.85
handleInputFunction · 0.70
tFunction · 0.50

Tested by

no test coverage detected