Skip to content

Commit dfbf0a9

Browse files
authored
remove external page links from consolidated views (#5880)
1 parent b0e8c8b commit dfbf0a9

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

assets/js/dashboard/site-context.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function parseSiteFromDataset(dataset: DOMStringMap): PlausibleSite {
2929
// Update this object when new feature flags are added to the frontend.
3030
type FeatureFlags = Record<never, boolean>
3131

32-
const siteContextDefaultValue = {
32+
export const siteContextDefaultValue = {
3333
domain: '',
3434
/** offset in seconds from UTC at site load time, @example 7200 */
3535
offset: 0,

assets/js/dashboard/stats/behaviours/goal-conversions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function SpecialPropBreakdown({ prop, afterFetchData }) {
5151

5252
function getExternalLinkUrlFactory() {
5353
if (prop === 'path') {
54-
return (listItem) => url.externalLinkForPage(site.domain, listItem.name)
54+
return (listItem) => url.externalLinkForPage(site, listItem.name)
5555
} else if (prop === 'search_query') {
5656
return null // WP Search Queries should not become external links
5757
} else {

assets/js/dashboard/stats/pages/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function EntryPages({ afterFetchData }) {
2020
}
2121

2222
function getExternalLinkUrl(page) {
23-
return url.externalLinkForPage(site.domain, page.name)
23+
return url.externalLinkForPage(site, page.name)
2424
}
2525

2626
function getFilterInfo(listItem) {
@@ -66,7 +66,7 @@ function ExitPages({ afterFetchData }) {
6666
}
6767

6868
function getExternalLinkUrl(page) {
69-
return url.externalLinkForPage(site.domain, page.name)
69+
return url.externalLinkForPage(site, page.name)
7070
}
7171

7272
function getFilterInfo(listItem) {
@@ -112,7 +112,7 @@ function TopPages({ afterFetchData }) {
112112
}
113113

114114
function getExternalLinkUrl(page) {
115-
return url.externalLinkForPage(site.domain, page.name)
115+
return url.externalLinkForPage(site, page.name)
116116
}
117117

118118
function getFilterInfo(listItem) {

assets/js/dashboard/util/url.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { apiPath, externalLinkForPage, isValidHttpUrl, trimURL } from './url'
2+
import { siteContextDefaultValue } from '../site-context'
23

34
describe('apiPath', () => {
45
it.each([
@@ -32,10 +33,19 @@ describe('externalLinkForPage', () => {
3233
])(
3334
'when domain is %s and page is %s, it should return %s',
3435
(domain, page, expected) => {
35-
const result = externalLinkForPage(domain, page)
36+
const site = { ...siteContextDefaultValue, domain: domain }
37+
const result = externalLinkForPage(site, page)
3638
expect(result).toBe(expected)
3739
}
3840
)
41+
42+
it('returns null for consolidated view', () => {
43+
const consolidatedView = {
44+
...siteContextDefaultValue,
45+
isConsolidatedView: true
46+
}
47+
expect(externalLinkForPage(consolidatedView, '/some-page')).toBe(null)
48+
})
3949
})
4050

4151
describe('isValidHttpUrl', () => {

assets/js/dashboard/util/url.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ export function apiPath(
88
}
99

1010
export function externalLinkForPage(
11-
domain: PlausibleSite['domain'],
11+
site: PlausibleSite,
1212
page: string
1313
): string | null {
14+
if (site.isConsolidatedView) {
15+
return null
16+
}
17+
1418
try {
15-
const domainURL = new URL(`https://${domain}`)
19+
const domainURL = new URL(`https://${site.domain}`)
1620
return `https://${domainURL.host}${page}`
1721
} catch (_error) {
1822
return null

0 commit comments

Comments
 (0)