mirror of
https://github.com/grafana/grafana.git
synced 2025-08-03 04:22:13 +08:00
Chore: Move getSearchFilterScopedVar to @grafana/data (#71839)
This commit is contained in:

committed by
GitHub

parent
f1af0502db
commit
5d07b1c884
@ -23,3 +23,4 @@ export { makeClassES5Compatible } from './makeClassES5Compatible';
|
||||
export { anyToNumber } from './anyToNumber';
|
||||
export { withLoadingIndicator, type WithLoadingIndicatorOptions } from './withLoadingIndicator';
|
||||
export { convertOldAngularValueMappings, LegacyMappingType } from './valueMappings';
|
||||
export { containsSearchFilter, type SearchFilterOptions, getSearchFilterScopedVar } from './variables';
|
||||
|
33
packages/grafana-data/src/utils/variables.ts
Normal file
33
packages/grafana-data/src/utils/variables.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { ScopedVars } from '../types';
|
||||
|
||||
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: '',
|
||||
},
|
||||
};
|
||||
};
|
@ -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';
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -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]);
|
||||
|
@ -19,14 +19,13 @@ import {
|
||||
TimeRange,
|
||||
TimeZone,
|
||||
toDataFrame,
|
||||
getSearchFilterScopedVar,
|
||||
} from '@grafana/data';
|
||||
import { getBackendSrv } from '@grafana/runtime';
|
||||
import { isVersionGtOrEq, SemVersion } from 'app/core/utils/version';
|
||||
import { getTemplateSrv, TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import { getRollupNotice, getRuntimeConsolidationNotice } from 'app/plugins/datasource/graphite/meta';
|
||||
|
||||
import { getSearchFilterScopedVar } from '../../../features/variables/utils';
|
||||
|
||||
import { AnnotationEditor } from './components/AnnotationsEditor';
|
||||
import { convertToGraphiteQueryObject } from './components/helpers';
|
||||
import gfunc, { FuncDefs, FuncInstance } from './gfunc';
|
||||
|
@ -16,9 +16,9 @@ import {
|
||||
toDataFrame,
|
||||
MutableDataFrame,
|
||||
AnnotationQuery,
|
||||
getSearchFilterScopedVar,
|
||||
} from '@grafana/data';
|
||||
import { DataSourceWithBackend, getBackendSrv, getGrafanaLiveSrv, getTemplateSrv, TemplateSrv } from '@grafana/runtime';
|
||||
import { getSearchFilterScopedVar } from 'app/features/variables/utils';
|
||||
|
||||
import { Scenario, TestData, TestDataQueryType } from './dataquery.gen';
|
||||
import { queryMetricTree } from './metricTree';
|
||||
|
Reference in New Issue
Block a user