Skip to content

Commit

Permalink
Fix routes not opening that take dynamic route params when the param …
Browse files Browse the repository at this point in the history
…contains forward slash (plausible#4824)
  • Loading branch information
apata authored Nov 14, 2024
1 parent b0933e1 commit d187e59
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.

- Fix returning filter suggestions for multiple custom property values in the dashboard Filter modal
- Fix typo on login screen
- Fix Direct / None details modal not opening

## v2.1.4 - 2024-10-08

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 @@ -72,7 +72,7 @@ function SpecialPropBreakdown({ prop, afterFetchData }) {
getFilterFor={getFilterFor}
keyLabel={prop}
metrics={chooseMetrics()}
detailsLinkProps={{ path: customPropsRoute.path, params: {propKey: prop}, search: (search) => search }}
detailsLinkProps={{ path: customPropsRoute.path, params: {propKey: url.maybeEncodeRouteParam(prop)}, search: (search) => search }}
externalLinkDest={externalLinkDest()}
maybeHideDetails={true}
color="bg-red-50"
Expand Down
2 changes: 1 addition & 1 deletion assets/js/dashboard/stats/modals/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function PropsModal() {
const reportInfo = {
title: specialTitleWhenGoalFilter(query, 'Custom Property Breakdown'),
dimension: propKey,
endpoint: url.apiPath(site, `/custom-prop-values/${propKey}`),
endpoint: url.apiPath(site, `/custom-prop-values/${url.maybeEncodeRouteParam(propKey)}`),
dimensionLabel: propKey,
defaultOrder: ["visitors", SortDirection.desc]
}
Expand Down
3 changes: 2 additions & 1 deletion assets/js/dashboard/stats/modals/referrer-drilldown.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ function ReferrerDrilldownModal() {
const reportInfo = {
title: "Referrer Drilldown",
dimension: 'referrer',
endpoint: url.apiPath(site, `/referrers/${referrer}`),
endpoint: url.apiPath(site, `/referrers/${url.maybeEncodeRouteParam(referrer)}`
),
dimensionLabel: "Referrer",
defaultOrder: ["visitors", SortDirection.desc]
}
Expand Down
8 changes: 5 additions & 3 deletions assets/js/dashboard/stats/sources/referrer-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { useQueryContext } from '../../query-context';
import { useSiteContext } from '../../site-context';
import { referrersDrilldownRoute } from '../../router';

const NO_REFERRER = 'Direct / None'

export default function Referrers({ source }) {
const { query } = useQueryContext();
const site = useSiteContext()
Expand All @@ -27,12 +29,12 @@ export default function Referrers({ source }) {
}

function externalLinkDest(referrer) {
if (referrer.name === 'Direct / None') { return null }
if (referrer.name === NO_REFERRER) { return null }
return `https://${referrer.name}`
}

function getFilterFor(referrer) {
if (referrer.name === 'Direct / None') { return null }
if (referrer.name === NO_REFERRER) { return null }

return {
prefix: 'referrer',
Expand Down Expand Up @@ -70,7 +72,7 @@ export default function Referrers({ source }) {
getFilterFor={getFilterFor}
keyLabel="Referrer"
metrics={chooseMetrics()}
detailsLinkProps={{ path: referrersDrilldownRoute.path, params: {referrer: source}, search: (search) => search }}
detailsLinkProps={{ path: referrersDrilldownRoute.path, params: {referrer: url.maybeEncodeRouteParam(source)}, search: (search) => search }}
externalLinkDest={externalLinkDest}
renderIcon={renderIcon}
color="bg-blue-50"
Expand Down
4 changes: 4 additions & 0 deletions assets/js/dashboard/util/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,7 @@ export function parseSearch(searchString: string): Record<string, unknown> {
urlSearchParams.forEach((v, k) => (searchRecord[k] = parseSearchFragment(v)))
return searchRecord
}

export function maybeEncodeRouteParam(param: string) {
return param.includes('/') ? encodeURIComponent(param) : param
}

0 comments on commit d187e59

Please sign in to comment.