diff --git a/frontend/src/queries/nodes/DataTable/EventRowActions.tsx b/frontend/src/queries/nodes/DataTable/EventRowActions.tsx index 158bd509e45ad..8b79efeb2b808 100644 --- a/frontend/src/queries/nodes/DataTable/EventRowActions.tsx +++ b/frontend/src/queries/nodes/DataTable/EventRowActions.tsx @@ -48,7 +48,7 @@ export function EventRowActions({ event }: EventActionProps): JSX.Element { data-attr="events-table-event-link" onClick={() => void copyToClipboard( - `${window.location.origin}${urls.event(String(event.uuid), event.timestamp)}`, + urls.absolute(urls.currentProject(urls.event(String(event.uuid), event.timestamp))), 'link to event' ) } diff --git a/frontend/src/scenes/notebooks/Notebook/NotebookShare.tsx b/frontend/src/scenes/notebooks/Notebook/NotebookShare.tsx index 68d4f03f5e30a..1a9233289616c 100644 --- a/frontend/src/scenes/notebooks/Notebook/NotebookShare.tsx +++ b/frontend/src/scenes/notebooks/Notebook/NotebookShare.tsx @@ -1,7 +1,6 @@ import { IconCopy } from '@posthog/icons' import { LemonBanner, LemonButton, LemonDivider } from '@posthog/lemon-ui' import { useValues } from 'kea' -import { combineUrl } from 'kea-router' import { LemonDialog } from 'lib/lemon-ui/LemonDialog' import { base64Encode } from 'lib/utils' import { copyToClipboard } from 'lib/utils/copyToClipboard' @@ -16,15 +15,14 @@ export type NotebookShareProps = { } export function NotebookShare({ shortId }: NotebookShareProps): JSX.Element { const { content, isLocalOnly } = useValues(notebookLogic({ shortId })) - const url = combineUrl(`${window.location.origin}${urls.notebook(shortId)}`).url - const canvasUrl = - combineUrl(`${window.location.origin}${urls.canvas()}`).url + `#🦔=${base64Encode(JSON.stringify(content))}` + const notebookUrl = urls.absolute(urls.currentProject(urls.notebook(shortId))) + const canvasUrl = urls.absolute(urls.canvas()) + `#🦔=${base64Encode(JSON.stringify(content))}` const [interestTracked, setInterestTracked] = useState(false) const trackInterest = (): void => { - posthog.capture('pressed interested in notebook sharing', { url }) + posthog.capture('pressed interested in notebook sharing', { url: notebookUrl }) } return ( @@ -41,10 +39,10 @@ export function NotebookShare({ shortId }: NotebookShareProps): JSX.Element { fullWidth center sideIcon={} - onClick={() => void copyToClipboard(url, 'notebook link')} - title={url} + onClick={() => void copyToClipboard(notebookUrl, 'notebook link')} + title={notebookUrl} > - {url} + {notebookUrl} @@ -66,7 +64,7 @@ export function NotebookShare({ shortId }: NotebookShareProps): JSX.Element { center sideIcon={} onClick={() => void copyToClipboard(canvasUrl, 'canvas link')} - title={url} + title={canvasUrl} > {canvasUrl} diff --git a/frontend/src/scenes/session-recordings/player/share/playerShareLogic.ts b/frontend/src/scenes/session-recordings/player/share/playerShareLogic.ts index 2b9689e813dbb..84db3f727749e 100644 --- a/frontend/src/scenes/session-recordings/player/share/playerShareLogic.ts +++ b/frontend/src/scenes/session-recordings/player/share/playerShareLogic.ts @@ -2,7 +2,6 @@ import { kea, key, path, props, selectors } from 'kea' import { forms } from 'kea-forms' import { combineUrl } from 'kea-router' import { colonDelimitedDuration, reverseColonDelimitedDuration } from 'lib/utils' -import { getCurrentTeamId } from 'lib/utils/getAppContext' import { urls } from 'scenes/urls' import type { playerShareLogicType } from './playerShareLogicType' @@ -45,8 +44,7 @@ export const playerShareLogic = kea([ url: [ (s) => [s.queryParams], (queryParams) => { - const path = urls.project(getCurrentTeamId(), urls.replaySingle(props.id)) - return combineUrl(`${window.location.origin}${path}`, queryParams).url + return combineUrl(urls.absolute(urls.currentProject(urls.replaySingle(props.id))), queryParams).url }, ], })), diff --git a/frontend/src/scenes/settings/settingsLogic.ts b/frontend/src/scenes/settings/settingsLogic.ts index f727e2a2dfe50..3120cff5d9af8 100644 --- a/frontend/src/scenes/settings/settingsLogic.ts +++ b/frontend/src/scenes/settings/settingsLogic.ts @@ -97,8 +97,12 @@ export const settingsLogic = kea([ listeners(({ values }) => ({ async selectSetting({ setting }) { - const url = urls.settings(values.selectedSectionId ?? values.selectedLevel, setting as SettingId) - await copyToClipboard(window.location.origin + url) + const url = urls.absolute( + urls.currentProject( + urls.settings(values.selectedSectionId ?? values.selectedLevel, setting as SettingId) + ) + ) + await copyToClipboard(url) }, })), ]) diff --git a/frontend/src/scenes/urls.ts b/frontend/src/scenes/urls.ts index 13262c0eb3656..3f4affdb4417c 100644 --- a/frontend/src/scenes/urls.ts +++ b/frontend/src/scenes/urls.ts @@ -1,5 +1,6 @@ import { combineUrl } from 'kea-router' import { toParams } from 'lib/utils' +import { getCurrentTeamId } from 'lib/utils/getAppContext' import { ExportOptions } from '~/exporter/types' import { HogQLFilters } from '~/queries/schema' @@ -33,9 +34,12 @@ import { SettingId, SettingLevelId, SettingSectionId } from './settings/types' * * Sync the paths with AutoProjectMiddleware! */ + export const urls = { + absolute: (path = ''): string => window.location.origin + path, default: (): string => '/', project: (id: string | number, path = ''): string => `/project/${id}` + path, + currentProject: (path = ''): string => urls.project(getCurrentTeamId(), path), dashboards: (): string => '/dashboard', dashboard: (id: string | number, highlightInsightId?: string): string => combineUrl(`/dashboard/${id}`, highlightInsightId ? { highlightInsightId } : {}).url,