From 53e0c30d249bfa8efcc6b648ccb6d312f73388fe Mon Sep 17 00:00:00 2001 From: Raquel Smith Date: Tue, 3 Sep 2024 10:41:16 -0700 Subject: [PATCH] feat(onboarding-dashboard-templates): get the iframe loading (#24692) --- .../IframedToolbarBrowser.tsx | 75 +++++ .../iframedToolbarBrowserLogic.ts | 272 ++++++++++++++++++ .../utils.ts | 0 .../src/scenes/heatmaps/HeatmapsBrowser.tsx | 2 +- .../scenes/heatmaps/heatmapsBrowserLogic.ts | 6 +- .../src/scenes/onboarding/OnboardingStep.tsx | 16 +- .../DashboardTemplateConfigureStep.tsx | 113 ++++++-- .../src/scenes/onboarding/sdks/sdksLogic.tsx | 41 ++- frontend/src/toolbar/bar/toolbarLogic.ts | 2 +- frontend/src/toolbar/elements/heatmapLogic.ts | 2 +- .../src/toolbar/stats/HeatmapToolbarMenu.tsx | 2 +- 11 files changed, 493 insertions(+), 38 deletions(-) create mode 100644 frontend/src/lib/components/IframedToolbarBrowser/IframedToolbarBrowser.tsx create mode 100644 frontend/src/lib/components/IframedToolbarBrowser/iframedToolbarBrowserLogic.ts rename frontend/src/lib/components/{heatmaps => IframedToolbarBrowser}/utils.ts (100%) diff --git a/frontend/src/lib/components/IframedToolbarBrowser/IframedToolbarBrowser.tsx b/frontend/src/lib/components/IframedToolbarBrowser/IframedToolbarBrowser.tsx new file mode 100644 index 0000000000000..3e34575b31c96 --- /dev/null +++ b/frontend/src/lib/components/IframedToolbarBrowser/IframedToolbarBrowser.tsx @@ -0,0 +1,75 @@ +import { LemonBanner, Spinner } from '@posthog/lemon-ui' +import { useActions, useValues } from 'kea' +import { useEffect } from 'react' +import useResizeObserver from 'use-resize-observer' + +import { ToolbarUserIntent } from '~/types' + +import { appEditorUrl } from '../AuthorizedUrlList/authorizedUrlListLogic' +import { iframedToolbarBrowserLogic } from './iframedToolbarBrowserLogic' + +function IframeErrorOverlay(): JSX.Element | null { + const logic = iframedToolbarBrowserLogic() + const { iframeBanner } = useValues(logic) + return iframeBanner ? ( +
+ + {iframeBanner.message}. Your site might not allow being embedded in an iframe. You can click "Open in + toolbar" above to visit your site and view the heatmap there. + +
+ ) : null +} + +function LoadingOverlay(): JSX.Element | null { + const logic = iframedToolbarBrowserLogic() + const { loading } = useValues(logic) + return loading ? ( +
+ +
+ ) : null +} + +export function IframedToolbarBrowser({ + iframeRef, + userIntent, +}: { + iframeRef?: React.MutableRefObject + userIntent: ToolbarUserIntent +}): JSX.Element | null { + const logic = iframedToolbarBrowserLogic() + + const { browserUrl } = useValues(logic) + const { onIframeLoad, setIframeWidth } = useActions(logic) + + const { width: iframeWidth } = useResizeObserver({ ref: iframeRef }) + useEffect(() => { + setIframeWidth(iframeWidth ?? null) + }, [iframeWidth]) + + return browserUrl ? ( +
+ + +