diff --git a/CHANGELOG.md b/CHANGELOG.md index 0edbc5169..0e6755196 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file. ### Fixed - Fixed weekly/monthly e-mail report [rendering issues](https://github.com/plausible/analytics/issues/284) +- Fixed [long URLs display](https://github.com/plausible/analytics/issues/3158) in Outbound Link breakdown view ## v2.0.0 - 2023-07-12 diff --git a/assets/js/dashboard/stats/behaviours/prop-breakdown.js b/assets/js/dashboard/stats/behaviours/prop-breakdown.js index 9fc60a910..764b441f8 100644 --- a/assets/js/dashboard/stats/behaviours/prop-breakdown.js +++ b/assets/js/dashboard/stats/behaviours/prop-breakdown.js @@ -6,24 +6,12 @@ import Bar from '../bar' import numberFormatter from '../../util/number-formatter' import * as api from '../../api' import Money from './money' +import { isValidHttpUrl, trimURL } from '../../util/url' const MOBILE_UPPER_WIDTH = 767 const DEFAULT_WIDTH = 1080 const BREAKDOWN_LIMIT = 100 -// https://stackoverflow.com/a/43467144 -function isValidHttpUrl(string) { - let url; - - try { - url = new URL(string); - } catch (_) { - return false; - } - - return url.protocol === "http:" || url.protocol === "https:"; -} - export default class PropertyBreakdown extends React.Component { constructor(props) { super(props) @@ -72,10 +60,10 @@ export default class PropertyBreakdown extends React.Component { this.setState({ viewport: window.innerWidth }); } - fetch({concat}) { + fetch({ concat }) { if (!this.props.query.filters['goal']) return - api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/property/${encodeURIComponent(this.state.propKey)}`, this.props.query, {limit: BREAKDOWN_LIMIT, page: this.state.page}) + api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/property/${encodeURIComponent(this.state.propKey)}`, this.props.query, { limit: BREAKDOWN_LIMIT, page: this.state.page }) .then((res) => { let breakdown = concat ? this.state.breakdown.concat(res) : res @@ -88,15 +76,15 @@ export default class PropertyBreakdown extends React.Component { } fetchAndReplace() { - this.fetch({concat: false}) + this.fetch({ concat: false }) } fetchAndConcat() { - this.fetch({concat: true}) + this.fetch({ concat: true }) } loadMore() { - this.setState({loading: true, page: this.state.page + 1}, this.fetchAndConcat.bind(this)) + this.setState({ loading: true, page: this.state.page + 1 }, this.fetchAndConcat.bind(this)) } renderUrl(value) { @@ -114,24 +102,24 @@ export default class PropertyBreakdown extends React.Component { return ( - { value.name } + {trimURL(value.name, 100)} - { this.renderUrl(value) } + {this.renderUrl(value)} ) } renderPropValue(value) { const query = new URLSearchParams(window.location.search) - query.set('props', JSON.stringify({[this.state.propKey]: value.name})) + query.set('props', JSON.stringify({ [this.state.propKey]: value.name })) const { viewport } = this.state; return (