mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Templating: Makes so __searchFilter can be used as part of regular expression (#20103)
* Fix: Fixes searchfilter wildcard char in regular expressions Fixes: #20006 * Refactor: Uses TemplateSrv and ScopedVars instead * Docs: Updates docs with new format * Tests: Corrects test description
This commit is contained in:
@@ -7,7 +7,7 @@ import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import { TimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
||||
//Types
|
||||
import { PostgresQueryForInterpolation } from './types';
|
||||
import { interpolateSearchFilter } from '../../../features/templating/variable';
|
||||
import { getSearchFilterScopedVar } from '../../../features/templating/variable';
|
||||
|
||||
export class PostgresDatasource {
|
||||
id: any;
|
||||
@@ -127,18 +127,17 @@ export class PostgresDatasource {
|
||||
.then((data: any) => this.responseParser.transformAnnotationResponse(options, data));
|
||||
}
|
||||
|
||||
metricFindQuery(query: string, optionalOptions: { variable?: any }) {
|
||||
metricFindQuery(query: string, optionalOptions: { variable?: any; searchFilter?: string }) {
|
||||
let refId = 'tempvar';
|
||||
if (optionalOptions && optionalOptions.variable && optionalOptions.variable.name) {
|
||||
refId = optionalOptions.variable.name;
|
||||
}
|
||||
|
||||
const rawSql = interpolateSearchFilter({
|
||||
query: this.templateSrv.replace(query, {}, this.interpolateVariable),
|
||||
options: optionalOptions,
|
||||
wildcardChar: '%',
|
||||
quoteLiteral: true,
|
||||
});
|
||||
const rawSql = this.templateSrv.replace(
|
||||
query,
|
||||
getSearchFilterScopedVar({ query, wildcardChar: '%', options: optionalOptions }),
|
||||
this.interpolateVariable
|
||||
);
|
||||
|
||||
const interpolatedQuery = {
|
||||
refId: refId,
|
||||
|
||||
@@ -131,7 +131,7 @@ describe('PostgreSQLDatasource', () => {
|
||||
describe('When performing metricFindQuery with $__searchFilter and a searchFilter is given', () => {
|
||||
let results: any;
|
||||
let calledWith: any = {};
|
||||
const query = 'select title from atable where title LIKE $__searchFilter';
|
||||
const query = "select title from atable where title LIKE '$__searchFilter'";
|
||||
const response = {
|
||||
results: {
|
||||
tempvar: {
|
||||
@@ -169,7 +169,7 @@ describe('PostgreSQLDatasource', () => {
|
||||
describe('When performing metricFindQuery with $__searchFilter but no searchFilter is given', () => {
|
||||
let results: any;
|
||||
let calledWith: any = {};
|
||||
const query = 'select title from atable where title LIKE $__searchFilter';
|
||||
const query = "select title from atable where title LIKE '$__searchFilter'";
|
||||
const response = {
|
||||
results: {
|
||||
tempvar: {
|
||||
|
||||
Reference in New Issue
Block a user