@grafana/scenes 6.29.3--canary.1206.16749060237.0 → 6.29.3

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/dist/index.js CHANGED
@@ -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 && canValueBeMerged(existingFilter.operator, filter.operator)) {
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 canValueBeMerged(adHocFilterOperator, filterOperator) {
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._setStateWithFiltersApplicabilityCheck({
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._setStateWithFiltersApplicabilityCheck({
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._setStateWithFiltersApplicabilityCheck({
5960
- filters: [...filters, { ..._wip, ...update }],
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._setStateWithFiltersApplicabilityCheck({
5993
- filters: this.state.filters.filter((f) => f !== filter),
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 _setStateWithFiltersApplicabilityCheck(update) {
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 (!update.filters) {
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: [...update.filters, ...(_a = update.originFilters) != null ? _a : []],
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
- (_b = update.originFilters) == null ? void 0 : _b.forEach((f) => {
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) {