Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Absolute urls didn't contain project url #21209

Merged
merged 4 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/src/queries/nodes/DataTable/EventRowActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
}
Expand Down
14 changes: 6 additions & 8 deletions frontend/src/scenes/notebooks/Notebook/NotebookShare.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -16,15 +15,14 @@
}
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 (
Expand All @@ -41,10 +39,10 @@
fullWidth
center
sideIcon={<IconCopy />}
onClick={() => void copyToClipboard(url, 'notebook link')}
title={url}
onClick={() => void copyToClipboard(notebookUrl, 'notebook link')}
title={notebookUrl}
>
<span className="truncate">{url}</span>
<span className="truncate">{notebookUrl}</span>
</LemonButton>

<LemonDivider className="my-4" />
Expand All @@ -66,7 +64,7 @@
center
sideIcon={<IconCopy />}
onClick={() => void copyToClipboard(canvasUrl, 'canvas link')}
title={url}

Check failure on line 67 in frontend/src/scenes/notebooks/Notebook/NotebookShare.tsx

View workflow job for this annotation

GitHub Actions / Code quality checks

Cannot find name 'url'. Did you mean 'urls'?
>
<span className="truncate">{canvasUrl}</span>
</LemonButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -45,8 +44,7 @@ export const playerShareLogic = kea<playerShareLogicType>([
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
},
],
})),
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/scenes/settings/settingsLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,12 @@ export const settingsLogic = kea<settingsLogicType>([

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)
},
})),
])
4 changes: 4 additions & 0 deletions frontend/src/scenes/urls.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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,
Expand Down
Loading