diff --git a/web_src/src/ui/CanvasPage/index.tsx b/web_src/src/ui/CanvasPage/index.tsx index dd0deb0a42..98993d3d08 100644 --- a/web_src/src/ui/CanvasPage/index.tsx +++ b/web_src/src/ui/CanvasPage/index.tsx @@ -1604,6 +1604,9 @@ function CanvasPage(props: CanvasPageProps) { canReadIntegrations={props.canReadIntegrations} canCreateIntegrations={props.canCreateIntegrations} canUpdateIntegrations={props.canUpdateIntegrations} + onEnterEditMode={props.onEnterEditMode} + enterEditModeDisabled={props.enterEditModeDisabled} + enterEditModeDisabledTooltip={props.enterEditModeDisabledTooltip} /> ) : null} @@ -1681,6 +1684,9 @@ function Sidebar({ canReadIntegrations, canCreateIntegrations, canUpdateIntegrations, + onEnterEditMode, + enterEditModeDisabled, + enterEditModeDisabledTooltip, }: { state: CanvasPageState; getSidebarData?: (nodeId: string) => SidebarData | null; @@ -1728,6 +1734,9 @@ function Sidebar({ canReadIntegrations?: boolean; canCreateIntegrations?: boolean; canUpdateIntegrations?: boolean; + onEnterEditMode?: () => void; + enterEditModeDisabled?: boolean; + enterEditModeDisabledTooltip?: string; }) { const sidebarData = useMemo(() => { if (!state.componentSidebar.selectedNodeId || !getSidebarData) { @@ -1892,6 +1901,9 @@ function Sidebar({ hideDocsTab={isAnnotationNode} hideNodeId={isAnnotationNode} readOnly={readOnly} + onEnterEditMode={onEnterEditMode} + enterEditModeDisabled={enterEditModeDisabled} + enterEditModeDisabledTooltip={enterEditModeDisabledTooltip} /> ); } @@ -2107,6 +2119,35 @@ function resolveAbsoluteNodeRect( }; } +type ComponentSidebarTab = "latest" | "settings" | "docs"; + +type NodeConfigurationWarningData = { + component?: { error?: string }; + composite?: { error?: string }; + trigger?: { error?: string }; +} | null; + +function shouldOpenSidebarSettingsTab(nodeData: NodeConfigurationWarningData, isEditMode: boolean): boolean { + return Boolean(nodeData?.component?.error || nodeData?.composite?.error || nodeData?.trigger?.error) || isEditMode; +} + +function applySidebarTabOnNodeOpen( + setCurrentTab: ((tab: ComponentSidebarTab) => void) | undefined, + wasSidebarOpen: boolean, + shouldOpenSettings: boolean, +): void { + if (!setCurrentTab) { + return; + } + if (!wasSidebarOpen) { + setCurrentTab(shouldOpenSettings ? "settings" : "latest"); + return; + } + if (shouldOpenSettings) { + setCurrentTab("settings"); + } +} + function CanvasContent({ state, onNodeEdit, @@ -2384,24 +2425,12 @@ function CanvasContent({ } else if (onNodeClick) { onNodeClick(nodeId); } else { + const wasSidebarOpen = stateRef.current.componentSidebar.isOpen; stateRef.current.componentSidebar.open(nodeId); - const nodeData = clickedNode?.data as { - component?: { error?: string }; - composite?: { error?: string }; - trigger?: { error?: string }; - } | null; - const hasConfigurationWarning = Boolean( - nodeData?.component?.error || nodeData?.composite?.error || nodeData?.trigger?.error, - ); - - if (setCurrentTab) { - setCurrentTab(hasConfigurationWarning || isEditMode ? "settings" : "latest"); - } - - if (onBuildingBlocksSidebarToggle) { - onBuildingBlocksSidebarToggle(false); - } + const nodeData = clickedNode?.data as NodeConfigurationWarningData; + applySidebarTabOnNodeOpen(setCurrentTab, wasSidebarOpen, shouldOpenSidebarSettingsTab(nodeData, isEditMode)); + onBuildingBlocksSidebarToggle?.(false); } stateRef.current.setNodes((nodes) => diff --git a/web_src/src/ui/componentSidebar/DocsTab.tsx b/web_src/src/ui/componentSidebar/DocsTab.tsx index 1ac51b35c6..b3cd286700 100644 --- a/web_src/src/ui/componentSidebar/DocsTab.tsx +++ b/web_src/src/ui/componentSidebar/DocsTab.tsx @@ -1,10 +1,12 @@ import type { ConfigurationField } from "@/api-client"; import { BookOpen, ExternalLink } from "lucide-react"; +import { Button } from "@/components/ui/button"; +import { cn } from "@/lib/utils"; import { PayloadPreview } from "@/ui/BuildingBlocksSidebar/PayloadPreview"; -function ConfigTable({ fields }: { fields: ConfigurationField[] }) { +function ConfigTable({ fields, showTopBorder }: { fields: ConfigurationField[]; showTopBorder?: boolean }) { return ( -