From 48dceff56338eefce7e81b303a4f2d22bc666526 Mon Sep 17 00:00:00 2001 From: Eli Kinsey Date: Wed, 22 Nov 2023 20:49:44 +0000 Subject: [PATCH] feat(3000): Add docs navigation dropdown --- .../sidepanel/panels/SidePanelDocs.tsx | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) 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 && } }