@grafana/scenes 5.18.0 → 5.18.2

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # v5.18.2 (Mon Oct 07 2024)
2
+
3
+ #### 🐛 Bug Fix
4
+
5
+ - Interpolation: Fixes queryparam variable format when used with adhoc filter variable [#931](https://github.com/grafana/scenes/pull/931) ([@torkelo](https://github.com/torkelo))
6
+
7
+ #### Authors: 1
8
+
9
+ - Torkel Ödegaard ([@torkelo](https://github.com/torkelo))
10
+
11
+ ---
12
+
1
13
  # v5.18.0 (Fri Oct 04 2024)
2
14
 
3
15
  #### 🚀 Enhancement
@@ -1,5 +1,5 @@
1
1
  import { map, isArray, replace } from 'lodash';
2
- import { Registry, escapeRegex, textUtil, dateTime } from '@grafana/data';
2
+ import { Registry, escapeRegex, textUtil, dateTime, urlUtil } from '@grafana/data';
3
3
  import { VariableFormatID } from '@grafana/schema';
4
4
 
5
5
  const formatRegistry = new Registry(() => {
@@ -230,6 +230,10 @@ const formatRegistry = new Registry(() => {
230
230
  name: "Query parameter",
231
231
  description: "Format variables as URL parameters. Example in multi-variable scenario A + B + C => var-foo=A&var-foo=B&var-foo=C.",
232
232
  formatter: (value, _args, variable) => {
233
+ if (variable.urlSync) {
234
+ const urlParam = variable.urlSync.getUrlState();
235
+ return urlUtil.toUrlParams(urlParam);
236
+ }
233
237
  if (Array.isArray(value)) {
234
238
  return value.map((v) => formatQueryParameter(variable.state.name, v)).join("&");
235
239
  }
@@ -1 +1 @@
1
- {"version":3,"file":"formatRegistry.js","sources":["../../../../src/variables/interpolation/formatRegistry.ts"],"sourcesContent":["import { isArray, map, replace } from 'lodash';\n\nimport { dateTime, Registry, RegistryItem, textUtil, escapeRegex } from '@grafana/data';\nimport { VariableType, VariableFormatID } from '@grafana/schema';\n\nimport { VariableValue, VariableValueSingle } from '../types';\nimport { ALL_VARIABLE_VALUE } from '../constants';\n\nexport interface FormatRegistryItem extends RegistryItem {\n formatter(value: VariableValue, args: string[], variable: FormatVariable): string;\n}\n\n/**\n * Slimmed down version of the SceneVariable interface so that it only contains what the formatters actually use.\n * This is useful as we have some implementations of this interface that does not need to be full scene objects.\n * For example ScopedVarsVariable and LegacyVariableWrapper.\n */\nexport interface FormatVariable {\n state: {\n name: string;\n type: VariableType | string;\n isMulti?: boolean;\n includeAll?: boolean;\n };\n\n getValue(fieldPath?: string): VariableValue | undefined | null;\n getValueText?(fieldPath?: string): string;\n}\n\nexport const formatRegistry = new Registry<FormatRegistryItem>(() => {\n const formats: FormatRegistryItem[] = [\n {\n id: VariableFormatID.Lucene,\n name: 'Lucene',\n description: 'Values are lucene escaped and multi-valued variables generate an OR expression',\n formatter: (value) => {\n if (typeof value === 'string') {\n return luceneEscape(value);\n }\n\n if (Array.isArray(value)) {\n if (value.length === 0) {\n return '__empty__';\n }\n const quotedValues = map(value, (val: string) => {\n return '\"' + luceneEscape(val) + '\"';\n });\n return '(' + quotedValues.join(' OR ') + ')';\n } else {\n return luceneEscape(`${value}`);\n }\n },\n },\n {\n id: VariableFormatID.Raw,\n name: 'raw',\n description: 'Keep value as is',\n formatter: (value) => String(value),\n },\n {\n id: VariableFormatID.Regex,\n name: 'Regex',\n description: 'Values are regex escaped and multi-valued variables generate a (<value>|<value>) expression',\n formatter: (value) => {\n if (typeof value === 'string') {\n return escapeRegex(value);\n }\n\n if (Array.isArray(value)) {\n const escapedValues = value.map((item) => {\n if (typeof item === 'string') {\n return escapeRegex(item);\n } else {\n return escapeRegex(String(item));\n }\n });\n\n if (escapedValues.length === 1) {\n return escapedValues[0];\n }\n\n return '(' + escapedValues.join('|') + ')';\n }\n\n return escapeRegex(`${value}`);\n },\n },\n {\n id: VariableFormatID.Pipe,\n name: 'Pipe',\n description: 'Values are separated by | character',\n formatter: (value) => {\n if (typeof value === 'string') {\n return value;\n }\n\n if (Array.isArray(value)) {\n return value.join('|');\n }\n\n return `${value}`;\n },\n },\n {\n id: VariableFormatID.Distributed,\n name: 'Distributed',\n description: 'Multiple values are formatted like variable=value',\n formatter: (value, args, variable) => {\n if (typeof value === 'string') {\n return value;\n }\n\n if (Array.isArray(value)) {\n value = map(value, (val: string, index: number) => {\n if (index !== 0) {\n return variable.state.name + '=' + val;\n } else {\n return val;\n }\n });\n\n return value.join(',');\n }\n\n return `${value}`;\n },\n },\n {\n id: VariableFormatID.CSV,\n name: 'Csv',\n description: 'Comma-separated values',\n formatter: (value) => {\n if (typeof value === 'string') {\n return value;\n }\n\n if (isArray(value)) {\n return value.join(',');\n }\n\n return String(value);\n },\n },\n {\n id: VariableFormatID.HTML,\n name: 'HTML',\n description: 'HTML escaping of values',\n formatter: (value) => {\n if (typeof value === 'string') {\n return textUtil.escapeHtml(value);\n }\n\n if (isArray(value)) {\n return textUtil.escapeHtml(value.join(', '));\n }\n\n return textUtil.escapeHtml(String(value));\n },\n },\n {\n id: VariableFormatID.JSON,\n name: 'JSON',\n description: 'JSON stringify value',\n formatter: (value) => {\n if (typeof value === 'string') {\n return value;\n }\n return JSON.stringify(value);\n },\n },\n {\n id: VariableFormatID.PercentEncode,\n name: 'Percent encode',\n description: 'Useful for URL escaping values',\n formatter: (value) => {\n // like glob, but url escaped\n if (isArray(value)) {\n return encodeURIComponentStrict('{' + value.join(',') + '}');\n }\n\n return encodeURIComponentStrict(value);\n },\n },\n {\n id: VariableFormatID.SingleQuote,\n name: 'Single quote',\n description: 'Single quoted values',\n formatter: (value) => {\n // escape single quotes with backslash\n const regExp = new RegExp(`'`, 'g');\n\n if (isArray(value)) {\n return map(value, (v: string) => `'${replace(v, regExp, `\\\\'`)}'`).join(',');\n }\n\n let strVal = typeof value === 'string' ? value : String(value);\n return `'${replace(strVal, regExp, `\\\\'`)}'`;\n },\n },\n {\n id: VariableFormatID.DoubleQuote,\n name: 'Double quote',\n description: 'Double quoted values',\n formatter: (value) => {\n // escape double quotes with backslash\n const regExp = new RegExp('\"', 'g');\n if (isArray(value)) {\n return map(value, (v: string) => `\"${replace(v, regExp, '\\\\\"')}\"`).join(',');\n }\n\n let strVal = typeof value === 'string' ? value : String(value);\n return `\"${replace(strVal, regExp, '\\\\\"')}\"`;\n },\n },\n {\n id: VariableFormatID.SQLString,\n name: 'SQL string',\n description: 'SQL string quoting and commas for use in IN statements and other scenarios',\n formatter: sqlStringFormatter,\n },\n {\n id: VariableFormatID.Date,\n name: 'Date',\n description: 'Format date in different ways',\n formatter: (value, args) => {\n let nrValue = NaN;\n\n if (typeof value === 'number') {\n nrValue = value;\n } else if (typeof value === 'string') {\n nrValue = parseInt(value, 10);\n }\n\n if (isNaN(nrValue)) {\n return 'NaN';\n }\n\n const arg = args[0] ?? 'iso';\n switch (arg) {\n case 'ms':\n return String(value);\n case 'seconds':\n return `${Math.round(nrValue! / 1000)}`;\n case 'iso':\n return dateTime(nrValue).toISOString();\n default:\n if ((args || []).length > 1) {\n return dateTime(nrValue).format(args.join(':'));\n }\n return dateTime(nrValue).format(arg);\n }\n },\n },\n {\n id: VariableFormatID.Glob,\n name: 'Glob',\n description: 'Format multi-valued variables using glob syntax, example {value1,value2}',\n formatter: (value) => {\n if (isArray(value) && value.length > 1) {\n return '{' + value.join(',') + '}';\n }\n return String(value);\n },\n },\n {\n id: VariableFormatID.Text,\n name: 'Text',\n description: 'Format variables in their text representation. Example in multi-variable scenario A + B + C.',\n formatter: (value, _args, variable) => {\n if (variable.getValueText) {\n return variable.getValueText();\n }\n\n return String(value);\n },\n },\n {\n id: VariableFormatID.QueryParam,\n name: 'Query parameter',\n description:\n 'Format variables as URL parameters. Example in multi-variable scenario A + B + C => var-foo=A&var-foo=B&var-foo=C.',\n formatter: (value, _args, variable) => {\n if (Array.isArray(value)) {\n return value.map((v) => formatQueryParameter(variable.state.name, v)).join('&');\n }\n return formatQueryParameter(variable.state.name, value);\n },\n },\n {\n id: VariableFormatID.UriEncode,\n name: 'Percent encode as URI',\n description: 'Useful for URL escaping values, taking into URI syntax characters',\n formatter: (value: VariableValue) => {\n if (isArray(value)) {\n return encodeURIStrict('{' + value.join(',') + '}');\n }\n\n return encodeURIStrict(value);\n },\n },\n ];\n\n return formats;\n});\n\nfunction luceneEscape(value: string) {\n if (isNaN(+value) === false) {\n return value;\n }\n\n return value.replace(/([\\!\\*\\+\\-\\=<>\\s\\&\\|\\(\\)\\[\\]\\{\\}\\^\\~\\?\\:\\\\/\"])/g, '\\\\$1');\n}\n\n/**\n * encode string according to RFC 3986; in contrast to encodeURIComponent()\n * also the sub-delims \"!\", \"'\", \"(\", \")\" and \"*\" are encoded;\n * unicode handling uses UTF-8 as in ECMA-262.\n */\nfunction encodeURIComponentStrict(str: VariableValueSingle) {\n if (typeof str === 'object') {\n str = String(str);\n }\n\n return replaceSpecialCharactersToASCII(encodeURIComponent(str));\n}\n\nconst encodeURIStrict = (str: VariableValueSingle): string => replaceSpecialCharactersToASCII(encodeURI(String(str)));\n\nconst replaceSpecialCharactersToASCII = (value: string): string =>\n value.replace(/[!'()*]/g, (c) => {\n return '%' + c.charCodeAt(0).toString(16).toUpperCase();\n });\n\nfunction formatQueryParameter(name: string, value: VariableValueSingle): string {\n return `var-${name}=${encodeURIComponentStrict(value)}`;\n}\n\nexport function isAllValue(value: VariableValueSingle) {\n return value === ALL_VARIABLE_VALUE || (Array.isArray(value) && value[0] === ALL_VARIABLE_VALUE);\n}\n\nconst SQL_ESCAPE_MAP: Record<string, string> = {\n \"'\": \"''\",\n '\"': '\\\\\"',\n};\n\nfunction sqlStringFormatter(value: VariableValue) {\n // escape single quotes by pairing them\n const regExp = new RegExp(`'|\"`, 'g');\n\n if (isArray(value)) {\n return map(value, (v: string) => `'${replace(v, regExp, (match) => SQL_ESCAPE_MAP[match] ?? '')}'`).join(',');\n }\n\n let strVal = typeof value === 'string' ? value : String(value);\n return `'${replace(strVal, regExp, (match) => SQL_ESCAPE_MAP[match] ?? '')}'`;\n}\n"],"names":[],"mappings":";;;;AA6Ba,MAAA,cAAA,GAAiB,IAAI,QAAA,CAA6B,MAAM;AACnE,EAAA,MAAM,OAAgC,GAAA;AAAA,IACpC;AAA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../../../../src/variables/interpolation/formatRegistry.ts"],"sourcesContent":["import { isArray, map, replace } from 'lodash';\n\nimport { dateTime, Registry, RegistryItem, textUtil, escapeRegex, urlUtil } from '@grafana/data';\nimport { VariableType, VariableFormatID } from '@grafana/schema';\n\nimport { VariableValue, VariableValueSingle } from '../types';\nimport { ALL_VARIABLE_VALUE } from '../constants';\nimport { SceneObjectUrlSyncHandler } from '../../core/types';\n\nexport interface FormatRegistryItem extends RegistryItem {\n formatter(value: VariableValue, args: string[], variable: FormatVariable): string;\n}\n\n/**\n * Slimmed down version of the SceneVariable interface so that it only contains what the formatters actually use.\n * This is useful as we have some implementations of this interface that does not need to be full scene objects.\n * For example ScopedVarsVariable and LegacyVariableWrapper.\n */\nexport interface FormatVariable {\n state: {\n name: string;\n type: VariableType | string;\n isMulti?: boolean;\n includeAll?: boolean;\n };\n\n getValue(fieldPath?: string): VariableValue | undefined | null;\n getValueText?(fieldPath?: string): string;\n urlSync?: SceneObjectUrlSyncHandler;\n}\n\nexport const formatRegistry = new Registry<FormatRegistryItem>(() => {\n const formats: FormatRegistryItem[] = [\n {\n id: VariableFormatID.Lucene,\n name: 'Lucene',\n description: 'Values are lucene escaped and multi-valued variables generate an OR expression',\n formatter: (value) => {\n if (typeof value === 'string') {\n return luceneEscape(value);\n }\n\n if (Array.isArray(value)) {\n if (value.length === 0) {\n return '__empty__';\n }\n const quotedValues = map(value, (val: string) => {\n return '\"' + luceneEscape(val) + '\"';\n });\n return '(' + quotedValues.join(' OR ') + ')';\n } else {\n return luceneEscape(`${value}`);\n }\n },\n },\n {\n id: VariableFormatID.Raw,\n name: 'raw',\n description: 'Keep value as is',\n formatter: (value) => String(value),\n },\n {\n id: VariableFormatID.Regex,\n name: 'Regex',\n description: 'Values are regex escaped and multi-valued variables generate a (<value>|<value>) expression',\n formatter: (value) => {\n if (typeof value === 'string') {\n return escapeRegex(value);\n }\n\n if (Array.isArray(value)) {\n const escapedValues = value.map((item) => {\n if (typeof item === 'string') {\n return escapeRegex(item);\n } else {\n return escapeRegex(String(item));\n }\n });\n\n if (escapedValues.length === 1) {\n return escapedValues[0];\n }\n\n return '(' + escapedValues.join('|') + ')';\n }\n\n return escapeRegex(`${value}`);\n },\n },\n {\n id: VariableFormatID.Pipe,\n name: 'Pipe',\n description: 'Values are separated by | character',\n formatter: (value) => {\n if (typeof value === 'string') {\n return value;\n }\n\n if (Array.isArray(value)) {\n return value.join('|');\n }\n\n return `${value}`;\n },\n },\n {\n id: VariableFormatID.Distributed,\n name: 'Distributed',\n description: 'Multiple values are formatted like variable=value',\n formatter: (value, args, variable) => {\n if (typeof value === 'string') {\n return value;\n }\n\n if (Array.isArray(value)) {\n value = map(value, (val: string, index: number) => {\n if (index !== 0) {\n return variable.state.name + '=' + val;\n } else {\n return val;\n }\n });\n\n return value.join(',');\n }\n\n return `${value}`;\n },\n },\n {\n id: VariableFormatID.CSV,\n name: 'Csv',\n description: 'Comma-separated values',\n formatter: (value) => {\n if (typeof value === 'string') {\n return value;\n }\n\n if (isArray(value)) {\n return value.join(',');\n }\n\n return String(value);\n },\n },\n {\n id: VariableFormatID.HTML,\n name: 'HTML',\n description: 'HTML escaping of values',\n formatter: (value) => {\n if (typeof value === 'string') {\n return textUtil.escapeHtml(value);\n }\n\n if (isArray(value)) {\n return textUtil.escapeHtml(value.join(', '));\n }\n\n return textUtil.escapeHtml(String(value));\n },\n },\n {\n id: VariableFormatID.JSON,\n name: 'JSON',\n description: 'JSON stringify value',\n formatter: (value) => {\n if (typeof value === 'string') {\n return value;\n }\n return JSON.stringify(value);\n },\n },\n {\n id: VariableFormatID.PercentEncode,\n name: 'Percent encode',\n description: 'Useful for URL escaping values',\n formatter: (value) => {\n // like glob, but url escaped\n if (isArray(value)) {\n return encodeURIComponentStrict('{' + value.join(',') + '}');\n }\n\n return encodeURIComponentStrict(value);\n },\n },\n {\n id: VariableFormatID.SingleQuote,\n name: 'Single quote',\n description: 'Single quoted values',\n formatter: (value) => {\n // escape single quotes with backslash\n const regExp = new RegExp(`'`, 'g');\n\n if (isArray(value)) {\n return map(value, (v: string) => `'${replace(v, regExp, `\\\\'`)}'`).join(',');\n }\n\n let strVal = typeof value === 'string' ? value : String(value);\n return `'${replace(strVal, regExp, `\\\\'`)}'`;\n },\n },\n {\n id: VariableFormatID.DoubleQuote,\n name: 'Double quote',\n description: 'Double quoted values',\n formatter: (value) => {\n // escape double quotes with backslash\n const regExp = new RegExp('\"', 'g');\n if (isArray(value)) {\n return map(value, (v: string) => `\"${replace(v, regExp, '\\\\\"')}\"`).join(',');\n }\n\n let strVal = typeof value === 'string' ? value : String(value);\n return `\"${replace(strVal, regExp, '\\\\\"')}\"`;\n },\n },\n {\n id: VariableFormatID.SQLString,\n name: 'SQL string',\n description: 'SQL string quoting and commas for use in IN statements and other scenarios',\n formatter: sqlStringFormatter,\n },\n {\n id: VariableFormatID.Date,\n name: 'Date',\n description: 'Format date in different ways',\n formatter: (value, args) => {\n let nrValue = NaN;\n\n if (typeof value === 'number') {\n nrValue = value;\n } else if (typeof value === 'string') {\n nrValue = parseInt(value, 10);\n }\n\n if (isNaN(nrValue)) {\n return 'NaN';\n }\n\n const arg = args[0] ?? 'iso';\n switch (arg) {\n case 'ms':\n return String(value);\n case 'seconds':\n return `${Math.round(nrValue! / 1000)}`;\n case 'iso':\n return dateTime(nrValue).toISOString();\n default:\n if ((args || []).length > 1) {\n return dateTime(nrValue).format(args.join(':'));\n }\n return dateTime(nrValue).format(arg);\n }\n },\n },\n {\n id: VariableFormatID.Glob,\n name: 'Glob',\n description: 'Format multi-valued variables using glob syntax, example {value1,value2}',\n formatter: (value) => {\n if (isArray(value) && value.length > 1) {\n return '{' + value.join(',') + '}';\n }\n return String(value);\n },\n },\n {\n id: VariableFormatID.Text,\n name: 'Text',\n description: 'Format variables in their text representation. Example in multi-variable scenario A + B + C.',\n formatter: (value, _args, variable) => {\n if (variable.getValueText) {\n return variable.getValueText();\n }\n\n return String(value);\n },\n },\n {\n id: VariableFormatID.QueryParam,\n name: 'Query parameter',\n description:\n 'Format variables as URL parameters. Example in multi-variable scenario A + B + C => var-foo=A&var-foo=B&var-foo=C.',\n formatter: (value, _args, variable) => {\n if (variable.urlSync) {\n const urlParam = variable.urlSync.getUrlState();\n return urlUtil.toUrlParams(urlParam);\n }\n\n if (Array.isArray(value)) {\n return value.map((v) => formatQueryParameter(variable.state.name, v)).join('&');\n }\n\n return formatQueryParameter(variable.state.name, value);\n },\n },\n {\n id: VariableFormatID.UriEncode,\n name: 'Percent encode as URI',\n description: 'Useful for URL escaping values, taking into URI syntax characters',\n formatter: (value: VariableValue) => {\n if (isArray(value)) {\n return encodeURIStrict('{' + value.join(',') + '}');\n }\n\n return encodeURIStrict(value);\n },\n },\n ];\n\n return formats;\n});\n\nfunction luceneEscape(value: string) {\n if (isNaN(+value) === false) {\n return value;\n }\n\n return value.replace(/([\\!\\*\\+\\-\\=<>\\s\\&\\|\\(\\)\\[\\]\\{\\}\\^\\~\\?\\:\\\\/\"])/g, '\\\\$1');\n}\n\n/**\n * encode string according to RFC 3986; in contrast to encodeURIComponent()\n * also the sub-delims \"!\", \"'\", \"(\", \")\" and \"*\" are encoded;\n * unicode handling uses UTF-8 as in ECMA-262.\n */\nfunction encodeURIComponentStrict(str: VariableValueSingle) {\n if (typeof str === 'object') {\n str = String(str);\n }\n\n return replaceSpecialCharactersToASCII(encodeURIComponent(str));\n}\n\nconst encodeURIStrict = (str: VariableValueSingle): string => replaceSpecialCharactersToASCII(encodeURI(String(str)));\n\nconst replaceSpecialCharactersToASCII = (value: string): string =>\n value.replace(/[!'()*]/g, (c) => {\n return '%' + c.charCodeAt(0).toString(16).toUpperCase();\n });\n\nfunction formatQueryParameter(name: string, value: VariableValueSingle): string {\n return `var-${name}=${encodeURIComponentStrict(value)}`;\n}\n\nexport function isAllValue(value: VariableValueSingle) {\n return value === ALL_VARIABLE_VALUE || (Array.isArray(value) && value[0] === ALL_VARIABLE_VALUE);\n}\n\nconst SQL_ESCAPE_MAP: Record<string, string> = {\n \"'\": \"''\",\n '\"': '\\\\\"',\n};\n\nfunction sqlStringFormatter(value: VariableValue) {\n // escape single quotes by pairing them\n const regExp = new RegExp(`'|\"`, 'g');\n\n if (isArray(value)) {\n return map(value, (v: string) => `'${replace(v, regExp, (match) => SQL_ESCAPE_MAP[match] ?? '')}'`).join(',');\n }\n\n let strVal = typeof value === 'string' ? value : String(value);\n return `'${replace(strVal, regExp, (match) => SQL_ESCAPE_MAP[match] ?? '')}'`;\n}\n"],"names":[],"mappings":";;;;AA+Ba,MAAA,cAAA,GAAiB,IAAI,QAAA,CAA6B,MAAM;AACnE,EAAA,MAAM,OAAgC,GAAA;AAAA,IACpC;AAAA,MACE,IAAI,gBAAiB,CAAA,MAAA;AAAA,MACrB,IAAM,EAAA,QAAA;AAAA,MACN,WAAa,EAAA,gFAAA;AAAA,MACb,SAAA,EAAW,CAAC,KAAU,KAAA;AACpB,QAAI,IAAA,OAAO,UAAU,QAAU,EAAA;AAC7B,UAAA,OAAO,aAAa,KAAK,CAAA,CAAA;AAAA,SAC3B;AAEA,QAAI,IAAA,KAAA,CAAM,OAAQ,CAAA,KAAK,CAAG,EAAA;AACxB,UAAI,IAAA,KAAA,CAAM,WAAW,CAAG,EAAA;AACtB,YAAO,OAAA,WAAA,CAAA;AAAA,WACT;AACA,UAAA,MAAM,YAAe,GAAA,GAAA,CAAI,KAAO,EAAA,CAAC,GAAgB,KAAA;AAC/C,YAAO,OAAA,GAAA,GAAM,YAAa,CAAA,GAAG,CAAI,GAAA,GAAA,CAAA;AAAA,WAClC,CAAA,CAAA;AACD,UAAA,OAAO,GAAM,GAAA,YAAA,CAAa,IAAK,CAAA,MAAM,CAAI,GAAA,GAAA,CAAA;AAAA,SACpC,MAAA;AACL,UAAO,OAAA,YAAA,CAAa,GAAG,KAAO,CAAA,CAAA,CAAA,CAAA;AAAA,SAChC;AAAA,OACF;AAAA,KACF;AAAA,IACA;AAAA,MACE,IAAI,gBAAiB,CAAA,GAAA;AAAA,MACrB,IAAM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,CAAA;AAuWuE,MAAA,OAAA,CAAA,EAAA,GAAA,cAAA,CAAe,WAAf,IAAyB,GAAA,EAAA,GAAA,EAAA,CAAA;AAAA,KAAE,CAAA,CAAA,CAAA,CAAI,CAAE,CAAA,IAAA,CAAK,GAAG,CAAA,CAAA;AAAA,GAC9G;AAEA,EAAA,IAAI,SAAS,OAAO,KAAA,KAAU,QAAW,GAAA,KAAA,GAAQ,OAAO,KAAK,CAAA,CAAA;AAC7D,EAAA,OAAO,CAAI,CAAA,EAAA,OAAA,CAAQ,MAAQ,EAAA,MAAA,EAAQ,CAAC,KAAO,KAAA;AA3W7C,IAAA,IAAA,EAAA,CAAA;AA2WgD,IAAA,OAAA,CAAA,EAAA,GAAA,cAAA,CAAe,WAAf,IAAyB,GAAA,EAAA,GAAA,EAAA,CAAA;AAAA,GAAE,CAAA,CAAA,CAAA,CAAA,CAAA;AAC3E;;;;"}
package/dist/index.d.ts CHANGED
@@ -505,6 +505,7 @@ interface FormatVariable {
505
505
  };
506
506
  getValue(fieldPath?: string): VariableValue | undefined | null;
507
507
  getValueText?(fieldPath?: string): string;
508
+ urlSync?: SceneObjectUrlSyncHandler;
508
509
  }
509
510
  declare const formatRegistry: Registry<FormatRegistryItem>;
510
511
 
package/dist/index.js CHANGED
@@ -1241,6 +1241,10 @@ const formatRegistry = new data.Registry(() => {
1241
1241
  name: "Query parameter",
1242
1242
  description: "Format variables as URL parameters. Example in multi-variable scenario A + B + C => var-foo=A&var-foo=B&var-foo=C.",
1243
1243
  formatter: (value, _args, variable) => {
1244
+ if (variable.urlSync) {
1245
+ const urlParam = variable.urlSync.getUrlState();
1246
+ return data.urlUtil.toUrlParams(urlParam);
1247
+ }
1244
1248
  if (Array.isArray(value)) {
1245
1249
  return value.map((v) => formatQueryParameter(variable.state.name, v)).join("&");
1246
1250
  }