@grafana/scenes 6.29.1 → 6.29.2--canary.1202.16723575264.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.
|
@@ -7,6 +7,10 @@ function isEqualityOrMultiOperator(value) {
|
|
|
7
7
|
const operators = /* @__PURE__ */ new Set(["equals", "not-equals", "one-of", "not-one-of"]);
|
|
8
8
|
return operators.has(value);
|
|
9
9
|
}
|
|
10
|
+
function isRegexOperator(value) {
|
|
11
|
+
const operators = /* @__PURE__ */ new Set(["regex-match", "regex-not-match"]);
|
|
12
|
+
return operators.has(value);
|
|
13
|
+
}
|
|
10
14
|
function getAdHocFiltersFromScopes(scopes) {
|
|
11
15
|
const formattedFilters = /* @__PURE__ */ new Map();
|
|
12
16
|
const duplicatedFilters = [];
|
|
@@ -22,8 +26,11 @@ function processFilter(formattedFilters, duplicatedFilters, filter) {
|
|
|
22
26
|
return;
|
|
23
27
|
}
|
|
24
28
|
const existingFilter = formattedFilters.get(filter.key);
|
|
25
|
-
if (existingFilter &&
|
|
29
|
+
if (existingFilter && isEqualityValue(existingFilter.operator, filter.operator)) {
|
|
26
30
|
mergeFilterValues(existingFilter, filter);
|
|
31
|
+
} else if (existingFilter && isRegexValue(existingFilter.operator, filter.operator)) {
|
|
32
|
+
existingFilter.value += `|${filter.value}`;
|
|
33
|
+
existingFilter.values = [existingFilter.value];
|
|
27
34
|
} else if (!existingFilter) {
|
|
28
35
|
formattedFilters.set(filter.key, {
|
|
29
36
|
key: filter.key,
|
|
@@ -59,16 +66,26 @@ function mergeFilterValues(adHocFilter, filter) {
|
|
|
59
66
|
adHocFilter.operator = reverseScopeFilterOperatorMap["not-one-of"];
|
|
60
67
|
}
|
|
61
68
|
}
|
|
62
|
-
function
|
|
69
|
+
function isRegexValue(adHocFilterOperator, filterOperator) {
|
|
70
|
+
const scopeConvertedOperator = scopeFilterOperatorMap[adHocFilterOperator];
|
|
71
|
+
if (!isRegexOperator(scopeConvertedOperator) || !isRegexOperator(filterOperator)) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
return hasSameOperators(scopeConvertedOperator, filterOperator);
|
|
75
|
+
}
|
|
76
|
+
function isEqualityValue(adHocFilterOperator, filterOperator) {
|
|
63
77
|
const scopeConvertedOperator = scopeFilterOperatorMap[adHocFilterOperator];
|
|
64
78
|
if (!isEqualityOrMultiOperator(scopeConvertedOperator) || !isEqualityOrMultiOperator(filterOperator)) {
|
|
65
79
|
return false;
|
|
66
80
|
}
|
|
81
|
+
return hasSameOperators(scopeConvertedOperator, filterOperator);
|
|
82
|
+
}
|
|
83
|
+
function hasSameOperators(scopeConvertedOperator, filterOperator) {
|
|
67
84
|
if (scopeConvertedOperator.includes("not") && !filterOperator.includes("not") || !scopeConvertedOperator.includes("not") && filterOperator.includes("not")) {
|
|
68
85
|
return false;
|
|
69
86
|
}
|
|
70
87
|
return true;
|
|
71
88
|
}
|
|
72
89
|
|
|
73
|
-
export { getAdHocFiltersFromScopes, isEqualityOrMultiOperator, reverseScopeFilterOperatorMap };
|
|
90
|
+
export { getAdHocFiltersFromScopes, isEqualityOrMultiOperator, isRegexOperator, reverseScopeFilterOperatorMap };
|
|
74
91
|
//# sourceMappingURL=getAdHocFiltersFromScopes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getAdHocFiltersFromScopes.js","sources":["../../../../src/variables/adhoc/getAdHocFiltersFromScopes.ts"],"sourcesContent":["import { Scope, ScopeFilterOperator, ScopeSpecFilter, scopeFilterOperatorMap } from '@grafana/data';\nimport { AdHocFilterWithLabels } from './AdHocFiltersVariable';\n\nexport type EqualityOrMultiOperator = Extract<ScopeFilterOperator, 'equals' | 'not-equals' | 'one-of' | 'not-one-of'>;\n\nexport const reverseScopeFilterOperatorMap: Record<ScopeFilterOperator, string> = Object.fromEntries(\n Object.entries(scopeFilterOperatorMap).map(([symbol, operator]) => [operator, symbol])\n) as Record<ScopeFilterOperator, string>;\n\nexport function isEqualityOrMultiOperator(value: string): value is EqualityOrMultiOperator {\n const operators = new Set(['equals', 'not-equals', 'one-of', 'not-one-of']);\n return operators.has(value);\n}\n\n// this function returns processed adhoc filters after parsing and processing\n// all scope filters from a scope list. The reason we need to process these filters is\n// because scopes can have multiple filter values with the same key. For example:\n// we have selected ScopeA which has a filter with a key1, operator one-of, a value1,\n// and a ScopeB which has a filter with key1, operator one-of, and value2. After processing,\n// the result will be just one adhoc filter with both values. This is held in formattedFilters.\n// DuplicatedFilters will containg unprocessable filters: if scopeA has instead of the one-of op\n// an equal op, then the result will be 2 adhoc filters with the same key, but diferent operator\n// and value. We return them this way and let the adhoc interface deal with this.\nexport function getAdHocFiltersFromScopes(scopes: Scope[]): AdHocFilterWithLabels[] {\n const formattedFilters: Map<string, AdHocFilterWithLabels> = new Map();\n // duplicated filters that could not be processed in any way are just appended to the list\n const duplicatedFilters: AdHocFilterWithLabels[] = [];\n const allFilters = scopes.flatMap((scope) => scope.spec.filters);\n\n for (const filter of allFilters) {\n processFilter(formattedFilters, duplicatedFilters, filter);\n }\n\n return [...formattedFilters.values(), ...duplicatedFilters];\n}\n\nfunction processFilter(\n formattedFilters: Map<string, AdHocFilterWithLabels>,\n duplicatedFilters: AdHocFilterWithLabels[],\n filter: ScopeSpecFilter\n) {\n if (!filter) {\n return;\n }\n\n const existingFilter = formattedFilters.get(filter.key);\n\n if (existingFilter &&
|
|
1
|
+
{"version":3,"file":"getAdHocFiltersFromScopes.js","sources":["../../../../src/variables/adhoc/getAdHocFiltersFromScopes.ts"],"sourcesContent":["import { Scope, ScopeFilterOperator, ScopeSpecFilter, scopeFilterOperatorMap } from '@grafana/data';\nimport { AdHocFilterWithLabels } from './AdHocFiltersVariable';\n\nexport type EqualityOrMultiOperator = Extract<ScopeFilterOperator, 'equals' | 'not-equals' | 'one-of' | 'not-one-of'>;\nexport type RegexOperator = Extract<ScopeFilterOperator, 'regex-match' | 'regex-not-match'>;\n\nexport const reverseScopeFilterOperatorMap: Record<ScopeFilterOperator, string> = Object.fromEntries(\n Object.entries(scopeFilterOperatorMap).map(([symbol, operator]) => [operator, symbol])\n) as Record<ScopeFilterOperator, string>;\n\nexport function isEqualityOrMultiOperator(value: string): value is EqualityOrMultiOperator {\n const operators = new Set(['equals', 'not-equals', 'one-of', 'not-one-of']);\n return operators.has(value);\n}\n\nexport function isRegexOperator(value: string): value is RegexOperator {\n const operators = new Set(['regex-match', 'regex-not-match']);\n return operators.has(value);\n}\n\n// this function returns processed adhoc filters after parsing and processing\n// all scope filters from a scope list. The reason we need to process these filters is\n// because scopes can have multiple filter values with the same key. For example:\n// we have selected ScopeA which has a filter with a key1, operator one-of, a value1,\n// and a ScopeB which has a filter with key1, operator one-of, and value2. After processing,\n// the result will be just one adhoc filter with both values. This is held in formattedFilters.\n// DuplicatedFilters will containg unprocessable filters: if scopeA has instead of the one-of op\n// an equal op, then the result will be 2 adhoc filters with the same key, but diferent operator\n// and value. We return them this way and let the adhoc interface deal with this.\nexport function getAdHocFiltersFromScopes(scopes: Scope[]): AdHocFilterWithLabels[] {\n const formattedFilters: Map<string, AdHocFilterWithLabels> = new Map();\n // duplicated filters that could not be processed in any way are just appended to the list\n const duplicatedFilters: AdHocFilterWithLabels[] = [];\n const allFilters = scopes.flatMap((scope) => scope.spec.filters);\n\n for (const filter of allFilters) {\n processFilter(formattedFilters, duplicatedFilters, filter);\n }\n\n return [...formattedFilters.values(), ...duplicatedFilters];\n}\n\nfunction processFilter(\n formattedFilters: Map<string, AdHocFilterWithLabels>,\n duplicatedFilters: AdHocFilterWithLabels[],\n filter: ScopeSpecFilter\n) {\n if (!filter) {\n return;\n }\n\n const existingFilter = formattedFilters.get(filter.key);\n\n if (existingFilter && isEqualityValue(existingFilter.operator, filter.operator)) {\n mergeFilterValues(existingFilter, filter);\n } else if (existingFilter && isRegexValue(existingFilter.operator, filter.operator)) {\n existingFilter.value += `|${filter.value}`;\n existingFilter.values = [existingFilter.value];\n } else if (!existingFilter) {\n // Add filter to map either only if it is new.\n // Otherwise it is an existing filter that cannot be converted to multi-value\n // and thus will be moved to the duplicatedFilters list\n formattedFilters.set(filter.key, {\n key: filter.key,\n operator: reverseScopeFilterOperatorMap[filter.operator],\n value: filter.value,\n values: filter.values ?? [filter.value],\n origin: 'scope',\n });\n } else {\n duplicatedFilters.push({\n key: filter.key,\n operator: reverseScopeFilterOperatorMap[filter.operator],\n value: filter.value,\n values: filter.values ?? [filter.value],\n origin: 'scope',\n });\n }\n}\n\nfunction mergeFilterValues(adHocFilter: AdHocFilterWithLabels, filter: ScopeSpecFilter) {\n const values = filter.values ?? [filter.value];\n\n for (const value of values) {\n if (!adHocFilter.values?.includes(value)) {\n adHocFilter.values?.push(value);\n }\n }\n\n // If there's only one value, there's no need to update the\n // operator to its multi-value equivalent\n if (adHocFilter.values?.length === 1) {\n return;\n }\n\n // Otherwise update it to the equivalent multi-value operator\n if (filter.operator === 'equals' && adHocFilter.operator === reverseScopeFilterOperatorMap['equals']) {\n adHocFilter.operator = reverseScopeFilterOperatorMap['one-of'];\n } else if (filter.operator === 'not-equals' && adHocFilter.operator === reverseScopeFilterOperatorMap['not-equals']) {\n adHocFilter.operator = reverseScopeFilterOperatorMap['not-one-of'];\n }\n}\n\nfunction isRegexValue(adHocFilterOperator: string, filterOperator: string) {\n const scopeConvertedOperator = scopeFilterOperatorMap[adHocFilterOperator];\n\n if (!isRegexOperator(scopeConvertedOperator) || !isRegexOperator(filterOperator)) {\n return false;\n }\n\n return hasSameOperators(scopeConvertedOperator, filterOperator);\n}\n\nfunction isEqualityValue(adHocFilterOperator: string, filterOperator: string) {\n const scopeConvertedOperator = scopeFilterOperatorMap[adHocFilterOperator];\n\n if (!isEqualityOrMultiOperator(scopeConvertedOperator) || !isEqualityOrMultiOperator(filterOperator)) {\n return false;\n }\n\n return hasSameOperators(scopeConvertedOperator, filterOperator);\n}\n\nfunction hasSameOperators(scopeConvertedOperator: string, filterOperator: string) {\n if (\n (scopeConvertedOperator.includes('not') && !filterOperator.includes('not'))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AAwB,EAAA;AAC5E,EAAM,MAAA,sBAAA,GAAyB,uBAAuB,mBAAmB,CAAA;AAEzE,EAAA,IAAI,CAAC,yBAA0B,CAAA,sBAAsB,KAAK,CAAC,yBAAA,CAA0B,cAAc,CAAG,EAAA;AACpG,IAAO,OAAA,KAAA;AAAA;AAGT,EAAO,OAAA,gBAAA,CAAiB,wBAAwB,cAAc,CAAA;AAChE;AAEA,SAAS,gBAAA,CAAiB,wBAAgC,cAAwB,EAAA;AAChF,EAAA,IACG,uBAAuB,QAAS,CAAA,KAAK,CAAK,IAAA,CAAC,eAAe,QAAS,CAAA,KAAK,CACxE,IAAA,CAAC,uBAAuB,QAAS,CAAA,KAAK,KAAK,cAAe,CAAA,QAAA,CAAS,KAAK,CACzE,EAAA;AACA,IAAO,OAAA,KAAA;AAAA;AAGT,EAAO,OAAA,IAAA;AACT;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -5631,6 +5631,10 @@ function isEqualityOrMultiOperator(value) {
|
|
|
5631
5631
|
const operators = /* @__PURE__ */ new Set(["equals", "not-equals", "one-of", "not-one-of"]);
|
|
5632
5632
|
return operators.has(value);
|
|
5633
5633
|
}
|
|
5634
|
+
function isRegexOperator(value) {
|
|
5635
|
+
const operators = /* @__PURE__ */ new Set(["regex-match", "regex-not-match"]);
|
|
5636
|
+
return operators.has(value);
|
|
5637
|
+
}
|
|
5634
5638
|
function getAdHocFiltersFromScopes(scopes) {
|
|
5635
5639
|
const formattedFilters = /* @__PURE__ */ new Map();
|
|
5636
5640
|
const duplicatedFilters = [];
|
|
@@ -5646,8 +5650,11 @@ function processFilter(formattedFilters, duplicatedFilters, filter) {
|
|
|
5646
5650
|
return;
|
|
5647
5651
|
}
|
|
5648
5652
|
const existingFilter = formattedFilters.get(filter.key);
|
|
5649
|
-
if (existingFilter &&
|
|
5653
|
+
if (existingFilter && isEqualityValue(existingFilter.operator, filter.operator)) {
|
|
5650
5654
|
mergeFilterValues(existingFilter, filter);
|
|
5655
|
+
} else if (existingFilter && isRegexValue(existingFilter.operator, filter.operator)) {
|
|
5656
|
+
existingFilter.value += `|${filter.value}`;
|
|
5657
|
+
existingFilter.values = [existingFilter.value];
|
|
5651
5658
|
} else if (!existingFilter) {
|
|
5652
5659
|
formattedFilters.set(filter.key, {
|
|
5653
5660
|
key: filter.key,
|
|
@@ -5683,11 +5690,21 @@ function mergeFilterValues(adHocFilter, filter) {
|
|
|
5683
5690
|
adHocFilter.operator = reverseScopeFilterOperatorMap["not-one-of"];
|
|
5684
5691
|
}
|
|
5685
5692
|
}
|
|
5686
|
-
function
|
|
5693
|
+
function isRegexValue(adHocFilterOperator, filterOperator) {
|
|
5694
|
+
const scopeConvertedOperator = data.scopeFilterOperatorMap[adHocFilterOperator];
|
|
5695
|
+
if (!isRegexOperator(scopeConvertedOperator) || !isRegexOperator(filterOperator)) {
|
|
5696
|
+
return false;
|
|
5697
|
+
}
|
|
5698
|
+
return hasSameOperators(scopeConvertedOperator, filterOperator);
|
|
5699
|
+
}
|
|
5700
|
+
function isEqualityValue(adHocFilterOperator, filterOperator) {
|
|
5687
5701
|
const scopeConvertedOperator = data.scopeFilterOperatorMap[adHocFilterOperator];
|
|
5688
5702
|
if (!isEqualityOrMultiOperator(scopeConvertedOperator) || !isEqualityOrMultiOperator(filterOperator)) {
|
|
5689
5703
|
return false;
|
|
5690
5704
|
}
|
|
5705
|
+
return hasSameOperators(scopeConvertedOperator, filterOperator);
|
|
5706
|
+
}
|
|
5707
|
+
function hasSameOperators(scopeConvertedOperator, filterOperator) {
|
|
5691
5708
|
if (scopeConvertedOperator.includes("not") && !filterOperator.includes("not") || !scopeConvertedOperator.includes("not") && filterOperator.includes("not")) {
|
|
5692
5709
|
return false;
|
|
5693
5710
|
}
|