[v11.0.x] Loki: Fix editor history in wrong order (#88669)

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

(cherry picked from commit 2fb63cd2e6)

Co-authored-by: Sven Grossmann <sven.grossmann@grafana.com>
This commit is contained in:
grafana-delivery-bot[bot]
2024-06-04 12:57:14 +03:00
committed by GitHub
co-authored by Sven Grossmann
parent b1b3bd0089
commit 0ff6442e45
2 changed files with 14 additions and 6 deletions
@@ -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
},
},
{
@@ -83,11 +90,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 = [
{
@@ -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();