Chore: Move getSearchFilterScopedVar to @grafana/data (#71839)

This commit is contained in:
Andres Martinez Gotor
2023-07-19 13:56:14 +02:00
committed by GitHub
parent f1af0502db
commit 5d07b1c884
8 changed files with 43 additions and 40 deletions

View File

@@ -13,6 +13,8 @@ import {
ScopedVars,
TimeRange,
CoreApp,
getSearchFilterScopedVar,
SearchFilterOptions,
} from '@grafana/data';
import { EditorMode } from '@grafana/experimental';
import {
@@ -27,7 +29,6 @@ import { toDataQueryResponse } from '@grafana/runtime/src/utils/queryResponse';
import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv';
import { VariableWithMultiSupport } from '../../../variables/types';
import { getSearchFilterScopedVar, SearchFilterOptions } from '../../../variables/utils';
import { ResponseParser } from '../ResponseParser';
import { SqlQueryEditor } from '../components/QueryEditor';
import { MACRO_NAMES } from '../constants';

View File

@@ -1,6 +1,6 @@
import { debounce, trim } from 'lodash';
import { isEmptyObject } from '@grafana/data';
import { isEmptyObject, containsSearchFilter } from '@grafana/data';
import { StoreState, ThunkDispatch, ThunkResult } from 'app/types';
import { variableAdapters } from '../../adapters';
@@ -10,7 +10,7 @@ import { getVariable, getVariablesState } from '../../state/selectors';
import { changeVariableProp, setCurrentVariableValue } from '../../state/sharedReducer';
import { KeyedVariableIdentifier } from '../../state/types';
import { VariableOption, VariableWithOptions } from '../../types';
import { containsSearchFilter, getCurrentValue, toVariablePayload } from '../../utils';
import { getCurrentValue, toVariablePayload } from '../../utils';
import { NavigationKey } from '../types';
import {

View File

@@ -1,11 +1,12 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { cloneDeep, isString, trimStart } from 'lodash';
import { containsSearchFilter } from '@grafana/data';
import { applyStateChanges } from '../../../../core/utils/applyStateChanges';
import { ALL_VARIABLE_VALUE } from '../../constants';
import { isMulti, isQuery } from '../../guard';
import { VariableOption, VariableWithOptions } from '../../types';
import { containsSearchFilter } from '../../utils';
export interface ToggleOption {
option?: VariableOption;

View File

@@ -1,6 +1,6 @@
import { isArray, isEqual } from 'lodash';
import { ScopedVars, UrlQueryMap, UrlQueryValue, VariableType } from '@grafana/data';
import { UrlQueryMap, UrlQueryValue, VariableType } from '@grafana/data';
import { getTemplateSrv } from '@grafana/runtime';
import { safeStringifyValue } from 'app/core/utils/explore';
@@ -29,38 +29,6 @@ export const variableRegexExec = (variableString: string) => {
return variableRegex.exec(variableString);
};
export const SEARCH_FILTER_VARIABLE = '__searchFilter';
export const containsSearchFilter = (query: string | unknown): boolean =>
query && typeof query === 'string' ? query.indexOf(SEARCH_FILTER_VARIABLE) !== -1 : false;
export interface SearchFilterOptions {
searchFilter?: string;
}
export const getSearchFilterScopedVar = (args: {
query: string;
wildcardChar: string;
options?: SearchFilterOptions;
}): ScopedVars => {
const { query, wildcardChar } = args;
if (!containsSearchFilter(query)) {
return {};
}
let { options } = args;
options = options || { searchFilter: '' };
const value = options.searchFilter ? `${options.searchFilter}${wildcardChar}` : `${wildcardChar}`;
return {
__searchFilter: {
value,
text: '',
},
};
};
export function containsVariable(...args: any[]) {
const variableName = args[args.length - 1];
args[0] = typeof args[0] === 'string' ? args[0] : safeStringifyValue(args[0]);