@grafana/scenes 6.20.1 → 6.20.2--canary.1153.15679061823.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.
@@ -19,6 +19,9 @@ function getAdHocFiltersFromScopes(scopes) {
|
|
19
19
|
}
|
20
20
|
function processFilter(formattedFilters, duplicatedFilters, filter) {
|
21
21
|
var _a, _b;
|
22
|
+
if (!filter) {
|
23
|
+
return;
|
24
|
+
}
|
22
25
|
const existingFilter = formattedFilters.get(filter.key);
|
23
26
|
if (existingFilter && canValueBeMerged(existingFilter.operator, filter.operator)) {
|
24
27
|
mergeFilterValues(existingFilter, filter);
|
@@ -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 // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\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 const existingFilter = formattedFilters.get(filter.key);\n\n if (existingFilter && canValueBeMerged(existingFilter.operator, filter.operator)) {\n mergeFilterValues(existingFilter, filter);\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 canValueBeMerged(adHocFilterOperator: string, filterOperator: string) {\n const scopeConvertedOperator = scopeFilterOperatorMap[adHocFilterOperator];\n\n if (!isEqualityOrMultiOperator(scopeConvertedOperator) || !isEqualityOrMultiOperator(filterOperator)) {\n return false;\n }\n\n if (\n (scopeConvertedOperator.includes('not') && !filterOperator.includes('not')) ||\n (!scopeConvertedOperator.includes('not') && filterOperator.includes('not'))\n ) {\n return false;\n }\n\n return true;\n}\n"],"names":[],"mappings":";;AAKO,MAAM,gCAAqE,MAAO,CAAA,WAAA;AAAA,EACvF,MAAO,CAAA,OAAA,CAAQ,sBAAsB,CAAA,CAAE,GAAI,CAAA,CAAC,CAAC,MAAA,EAAQ,QAAQ,CAAA,KAAM,CAAC,QAAA,EAAU,MAAM,CAAC;AAAA;AAEvF;AAEO,SAAS,0BAA0B,KAAiD,EAAA;AACzF,EAAM,MAAA,SAAA,uBAAgB,GAAI,CAAA,CAAC,UAAU,YAAc,EAAA,QAAA,EAAU,YAAY,CAAC,CAAA;AAC1E,EAAO,OAAA,SAAA,CAAU,IAAI,KAAK,CAAA;AAC5B;AAWO,SAAS,0BAA0B,MAA0C,EAAA;AAClF,EAAM,MAAA,gBAAA,uBAA2D,GAAI,EAAA;AAErE,EAAA,MAAM,oBAA6C,EAAC;AACpD,EAAA,MAAM,aAAa,MAAO,CAAA,OAAA,CAAQ,CAAC,KAAU,KAAA,KAAA,CAAM,KAAK,OAAO,CAAA;AAE/D,EAAA,KAAA,MAAW,UAAU,UAAY,EAAA;AAC/B,IAAc,aAAA,CAAA,gBAAA,EAAkB,mBAAmB,MAAM,CAAA;AAAA;AAG3D,EAAA,OAAO,CAAC,GAAG,gBAAA,CAAiB,MAAO,EAAA,EAAG,GAAG,iBAAiB,CAAA;AAC5D;AAEA,SAAS,aAAA,CACP,gBACA,EAAA,iBAAA,EACA,MACA,EAAA;AAzCF,EAAA,IAAA,EAAA,EAAA,EAAA;AA0CE,EAAA,MAAM,cAAiB,GAAA,gBAAA,CAAiB,GAAI,CAAA,MAAA,CAAO,GAAG,CAAA;AAEtD,EAAA,IAAI,kBAAkB,gBAAiB,CAAA,cAAA,CAAe,QAAU,EAAA,MAAA,CAAO,QAAQ,CAAG,EAAA;AAChF,IAAA,iBAAA,CAAkB,gBAAgB,MAAM,CAAA;AAAA,GAC1C,MAAA,IAAW,CAAC,cAAgB,EAAA;AAI1B,IAAiB,gBAAA,CAAA,GAAA,CAAI,OAAO,GAAK,EAAA;AAAA,MAC/B,KAAK,MAAO,CAAA,GAAA;AAAA,MACZ,QAAA,EAAU,6BAA8B,CAAA,MAAA,CAAO,QAAQ,CAAA;AAAA,MACvD,OAAO,MAAO,CAAA,KAAA;AAAA,MACd,SAAQ,EAAO,GAAA,MAAA,CAAA,MAAA,KAAP,IAAiB,GAAA,EAAA,GAAA,CAAC,OAAO,KAAK,CAAA;AAAA,MACtC,MAAQ,EAAA;AAAA,KACT,CAAA;AAAA,GACI,MAAA;AACL,IAAA,iBAAA,CAAkB,IAAK,CAAA;AAAA,MACrB,KAAK,MAAO,CAAA,GAAA;AAAA,MACZ,QAAA,EAAU,6BAA8B,CAAA,MAAA,CAAO,QAAQ,CAAA;AAAA,MACvD,OAAO,MAAO,CAAA,KAAA;AAAA,MACd,SAAQ,EAAO,GAAA,MAAA,CAAA,MAAA,KAAP,IAAiB,GAAA,EAAA,GAAA,CAAC,OAAO,KAAK,CAAA;AAAA,MACtC,MAAQ,EAAA;AAAA,KACT,CAAA;AAAA;AAEL;AAEA,SAAS,iBAAA,CAAkB,aAAoC,MAAyB,EAAA;
|
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 // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\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 && canValueBeMerged(existingFilter.operator, filter.operator)) {\n mergeFilterValues(existingFilter, filter);\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 canValueBeMerged(adHocFilterOperator: string, filterOperator: string) {\n const scopeConvertedOperator = scopeFilterOperatorMap[adHocFilterOperator];\n\n if (!isEqualityOrMultiOperator(scopeConvertedOperator) || !isEqualityOrMultiOperator(filterOperator)) {\n return false;\n }\n\n if (\n (scopeConvertedOperator.includes('not') && !filterOperator.includes('not')) ||\n (!scopeConvertedOperator.includes('not') && filterOperator.includes('not'))\n ) {\n return false;\n }\n\n return true;\n}\n"],"names":[],"mappings":";;AAKO,MAAM,gCAAqE,MAAO,CAAA,WAAA;AAAA,EACvF,MAAO,CAAA,OAAA,CAAQ,sBAAsB,CAAA,CAAE,GAAI,CAAA,CAAC,CAAC,MAAA,EAAQ,QAAQ,CAAA,KAAM,CAAC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AAA,CAA8B,QAAQ,CAAG,EAAA;AACpG,IAAY,WAAA,CAAA,QAAA,GAAW,8BAA8B,QAAQ,CAAA;AAAA,GAC/D,MAAA,IAAW,OAAO,QAAa,KAAA,YAAA,IAAgB,YAAY,QAAa,KAAA,6BAAA,CAA8B,YAAY,CAAG,EAAA;AACnH,IAAY,WAAA,CAAA,QAAA,GAAW,8BAA8B,YAAY,CAAA;AAAA;AAErE;AAEA,SAAS,gBAAA,CAAiB,qBAA6B,cAAwB,EAAA;AAC7E,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,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
@@ -5408,6 +5408,9 @@ function getAdHocFiltersFromScopes(scopes) {
|
|
5408
5408
|
}
|
5409
5409
|
function processFilter(formattedFilters, duplicatedFilters, filter) {
|
5410
5410
|
var _a, _b;
|
5411
|
+
if (!filter) {
|
5412
|
+
return;
|
5413
|
+
}
|
5411
5414
|
const existingFilter = formattedFilters.get(filter.key);
|
5412
5415
|
if (existingFilter && canValueBeMerged(existingFilter.operator, filter.operator)) {
|
5413
5416
|
mergeFilterValues(existingFilter, filter);
|