@grafana/scenes 6.47.0--canary.1236.19306776868.0 → 6.47.0--canary.1236.19307548733.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -55,14 +55,14 @@ class CustomVariable extends MultiValueVariable {
|
|
|
55
55
|
return parsedOptions.map((o) => {
|
|
56
56
|
var _a;
|
|
57
57
|
return {
|
|
58
|
-
value: String(o[valueProp]).trim(),
|
|
59
58
|
label: (_a = String(o[textProp] || o[valueProp])) == null ? void 0 : _a.trim(),
|
|
59
|
+
value: String(o[valueProp]).trim(),
|
|
60
60
|
properties: o
|
|
61
61
|
};
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
getValueOptions(args) {
|
|
65
|
-
const options = this.state.valuesFormat === "
|
|
65
|
+
const options = this.state.valuesFormat === "json" ? this.transformJsonToOptions(this.state.query) : this.transformCsvStringToOptions(this.state.query);
|
|
66
66
|
if (!options.length) {
|
|
67
67
|
this.skipNextValidation = true;
|
|
68
68
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomVariable.js","sources":["../../../../src/variables/variants/CustomVariable.tsx"],"sourcesContent":["import { Observable, of } from 'rxjs';\n\nimport { SceneComponentProps } from '../../core/types';\nimport { VariableDependencyConfig } from '../VariableDependencyConfig';\nimport { MultiOrSingleValueSelect } from '../components/VariableValueSelect';\nimport { VariableValueOption } from '../types';\n\nimport { MultiValueVariable, MultiValueVariableState, VariableGetOptionsArgs } from './MultiValueVariable';\nimport { sceneGraph } from '../../core/sceneGraph';\nimport React from 'react';\n\nexport interface CustomVariableState extends MultiValueVariableState {\n query: string;\n valuesFormat?: 'csv' | 'json';\n}\n\nexport class CustomVariable extends MultiValueVariable<CustomVariableState> {\n protected _variableDependency = new VariableDependencyConfig(this, {\n statePaths: ['query'],\n });\n\n public constructor(initialState: Partial<CustomVariableState>) {\n super({\n type: 'custom',\n query: '',\n valuesFormat: 'csv',\n value: '',\n text: '',\n options: [],\n name: '',\n ...initialState,\n });\n }\n\n // We expose this publicly as we also need it outside the variable\n // The interpolate flag is needed since we don't always want to get the interpolated options\n public transformCsvStringToOptions(str: string, interpolate = true): VariableValueOption[] {\n str = interpolate ? sceneGraph.interpolate(this, str) : str;\n const match = str.match(/(?:\\\\,|[^,])+/g) ?? [];\n\n return match.map((text) => {\n text = text.replace(/\\\\,/g, ',');\n const textMatch = /^\\s*(.+)\\s:\\s(.+)$/g.exec(text) ?? [];\n if (textMatch.length === 3) {\n const [, key, value] = textMatch;\n return { label: key.trim(), value: value.trim() };\n } else {\n return { label: text.trim(), value: text.trim() };\n }\n });\n }\n\n public transformJsonToOptions(json: string) {\n const parsedOptions = JSON.parse(json);\n\n if (!Array.isArray(parsedOptions)) {\n throw new Error('Query must be a JSON array');\n }\n\n if (typeof parsedOptions[0] === 'string') {\n return parsedOptions.map((value) => ({ label: value.trim(), value: value.trim() }));\n }\n\n if (typeof parsedOptions[0] !== 'object' || parsedOptions[0] === null) {\n throw new Error('Query must be a JSON array of strings or objects');\n }\n\n const valueProp = 'value';\n const textProp = 'text';\n\n return parsedOptions.map((o) => ({\n
|
|
1
|
+
{"version":3,"file":"CustomVariable.js","sources":["../../../../src/variables/variants/CustomVariable.tsx"],"sourcesContent":["import { Observable, of } from 'rxjs';\n\nimport { SceneComponentProps } from '../../core/types';\nimport { VariableDependencyConfig } from '../VariableDependencyConfig';\nimport { MultiOrSingleValueSelect } from '../components/VariableValueSelect';\nimport { VariableValueOption } from '../types';\n\nimport { MultiValueVariable, MultiValueVariableState, VariableGetOptionsArgs } from './MultiValueVariable';\nimport { sceneGraph } from '../../core/sceneGraph';\nimport React from 'react';\n\nexport interface CustomVariableState extends MultiValueVariableState {\n query: string;\n valuesFormat?: 'csv' | 'json';\n}\n\nexport class CustomVariable extends MultiValueVariable<CustomVariableState> {\n protected _variableDependency = new VariableDependencyConfig(this, {\n statePaths: ['query'],\n });\n\n public constructor(initialState: Partial<CustomVariableState>) {\n super({\n type: 'custom',\n query: '',\n valuesFormat: 'csv',\n value: '',\n text: '',\n options: [],\n name: '',\n ...initialState,\n });\n }\n\n // We expose this publicly as we also need it outside the variable\n // The interpolate flag is needed since we don't always want to get the interpolated options\n public transformCsvStringToOptions(str: string, interpolate = true): VariableValueOption[] {\n str = interpolate ? sceneGraph.interpolate(this, str) : str;\n const match = str.match(/(?:\\\\,|[^,])+/g) ?? [];\n\n return match.map((text) => {\n text = text.replace(/\\\\,/g, ',');\n const textMatch = /^\\s*(.+)\\s:\\s(.+)$/g.exec(text) ?? [];\n if (textMatch.length === 3) {\n const [, key, value] = textMatch;\n return { label: key.trim(), value: value.trim() };\n } else {\n return { label: text.trim(), value: text.trim() };\n }\n });\n }\n\n public transformJsonToOptions(json: string): VariableValueOption[] {\n const parsedOptions = JSON.parse(json);\n\n if (!Array.isArray(parsedOptions)) {\n throw new Error('Query must be a JSON array');\n }\n\n if (typeof parsedOptions[0] === 'string') {\n return parsedOptions.map((value) => ({ label: value.trim(), value: value.trim() }));\n }\n\n if (typeof parsedOptions[0] !== 'object' || parsedOptions[0] === null) {\n throw new Error('Query must be a JSON array of strings or objects');\n }\n\n const valueProp = 'value';\n const textProp = 'text';\n\n return parsedOptions.map((o) => ({\n label: String(o[textProp] || o[valueProp])?.trim(),\n value: String(o[valueProp]).trim(),\n properties: o,\n }));\n }\n\n public getValueOptions(args: VariableGetOptionsArgs): Observable<VariableValueOption[]> {\n const options =\n this.state.valuesFormat === 'json'\n ? this.transformJsonToOptions(this.state.query)\n : this.transformCsvStringToOptions(this.state.query);\n\n if (!options.length) {\n this.skipNextValidation = true;\n }\n\n return of(options);\n }\n\n public static Component = ({ model }: SceneComponentProps<MultiValueVariable>) => {\n return <MultiOrSingleValueSelect model={model} />;\n };\n}\n"],"names":["_a"],"mappings":";;;;;;;AAgBO,MAAM,uBAAuB,kBAAwC,CAAA;AAAA,EAKnE,YAAY,YAA4C,EAAA;AAC7D,IAAM,KAAA,CAAA;AAAA,MACJ,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AAA,KAAA,CAAM,KAAK,CAC5C,GAAA,IAAA,CAAK,2BAA4B,CAAA,IAAA,CAAK,MAAM,KAAK,CAAA;AAEvD,IAAI,IAAA,CAAC,QAAQ,MAAQ,EAAA;AACnB,MAAA,IAAA,CAAK,kBAAqB,GAAA,IAAA;AAAA;AAG5B,IAAA,OAAO,GAAG,OAAO,CAAA;AAAA;AAMrB;AA7Ea,cAAA,CA0EG,SAAY,GAAA,CAAC,EAAE,KAAA,EAAqD,KAAA;AAChF,EAAO,uBAAA,KAAA,CAAA,aAAA,CAAC,4BAAyB,KAAc,EAAA,CAAA;AACjD,CAAA;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1264,10 +1264,7 @@ declare class CustomVariable extends MultiValueVariable<CustomVariableState> {
|
|
|
1264
1264
|
protected _variableDependency: VariableDependencyConfig<CustomVariableState>;
|
|
1265
1265
|
constructor(initialState: Partial<CustomVariableState>);
|
|
1266
1266
|
transformCsvStringToOptions(str: string, interpolate?: boolean): VariableValueOption[];
|
|
1267
|
-
transformJsonToOptions(json: string):
|
|
1268
|
-
label: any;
|
|
1269
|
-
value: any;
|
|
1270
|
-
}[];
|
|
1267
|
+
transformJsonToOptions(json: string): VariableValueOption[];
|
|
1271
1268
|
getValueOptions(args: VariableGetOptionsArgs): Observable<VariableValueOption[]>;
|
|
1272
1269
|
static Component: ({ model }: SceneComponentProps<MultiValueVariable>) => React__default.JSX.Element;
|
|
1273
1270
|
}
|
package/dist/index.js
CHANGED
|
@@ -11896,14 +11896,14 @@ class CustomVariable extends MultiValueVariable {
|
|
|
11896
11896
|
return parsedOptions.map((o) => {
|
|
11897
11897
|
var _a;
|
|
11898
11898
|
return {
|
|
11899
|
-
value: String(o[valueProp]).trim(),
|
|
11900
11899
|
label: (_a = String(o[textProp] || o[valueProp])) == null ? void 0 : _a.trim(),
|
|
11900
|
+
value: String(o[valueProp]).trim(),
|
|
11901
11901
|
properties: o
|
|
11902
11902
|
};
|
|
11903
11903
|
});
|
|
11904
11904
|
}
|
|
11905
11905
|
getValueOptions(args) {
|
|
11906
|
-
const options = this.state.valuesFormat === "
|
|
11906
|
+
const options = this.state.valuesFormat === "json" ? this.transformJsonToOptions(this.state.query) : this.transformCsvStringToOptions(this.state.query);
|
|
11907
11907
|
if (!options.length) {
|
|
11908
11908
|
this.skipNextValidation = true;
|
|
11909
11909
|
}
|