@@ -9,21 +9,11 @@ import {
99 parseUTCDate ,
1010 isAfter
1111} from './util/date'
12- import {
13- FILTER_OPERATIONS ,
14- getFiltersByKeyPrefix ,
15- parseLegacyFilter ,
16- parseLegacyPropsFilter
17- } from './util/filters'
12+ import { FILTER_OPERATIONS , getFiltersByKeyPrefix } from './util/filters'
1813import { PlausibleSite } from './site-context'
1914import { ComparisonMode , QueryPeriod } from './query-time-periods'
2015import { AppNavigationTarget } from './navigation/use-app-navigate'
2116import { Dayjs } from 'dayjs'
22- import { legacyParseSearch } from './util/legacy-jsonurl-url-search-params'
23- import {
24- FILTER_URL_PARAM_NAME ,
25- stringifySearch
26- } from './util/url-search-params'
2717
2818export type FilterClause = string | number
2919
@@ -71,29 +61,6 @@ export function addFilter(
7161 return { ...query , filters : [ ...query . filters , filter ] }
7262}
7363
74- const LEGACY_URL_PARAMETERS = {
75- goal : null ,
76- source : null ,
77- utm_medium : null ,
78- utm_source : null ,
79- utm_campaign : null ,
80- utm_content : null ,
81- utm_term : null ,
82- referrer : null ,
83- screen : null ,
84- browser : null ,
85- browser_version : null ,
86- os : null ,
87- os_version : null ,
88- country : 'country_labels' ,
89- region : 'region_labels' ,
90- city : 'city_labels' ,
91- page : null ,
92- hostname : null ,
93- entry_page : null ,
94- exit_page : null
95- }
96-
9764export function postProcessFilters ( filters : Array < Filter > ) : Array < Filter > {
9865 return filters . map ( ( [ operation , dimension , clauses ] ) => {
9966 // Rename old name of the operation
@@ -104,79 +71,6 @@ export function postProcessFilters(filters: Array<Filter>): Array<Filter> {
10471 } )
10572}
10673
107- export function maybeGetRedirectTargetFromLegacySearchParams (
108- windowLocation : Location
109- ) : null | string {
110- const searchParams = new URLSearchParams ( windowLocation . search )
111- const isCurrentVersion = searchParams . get ( FILTER_URL_PARAM_NAME )
112- if ( isCurrentVersion ) {
113- return null
114- }
115-
116- const isJsonURLVersion = searchParams . get ( 'filters' )
117- if ( isJsonURLVersion ) {
118- return `${ windowLocation . pathname } ${ stringifySearch ( legacyParseSearch ( windowLocation . search ) ) } `
119- }
120-
121- const searchRecord = legacyParseSearch ( windowLocation . search )
122- const searchRecordEntries = Object . entries (
123- legacyParseSearch ( windowLocation . search )
124- )
125-
126- const isBeforeJsonURLVersion = searchRecordEntries . some (
127- ( [ k ] ) => k === 'props' || LEGACY_URL_PARAMETERS . hasOwnProperty ( k )
128- )
129-
130- if ( ! isBeforeJsonURLVersion ) {
131- return null
132- }
133-
134- const changedSearchRecordEntries = [ ]
135- const filters : DashboardQuery [ 'filters' ] = [ ]
136- let labels : DashboardQuery [ 'labels' ] = { }
137-
138- for ( const [ key , value ] of searchRecordEntries ) {
139- if ( LEGACY_URL_PARAMETERS . hasOwnProperty ( key ) ) {
140- const filter = parseLegacyFilter ( key , value ) as Filter
141- filters . push ( filter )
142- const labelsKey : string | null | undefined =
143- LEGACY_URL_PARAMETERS [ key as keyof typeof LEGACY_URL_PARAMETERS ]
144- if ( labelsKey && searchRecord [ labelsKey ] ) {
145- const clauses = filter [ 2 ]
146- const labelsValues = ( searchRecord [ labelsKey ] as string )
147- . split ( '|' )
148- . filter ( ( label ) => ! ! label )
149- const newLabels = Object . fromEntries (
150- clauses . map ( ( clause , index ) => [ clause , labelsValues [ index ] ] )
151- )
152-
153- labels = Object . assign ( labels , newLabels )
154- }
155- } else {
156- changedSearchRecordEntries . push ( [ key , value ] )
157- }
158- }
159-
160- if ( searchRecord [ 'props' ] ) {
161- filters . push ( ...( parseLegacyPropsFilter ( searchRecord [ 'props' ] ) as Filter [ ] ) )
162- }
163- changedSearchRecordEntries . push ( [ 'filters' , filters ] , [ 'labels' , labels ] )
164- return `${ windowLocation . pathname } ${ stringifySearch ( Object . fromEntries ( changedSearchRecordEntries ) ) } `
165- }
166-
167- /** Called once before React app mounts. If legacy url search params are present, does a redirect to new format. */
168- export function filtersBackwardsCompatibilityRedirect (
169- windowLocation : Location ,
170- windowHistory : History
171- ) {
172- const redirectTargetURL =
173- maybeGetRedirectTargetFromLegacySearchParams ( windowLocation )
174- if ( redirectTargetURL === null ) {
175- return
176- }
177- windowHistory . pushState ( { } , '' , redirectTargetURL )
178- }
179-
18074// Returns a boolean indicating whether the given query includes a
18175// non-empty goal filterset containing a single, or multiple revenue
18276// goals with the same currency. Used to decide whether to render
0 commit comments