Chore: Remove unnecessary exports (#108124)
* no unnecessary exports * needs exports * put query builder types back * put types back * betterer
This commit is contained in:
+1
-2
@@ -476,8 +476,7 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Do not use any type assertions.", "2"]
|
||||
],
|
||||
"packages/grafana-prometheus/src/querybuilder/shared/types.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||
],
|
||||
"packages/grafana-prometheus/src/resource_clients.test.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
|
||||
@@ -25,7 +25,7 @@ import {
|
||||
StandardPromVariableQuery,
|
||||
} from '../types';
|
||||
|
||||
export const variableOptions = [
|
||||
const variableOptions = [
|
||||
{ label: 'Label names', value: QueryType.LabelNames },
|
||||
{ label: 'Label values', value: QueryType.LabelValues },
|
||||
{ label: 'Metrics', value: QueryType.MetricNames },
|
||||
|
||||
@@ -6,7 +6,7 @@ export interface CancelablePromise<T> {
|
||||
cancel: () => void;
|
||||
}
|
||||
|
||||
export interface CancelablePromiseRejection {
|
||||
interface CancelablePromiseRejection {
|
||||
isCanceled: boolean;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import { isValidLegacyName } from '../../../utf8_support';
|
||||
|
||||
export const CODE_MODE_SUGGESTIONS_INCOMPLETE_EVENT = 'codeModeSuggestionsIncomplete';
|
||||
|
||||
export type SuggestionsIncompleteEvent = CustomEvent<{
|
||||
type SuggestionsIncompleteEvent = CustomEvent<{
|
||||
limit: number;
|
||||
datasourceUid: string;
|
||||
}>;
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ import { SyntaxNode } from '@lezer/common';
|
||||
import { LRParser } from '@lezer/lr';
|
||||
|
||||
// Although 0 isn't explicitly provided in the @grafana/lezer-logql library as the error node ID, it does appear to be the ID of error nodes within lezer.
|
||||
export const ErrorId = 0;
|
||||
const ErrorId = 0;
|
||||
|
||||
export const warningTypes: Record<string, string> = {
|
||||
SubqueryExpr:
|
||||
|
||||
@@ -12,7 +12,7 @@ import { AlertingSettingsOverhaul } from './AlertingSettingsOverhaul';
|
||||
import { DataSourceHttpSettingsOverhaul } from './DataSourceHttpSettingsOverhaul';
|
||||
import { PromSettings } from './PromSettings';
|
||||
import { overhaulStyles } from './shared/utils';
|
||||
export type PrometheusConfigProps = DataSourcePluginOptionsEditorProps<PromOptions>;
|
||||
type PrometheusConfigProps = DataSourcePluginOptionsEditorProps<PromOptions>;
|
||||
|
||||
export const ConfigEditor = (props: PrometheusConfigProps) => {
|
||||
const { options, onOptionsChange } = props;
|
||||
|
||||
@@ -8,7 +8,7 @@ import { PromOptions } from '../types';
|
||||
|
||||
import { docsTip, overhaulStyles } from './shared/utils';
|
||||
|
||||
export type DataSourceHttpSettingsProps = {
|
||||
type DataSourceHttpSettingsProps = {
|
||||
options: DataSourceSettings<PromOptions, {}>;
|
||||
onOptionsChange: (options: DataSourceSettings<PromOptions, {}>) => void;
|
||||
secureSocksDSProxyEnabled: boolean;
|
||||
|
||||
@@ -45,7 +45,7 @@ const API_V1 = {
|
||||
LABELS_VALUES: (labelKey: string) => `/api/v1/label/${labelKey}/values`,
|
||||
};
|
||||
|
||||
export interface PrometheusBaseLanguageProvider {
|
||||
interface PrometheusBaseLanguageProvider {
|
||||
datasource: PrometheusDatasource;
|
||||
|
||||
/**
|
||||
@@ -70,7 +70,7 @@ export interface PrometheusBaseLanguageProvider {
|
||||
/**
|
||||
* @deprecated This interface is deprecated and will be removed.
|
||||
*/
|
||||
export interface PrometheusLegacyLanguageProvider {
|
||||
interface PrometheusLegacyLanguageProvider {
|
||||
/**
|
||||
* @deprecated Use retrieveHistogramMetrics() method instead
|
||||
*/
|
||||
|
||||
@@ -70,7 +70,7 @@ export function processLabels(labels: Array<{ [key: string]: string }>, withName
|
||||
// 4. comma: if there is a comma it will give ,
|
||||
// 5. space: if there is a space after comma it will give the whole space
|
||||
// comma and space is useful for addLabelsToExpression function
|
||||
export const labelRegexp = /\b(\w+)(!?=~?)("[^"\n]*?")(,)?(\s*)?/g;
|
||||
const labelRegexp = /\b(\w+)(!?=~?)("[^"\n]*?")(,)?(\s*)?/g;
|
||||
|
||||
export function expandRecordingRules(query: string, mapping: { [name: string]: RecordingRuleIdentifier }): string {
|
||||
const getRuleRegex = (ruleName: string) => new RegExp(`(\\s|\\(|^)(${ruleName})(\\s|$|\\(|\\[|\\{)`, 'ig');
|
||||
@@ -267,23 +267,19 @@ export function roundMsToMin(milliseconds: number): number {
|
||||
return roundSecToMin(milliseconds / 1000);
|
||||
}
|
||||
|
||||
export function roundSecToMin(seconds: number): number {
|
||||
function roundSecToMin(seconds: number): number {
|
||||
return Math.floor(seconds / 60);
|
||||
}
|
||||
|
||||
// Returns number of minutes rounded up to the nearest nth minute
|
||||
export function roundSecToNextMin(seconds: number, secondsToRound = 1): number {
|
||||
function roundSecToNextMin(seconds: number, secondsToRound = 1): number {
|
||||
return Math.ceil(seconds / 60) - (Math.ceil(seconds / 60) % secondsToRound);
|
||||
}
|
||||
|
||||
export function limitSuggestions(items: string[]) {
|
||||
function limitSuggestions(items: string[]) {
|
||||
return items.slice(0, SUGGESTIONS_LIMIT);
|
||||
}
|
||||
|
||||
export function addLimitInfo(items: unknown[] | undefined): string {
|
||||
return items && items.length >= SUGGESTIONS_LIMIT ? `, limited to the first ${SUGGESTIONS_LIMIT} received items` : '';
|
||||
}
|
||||
|
||||
const FromPromLikeMap: Record<string, AbstractLabelOperator> = {
|
||||
'=': AbstractLabelOperator.Equal,
|
||||
'!=': AbstractLabelOperator.NotEqual,
|
||||
@@ -296,7 +292,7 @@ const ToPromLikeMap: Record<AbstractLabelOperator, string> = invert(FromPromLike
|
||||
string
|
||||
>;
|
||||
|
||||
export function toPromLikeExpr(labelBasedQuery: AbstractQuery): string {
|
||||
function toPromLikeExpr(labelBasedQuery: AbstractQuery): string {
|
||||
const expr = labelBasedQuery.labelMatchers
|
||||
.map((selector: AbstractLabelMatcher) => {
|
||||
const operator = ToPromLikeMap[selector.operator];
|
||||
@@ -320,7 +316,7 @@ export function toPromLikeQuery(labelBasedQuery: AbstractQuery): PromLikeQuery {
|
||||
};
|
||||
}
|
||||
|
||||
export interface PromLikeQuery extends DataQuery {
|
||||
interface PromLikeQuery extends DataQuery {
|
||||
expr: string;
|
||||
range: boolean;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import { AsyncSelect, Select } from '@grafana/ui';
|
||||
import { truncateResult } from '../../language_utils';
|
||||
import { QueryBuilderLabelFilter } from '../shared/types';
|
||||
|
||||
export interface LabelFilterItemProps {
|
||||
interface LabelFilterItemProps {
|
||||
defaultOp: string;
|
||||
item: Partial<QueryBuilderLabelFilter>;
|
||||
onChange: (value: QueryBuilderLabelFilter) => void;
|
||||
|
||||
@@ -13,7 +13,7 @@ import { PromVisualQuery, PromQueryModellerInterface } from '../types';
|
||||
* Props for the LabelParamEditor component.
|
||||
* This editor specifically requires a Prometheus query modeller instance.
|
||||
*/
|
||||
export interface LabelParamEditorProps extends Omit<QueryBuilderOperationParamEditorProps, 'queryModeller'> {
|
||||
interface LabelParamEditorProps extends Omit<QueryBuilderOperationParamEditorProps, 'queryModeller'> {
|
||||
queryModeller: PromQueryModellerInterface;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import { PromVisualQuery } from '../types';
|
||||
import { LabelFilters } from './LabelFilters';
|
||||
import { MetricCombobox } from './MetricCombobox';
|
||||
|
||||
export interface MetricsLabelsSectionProps {
|
||||
interface MetricsLabelsSectionProps {
|
||||
query: PromVisualQuery;
|
||||
datasource: PrometheusDatasource;
|
||||
onChange: (update: PromVisualQuery) => void;
|
||||
@@ -194,7 +194,7 @@ async function getMetrics(
|
||||
}));
|
||||
}
|
||||
|
||||
export function getMetadataString(metric: string, metadata: PromMetricsMetadata): string | undefined {
|
||||
function getMetadataString(metric: string, metadata: PromMetricsMetadata): string | undefined {
|
||||
if (!metadata[metric]) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import { PromVisualQueryBinary } from '../types';
|
||||
|
||||
import { QueryBuilderContent } from './shared/QueryBuilderContent';
|
||||
|
||||
export interface NestedQueryProps {
|
||||
interface NestedQueryProps {
|
||||
nestedQuery: PromVisualQueryBinary;
|
||||
datasource: PrometheusDatasource;
|
||||
index: number;
|
||||
|
||||
@@ -6,7 +6,7 @@ import { PromVisualQuery, PromVisualQueryBinary } from '../types';
|
||||
|
||||
import { NestedQuery } from './NestedQuery';
|
||||
|
||||
export interface NestedQueryListProps {
|
||||
interface NestedQueryListProps {
|
||||
query: PromVisualQuery;
|
||||
datasource: PrometheusDatasource;
|
||||
onChange: (query: PromVisualQuery) => void;
|
||||
|
||||
@@ -8,7 +8,7 @@ import { PromVisualQuery } from '../types';
|
||||
|
||||
import { BaseQueryBuilder } from './shared/BaseQueryBuilder';
|
||||
|
||||
export interface PromQueryBuilderProps {
|
||||
interface PromQueryBuilderProps {
|
||||
query: PromVisualQuery;
|
||||
datasource: PrometheusDatasource;
|
||||
onChange: (update: PromVisualQuery) => void;
|
||||
|
||||
+2
-2
@@ -14,7 +14,7 @@ import { PromQueryBuilder } from './PromQueryBuilder';
|
||||
import { QueryPreview } from './QueryPreview';
|
||||
import { getSettings, MetricsModalSettings } from './metrics-modal/state/state';
|
||||
|
||||
export interface PromQueryBuilderContainerProps {
|
||||
interface PromQueryBuilderContainerProps {
|
||||
query: PromQuery;
|
||||
datasource: PrometheusDatasource;
|
||||
onChange: (update: PromQuery) => void;
|
||||
@@ -23,7 +23,7 @@ export interface PromQueryBuilderContainerProps {
|
||||
showExplain: boolean;
|
||||
}
|
||||
|
||||
export interface State {
|
||||
interface State {
|
||||
visQuery?: PromVisualQuery;
|
||||
expr: string;
|
||||
}
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ import { PromVisualQuery } from '../types';
|
||||
|
||||
export const EXPLAIN_LABEL_FILTER_CONTENT = 'Fetch all series matching metric name and label filters.';
|
||||
|
||||
export interface PromQueryBuilderExplainedProps {
|
||||
interface PromQueryBuilderExplainedProps {
|
||||
query: string;
|
||||
}
|
||||
|
||||
|
||||
+1
-10
@@ -16,16 +16,7 @@ import { QueryOptionGroup } from '../shared/QueryOptionGroup';
|
||||
|
||||
import { getLegendModeLabel, PromQueryLegendEditor } from './PromQueryLegendEditor';
|
||||
|
||||
export interface UIOptions {
|
||||
exemplars: boolean;
|
||||
type: boolean;
|
||||
format: boolean;
|
||||
minStep: boolean;
|
||||
legend: boolean;
|
||||
resolution: boolean;
|
||||
}
|
||||
|
||||
export interface PromQueryBuilderOptionsProps {
|
||||
interface PromQueryBuilderOptionsProps {
|
||||
query: PromQuery;
|
||||
app?: CoreApp;
|
||||
onChange: (update: PromQuery) => void;
|
||||
|
||||
@@ -10,7 +10,7 @@ import { AutoSizeInput, Select } from '@grafana/ui';
|
||||
|
||||
import { LegendFormatMode } from '../../types';
|
||||
|
||||
export interface PromQueryLegendEditorProps {
|
||||
interface PromQueryLegendEditorProps {
|
||||
legendFormat: string | undefined;
|
||||
onChange: (legendFormat: string) => void;
|
||||
onRunQuery: () => void;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { EditorFieldGroup, EditorRow } from '@grafana/plugin-ui';
|
||||
import { promqlGrammar } from '../../promql';
|
||||
import { RawQuery } from '../shared/RawQuery';
|
||||
|
||||
export interface QueryPreviewProps {
|
||||
interface QueryPreviewProps {
|
||||
query: string;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import { GrafanaTheme2 } from '@grafana/data';
|
||||
import { Trans, t } from '@grafana/i18n';
|
||||
import { Icon, useStyles2, Stack } from '@grafana/ui';
|
||||
|
||||
export interface Props {
|
||||
interface Props {
|
||||
feedbackUrl?: string;
|
||||
}
|
||||
|
||||
|
||||
+14
-18
@@ -38,10 +38,24 @@ import {
|
||||
tracking,
|
||||
} from './state/helpers';
|
||||
import {
|
||||
buildMetrics,
|
||||
DEFAULT_RESULTS_PER_PAGE,
|
||||
filterMetricsBackend,
|
||||
initialState,
|
||||
MAXIMUM_RESULTS_PER_PAGE,
|
||||
MetricsModalMetadata,
|
||||
setDisableTextWrap,
|
||||
setFullMetaSearch,
|
||||
setFuzzySearchQuery,
|
||||
setIncludeNullMetadata,
|
||||
setIsLoading,
|
||||
setMetaHaystack,
|
||||
setNameHaystack,
|
||||
setPageNum,
|
||||
setResultsPerPage,
|
||||
setSelectedTypes,
|
||||
setUseBackend,
|
||||
showAdditionalSettings,
|
||||
stateSlice,
|
||||
} from './state/state';
|
||||
import { getStyles } from './styles';
|
||||
@@ -354,21 +368,3 @@ export const metricsModaltestIds = {
|
||||
setUseBackend: 'set-use-backend',
|
||||
showAdditionalSettings: 'show-additional-settings',
|
||||
};
|
||||
// actions to update the state
|
||||
export const {
|
||||
setIsLoading,
|
||||
buildMetrics,
|
||||
filterMetricsBackend,
|
||||
setResultsPerPage,
|
||||
setPageNum,
|
||||
setFuzzySearchQuery,
|
||||
setNameHaystack,
|
||||
setMetaHaystack,
|
||||
setFullMetaSearch,
|
||||
setIncludeNullMetadata,
|
||||
setSelectedTypes,
|
||||
setUseBackend,
|
||||
setDisableTextWrap,
|
||||
showAdditionalSettings,
|
||||
setFilteredMetricCount,
|
||||
} = stateSlice.actions;
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ import { TimeRange } from '@grafana/data';
|
||||
import { PrometheusDatasource } from '../../../../datasource';
|
||||
import { PromVisualQuery } from '../../../types';
|
||||
|
||||
export interface MetricsModalState {
|
||||
interface MetricsModalState {
|
||||
useBackend: boolean;
|
||||
disableTextWrap: boolean;
|
||||
includeNullMetadata: boolean;
|
||||
|
||||
+5
-34
@@ -6,12 +6,11 @@ import { reportInteraction } from '@grafana/runtime';
|
||||
|
||||
import { PrometheusDatasource } from '../../../../datasource';
|
||||
import { PromMetricsMetadata } from '../../../../types';
|
||||
import { regexifyLabelValuesQueryString } from '../../../parsingUtils';
|
||||
import { QueryBuilderLabelFilter } from '../../../shared/types';
|
||||
import { PromVisualQuery } from '../../../types';
|
||||
import { HaystackDictionary, MetricData, MetricsData, PromFilterOption } from '../types';
|
||||
|
||||
import { MetricsModalMetadata, MetricsModalState, setFilteredMetricCount } from './state';
|
||||
|
||||
export async function setMetrics(
|
||||
datasource: PrometheusDatasource,
|
||||
query: PromVisualQuery,
|
||||
@@ -86,11 +85,11 @@ function buildMetricData(metric: string, datasource: PrometheusDatasource): Metr
|
||||
return metricData;
|
||||
}
|
||||
|
||||
export function getMetadataHelp(metric: string, metadata: PromMetricsMetadata): string | undefined {
|
||||
function getMetadataHelp(metric: string, metadata: PromMetricsMetadata): string | undefined {
|
||||
return metadata[metric]?.help;
|
||||
}
|
||||
|
||||
export function getMetadataType(metric: string, metadata: PromMetricsMetadata): string | undefined {
|
||||
function getMetadataType(metric: string, metadata: PromMetricsMetadata): string | undefined {
|
||||
return metadata[metric]?.type;
|
||||
}
|
||||
|
||||
@@ -110,7 +109,7 @@ export function displayedMetrics(state: MetricsModalState, dispatch: React.Dispa
|
||||
/**
|
||||
* Filter the metrics with all the options, fuzzy, type, null metadata
|
||||
*/
|
||||
export function filterMetrics(state: MetricsModalState): MetricsData {
|
||||
function filterMetrics(state: MetricsModalState): MetricsData {
|
||||
let filteredMetrics: MetricsData = state.metrics;
|
||||
|
||||
if (state.fuzzySearchQuery && !state.useBackend) {
|
||||
@@ -162,7 +161,7 @@ export function calculatePageList(state: MetricsModalState) {
|
||||
return [...Array(pages).keys()].map((i) => i + 1);
|
||||
}
|
||||
|
||||
export function sliceMetrics(metrics: MetricsData, pageNum: number, resultsPerPage: number) {
|
||||
function sliceMetrics(metrics: MetricsData, pageNum: number, resultsPerPage: number) {
|
||||
const calcResultsPerPage: number = resultsPerPage === 0 ? 1 : resultsPerPage;
|
||||
const start: number = pageNum === 1 ? 0 : (pageNum - 1) * calcResultsPerPage;
|
||||
const end: number = start + calcResultsPerPage;
|
||||
@@ -181,34 +180,6 @@ export const calculateResultsPerPage = (results: number, defaultResults: number,
|
||||
return results ?? defaultResults;
|
||||
};
|
||||
|
||||
/**
|
||||
* The backend query that replaces the uFuzzy search when the option 'useBackend' has been selected
|
||||
* this is a regex search either to the series or labels Prometheus endpoint
|
||||
* depending on which the Prometheus type or version supports
|
||||
* @param metricText
|
||||
* @param labels
|
||||
* @param datasource
|
||||
*/
|
||||
export async function getBackendSearchMetrics(
|
||||
metricText: string,
|
||||
labels: QueryBuilderLabelFilter[],
|
||||
datasource: PrometheusDatasource
|
||||
): Promise<Array<{ value: string }>> {
|
||||
const queryString = regexifyLabelValuesQueryString(metricText);
|
||||
|
||||
const labelsParams = labels.map((label) => {
|
||||
return `,${label.label}="${label.value}"`;
|
||||
});
|
||||
|
||||
const params = `label_values({__name__=~".*${queryString}"${labels ? labelsParams.join() : ''}},__name__)`;
|
||||
|
||||
const results = datasource.metricFindQuery(params);
|
||||
|
||||
return await results.then((results) => {
|
||||
return results.map((result) => buildMetricData(result.text, datasource));
|
||||
});
|
||||
}
|
||||
|
||||
export function tracking(event: string, state?: MetricsModalState | null, metric?: string, query?: PromVisualQuery) {
|
||||
switch (event) {
|
||||
case 'grafana_prom_metric_encycopedia_tracking':
|
||||
|
||||
@@ -16,17 +16,3 @@ export type PromFilterOption = {
|
||||
export interface HaystackDictionary {
|
||||
[needle: string]: MetricData;
|
||||
}
|
||||
|
||||
export type UFuzzyInfo = {
|
||||
idx: number[];
|
||||
start: number[];
|
||||
chars: number[];
|
||||
terms: number[];
|
||||
interIns: number[];
|
||||
intraIns: number[];
|
||||
interLft2: number[];
|
||||
interRgt2: number[];
|
||||
interLft1: number[];
|
||||
interRgt1: number[];
|
||||
ranges: number[][];
|
||||
};
|
||||
|
||||
@@ -10,7 +10,7 @@ const uf = new uFuzzy({
|
||||
intraDel: 1,
|
||||
});
|
||||
|
||||
export function fuzzySearch(haystack: string[], query: string, dispatcher: (data: string[][]) => void) {
|
||||
function fuzzySearch(haystack: string[], query: string, dispatcher: (data: string[][]) => void) {
|
||||
const [idxs, info, order] = uf.search(haystack, query, 0, 1e5);
|
||||
|
||||
let haystackOrder: string[] = [];
|
||||
|
||||
@@ -5,7 +5,7 @@ import { store } from '@grafana/data';
|
||||
|
||||
export const promQueryEditorExplainKey = 'PrometheusQueryEditorExplainDefault';
|
||||
|
||||
export type QueryEditorFlags = typeof promQueryEditorExplainKey;
|
||||
type QueryEditorFlags = typeof promQueryEditorExplainKey;
|
||||
|
||||
function getFlagValue(key: QueryEditorFlags, defaultValue = false): boolean {
|
||||
const val = store.get(key);
|
||||
|
||||
@@ -284,7 +284,7 @@ export function getOperationDefinitions(): QueryBuilderOperationDef[] {
|
||||
return list;
|
||||
}
|
||||
|
||||
export function createFunction(definition: Partial<QueryBuilderOperationDef>): QueryBuilderOperationDef {
|
||||
function createFunction(definition: Partial<QueryBuilderOperationDef>): QueryBuilderOperationDef {
|
||||
return {
|
||||
...definition,
|
||||
id: definition.id!,
|
||||
@@ -297,7 +297,7 @@ export function createFunction(definition: Partial<QueryBuilderOperationDef>): Q
|
||||
};
|
||||
}
|
||||
|
||||
export function createRangeFunction(name: string, withRateInterval = false): QueryBuilderOperationDef {
|
||||
function createRangeFunction(name: string, withRateInterval = false): QueryBuilderOperationDef {
|
||||
return {
|
||||
id: name,
|
||||
name: getPromOperationDisplayName(name),
|
||||
@@ -325,7 +325,7 @@ function operationTypeChangedHandlerForRangeFunction(
|
||||
return operation;
|
||||
}
|
||||
|
||||
export function operationWithRangeVectorRenderer(
|
||||
function operationWithRangeVectorRenderer(
|
||||
model: QueryBuilderOperation,
|
||||
def: QueryBuilderOperationDef,
|
||||
innerExpr: string
|
||||
|
||||
@@ -110,7 +110,7 @@ interface Context {
|
||||
* @param node
|
||||
* @param context
|
||||
*/
|
||||
export function handleExpression(expr: string, node: SyntaxNode, context: Context) {
|
||||
function handleExpression(expr: string, node: SyntaxNode, context: Context) {
|
||||
const visQuery = context.query;
|
||||
|
||||
switch (node.type.id) {
|
||||
|
||||
@@ -70,7 +70,7 @@ const varTypeFunc = [
|
||||
* Get back the text with variables in their original format.
|
||||
* @param expr
|
||||
*/
|
||||
export function returnVariables(expr: string) {
|
||||
function returnVariables(expr: string) {
|
||||
return expr.replace(/__V_(\d)__(.+?)__V__(?:__F__(\w+)__F__)?/g, (match, type, v, f) => {
|
||||
return varTypeFunc[parseInt(type, 10)](v, f);
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
VisualQueryModeller,
|
||||
} from './types';
|
||||
|
||||
export interface Props {
|
||||
interface Props {
|
||||
operation: QueryBuilderOperation;
|
||||
index: number;
|
||||
query: any;
|
||||
|
||||
@@ -5,7 +5,7 @@ import * as React from 'react';
|
||||
import { GrafanaTheme2, renderMarkdown } from '@grafana/data';
|
||||
import { useStyles2 } from '@grafana/ui';
|
||||
|
||||
export interface Props {
|
||||
interface Props {
|
||||
title?: React.ReactNode;
|
||||
children?: React.ReactNode;
|
||||
markdown?: string;
|
||||
|
||||
@@ -11,7 +11,7 @@ import { Button, Select, useStyles2 } from '@grafana/ui';
|
||||
import { OperationInfoButton } from './OperationInfoButton';
|
||||
import { QueryBuilderOperation, QueryBuilderOperationDef, VisualQueryModeller } from './types';
|
||||
|
||||
export interface Props {
|
||||
interface Props {
|
||||
operation: QueryBuilderOperation;
|
||||
def: QueryBuilderOperationDef;
|
||||
index: number;
|
||||
|
||||
@@ -19,7 +19,7 @@ import { Button, Portal, useStyles2 } from '@grafana/ui';
|
||||
|
||||
import { QueryBuilderOperation, QueryBuilderOperationDef } from './types';
|
||||
|
||||
export interface Props {
|
||||
interface Props {
|
||||
operation: QueryBuilderOperation;
|
||||
def: QueryBuilderOperationDef;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import { Button, Cascader, CascaderOption, useStyles2, Stack } from '@grafana/ui
|
||||
import { OperationEditor } from './OperationEditor';
|
||||
import { QueryBuilderOperation, QueryWithOperations, VisualQueryModeller } from './types';
|
||||
|
||||
export interface Props<T extends QueryWithOperations> {
|
||||
interface Props<T extends QueryWithOperations> {
|
||||
query: T;
|
||||
datasource: DataSourceApi;
|
||||
onChange: (query: T) => void;
|
||||
|
||||
@@ -5,7 +5,7 @@ import { OperationExplainedBox } from './OperationExplainedBox';
|
||||
import { RawQuery } from './RawQuery';
|
||||
import { QueryBuilderOperation, QueryWithOperations, VisualQueryModeller } from './types';
|
||||
|
||||
export interface Props<T extends QueryWithOperations> {
|
||||
interface Props<T extends QueryWithOperations> {
|
||||
query: T;
|
||||
queryModeller: VisualQueryModeller;
|
||||
explainMode?: boolean;
|
||||
|
||||
@@ -10,7 +10,7 @@ import { Button, Tooltip, useStyles2 } from '@grafana/ui';
|
||||
import { PrometheusDatasource } from '../../datasource';
|
||||
import { PromQueryModellerInterface, PromVisualQuery } from '../types';
|
||||
|
||||
export interface Props {
|
||||
interface Props {
|
||||
query: PromVisualQuery;
|
||||
datasource: PrometheusDatasource;
|
||||
queryModeller: PromQueryModellerInterface;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { RadioButtonGroup } from '@grafana/ui';
|
||||
|
||||
import { QueryEditorMode } from './types';
|
||||
|
||||
export interface Props {
|
||||
interface Props {
|
||||
mode: QueryEditorMode;
|
||||
onChange: (mode: QueryEditorMode) => void;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { HTMLProps, useRef } from 'react';
|
||||
import { GrafanaTheme2 } from '@grafana/data';
|
||||
import { Switch, useStyles2, Stack } from '@grafana/ui';
|
||||
|
||||
export interface Props extends Omit<HTMLProps<HTMLInputElement>, 'value' | 'ref'> {
|
||||
interface Props extends Omit<HTMLProps<HTMLInputElement>, 'value' | 'ref'> {
|
||||
value?: boolean;
|
||||
label: string;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { useToggle } from 'react-use';
|
||||
import { GrafanaTheme2 } from '@grafana/data';
|
||||
import { Collapse, useStyles2, Stack } from '@grafana/ui';
|
||||
|
||||
export interface Props {
|
||||
interface Props {
|
||||
title: string;
|
||||
collapsedInfo: string[];
|
||||
children: React.ReactNode;
|
||||
|
||||
@@ -6,7 +6,7 @@ import { GrafanaTheme2 } from '@grafana/data';
|
||||
import { t } from '@grafana/i18n';
|
||||
import { useTheme2 } from '@grafana/ui';
|
||||
|
||||
export interface Props {
|
||||
interface Props {
|
||||
query: string;
|
||||
lang: {
|
||||
grammar: Grammar;
|
||||
|
||||
@@ -23,7 +23,7 @@ export function renderBinaryQueries(
|
||||
/**
|
||||
* Renders a binary query
|
||||
*/
|
||||
export function renderBinaryQuery(leftOperand: string, binaryQuery: VisualQueryBinary<PromLokiVisualQuery>): string {
|
||||
function renderBinaryQuery(leftOperand: string, binaryQuery: VisualQueryBinary<PromLokiVisualQuery>): string {
|
||||
let result = leftOperand + ` ${binaryQuery.operator} `;
|
||||
|
||||
if (binaryQuery.vectorMatches) {
|
||||
|
||||
@@ -39,21 +39,17 @@ export interface QueryBuilderOperationDef<T = any> extends RegistryItem {
|
||||
changeTypeHandler?: (op: QueryBuilderOperation, newDef: QueryBuilderOperationDef<T>) => QueryBuilderOperation;
|
||||
}
|
||||
|
||||
export type QueryBuilderAddOperationHandler<T> = (
|
||||
def: QueryBuilderOperationDef,
|
||||
query: T,
|
||||
modeller: VisualQueryModeller
|
||||
) => T;
|
||||
type QueryBuilderAddOperationHandler<T> = (def: QueryBuilderOperationDef, query: T, modeller: VisualQueryModeller) => T;
|
||||
|
||||
export type QueryBuilderExplainOperationHandler = (op: QueryBuilderOperation, def?: QueryBuilderOperationDef) => string;
|
||||
type QueryBuilderExplainOperationHandler = (op: QueryBuilderOperation, def?: QueryBuilderOperationDef) => string;
|
||||
|
||||
export type QueryBuilderOnParamChangedHandler = (
|
||||
type QueryBuilderOnParamChangedHandler = (
|
||||
index: number,
|
||||
operation: QueryBuilderOperation,
|
||||
operationDef: QueryBuilderOperationDef
|
||||
) => QueryBuilderOperation;
|
||||
|
||||
export type QueryBuilderOperationRenderer = (
|
||||
type QueryBuilderOperationRenderer = (
|
||||
model: QueryBuilderOperation,
|
||||
def: QueryBuilderOperationDef,
|
||||
innerExpr: string
|
||||
@@ -75,16 +71,6 @@ export interface QueryBuilderOperationParamDef {
|
||||
runQueryOnEnter?: boolean;
|
||||
}
|
||||
|
||||
export interface QueryBuilderOperationEditorProps {
|
||||
operation: QueryBuilderOperation;
|
||||
index: number;
|
||||
query: any;
|
||||
datasource: DataSourceApi;
|
||||
queryModeller: VisualQueryModeller;
|
||||
onChange: (index: number, update: QueryBuilderOperation) => void;
|
||||
onRemove: (index: number) => void;
|
||||
}
|
||||
|
||||
export interface QueryBuilderOperationParamEditorProps {
|
||||
onChange: (index: number, value: QueryBuilderOperationParamValue) => void;
|
||||
onRunQuery: () => void;
|
||||
|
||||
@@ -19,12 +19,19 @@ export interface PromVisualQuery {
|
||||
|
||||
export interface PromQueryModellerInterface {
|
||||
renderLabels(labels: QueryBuilderLabelFilter[]): string;
|
||||
|
||||
renderQuery(query: PromVisualQuery, nested?: boolean): string;
|
||||
|
||||
hasBinaryOp(query: PromVisualQuery): boolean;
|
||||
|
||||
getQueryPatterns(): PromQueryPattern[];
|
||||
|
||||
getOperationsForCategory(category: string): QueryBuilderOperationDef[];
|
||||
|
||||
getOperationDef(id: string): QueryBuilderOperationDef | undefined;
|
||||
|
||||
getAlternativeOperations(key: string): QueryBuilderOperationDef[];
|
||||
|
||||
getCategories(): string[];
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ export interface CacheRequestInfo<T extends SupportedQueryTypes> {
|
||||
* This is the string used to uniquely identify a field within a "target"
|
||||
* @param field
|
||||
*/
|
||||
export const getFieldIdentity = (field: Field) => `${field.type}|${field.name}|${JSON.stringify(field.labels ?? '')}`;
|
||||
const getFieldIdentity = (field: Field) => `${field.type}|${field.name}|${JSON.stringify(field.labels ?? '')}`;
|
||||
|
||||
/**
|
||||
* NOMENCLATURE
|
||||
|
||||
@@ -7,7 +7,7 @@ import { clone } from 'lodash';
|
||||
* @param start - First timestamp (ms)
|
||||
* @param step - step duration (ms)
|
||||
*/
|
||||
export const getMockTimeFrameArray = (length: number, start: number, step: number) => {
|
||||
const getMockTimeFrameArray = (length: number, start: number, step: number) => {
|
||||
let timeValues: number[] = [];
|
||||
for (let i = 0; i < length; i++) {
|
||||
timeValues.push(start + i * step);
|
||||
@@ -21,7 +21,7 @@ export const getMockTimeFrameArray = (length: number, start: number, step: numbe
|
||||
* @param values
|
||||
* @param high
|
||||
*/
|
||||
export const getMockValueFrameArray = (length: number, values = 0): number[] => {
|
||||
const getMockValueFrameArray = (length: number, values = 0): number[] => {
|
||||
return Array(length).fill(values);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,20 +1,9 @@
|
||||
// Core Grafana history https://github.com/grafana/grafana/blob/v11.0.0-preview/packages/grafana-ui/src/components/Select/SelectBase.tsx
|
||||
import { waitFor } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { select } from 'react-select-event';
|
||||
import { byRole } from 'testing-library-selector';
|
||||
|
||||
// Used to select an option or options from a Select in unit tests
|
||||
export const selectOptionInTest = async (
|
||||
input: HTMLElement,
|
||||
optionOrOptions: string | RegExp | Array<string | RegExp>
|
||||
) => await waitFor(() => select(input, optionOrOptions, { container: document.body }));
|
||||
|
||||
// Finds the parent of the Select so you can assert if it has a value
|
||||
export const getSelectParent = (input: HTMLElement) =>
|
||||
input.parentElement?.parentElement?.parentElement?.parentElement?.parentElement;
|
||||
|
||||
export const clickSelectOption = async (selectElement: HTMLElement, optionText: string): Promise<void> => {
|
||||
await userEvent.click(byRole('combobox').get(selectElement));
|
||||
await selectOptionInTest(selectElement, optionText);
|
||||
};
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
|
||||
import { PromOptions, PromQuery } from '../../types';
|
||||
|
||||
export const getMockDataSource = <T extends DataSourceJsonData>(
|
||||
const getMockDataSource = <T extends DataSourceJsonData>(
|
||||
overrides?: Partial<DataSourceSettings<T>>
|
||||
): DataSourceSettings<T> =>
|
||||
merge(
|
||||
@@ -98,82 +98,6 @@ export function createDefaultPromResponse() {
|
||||
};
|
||||
}
|
||||
|
||||
export function createAnnotationResponse() {
|
||||
const response = {
|
||||
data: {
|
||||
results: {
|
||||
X: {
|
||||
frames: [
|
||||
{
|
||||
schema: {
|
||||
name: 'bar',
|
||||
refId: 'X',
|
||||
meta: {
|
||||
typeVersion: [0, 0],
|
||||
executedQueryString: 'Expr: ALERTS{}\nStep: 1m0s',
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: 'Time',
|
||||
type: 'time',
|
||||
typeInfo: {
|
||||
frame: 'time.Time',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Value',
|
||||
type: 'number',
|
||||
typeInfo: {
|
||||
frame: 'float64',
|
||||
},
|
||||
labels: {
|
||||
__name__: 'ALERTS',
|
||||
alertname: 'InstanceDown',
|
||||
alertstate: 'firing',
|
||||
instance: 'testinstance',
|
||||
job: 'testjob',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
data: {
|
||||
values: [[123], [456]],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
return { ...response };
|
||||
}
|
||||
|
||||
export function createEmptyAnnotationResponse() {
|
||||
const response = {
|
||||
data: {
|
||||
results: {
|
||||
X: {
|
||||
frames: [
|
||||
{
|
||||
schema: {
|
||||
name: 'bar',
|
||||
refId: 'X',
|
||||
fields: [],
|
||||
},
|
||||
data: {
|
||||
values: [],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
return { ...response };
|
||||
}
|
||||
|
||||
export function getMockTimeRange(range = '6h'): TimeRange {
|
||||
return rangeUtil.convertRawToRange({
|
||||
from: `now-${range}`,
|
||||
|
||||
Reference in New Issue
Block a user