diff --git a/frontend/src/components/reactflow/overlayui/TopologyName.tsx b/frontend/src/components/reactflow/overlayui/TopologyName.tsx index a12d140..3d433dc 100644 --- a/frontend/src/components/reactflow/overlayui/TopologyName.tsx +++ b/frontend/src/components/reactflow/overlayui/TopologyName.tsx @@ -9,15 +9,27 @@ export default function TopologyName() { const [isEditing, setIsEditing] = useState(false); const [inputWidth, setInputWidth] = useState(0); const spanRef = useRef(null); - const initialNameRef = useRef(topologyData?.name || ""); + const inputRef = useRef(null); const { authenticatedApiClient } = useAuth(); + const prevRenderTopologyName = topologyData?.name || "Topology Name"; + useEffect(() => { if (spanRef.current) { setInputWidth(spanRef.current.offsetWidth); } }, [topologyName, isEditing]); + useEffect(() => { + if (!topologyData?.name) return; + + document.title = topologyData.name; + + return () => { + document.title = 'TOPHAT' + } + }, [topologyData?.name]); + const updateTopologyName = useCallback(async () => { setIsSaving(true); try { @@ -30,7 +42,6 @@ export default function TopologyName() { setTopologyData(res.data); } } - initialNameRef.current = topologyName; // Update the initial name reference } catch (error) { console.error("Failed to update topology name:", error); } finally { @@ -44,7 +55,7 @@ export default function TopologyName() { const handleBlur = async () => { setIsEditing(false); - if (topologyName !== initialNameRef.current) { + if (topologyName !== prevRenderTopologyName) { await updateTopologyName(); } }; @@ -53,14 +64,27 @@ export default function TopologyName() { setIsEditing(true); }; + const handleKeyDown = async (e: React.KeyboardEvent) => { + if (e.key === 'Enter') { + e.preventDefault(); + if (inputRef.current) { + inputRef.current.blur(); + } + await updateTopologyName(); + } + }; + + return (
{/* Topology Name Input */} {isEditing ? ( { })(); }, [user, authenticatedApiClient, id, setTopologyData, setLastUpdated, navigateTo, bookDevices]); - useEffect(() => { - if (!topologyData?.name) return; - - document.title = topologyData.name; - - return () => { - document.title = 'TOPHAT' - } - }, [topologyData?.name]); - useEffect(() => { if (!loading && topologyData?.reactFlowState?.edges && !hasReinitializedLinks.current) { hasReinitializedLinks.current = true;