mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki Autocomplete: Suggest only possible labels for unwrap (#61411)
* feat(loki-autocomplete): filter valid labels for unwrap autocomplete suggestions * refactor(unwrap): reuse new function in builder
This commit is contained in:
@@ -6,7 +6,11 @@ import { TypeaheadInput } from '@grafana/ui';
|
||||
import LanguageProvider, { LokiHistoryItem } from './LanguageProvider';
|
||||
import { LokiDatasource } from './datasource';
|
||||
import { createLokiDatasource, createMetadataRequest } from './mocks';
|
||||
import { extractLogParserFromDataFrame, extractLabelKeysFromDataFrame } from './responseUtils';
|
||||
import {
|
||||
extractLogParserFromDataFrame,
|
||||
extractLabelKeysFromDataFrame,
|
||||
extractUnwrapLabelKeysFromDataFrame,
|
||||
} from './responseUtils';
|
||||
import { LokiQueryType } from './types';
|
||||
|
||||
jest.mock('./responseUtils');
|
||||
@@ -304,11 +308,13 @@ describe('Query imports', () => {
|
||||
let datasource: LokiDatasource, languageProvider: LanguageProvider;
|
||||
const extractLogParserFromDataFrameMock = jest.mocked(extractLogParserFromDataFrame);
|
||||
const extractedLabelKeys = ['extracted', 'label'];
|
||||
const unwrapLabelKeys = ['unwrap', 'labels'];
|
||||
|
||||
beforeEach(() => {
|
||||
datasource = createLokiDatasource();
|
||||
languageProvider = new LanguageProvider(datasource);
|
||||
jest.mocked(extractLabelKeysFromDataFrame).mockReturnValue(extractedLabelKeys);
|
||||
jest.mocked(extractUnwrapLabelKeysFromDataFrame).mockReturnValue(unwrapLabelKeys);
|
||||
});
|
||||
|
||||
it('identifies selectors with JSON parser data', async () => {
|
||||
@@ -317,6 +323,7 @@ describe('Query imports', () => {
|
||||
|
||||
expect(await languageProvider.getParserAndLabelKeys('{place="luna"}')).toEqual({
|
||||
extractedLabelKeys,
|
||||
unwrapLabelKeys,
|
||||
hasJSON: true,
|
||||
hasLogfmt: false,
|
||||
});
|
||||
@@ -328,6 +335,7 @@ describe('Query imports', () => {
|
||||
|
||||
expect(await languageProvider.getParserAndLabelKeys('{place="luna"}')).toEqual({
|
||||
extractedLabelKeys,
|
||||
unwrapLabelKeys,
|
||||
hasJSON: false,
|
||||
hasLogfmt: true,
|
||||
});
|
||||
@@ -339,6 +347,7 @@ describe('Query imports', () => {
|
||||
|
||||
expect(await languageProvider.getParserAndLabelKeys('{place="luna"}')).toEqual({
|
||||
extractedLabelKeys: [],
|
||||
unwrapLabelKeys: [],
|
||||
hasJSON: false,
|
||||
hasLogfmt: false,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user