Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 assets/js/dashboard/site-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function parseSiteFromDataset(dataset: DOMStringMap): PlausibleSite {
// Update this object when new feature flags are added to the frontend.
type FeatureFlags = Record<never, boolean>

const siteContextDefaultValue = {
export const siteContextDefaultValue = {
domain: '',
/** offset in seconds from UTC at site load time, @example 7200 */
offset: 0,
Expand Down
2 changes: 1 addition & 1 deletion assets/js/dashboard/stats/behaviours/goal-conversions.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function SpecialPropBreakdown({ prop, afterFetchData }) {

function getExternalLinkUrlFactory() {
if (prop === 'path') {
return (listItem) => url.externalLinkForPage(site.domain, listItem.name)
return (listItem) => url.externalLinkForPage(site, listItem.name)
} else if (prop === 'search_query') {
return null // WP Search Queries should not become external links
} else {
Expand Down
6 changes: 3 additions & 3 deletions assets/js/dashboard/stats/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function EntryPages({ afterFetchData }) {
}

function getExternalLinkUrl(page) {
return url.externalLinkForPage(site.domain, page.name)
return url.externalLinkForPage(site, page.name)
}

function getFilterInfo(listItem) {
Expand Down Expand Up @@ -66,7 +66,7 @@ function ExitPages({ afterFetchData }) {
}

function getExternalLinkUrl(page) {
return url.externalLinkForPage(site.domain, page.name)
return url.externalLinkForPage(site, page.name)
}

function getFilterInfo(listItem) {
Expand Down Expand Up @@ -112,7 +112,7 @@ function TopPages({ afterFetchData }) {
}

function getExternalLinkUrl(page) {
return url.externalLinkForPage(site.domain, page.name)
return url.externalLinkForPage(site, page.name)
}

function getFilterInfo(listItem) {
Expand Down
12 changes: 11 additions & 1 deletion assets/js/dashboard/util/url.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { apiPath, externalLinkForPage, isValidHttpUrl, trimURL } from './url'
import { siteContextDefaultValue } from '../site-context'

describe('apiPath', () => {
it.each([
Expand Down Expand Up @@ -32,10 +33,19 @@ describe('externalLinkForPage', () => {
])(
'when domain is %s and page is %s, it should return %s',
(domain, page, expected) => {
const result = externalLinkForPage(domain, page)
const site = { ...siteContextDefaultValue, domain: domain }
const result = externalLinkForPage(site, page)
expect(result).toBe(expected)
}
)

it('returns null for consolidated view', () => {
const consolidatedView = {
...siteContextDefaultValue,
isConsolidatedView: true
}
expect(externalLinkForPage(consolidatedView, '/some-page')).toBe(null)
})
})

describe('isValidHttpUrl', () => {
Expand Down
8 changes: 6 additions & 2 deletions assets/js/dashboard/util/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ export function apiPath(
}

export function externalLinkForPage(
domain: PlausibleSite['domain'],
site: PlausibleSite,
page: string
): string | null {
if (site.isConsolidatedView) {
return null
}

try {
const domainURL = new URL(`https://${domain}`)
const domainURL = new URL(`https://${site.domain}`)
return `https://${domainURL.host}${page}`
} catch (_error) {
return null
Expand Down
Loading