mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 16:15:42 -06:00
Cloud Monitoring: Support AliasBy property in MQL mode (#73116)
This commit is contained in:
parent
89c7116720
commit
eeefa7dd22
@ -1,4 +1,4 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { render, screen, waitFor } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
|
||||
import { createMockDatasource } from '../__mocks__/cloudMonitoringDatasource';
|
||||
@ -64,4 +64,17 @@ describe('MetricQueryEditor', () => {
|
||||
const projectDropdown = await screen.findByLabelText('Project');
|
||||
expect(projectDropdown).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('preserves the aliasBy property when switching between Builder and MQL queries', async () => {
|
||||
const query = createMockQuery({ aliasBy: 'AliasTest' });
|
||||
query.queryType = QueryType.TIME_SERIES_QUERY;
|
||||
|
||||
render(<MetricQueryEditor {...defaultProps} query={query} />);
|
||||
await waitFor(() => expect(screen.getByLabelText('Alias by').closest('input')!.value).toEqual('AliasTest'));
|
||||
|
||||
query.queryType = QueryType.TIME_SERIES_LIST;
|
||||
|
||||
render(<MetricQueryEditor {...defaultProps} query={query} />);
|
||||
await waitFor(() => expect(screen.getByLabelText('Alias by').closest('input')!.value).toEqual('AliasTest'));
|
||||
});
|
||||
});
|
||||
|
@ -1,12 +1,13 @@
|
||||
import React, { useCallback, useEffect } from 'react';
|
||||
|
||||
import { SelectableValue } from '@grafana/data';
|
||||
import { EditorRows } from '@grafana/experimental';
|
||||
import { EditorRows, Stack } from '@grafana/experimental';
|
||||
|
||||
import CloudMonitoringDatasource from '../datasource';
|
||||
import { AlignmentTypes, CloudMonitoringQuery, QueryType, TimeSeriesList, TimeSeriesQuery } from '../types/query';
|
||||
import { CustomMetaData } from '../types/types';
|
||||
|
||||
import { AliasBy } from './AliasBy';
|
||||
import { GraphPeriod } from './GraphPeriod';
|
||||
import { MQLQueryEditor } from './MQLQueryEditor';
|
||||
import { Project } from './Project';
|
||||
@ -68,6 +69,7 @@ function Editor({
|
||||
datasource: query.datasource,
|
||||
queryType: QueryType.TIME_SERIES_LIST,
|
||||
timeSeriesList: defaultTimeSeriesList(datasource),
|
||||
aliasBy: query.aliasBy,
|
||||
});
|
||||
}
|
||||
if (query.queryType === QueryType.TIME_SERIES_QUERY && !query.timeSeriesQuery) {
|
||||
@ -76,6 +78,7 @@ function Editor({
|
||||
datasource: query.datasource,
|
||||
queryType: QueryType.TIME_SERIES_QUERY,
|
||||
timeSeriesQuery: defaultTimeSeriesQuery(datasource),
|
||||
aliasBy: query.aliasBy,
|
||||
});
|
||||
}
|
||||
}, [onQueryChange, query, datasource]);
|
||||
@ -98,13 +101,22 @@ function Editor({
|
||||
|
||||
{query.queryType === QueryType.TIME_SERIES_QUERY && query.timeSeriesQuery && (
|
||||
<>
|
||||
<Project
|
||||
refId={refId}
|
||||
datasource={datasource}
|
||||
onChange={(projectName) => onChangeTimeSeriesQuery({ ...query.timeSeriesQuery!, projectName: projectName })}
|
||||
templateVariableOptions={variableOptionGroup.options}
|
||||
projectName={query.timeSeriesQuery.projectName!}
|
||||
/>
|
||||
<Stack gap={1} direction="row">
|
||||
<Project
|
||||
refId={refId}
|
||||
datasource={datasource}
|
||||
onChange={(projectName) =>
|
||||
onChangeTimeSeriesQuery({ ...query.timeSeriesQuery!, projectName: projectName })
|
||||
}
|
||||
templateVariableOptions={variableOptionGroup.options}
|
||||
projectName={query.timeSeriesQuery.projectName!}
|
||||
/>
|
||||
<AliasBy
|
||||
refId={refId}
|
||||
value={query.aliasBy}
|
||||
onChange={(aliasBy: string) => onQueryChange({ ...query, aliasBy })}
|
||||
/>
|
||||
</Stack>
|
||||
<MQLQueryEditor
|
||||
onChange={(q: string) => onChangeTimeSeriesQuery({ ...query.timeSeriesQuery!, query: q })}
|
||||
onRunQuery={onRunQuery}
|
||||
|
Loading…
Reference in New Issue
Block a user