mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 16:15:42 -06:00
Chore: Use the const instead of hardcoded string (#72925)
* Use the const instead of hardcoded string * Use the const instead of hardcoded string * Fix unit test
This commit is contained in:
parent
4b73e96d93
commit
c344b0e427
@ -34,7 +34,7 @@ export const FromSection = ({
|
||||
const handlePolicyLoadOptions = async () => {
|
||||
const allPolicies = await getPolicyOptions();
|
||||
// if `default` does not exist in the list of policies, we add it
|
||||
const allPoliciesWithDefault = allPolicies.some((p) => p === 'default')
|
||||
const allPoliciesWithDefault = allPolicies.some((p) => p === DEFAULT_POLICY)
|
||||
? allPolicies
|
||||
: [DEFAULT_POLICY, ...allPolicies];
|
||||
|
||||
|
@ -4,7 +4,7 @@ import React from 'react';
|
||||
|
||||
import InfluxDatasource from '../../../../../datasource';
|
||||
import * as mockedMeta from '../../../../../influxql_metadata_query';
|
||||
import { InfluxQuery } from '../../../../../types';
|
||||
import { DEFAULT_POLICY, InfluxQuery } from '../../../../../types';
|
||||
|
||||
import { VisualInfluxQLEditor } from './VisualInfluxQLEditor';
|
||||
|
||||
@ -74,7 +74,7 @@ const ONLY_TAGS = [
|
||||
|
||||
const query: InfluxQuery = {
|
||||
refId: 'A',
|
||||
policy: 'default',
|
||||
policy: DEFAULT_POLICY,
|
||||
tags: [
|
||||
{
|
||||
key: 'cpu',
|
||||
|
@ -3,7 +3,7 @@ import React from 'react';
|
||||
|
||||
import InfluxDatasource from '../../../../../datasource';
|
||||
import { getMockDS, getMockDSInstanceSettings } from '../../../../../specs/mocks';
|
||||
import { InfluxQuery } from '../../../../../types';
|
||||
import { DEFAULT_POLICY, InfluxQuery } from '../../../../../types';
|
||||
|
||||
import { VisualInfluxQLEditor } from './VisualInfluxQLEditor';
|
||||
|
||||
@ -53,7 +53,7 @@ describe('InfluxDB InfluxQL Visual Editor', () => {
|
||||
it('should handle minimal query', async () => {
|
||||
const query: InfluxQuery = {
|
||||
refId: 'A',
|
||||
policy: 'default',
|
||||
policy: DEFAULT_POLICY,
|
||||
};
|
||||
await assertEditor(
|
||||
query,
|
||||
@ -70,7 +70,7 @@ describe('InfluxDB InfluxQL Visual Editor', () => {
|
||||
refId: 'A',
|
||||
alias: 'test-alias',
|
||||
resultFormat: 'table',
|
||||
policy: 'default',
|
||||
policy: DEFAULT_POLICY,
|
||||
};
|
||||
await assertEditor(
|
||||
query,
|
||||
|
@ -4,7 +4,7 @@ import { escapeRegex, ScopedVars } from '@grafana/data';
|
||||
import { TemplateSrv } from '@grafana/runtime';
|
||||
|
||||
import queryPart from './query_part';
|
||||
import { InfluxQuery, InfluxQueryTag } from './types';
|
||||
import { DEFAULT_POLICY, InfluxQuery, InfluxQueryTag } from './types';
|
||||
|
||||
export default class InfluxQueryModel {
|
||||
target: InfluxQuery;
|
||||
@ -20,7 +20,7 @@ export default class InfluxQueryModel {
|
||||
this.templateSrv = templateSrv;
|
||||
this.scopedVars = scopedVars;
|
||||
|
||||
target.policy = target.policy || 'default';
|
||||
target.policy = target.policy || DEFAULT_POLICY;
|
||||
target.resultFormat = target.resultFormat || 'time_series';
|
||||
target.orderByTime = target.orderByTime || 'ASC';
|
||||
target.tags = target.tags || [];
|
||||
@ -193,7 +193,7 @@ export default class InfluxQueryModel {
|
||||
measurement = this.templateSrv.replace(measurement, this.scopedVars, 'regex');
|
||||
}
|
||||
|
||||
if (policy !== 'default') {
|
||||
if (policy !== DEFAULT_POLICY) {
|
||||
policy = '"' + this.target.policy + '".';
|
||||
} else {
|
||||
policy = '';
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { buildMetadataQuery } from './influxql_query_builder';
|
||||
import { templateSrvStub as templateService } from './specs/mocks';
|
||||
import { DEFAULT_POLICY } from './types';
|
||||
|
||||
describe('influxql-query-builder', () => {
|
||||
describe('RETENTION_POLICIES', () => {
|
||||
@ -167,7 +168,7 @@ describe('influxql-query-builder', () => {
|
||||
templateService,
|
||||
withKey: 'app',
|
||||
measurement: 'cpu',
|
||||
retentionPolicy: 'default',
|
||||
retentionPolicy: DEFAULT_POLICY,
|
||||
tags: [],
|
||||
});
|
||||
expect(query).toBe('SHOW TAG VALUES FROM "cpu" WITH KEY = "app"');
|
||||
|
@ -4,7 +4,7 @@ import { escapeRegex, ScopedVars } from '@grafana/data/src';
|
||||
|
||||
import { TemplateSrv } from '../../../features/templating/template_srv';
|
||||
|
||||
import { InfluxQueryTag, MetadataQueryType } from './types';
|
||||
import { DEFAULT_POLICY, InfluxQueryTag, MetadataQueryType } from './types';
|
||||
|
||||
export const buildMetadataQuery = (params: {
|
||||
type: MetadataQueryType;
|
||||
@ -42,7 +42,7 @@ export const buildMetadataQuery = (params: {
|
||||
if (measurement && !measurement.match(/^\/.*\/|^$/)) {
|
||||
measurement = '"' + measurement + '"';
|
||||
|
||||
if (retentionPolicy && retentionPolicy !== 'default') {
|
||||
if (retentionPolicy && retentionPolicy !== DEFAULT_POLICY) {
|
||||
retentionPolicy = '"' + retentionPolicy + '"';
|
||||
measurement = retentionPolicy + '.' + measurement;
|
||||
}
|
||||
@ -70,7 +70,7 @@ export const buildMetadataQuery = (params: {
|
||||
measurement = '"' + measurement + '"';
|
||||
}
|
||||
|
||||
if (retentionPolicy && retentionPolicy !== 'default') {
|
||||
if (retentionPolicy && retentionPolicy !== DEFAULT_POLICY) {
|
||||
retentionPolicy = '"' + retentionPolicy + '"';
|
||||
measurement = retentionPolicy + '.' + measurement;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { cloneDeep } from 'lodash';
|
||||
|
||||
import { buildRawQuery, changeGroupByPart, changeSelectPart, normalizeQuery } from './queryUtils';
|
||||
import { InfluxQuery } from './types';
|
||||
import { DEFAULT_POLICY, InfluxQuery } from './types';
|
||||
|
||||
describe('InfluxDB query utils', () => {
|
||||
describe('buildRawQuery', () => {
|
||||
@ -10,7 +10,7 @@ describe('InfluxDB query utils', () => {
|
||||
buildRawQuery({
|
||||
refId: 'A',
|
||||
hide: false,
|
||||
policy: 'default',
|
||||
policy: DEFAULT_POLICY,
|
||||
resultFormat: 'time_series',
|
||||
orderByTime: 'ASC',
|
||||
tags: [],
|
||||
@ -182,7 +182,7 @@ describe('InfluxDB query utils', () => {
|
||||
hide: false,
|
||||
measurement: 'cpu',
|
||||
orderByTime: 'DESC',
|
||||
policy: 'default',
|
||||
policy: DEFAULT_POLICY,
|
||||
rawQuery: false,
|
||||
refId: 'A',
|
||||
resultFormat: 'time_series',
|
||||
@ -283,7 +283,7 @@ describe('InfluxDB query utils', () => {
|
||||
groupBy: [],
|
||||
measurement: 'cpu',
|
||||
orderByTime: 'ASC',
|
||||
policy: 'default',
|
||||
policy: DEFAULT_POLICY,
|
||||
resultFormat: 'table',
|
||||
select: [
|
||||
[
|
||||
|
Loading…
Reference in New Issue
Block a user