diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/SidePanelDocs.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/SidePanelDocs.tsx index e080f49c67f26..e193083feef00 100644 --- a/frontend/src/layout/navigation-3000/sidepanel/panels/SidePanelDocs.tsx +++ b/frontend/src/layout/navigation-3000/sidepanel/panels/SidePanelDocs.tsx @@ -1,5 +1,5 @@ import { IconExternal } from '@posthog/icons' -import { LemonButton, LemonSkeleton } from '@posthog/lemon-ui' +import { LemonButton, LemonSelect, LemonSkeleton } from '@posthog/lemon-ui' import clsx from 'clsx' import { useActions, useValues } from 'kea' import { useEffect, useRef, useState } from 'react' @@ -8,6 +8,11 @@ import { themeLogic } from '../../themeLogic' import { SidePanelPaneHeader } from '../components/SidePanelPane' import { POSTHOG_WEBSITE_ORIGIN, sidePanelDocsLogic } from './sidePanelDocsLogic' +type Menu = { + name: string + url?: string +} + function SidePanelDocsSkeleton(): JSX.Element { return (
@@ -23,12 +28,50 @@ function SidePanelDocsSkeleton(): JSX.Element { ) } +function Menu({ + menu, + activeMenuName, + onChange, +}: { + menu: Menu[] + activeMenuName: string | null + onChange: (newValue: string | null) => void +}): JSX.Element { + return ( +
+ ({ label: name, value: name }))} + /> +
+ ) +} + export const SidePanelDocs = (): JSX.Element => { const { iframeSrc, currentUrl } = useValues(sidePanelDocsLogic) const { updatePath, unmountIframe, closeSidePanel, handleExternalUrl } = useActions(sidePanelDocsLogic) const ref = useRef(null) const [ready, setReady] = useState(false) const { isDarkModeOn } = useValues(themeLogic) + const [menu, setMenu] = useState(null) + const [activeMenuName, setActiveMenuName] = useState(null) + + const handleMenuChange = (newValue: string | null): void => { + const url = menu?.find(({ name }: Menu) => name === newValue)?.url + if (url) { + ref.current?.contentWindow?.postMessage( + { + type: 'navigate', + url, + }, + '*' + ) + } + } useEffect(() => { ref.current?.contentWindow?.postMessage( @@ -57,6 +100,15 @@ export const SidePanelDocs = (): JSX.Element => { handleExternalUrl(event.data.url) return } + if (event.data.type === 'docs-menu') { + setMenu(event.data.menu) + return + } + + if (event.data.type === 'docs-active-menu') { + setActiveMenuName(event.data.activeMenuName) + return + } console.warn('Unhandled iframe message from Docs:', event.data) } @@ -79,6 +131,7 @@ export const SidePanelDocs = (): JSX.Element => { return ( <> + {menu && } }