mirror of
https://github.com/grafana/grafana.git
synced 2024-11-24 09:50:29 -06:00
feat(loki-query-autocomplete): suggest unique history items (#60262)
This commit is contained in:
parent
9a41277ecd
commit
2c1b65021d
@ -23,6 +23,13 @@ const history = [
|
||||
expr: '{unit: test}',
|
||||
},
|
||||
},
|
||||
{
|
||||
ts: 87654321,
|
||||
query: {
|
||||
refId: 'test-1',
|
||||
expr: '{unit: test}',
|
||||
},
|
||||
},
|
||||
{
|
||||
ts: 0,
|
||||
query: {
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { chain } from 'lodash';
|
||||
|
||||
import { HistoryItem } from '@grafana/data';
|
||||
import { escapeLabelValueInExactSelector } from 'app/plugins/datasource/prometheus/language_utils';
|
||||
|
||||
@ -7,7 +9,10 @@ import { LokiQuery } from '../../../types';
|
||||
import { Label } from './situation';
|
||||
|
||||
export class CompletionDataProvider {
|
||||
constructor(private languageProvider: LanguageProvider, private history: Array<HistoryItem<LokiQuery>> = []) {}
|
||||
private history: string[] = [];
|
||||
constructor(private languageProvider: LanguageProvider, history: Array<HistoryItem<LokiQuery>> = []) {
|
||||
this.setHistory(history);
|
||||
}
|
||||
|
||||
private buildSelector(labels: Label[]): string {
|
||||
const allLabelTexts = labels.map(
|
||||
@ -17,8 +22,16 @@ export class CompletionDataProvider {
|
||||
return `{${allLabelTexts.join(',')}}`;
|
||||
}
|
||||
|
||||
setHistory(history: Array<HistoryItem<LokiQuery>> = []) {
|
||||
this.history = chain(history)
|
||||
.map((history: HistoryItem<LokiQuery>) => history.query.expr)
|
||||
.filter()
|
||||
.uniq()
|
||||
.value();
|
||||
}
|
||||
|
||||
getHistory() {
|
||||
return this.history.map((entry) => entry.query.expr).filter((expr) => expr !== undefined);
|
||||
return this.history;
|
||||
}
|
||||
|
||||
async getLabelNames(otherLabels: Label[] = []) {
|
||||
|
@ -197,7 +197,7 @@ describe('getCompletions', () => {
|
||||
const situation = { type } as Situation;
|
||||
const completions = await getCompletions(situation, completionProvider);
|
||||
|
||||
expect(completions).toHaveLength(25);
|
||||
expect(completions).toHaveLength(24);
|
||||
});
|
||||
|
||||
test('Returns completion options when the situation is IN_DURATION', async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user