Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat: multi-region button (#64903)

Christian Rafferty9b8286fb709f
diff --git a/frontend/src/layout/navigation/ImpersonationNotice/AdminLoginButtons.tsx b/frontend/src/layout/navigation/ImpersonationNotice/AdminLoginButtons.tsx
new file mode 100644
index 000000000000..4a910cd909ab
--- /dev/null
+++ b/frontend/src/layout/navigation/ImpersonationNotice/AdminLoginButtons.tsx
@@ -0,0 +1,40 @@
+import { LemonButton } from '@posthog/lemon-ui'
+
+import { AdminLoginUrl, ImpersonationTicketContext } from './impersonationNoticeLogic'
+
+export function AdminLoginButtons({
+ ticketContext,
+ adminLoginUrls,
+}: {
+ ticketContext: ImpersonationTicketContext | null
+ adminLoginUrls: AdminLoginUrl[]
+}): JSX.Element {
+ const disabledReason = !ticketContext?.email ? 'This ticket has no associated email' : undefined
+
+ // Region is ambiguous when we couldn't infer it, so we offer one button per
+ // region and label each so staff know which admin page they're opening.
+ const showRegionLabel = adminLoginUrls.length > 1
+
+ return (
+ <div className="flex flex-wrap justify-end gap-2">
+ {disabledReason ? (
+ <LemonButton type="secondary" size="small" disabledReason={disabledReason}>
+ Login as {ticketContext?.email || 'customer'}
+ </LemonButton>
+ ) : (
+ adminLoginUrls.map(({ region, url }) => (
+ <LemonButton
+ key={region}
+ type="secondary"
+ size="small"
+ tooltip="This currently redirects to the admin login page, but in future will log you in directly."
+ onClick={() => window.open(url, '_blank')}
+ >
+ Login as {ticketContext?.email}
+ {showRegionLabel ? ` (${region})` : ''}
+ </LemonButton>
+ ))
+ )}
+ </div>
+ )
+}
diff --git a/frontend/src/layout/navigation/ImpersonationNotice/ImpersonationNotice.tsx b/frontend/src/layout/navigation/ImpersonationNotice/ImpersonationNotice.tsx
index 30fba5ed814b..ed021fa8a433 100644
--- a/frontend/src/layout/navigation/ImpersonationNotice/ImpersonationNotice.tsx
+++ b/frontend/src/layout/navigation/ImpersonationNotice/ImpersonationNotice.tsx
@@ -13,7 +13,13 @@ import { IconDragHandle } from 'lib/lemon-ui/icons'
import { cn } from 'lib/utils/css-classes'
import { userLogic } from 'scenes/userLogic'
-import { ExpiredSessionInfo, ImpersonationTicketContext, impersonationNoticeLogic } from './impersonationNoticeLogic'
+import { AdminLoginButtons } from './AdminLoginButtons'
+import {
+ AdminLoginUrl,
+ ExpiredSessionInfo,
+ ImpersonationTicketContext,
+ impersonationNoticeLogic,
+} from './impersonationNoticeLogic'
import { ImpersonationReasonModal } from './ImpersonationReasonModal'
function CountDown({ datetime, callback }: { datetime: dayjs.Dayjs; callback?: () => void }): JSX.Element {
@@ -50,19 +56,11 @@ function CountDown({ datetime, callback }: { datetime: dayjs.Dayjs; callback?: (
function LoginAsContent({
ticketContext,
- adminLoginUrl,
+ adminLoginUrls,
}: {
ticketContext: ImpersonationTicketContext
- adminLoginUrl: string | null
+ adminLoginUrls: AdminLoginUrl[]
}): JSX.Element {
- const disabledReason = !ticketContext.email
- ? 'This ticket has no associated email'
- : !ticketContext.region
- ? 'Unable to determine region for this ticket, no login available'
- : !adminLoginUrl
- ? 'Unable to determine admin URL'
- : undefined
-
return (
<>
<p className="ImpersonationNotice__message">
@@ -74,21 +72,7 @@ function LoginAsContent({
'No customer email on this ticket'
)}
</p>
- <div className="flex gap-2 justify-end">
- <LemonButton
- type="secondary"
- size="small"
- tooltip={
- !disabledReason
- ? 'This currently redirects to the admin login page, but in future will log you in directly.'
- : undefined
- }
- disabledReason={disabledReason}
- onClick={() => adminLoginUrl && window.open(adminLoginUrl, '_blank')}
- >
- Login as {ticketContext.email || 'customer'}
- </LemonButton>
- </div>
+ <AdminLoginButtons ticketContext={ticketContext} adminLoginUrls={adminLoginUrls} />
</>
)
}
@@ -215,7 +199,7 @@ export function ImpersonationNotice(): JSX.Element | null {
isSessionExpired,
expiredSessionInfo,
ticketContext,
- adminLoginUrl,
+ adminLoginUrls,
} = useValues(impersonationNoticeLogic)
const { minimize, maximize, openUpgradeModal, setPageVisible } = useActions(impersonationNoticeLogic)
@@ -304,7 +288,7 @@ export function ImpersonationNotice(): JSX.Element | null {
</div>
<div className="ImpersonationNotice__content">
{showLoginAs ? (
- <LoginAsContent ticketContext={ticketContext!} adminLoginUrl={adminLoginUrl} />
+ <LoginAsContent ticketContext={ticketContext!} adminLoginUrls={adminLoginUrls} />
) : (
<ImpersonationNoticeContent />
)}
diff --git a/frontend/src/layout/navigation/ImpersonationNotice/impersonationNoticeLogic.test.ts b/frontend/src/layout/navigation/ImpersonationNotice/impersonationNoticeLogic.test.ts
index 368004c954e5..485adfc6fdc9 100644
--- a/frontend/src/layout/navigation/ImpersonationNotice/impersonationNoticeLogic.test.ts
+++ b/frontend/src/layout/navigation/ImpersonationNotice/impersonationNoticeLogic.test.ts
@@ -8,7 +8,7 @@ import { userLogic } from 'scenes/userLogic'
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
-import { UserType } from '~/types'
+import { Region, UserType } from '~/types'
import { impersonationNoticeLogic } from './impersonationNoticeLogic'
@@ -130,6 +130,48 @@ describe('impersonationNoticeLogic', () => {
isReadOnly: true,
})
})
+
+ describe('adminLoginUrls', () => {
+ it('returns no urls when there is no ticket context', async () => {
+ await expectLogic(logic).toMatchValues({ adminLoginUrls: [] })
+ })
+
+ it('returns no urls when the ticket has no email', async () => {
+ logic.actions.setTicketContext({ ticketId: '1', email: '', region: Region.US })
+
+ await expectLogic(logic).toMatchValues({ adminLoginUrls: [] })
+ })
+
+ it('returns a single region url when the region is known', async () => {
+ logic.actions.setTicketContext({ ticketId: '1', email: '[email protected]', region: Region.EU })
+
+ await expectLogic(logic).toMatchValues({
+ adminLoginUrls: [
+ {
+ region: Region.EU,
+ url: 'https://eu.posthog.com/admin/posthog/user/?q=a%2Bb%40example.com',
+ },
+ ],
+ })
+ })
+
+ it('falls back to both production regions when the region is unknown', async () => {
+ logic.actions.setTicketContext({ ticketId: '1', email: '[email protected]' })
+
+ await expectLogic(logic).toMatchValues({
+ adminLoginUrls: [
+ {
+ region: Region.US,
+ url: 'https://us.posthog.com/admin/posthog/user/?q=slack%40example.com',
+ },
+ {
+ region: Region.EU,
+ url: 'https://eu.posthog.com/admin/posthog/user/?q=slack%40example.com',
+ },
+ ],
+ })
+ })
+ })
})
describe('reImpersonate listener', () => {
diff --git a/frontend/src/layout/navigation/ImpersonationNotice/impersonationNoticeLogic.ts b/frontend/src/layout/navigation/ImpersonationNotice/impersonationNoticeLogic.ts
index 7bd8b4b5175b..61442e385d29 100644
--- a/frontend/src/layout/navigation/ImpersonationNotice/impersonationNoticeLogic.ts
+++ b/frontend/src/layout/navigation/ImpersonationNotice/impersonationNoticeLogic.ts
@@ -28,12 +28,19 @@ export interface ImpersonationTicketContext {
region?: Region
}
-function adminLoginUrlForTicket(context: ImpersonationTicketContext): string | null {
- if (!context.region) {
- return null
- }
- const domain = CLOUD_HOSTNAMES[context.region]
- return `https://${domain}/admin/posthog/user/?q=${encodeURIComponent(context.email)}`
+export interface AdminLoginUrl {
+ region: Region
+ url: string
+}
+
+// When a ticket's region is unknown (e.g. tickets opened from a Slack channel
+// carry no app URL to infer it from), fall back to offering a lookup in each
+// production cloud region rather than no link at all.
+const ADMIN_LOOKUP_REGIONS: Region[] = [Region.US, Region.EU]
+
+function adminLoginUrlForRegion(region: Region, email: string): string {
+ const domain = CLOUD_HOSTNAMES[region]
+ return `https://${domain}/admin/posthog/user/?q=${encodeURIComponent(email)}`
}
export const impersonationNoticeLogic = kea<impersonationNoticeLogicType>([
@@ -107,13 +114,17 @@ export const impersonationNoticeLogic = kea<impersonationNoticeLogicType>([
selectors({
isReadOnly: [(s) => [s.user], (user: UserType | null): boolean => user?.is_impersonated_read_only ?? true],
isImpersonated: [(s) => [s.user], (user: UserType | null): boolean => user?.is_impersonated ?? false],
- adminLoginUrl: [
+ adminLoginUrls: [
(s) => [s.ticketContext],
- (ticketContext: ImpersonationTicketContext | null): string | null => {
+ (ticketContext: ImpersonationTicketContext | null): AdminLoginUrl[] => {
if (!ticketContext?.email) {
- return null
+ return []
}
- return adminLoginUrlForTicket(ticketContext)
+ const regions = ticketContext.region ? [ticketContext.region] : ADMIN_LOOKUP_REGIONS
+ return regions.map((region) => ({
+ region,
+ url: adminLoginUrlForRegion(region, ticketContext.email),
+ }))
},
],
isSessionExpired: [(s) => [s.expiredSessionInfo], (info: ExpiredSessionInfo | null): boolean => info !== null],
diff --git a/products/conversations/frontend/scenes/ticket/StaffActionsPanel.tsx b/products/conversations/frontend/scenes/ticket/StaffActionsPanel.tsx
index c99e71cd4f61..1abff1ea9f51 100644
--- a/products/conversations/frontend/scenes/ticket/StaffActionsPanel.tsx
+++ b/products/conversations/frontend/scenes/ticket/StaffActionsPanel.tsx
@@ -1,19 +1,12 @@
import { useValues } from 'kea'
-import { LemonButton, LemonCollapse } from '@posthog/lemon-ui'
+import { LemonCollapse } from '@posthog/lemon-ui'
+import { AdminLoginButtons } from '~/layout/navigation/ImpersonationNotice/AdminLoginButtons'
import { impersonationNoticeLogic } from '~/layout/navigation/ImpersonationNotice/impersonationNoticeLogic'
export function StaffActionsPanel(): JSX.Element {
- const { ticketContext, adminLoginUrl } = useValues(impersonationNoticeLogic)
-
- const disabledReason = !ticketContext?.email
- ? 'This ticket has no associated email'
- : !ticketContext?.region
- ? 'Unable to determine region for this ticket, no login available'
- : !adminLoginUrl
- ? 'Unable to determine admin URL'
- : undefined
+ const { ticketContext, adminLoginUrls } = useValues(impersonationNoticeLogic)
return (
<LemonCollapse
@@ -25,7 +18,7 @@ export function StaffActionsPanel(): JSX.Element {
header: 'Staff actions',
content: (
<div className="space-y-2">
- <div className="flex items-center justify-between">
+ <div className="flex items-center justify-between gap-2">
<span className="text-xs text-muted-alt">
{ticketContext?.email ? (
<>
@@ -35,19 +28,7 @@ export function StaffActionsPanel(): JSX.Element {
'No customer email on this ticket'
)}
</span>
- <LemonButton
- type="secondary"
- size="small"
- tooltip={
- !disabledReason
- ? 'This currently redirects to the admin login page, but in future will log you in directly.'
- : undefined
- }
- disabledReason={disabledReason}
- onClick={() => adminLoginUrl && window.open(adminLoginUrl, '_blank')}
- >
- Login as {ticketContext?.email || 'customer'}
- </LemonButton>
+ <AdminLoginButtons ticketContext={ticketContext} adminLoginUrls={adminLoginUrls} />
</div>
</div>
),