11/** @format */
22import { Filter , FilterClauseLabels } from '../query'
33
4+ /**
5+ * These charcters are not URL encoded to have more readable URLs.
6+ * Browsers seem to handle this just fine.
7+ * `?f=is,page,/my/page/:some_param` vs `?f=is,page,%2Fmy%2Fpage%2F%3Asome_param``
8+ */
9+ const NOT_URL_ENCODED_CHARACTERS = ':/'
10+
11+ export const FILTER_URL_PARAM_NAME = 'f'
12+
13+ const LABEL_URL_PARAM_NAME = 'l'
14+
415/**
516 * This function is able to serialize for URL simple params @see serializeSimpleSearchEntry as well
617 * two complex params, labels and filters.
@@ -94,7 +105,7 @@ export function parseSearch(searchString: string): Record<string, unknown> {
94105 * ["5391959","San Francisco"] -> "5391959,San%20Francisco"
95106 */
96107export function serializeLabelsEntry ( [ labelKey , labelValue ] : [ string , string ] ) {
97- return `${ encodeURIComponentPermissive ( labelKey , ':/' ) } ,${ encodeURIComponentPermissive ( labelValue , ':/' ) } `
108+ return `${ encodeURIComponentPermissive ( labelKey , NOT_URL_ENCODED_CHARACTERS ) } ,${ encodeURIComponentPermissive ( labelValue , NOT_URL_ENCODED_CHARACTERS ) } `
98109}
99110
100111/**
@@ -114,10 +125,13 @@ export function parseLabelsEntry(
114125 */
115126export function serializeFilter ( [ operator , dimension , clauses ] : Filter ) {
116127 const serializedFilter = [
117- encodeURIComponentPermissive ( operator , ':/' ) ,
118- encodeURIComponentPermissive ( dimension , ':/' ) ,
128+ encodeURIComponentPermissive ( operator , NOT_URL_ENCODED_CHARACTERS ) ,
129+ encodeURIComponentPermissive ( dimension , NOT_URL_ENCODED_CHARACTERS ) ,
119130 ...clauses . map ( ( clause ) =>
120- encodeURIComponentPermissive ( clause . toString ( ) , ':/' )
131+ encodeURIComponentPermissive (
132+ clause . toString ( ) ,
133+ NOT_URL_ENCODED_CHARACTERS
134+ )
121135 )
122136 ] . join ( ',' )
123137 return serializedFilter
@@ -189,6 +203,3 @@ export function isSearchEntryDefined(
189203) : entry is [ string , string ] {
190204 return entry [ 1 ] !== undefined
191205}
192-
193- export const FILTER_URL_PARAM_NAME = 'f'
194- const LABEL_URL_PARAM_NAME = 'l'
0 commit comments