Loki: Fix editor history in wrong order (#88666)

This commit is contained in:
Sven Grossmann 2024-06-04 11:40:04 +02:00 committed by GitHub
parent 3f7017a471
commit 2fb63cd2e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 6 deletions

View File

@ -13,21 +13,28 @@ const history: Array<HistoryItem<LokiQuery>> = [
ts: 12345678,
query: {
refId: 'test-1',
expr: '{test: unit}',
expr: '{test="unit"}',
},
},
{
ts: 87654321,
query: {
refId: 'test-1',
expr: '{unit: test}',
expr: '{unit="test"}',
},
},
{
ts: 87654321,
query: {
refId: 'test-1',
expr: '{unit: test}',
expr: '{unit="test"}',
},
},
{
ts: 87654325,
query: {
refId: 'test-2',
expr: '{unit="test"} ', // will be trimmed and removed
},
},
{
@ -82,11 +89,11 @@ describe('CompletionDataProvider', () => {
});
test('Returns the expected history entries', () => {
expect(completionProvider.getHistory()).toEqual(['{test: unit}', '{unit: test}']);
expect(completionProvider.getHistory()).toEqual(['{unit="test"}', '{test="unit"}']);
});
test('Processes updates to the current historyRef value', () => {
expect(completionProvider.getHistory()).toEqual(['{test: unit}', '{unit: test}']);
expect(completionProvider.getHistory()).toEqual(['{unit="test"}', '{test="unit"}']);
historyRef.current = [
{

View File

@ -32,7 +32,8 @@ export class CompletionDataProvider {
getHistory() {
return chain(this.historyRef.current)
.map((history: HistoryItem<LokiQuery>) => history.query.expr)
.orderBy('ts', 'desc')
.map((history: HistoryItem<LokiQuery>) => history.query.expr.trim())
.filter()
.uniq()
.value();