@@ -6,24 +6,12 @@ import Bar from '../bar'
6
6
import numberFormatter from '../../util/number-formatter'
7
7
import * as api from '../../api'
8
8
import Money from './money'
9
+ import { isValidHttpUrl , trimURL } from '../../util/url'
9
10
10
11
const MOBILE_UPPER_WIDTH = 767
11
12
const DEFAULT_WIDTH = 1080
12
13
const BREAKDOWN_LIMIT = 100
13
14
14
- // https://stackoverflow.com/a/43467144
15
- function isValidHttpUrl ( string ) {
16
- let url ;
17
-
18
- try {
19
- url = new URL ( string ) ;
20
- } catch ( _ ) {
21
- return false ;
22
- }
23
-
24
- return url . protocol === "http:" || url . protocol === "https:" ;
25
- }
26
-
27
15
export default class PropertyBreakdown extends React . Component {
28
16
constructor ( props ) {
29
17
super ( props )
@@ -72,10 +60,10 @@ export default class PropertyBreakdown extends React.Component {
72
60
this . setState ( { viewport : window . innerWidth } ) ;
73
61
}
74
62
75
- fetch ( { concat} ) {
63
+ fetch ( { concat } ) {
76
64
if ( ! this . props . query . filters [ 'goal' ] ) return
77
65
78
- api . get ( `/api/stats/${ encodeURIComponent ( this . props . site . domain ) } /property/${ encodeURIComponent ( this . state . propKey ) } ` , this . props . query , { limit : BREAKDOWN_LIMIT , page : this . state . page } )
66
+ api . get ( `/api/stats/${ encodeURIComponent ( this . props . site . domain ) } /property/${ encodeURIComponent ( this . state . propKey ) } ` , this . props . query , { limit : BREAKDOWN_LIMIT , page : this . state . page } )
79
67
. then ( ( res ) => {
80
68
let breakdown = concat ? this . state . breakdown . concat ( res ) : res
81
69
@@ -88,15 +76,15 @@ export default class PropertyBreakdown extends React.Component {
88
76
}
89
77
90
78
fetchAndReplace ( ) {
91
- this . fetch ( { concat : false } )
79
+ this . fetch ( { concat : false } )
92
80
}
93
81
94
82
fetchAndConcat ( ) {
95
- this . fetch ( { concat : true } )
83
+ this . fetch ( { concat : true } )
96
84
}
97
85
98
86
loadMore ( ) {
99
- this . setState ( { loading : true , page : this . state . page + 1 } , this . fetchAndConcat . bind ( this ) )
87
+ this . setState ( { loading : true , page : this . state . page + 1 } , this . fetchAndConcat . bind ( this ) )
100
88
}
101
89
102
90
renderUrl ( value ) {
@@ -114,24 +102,24 @@ export default class PropertyBreakdown extends React.Component {
114
102
return (
115
103
< span className = "flex px-2 py-1.5 group dark:text-gray-300 relative z-9 break-all" >
116
104
< Link
117
- to = { { pathname : window . location . pathname , search : query . toString ( ) } }
105
+ to = { { pathname : window . location . pathname , search : query . toString ( ) } }
118
106
className = "md:truncate hover:underline block"
119
107
>
120
- { value . name }
108
+ { trimURL ( value . name , 100 ) }
121
109
</ Link >
122
- { this . renderUrl ( value ) }
110
+ { this . renderUrl ( value ) }
123
111
</ span >
124
112
)
125
113
}
126
114
127
115
renderPropValue ( value ) {
128
116
const query = new URLSearchParams ( window . location . search )
129
- query . set ( 'props' , JSON . stringify ( { [ this . state . propKey ] : value . name } ) )
117
+ query . set ( 'props' , JSON . stringify ( { [ this . state . propKey ] : value . name } ) )
130
118
const { viewport } = this . state ;
131
119
132
120
return (
133
121
< div className = "flex items-center justify-between my-2" key = { value . name } >
134
- < div className = "flex-1" >
122
+ < div className = "flex-1 truncate " >
135
123
< Bar
136
124
count = { value . unique_conversions }
137
125
plot = "unique_conversions"
@@ -141,17 +129,17 @@ export default class PropertyBreakdown extends React.Component {
141
129
{ this . renderPropContent ( value , query ) }
142
130
</ Bar >
143
131
</ div >
144
- < div className = "dark:text-gray-200" >
132
+ < div className = "flex dark:text-gray-200" >
145
133
< span className = "font-medium inline-block w-20 text-right" > { numberFormatter ( value . unique_conversions ) } </ span >
146
134
{
147
135
viewport > MOBILE_UPPER_WIDTH ?
148
- (
149
- < span
150
- className = "font-medium inline-block w-20 text-right"
151
- > { numberFormatter ( value . total_conversions ) }
152
- </ span >
153
- )
154
- : null
136
+ (
137
+ < span
138
+ className = "font-medium inline-block w-20 text-right"
139
+ > { numberFormatter ( value . total_conversions ) }
140
+ </ span >
141
+ )
142
+ : null
155
143
}
156
144
< span className = "font-medium inline-block w-20 text-right" > { numberFormatter ( value . conversion_rate ) } %</ span >
157
145
{ this . props . renderRevenueColumn && < span className = "hidden md:inline-block md:w-20 font-medium text-right" > < Money formatted = { value . total_revenue } /> </ span > }
@@ -163,7 +151,7 @@ export default class PropertyBreakdown extends React.Component {
163
151
164
152
changePropKey ( newKey ) {
165
153
storage . setItem ( this . storageKey , newKey )
166
- this . setState ( { propKey : newKey , loading : true , breakdown : [ ] , page : 1 , moreResultsAvailable : false } , this . fetchAndReplace )
154
+ this . setState ( { propKey : newKey , loading : true , breakdown : [ ] , page : 1 , moreResultsAvailable : false } , this . fetchAndReplace )
167
155
}
168
156
169
157
renderLoading ( ) {
@@ -200,11 +188,11 @@ export default class PropertyBreakdown extends React.Component {
200
188
< div className = "flex-col sm:flex-row flex items-center pb-1" >
201
189
< span className = "text-xs font-bold text-gray-600 dark:text-gray-300 self-start sm:self-auto mb-1 sm:mb-0" > Breakdown by:</ span >
202
190
< ul className = "flex flex-wrap font-medium text-xs text-gray-500 dark:text-gray-400 leading-5 pl-1 sm:pl-2" >
203
- { this . props . goal . prop_names . map ( this . renderPill . bind ( this ) ) }
191
+ { this . props . goal . prop_names . map ( this . renderPill . bind ( this ) ) }
204
192
</ ul >
205
193
</ div >
206
- { this . renderBody ( ) }
207
- { this . renderLoading ( ) }
194
+ { this . renderBody ( ) }
195
+ { this . renderLoading ( ) }
208
196
</ div >
209
197
)
210
198
}
0 commit comments