@grafana/scenes 6.29.3--canary.1204.16750133031.0 → 6.29.4
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.
- package/CHANGELOG.md +25 -0
- package/dist/esm/variables/adhoc/AdHocFiltersVariable.js +20 -24
- package/dist/esm/variables/adhoc/AdHocFiltersVariable.js.map +1 -1
- package/dist/esm/variables/adhoc/getAdHocFiltersFromScopes.js +20 -3
- package/dist/esm/variables/adhoc/getAdHocFiltersFromScopes.js.map +1 -1
- package/dist/esm/variables/interpolation/formatRegistry.js +2 -2
- package/dist/esm/variables/interpolation/formatRegistry.js.map +1 -1
- package/dist/esm/variables/interpolation/sceneInterpolator.js +3 -3
- package/dist/esm/variables/interpolation/sceneInterpolator.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +43 -30
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -21,7 +21,7 @@ function sceneInterpolator(sceneObject, target, scopedVars, format, interpolatio
|
|
|
21
21
|
}
|
|
22
22
|
return match;
|
|
23
23
|
}
|
|
24
|
-
const value = formatValue(sceneObject, variable, variable.getValue(fieldPath), fmt
|
|
24
|
+
const value = formatValue(sceneObject, variable, variable.getValue(fieldPath), fmt);
|
|
25
25
|
if (interpolations) {
|
|
26
26
|
interpolations.push({ match, variableName, fieldPath, format: fmt, value, found: value !== match });
|
|
27
27
|
}
|
|
@@ -45,7 +45,7 @@ function lookupFormatVariable(name, match, scopedVars, sceneObject) {
|
|
|
45
45
|
}
|
|
46
46
|
return null;
|
|
47
47
|
}
|
|
48
|
-
function formatValue(context, variable, value, formatNameOrFn
|
|
48
|
+
function formatValue(context, variable, value, formatNameOrFn) {
|
|
49
49
|
if (value === null || value === void 0) {
|
|
50
50
|
return "";
|
|
51
51
|
}
|
|
@@ -80,7 +80,7 @@ function formatValue(context, variable, value, formatNameOrFn, fieldPath) {
|
|
|
80
80
|
console.error(`Variable format ${formatNameOrFn} not found. Using glob format as fallback.`);
|
|
81
81
|
formatter = formatRegistry.get(VariableFormatID.Glob);
|
|
82
82
|
}
|
|
83
|
-
return formatter.formatter(value, args, variable
|
|
83
|
+
return formatter.formatter(value, args, variable);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
export { sceneInterpolator };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sceneInterpolator.js","sources":["../../../../src/variables/interpolation/sceneInterpolator.ts"],"sourcesContent":["import { ScopedVars } from '@grafana/data';\nimport { VariableInterpolation } from '@grafana/runtime';\nimport { VariableType, VariableFormatID } from '@grafana/schema';\n\nimport { SceneObject } from '../../core/types';\nimport { InterpolationFormatParameter, isCustomVariableValue, VariableValue } from '../types';\n\nimport { getSceneVariableForScopedVar } from './ScopedVarsVariable';\nimport { formatRegistry, FormatVariable } from './formatRegistry';\nimport { VARIABLE_REGEX } from '../constants';\nimport { lookupVariable } from '../lookupVariable';\nimport { macrosIndex } from '../macros';\n\n/**\n * This function will try to parse and replace any variable expression found in the target string. The sceneObject will be used as the source of variables. It will\n * use the scene graph and walk up the parent tree until it finds the closest variable.\n *\n * ScopedVars should not really be needed much in the new scene architecture as they can be added to the local scene node instead of passed in interpolate function.\n * It is supported here for backward compatibility and some edge cases where adding scoped vars to local scene node is not practical.\n */\nexport function sceneInterpolator(\n sceneObject: SceneObject,\n target: string | undefined | null,\n scopedVars?: ScopedVars,\n format?: InterpolationFormatParameter,\n interpolations?: VariableInterpolation[]\n): string {\n if (!target || typeof target !== 'string') {\n return target ?? '';\n }\n\n VARIABLE_REGEX.lastIndex = 0;\n\n return target.replace(VARIABLE_REGEX, (match, var1, var2, fmt2, var3, fieldPath, fmt3) => {\n const variableName = var1 || var2 || var3;\n const fmt = fmt2 || fmt3 || format;\n const variable = lookupFormatVariable(variableName, match, scopedVars, sceneObject);\n\n if (!variable) {\n if (interpolations) {\n // Set `value` equal to `match` as documented in the `VariableInterpolation` interface.\n interpolations.push({ match, variableName, fieldPath, format: fmt, value: match, found: false });\n }\n return match;\n }\n\n const value = formatValue(sceneObject, variable, variable.getValue(fieldPath), fmt
|
|
1
|
+
{"version":3,"file":"sceneInterpolator.js","sources":["../../../../src/variables/interpolation/sceneInterpolator.ts"],"sourcesContent":["import { ScopedVars } from '@grafana/data';\nimport { VariableInterpolation } from '@grafana/runtime';\nimport { VariableType, VariableFormatID } from '@grafana/schema';\n\nimport { SceneObject } from '../../core/types';\nimport { InterpolationFormatParameter, isCustomVariableValue, VariableValue } from '../types';\n\nimport { getSceneVariableForScopedVar } from './ScopedVarsVariable';\nimport { formatRegistry, FormatVariable } from './formatRegistry';\nimport { VARIABLE_REGEX } from '../constants';\nimport { lookupVariable } from '../lookupVariable';\nimport { macrosIndex } from '../macros';\n\n/**\n * This function will try to parse and replace any variable expression found in the target string. The sceneObject will be used as the source of variables. It will\n * use the scene graph and walk up the parent tree until it finds the closest variable.\n *\n * ScopedVars should not really be needed much in the new scene architecture as they can be added to the local scene node instead of passed in interpolate function.\n * It is supported here for backward compatibility and some edge cases where adding scoped vars to local scene node is not practical.\n */\nexport function sceneInterpolator(\n sceneObject: SceneObject,\n target: string | undefined | null,\n scopedVars?: ScopedVars,\n format?: InterpolationFormatParameter,\n interpolations?: VariableInterpolation[]\n): string {\n if (!target || typeof target !== 'string') {\n return target ?? '';\n }\n\n VARIABLE_REGEX.lastIndex = 0;\n\n return target.replace(VARIABLE_REGEX, (match, var1, var2, fmt2, var3, fieldPath, fmt3) => {\n const variableName = var1 || var2 || var3;\n const fmt = fmt2 || fmt3 || format;\n const variable = lookupFormatVariable(variableName, match, scopedVars, sceneObject);\n\n if (!variable) {\n if (interpolations) {\n // Set `value` equal to `match` as documented in the `VariableInterpolation` interface.\n interpolations.push({ match, variableName, fieldPath, format: fmt, value: match, found: false });\n }\n return match;\n }\n\n const value = formatValue(sceneObject, variable, variable.getValue(fieldPath), fmt);\n\n if (interpolations) {\n interpolations.push({ match, variableName, fieldPath, format: fmt, value, found: value !== match });\n }\n\n return value;\n });\n}\n\nfunction lookupFormatVariable(\n name: string,\n match: string,\n scopedVars: ScopedVars | undefined,\n sceneObject: SceneObject\n): FormatVariable | null {\n if (scopedVars && scopedVars.hasOwnProperty(name)) {\n const scopedVar = scopedVars[name];\n\n if (scopedVar) {\n return getSceneVariableForScopedVar(name, scopedVar);\n }\n }\n\n const variable = lookupVariable(name, sceneObject);\n if (variable) {\n return variable;\n }\n\n const Macro = macrosIndex.get(name);\n if (Macro) {\n return new Macro(name, sceneObject, match, scopedVars);\n }\n\n return null;\n}\n\nfunction formatValue(\n context: SceneObject,\n variable: FormatVariable,\n value: VariableValue | undefined | null,\n formatNameOrFn?: InterpolationFormatParameter\n): string {\n if (value === null || value === undefined) {\n return '';\n }\n\n // Variable can return a custom value that handles formatting\n // This is useful for customAllValue and macros that return values that are already formatted or need special formatting\n if (isCustomVariableValue(value)) {\n return sceneInterpolator(context, value.formatter(formatNameOrFn));\n }\n\n // if it's an object transform value to string\n if (!Array.isArray(value) && typeof value === 'object') {\n value = `${value}`;\n }\n\n if (typeof formatNameOrFn === 'function') {\n return formatNameOrFn(value, {\n name: variable.state.name,\n type: variable.state.type as VariableType,\n multi: variable.state.isMulti,\n includeAll: variable.state.includeAll,\n });\n }\n\n let args: string[] = [];\n\n if (!formatNameOrFn) {\n formatNameOrFn = VariableFormatID.Glob;\n } else {\n // some formats have arguments that come after ':' character\n args = formatNameOrFn.split(':');\n if (args.length > 1) {\n formatNameOrFn = args[0];\n args = args.slice(1);\n } else {\n args = [];\n }\n }\n\n let formatter = formatRegistry.getIfExists(formatNameOrFn);\n\n if (!formatter) {\n console.error(`Variable format ${formatNameOrFn} not found. Using glob format as fallback.`);\n formatter = formatRegistry.get(VariableFormatID.Glob);\n }\n\n return formatter.formatter(value, args, variable);\n}\n"],"names":[],"mappings":";;;;;;;;AAoBO,SAAS,iBACd,CAAA,WAAA,EACA,MACA,EAAA,UAAA,EACA,QACA,cACQ,EAAA;AACR,EAAA,IAAI,CAAC,MAAA,IAAU,OA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,IAAI,OAAiB,EAAC;AAEtB,EAAA,IAAI,CAAC,cAAgB,EAAA;AACnB,IAAA,cAAA,GAAiB,gBAAiB,CAAA,IAAA;AAAA,GAC7B,MAAA;AAEL,IAAO,IAAA,GAAA,cAAA,CAAe,MAAM,GAAG,CAAA;AAC/B,IAAI,IAAA,IAAA,CAAK,SAAS,CAAG,EAAA;AACnB,MAAA,cAAA,GAAiB,KAAK,CAAC,CAAA;AACvB,MAAO,IAAA,GAAA,IAAA,CAAK,MAAM,CAAC,CAAA;AAAA,KACd,MAAA;AACL,MAAA,IAAA,GAAO,EAAC;AAAA;AACV;AAGF,EAAI,IAAA,SAAA,GAAY,cAAe,CAAA,WAAA,CAAY,cAAc,CAAA;AAEzD,EAAA,IAAI,CAAC,SAAW,EAAA;AACd,IAAQ,OAAA,CAAA,KAAA,CAAM,CAAmB,gBAAA,EAAA,cAAc,CAA4C,0CAAA,CAAA,CAAA;AAC3F,IAAY,SAAA,GAAA,cAAA,CAAe,GAAI,CAAA,gBAAA,CAAiB,IAAI,CAAA;AAAA;AAGtD,EAAA,OAAO,SAAU,CAAA,SAAA,CAAU,KAAO,EAAA,IAAA,EAAM,QAAQ,CAAA;AAClD;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -802,7 +802,7 @@ declare function getUrlState(root: SceneObject, uniqueUrlKeyMapperOptions?: Uniq
|
|
|
802
802
|
declare function syncStateFromSearchParams(root: SceneObject, urlParams: URLSearchParams, uniqueUrlKeyMapperOptions?: UniqueUrlKeyMapperOptions): void;
|
|
803
803
|
|
|
804
804
|
interface FormatRegistryItem extends RegistryItem {
|
|
805
|
-
formatter(value: VariableValue, args: string[], variable: FormatVariable
|
|
805
|
+
formatter(value: VariableValue, args: string[], variable: FormatVariable): string;
|
|
806
806
|
}
|
|
807
807
|
/**
|
|
808
808
|
* Slimmed down version of the SceneVariable interface so that it only contains what the formatters actually use.
|
|
@@ -970,6 +970,7 @@ declare class AdHocFiltersVariable extends SceneObjectBase<AdHocFiltersVariableS
|
|
|
970
970
|
/** Needed for scopes dependency */
|
|
971
971
|
protected _variableDependency: VariableDependencyConfig<AdHocFiltersVariableState>;
|
|
972
972
|
protected _urlSync: AdHocFiltersVariableUrlSyncHandler;
|
|
973
|
+
private _debouncedVerifyApplicability;
|
|
973
974
|
constructor(state: Partial<AdHocFiltersVariableState>);
|
|
974
975
|
private _activationHandler;
|
|
975
976
|
private _updateScopesFilters;
|
|
@@ -990,7 +991,7 @@ declare class AdHocFiltersVariable extends SceneObjectBase<AdHocFiltersVariableS
|
|
|
990
991
|
_removeFilter(filter: AdHocFilterWithLabels): void;
|
|
991
992
|
_removeLastFilter(): void;
|
|
992
993
|
_handleComboboxBackspace(filter: AdHocFilterWithLabels): void;
|
|
993
|
-
|
|
994
|
+
_verifyApplicability(): Promise<void>;
|
|
994
995
|
/**
|
|
995
996
|
* Get possible keys given current filters. Do not call from plugins directly
|
|
996
997
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1642,9 +1642,9 @@ const formatRegistry = new data.Registry(() => {
|
|
|
1642
1642
|
id: schema.VariableFormatID.Text,
|
|
1643
1643
|
name: "Text",
|
|
1644
1644
|
description: "Format variables in their text representation. Example in multi-variable scenario A + B + C.",
|
|
1645
|
-
formatter: (value, _args, variable
|
|
1645
|
+
formatter: (value, _args, variable) => {
|
|
1646
1646
|
if (variable.getValueText) {
|
|
1647
|
-
return variable.getValueText(
|
|
1647
|
+
return variable.getValueText();
|
|
1648
1648
|
}
|
|
1649
1649
|
return String(value);
|
|
1650
1650
|
}
|
|
@@ -2501,7 +2501,7 @@ function sceneInterpolator(sceneObject, target, scopedVars, format, interpolatio
|
|
|
2501
2501
|
}
|
|
2502
2502
|
return match;
|
|
2503
2503
|
}
|
|
2504
|
-
const value = formatValue(sceneObject, variable, variable.getValue(fieldPath), fmt
|
|
2504
|
+
const value = formatValue(sceneObject, variable, variable.getValue(fieldPath), fmt);
|
|
2505
2505
|
if (interpolations) {
|
|
2506
2506
|
interpolations.push({ match, variableName, fieldPath, format: fmt, value, found: value !== match });
|
|
2507
2507
|
}
|
|
@@ -2525,7 +2525,7 @@ function lookupFormatVariable(name, match, scopedVars, sceneObject) {
|
|
|
2525
2525
|
}
|
|
2526
2526
|
return null;
|
|
2527
2527
|
}
|
|
2528
|
-
function formatValue(context, variable, value, formatNameOrFn
|
|
2528
|
+
function formatValue(context, variable, value, formatNameOrFn) {
|
|
2529
2529
|
if (value === null || value === void 0) {
|
|
2530
2530
|
return "";
|
|
2531
2531
|
}
|
|
@@ -2560,7 +2560,7 @@ function formatValue(context, variable, value, formatNameOrFn, fieldPath) {
|
|
|
2560
2560
|
console.error(`Variable format ${formatNameOrFn} not found. Using glob format as fallback.`);
|
|
2561
2561
|
formatter = formatRegistry.get(schema.VariableFormatID.Glob);
|
|
2562
2562
|
}
|
|
2563
|
-
return formatter.formatter(value, args, variable
|
|
2563
|
+
return formatter.formatter(value, args, variable);
|
|
2564
2564
|
}
|
|
2565
2565
|
|
|
2566
2566
|
function isSceneObject(obj) {
|
|
@@ -5676,6 +5676,10 @@ function isEqualityOrMultiOperator(value) {
|
|
|
5676
5676
|
const operators = /* @__PURE__ */ new Set(["equals", "not-equals", "one-of", "not-one-of"]);
|
|
5677
5677
|
return operators.has(value);
|
|
5678
5678
|
}
|
|
5679
|
+
function isRegexOperator(value) {
|
|
5680
|
+
const operators = /* @__PURE__ */ new Set(["regex-match", "regex-not-match"]);
|
|
5681
|
+
return operators.has(value);
|
|
5682
|
+
}
|
|
5679
5683
|
function getAdHocFiltersFromScopes(scopes) {
|
|
5680
5684
|
const formattedFilters = /* @__PURE__ */ new Map();
|
|
5681
5685
|
const duplicatedFilters = [];
|
|
@@ -5691,8 +5695,11 @@ function processFilter(formattedFilters, duplicatedFilters, filter) {
|
|
|
5691
5695
|
return;
|
|
5692
5696
|
}
|
|
5693
5697
|
const existingFilter = formattedFilters.get(filter.key);
|
|
5694
|
-
if (existingFilter &&
|
|
5698
|
+
if (existingFilter && isEqualityValue(existingFilter.operator, filter.operator)) {
|
|
5695
5699
|
mergeFilterValues(existingFilter, filter);
|
|
5700
|
+
} else if (existingFilter && isRegexValue(existingFilter.operator, filter.operator)) {
|
|
5701
|
+
existingFilter.value += `|${filter.value}`;
|
|
5702
|
+
existingFilter.values = [existingFilter.value];
|
|
5696
5703
|
} else if (!existingFilter) {
|
|
5697
5704
|
formattedFilters.set(filter.key, {
|
|
5698
5705
|
key: filter.key,
|
|
@@ -5728,11 +5735,21 @@ function mergeFilterValues(adHocFilter, filter) {
|
|
|
5728
5735
|
adHocFilter.operator = reverseScopeFilterOperatorMap["not-one-of"];
|
|
5729
5736
|
}
|
|
5730
5737
|
}
|
|
5731
|
-
function
|
|
5738
|
+
function isRegexValue(adHocFilterOperator, filterOperator) {
|
|
5739
|
+
const scopeConvertedOperator = data.scopeFilterOperatorMap[adHocFilterOperator];
|
|
5740
|
+
if (!isRegexOperator(scopeConvertedOperator) || !isRegexOperator(filterOperator)) {
|
|
5741
|
+
return false;
|
|
5742
|
+
}
|
|
5743
|
+
return hasSameOperators(scopeConvertedOperator, filterOperator);
|
|
5744
|
+
}
|
|
5745
|
+
function isEqualityValue(adHocFilterOperator, filterOperator) {
|
|
5732
5746
|
const scopeConvertedOperator = data.scopeFilterOperatorMap[adHocFilterOperator];
|
|
5733
5747
|
if (!isEqualityOrMultiOperator(scopeConvertedOperator) || !isEqualityOrMultiOperator(filterOperator)) {
|
|
5734
5748
|
return false;
|
|
5735
5749
|
}
|
|
5750
|
+
return hasSameOperators(scopeConvertedOperator, filterOperator);
|
|
5751
|
+
}
|
|
5752
|
+
function hasSameOperators(scopeConvertedOperator, filterOperator) {
|
|
5736
5753
|
if (scopeConvertedOperator.includes("not") && !filterOperator.includes("not") || !scopeConvertedOperator.includes("not") && filterOperator.includes("not")) {
|
|
5737
5754
|
return false;
|
|
5738
5755
|
}
|
|
@@ -5802,11 +5819,9 @@ class AdHocFiltersVariable extends SceneObjectBase {
|
|
|
5802
5819
|
onReferencedVariableValueChanged: () => this._updateScopesFilters()
|
|
5803
5820
|
});
|
|
5804
5821
|
this._urlSync = new AdHocFiltersVariableUrlSyncHandler(this);
|
|
5822
|
+
this._debouncedVerifyApplicability = lodash.debounce(this._verifyApplicability, 100);
|
|
5805
5823
|
this._activationHandler = () => {
|
|
5806
|
-
this.
|
|
5807
|
-
filters: this.state.filters,
|
|
5808
|
-
originFilters: this.state.originFilters
|
|
5809
|
-
});
|
|
5824
|
+
this._debouncedVerifyApplicability();
|
|
5810
5825
|
return () => {
|
|
5811
5826
|
var _a;
|
|
5812
5827
|
(_a = this.state.originFilters) == null ? void 0 : _a.forEach((filter) => {
|
|
@@ -5861,6 +5876,7 @@ class AdHocFiltersVariable extends SceneObjectBase {
|
|
|
5861
5876
|
if (this._prevScopes.length) {
|
|
5862
5877
|
this.setState({ originFilters: [...finalFilters, ...remainingFilters] });
|
|
5863
5878
|
this._prevScopes = scopes;
|
|
5879
|
+
this._debouncedVerifyApplicability();
|
|
5864
5880
|
return;
|
|
5865
5881
|
}
|
|
5866
5882
|
const editedScopeFilters = scopeInjectedFilters.filter((filter) => filter.restorable);
|
|
@@ -5870,11 +5886,9 @@ class AdHocFiltersVariable extends SceneObjectBase {
|
|
|
5870
5886
|
...editedScopeFilters.filter((filter) => scopeFilterKeys.includes(filter.key)),
|
|
5871
5887
|
...scopeFilters.filter((filter) => !editedScopeFilterKeys.includes(filter.key))
|
|
5872
5888
|
];
|
|
5873
|
-
this.
|
|
5874
|
-
filters: this.state.filters,
|
|
5875
|
-
originFilters: [...finalFilters, ...remainingFilters]
|
|
5876
|
-
});
|
|
5889
|
+
this.setState({ originFilters: [...finalFilters, ...remainingFilters] });
|
|
5877
5890
|
this._prevScopes = scopes;
|
|
5891
|
+
this._debouncedVerifyApplicability();
|
|
5878
5892
|
}
|
|
5879
5893
|
setState(update) {
|
|
5880
5894
|
var _a, _b;
|
|
@@ -5956,11 +5970,8 @@ class AdHocFiltersVariable extends SceneObjectBase {
|
|
|
5956
5970
|
}
|
|
5957
5971
|
if (filter === _wip) {
|
|
5958
5972
|
if ("value" in update && update["value"] !== "") {
|
|
5959
|
-
this.
|
|
5960
|
-
|
|
5961
|
-
originFilters: this.state.originFilters,
|
|
5962
|
-
_wip: void 0
|
|
5963
|
-
});
|
|
5973
|
+
this.setState({ filters: [...filters, { ..._wip, ...update }], _wip: void 0 });
|
|
5974
|
+
this._debouncedVerifyApplicability();
|
|
5964
5975
|
} else {
|
|
5965
5976
|
this.setState({ _wip: { ...filter, ...update } });
|
|
5966
5977
|
}
|
|
@@ -5989,10 +6000,8 @@ class AdHocFiltersVariable extends SceneObjectBase {
|
|
|
5989
6000
|
}
|
|
5990
6001
|
const queryController = getQueryController(this);
|
|
5991
6002
|
queryController == null ? void 0 : queryController.startProfile(FILTER_REMOVED_INTERACTION);
|
|
5992
|
-
this.
|
|
5993
|
-
|
|
5994
|
-
originFilters: this.state.originFilters
|
|
5995
|
-
});
|
|
6003
|
+
this.setState({ filters: this.state.filters.filter((f) => f !== filter) });
|
|
6004
|
+
this._debouncedVerifyApplicability();
|
|
5996
6005
|
}
|
|
5997
6006
|
_removeLastFilter() {
|
|
5998
6007
|
const filterToRemove = this.state.filters.at(-1);
|
|
@@ -6048,20 +6057,20 @@ class AdHocFiltersVariable extends SceneObjectBase {
|
|
|
6048
6057
|
});
|
|
6049
6058
|
}
|
|
6050
6059
|
}
|
|
6051
|
-
async
|
|
6052
|
-
var _a, _b;
|
|
6060
|
+
async _verifyApplicability() {
|
|
6061
|
+
var _a, _b, _c;
|
|
6062
|
+
const filters = [...this.state.filters, ...(_a = this.state.originFilters) != null ? _a : []];
|
|
6053
6063
|
const ds = await this._dataSourceSrv.get(this.state.datasource, this._scopedVars);
|
|
6054
6064
|
if (!ds || !ds.getFiltersApplicability) {
|
|
6055
|
-
this.setState(update);
|
|
6056
6065
|
return;
|
|
6057
6066
|
}
|
|
6058
|
-
if (!
|
|
6067
|
+
if (!filters) {
|
|
6059
6068
|
return;
|
|
6060
6069
|
}
|
|
6061
6070
|
const timeRange = sceneGraph.getTimeRange(this).state.value;
|
|
6062
6071
|
const queries = this.state.useQueriesAsFilterForOptions ? getQueriesForVariables(this) : void 0;
|
|
6063
6072
|
const response = await ds.getFiltersApplicability({
|
|
6064
|
-
filters
|
|
6073
|
+
filters,
|
|
6065
6074
|
queries,
|
|
6066
6075
|
timeRange,
|
|
6067
6076
|
scopes: sceneGraph.getScopes(this),
|
|
@@ -6071,6 +6080,10 @@ class AdHocFiltersVariable extends SceneObjectBase {
|
|
|
6071
6080
|
response.forEach((filter) => {
|
|
6072
6081
|
responseMap.set(`${filter.key}${filter.origin ? `-${filter.origin}` : ""}`, filter);
|
|
6073
6082
|
});
|
|
6083
|
+
const update = {
|
|
6084
|
+
filters: [...this.state.filters],
|
|
6085
|
+
originFilters: [...(_b = this.state.originFilters) != null ? _b : []]
|
|
6086
|
+
};
|
|
6074
6087
|
update.filters.forEach((f) => {
|
|
6075
6088
|
const filter = responseMap.get(f.key);
|
|
6076
6089
|
if (filter) {
|
|
@@ -6078,7 +6091,7 @@ class AdHocFiltersVariable extends SceneObjectBase {
|
|
|
6078
6091
|
f.nonApplicableReason = filter.reason;
|
|
6079
6092
|
}
|
|
6080
6093
|
});
|
|
6081
|
-
(
|
|
6094
|
+
(_c = update.originFilters) == null ? void 0 : _c.forEach((f) => {
|
|
6082
6095
|
const filter = responseMap.get(`${f.key}-${f.origin}`);
|
|
6083
6096
|
if (filter) {
|
|
6084
6097
|
if (!f.matchAllFilter) {
|