Skip to content

Commit

Permalink
redirect notice in debug notice
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra committed Dec 20, 2024
1 parent 9835111 commit 1c3e8ac
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
57 changes: 52 additions & 5 deletions frontend/src/lib/components/DebugNotice.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
import { IconCode, IconX } from '@posthog/icons'
import { useValues } from 'kea'
import { IconBranch } from 'lib/lemon-ui/icons'
import { IconBranch, IconOpenInNew } from 'lib/lemon-ui/icons'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { useEffect, useState } from 'react'
import { useEffect, useMemo, useState } from 'react'

import { NavbarButton } from '~/layout/navigation-3000/components/NavbarButton'
import { navigation3000Logic } from '~/layout/navigation-3000/navigationLogic'

export function DebugNotice(): JSX.Element | null {
const [debugInfo, setDebugInfo] = useState<{ branch: string; revision: string } | undefined>()
const [noticeHidden, setNoticeHidden] = useState(false)
const [isPort8000, setIsPort8000] = useState(false)

const { isNavCollapsed } = useValues(navigation3000Logic)

useEffect(() => {
const isLocal = ['127.0.0.1', '0.0.0.0', 'localhost'].includes(window.location.hostname)
const port = window.location.port

if (isLocal && port === '8000') {
setIsPort8000(true)
}
}, [])

const redirectOrHideOnClick = useMemo(
() =>
isPort8000
? () => {
window.location.assign(
`${window.location.protocol}//${window.location.hostname}:8010${window.location.pathname}${window.location.search}${window.location.hash}`
)
}
: () => setNoticeHidden(true),
[isPort8000]
)

useEffect(() => {
const bottomNotice = document.getElementById('bottom-notice')
const bottomNoticeRevision = document.getElementById('bottom-notice-revision')?.textContent
Expand All @@ -29,7 +52,11 @@ export function DebugNotice(): JSX.Element | null {
return () => {}
}, [])

if (!debugInfo || noticeHidden) {
if (!debugInfo) {
return null
}

if (!isPort8000 && noticeHidden) {
return null
}

Expand All @@ -49,10 +76,16 @@ export function DebugNotice(): JSX.Element | null {
<div>
Revision: <b>{debugInfo.revision}</b>
</div>
<div className="italic">Click to hide</div>
<div className="italic">
{isPort8000 ? (
<>Development should run on port 8010 now! Click to redirect</>
) : (
<>Click to hide</>
)}
</div>
</div>
}
onClick={() => setNoticeHidden(true)}
onClick={redirectOrHideOnClick}
/>
)
}
Expand All @@ -68,6 +101,20 @@ export function DebugNotice(): JSX.Element | null {
onClick={() => setNoticeHidden(true)}
/>
</div>
{isPort8000 && (
<div className="flex items-center gap-2 px-2 border-l-4 border-brand-blue justify-between">
<LemonButton
type="secondary"
status="alt"
icon={<IconOpenInNew />}
size="small"
fullWidth={true}
onClick={redirectOrHideOnClick}
>
Development should run on port 8010 now! Click to redirect
</LemonButton>
</div>
)}
<div
className="flex items-center gap-2 px-2 h-8 border-l-4 border-brand-red"
title={`Branch: ${debugInfo.branch}`}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/scenes/settings/environment/ReplayTriggers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ function UrlBlocklistOptions(): JSX.Element | null {
return (
<UrlConfigSection
type="blocklist"
title="Block recordings when URL matches"
description="Adding a URL blocklist means recording will be paused when the user visits a page that matches the URL."
title="Pause recordings when URL matches"
description="Recording will be paused when the user visits a page that matches the URL."
isAddFormVisible={isAddUrlBlocklistConfigFormVisible}
config={urlBlocklistConfig}
editIndex={editUrlBlocklistIndex}
Expand Down

0 comments on commit 1c3e8ac

Please sign in to comment.