Loki: Fix showing of duplicated label values in dropdown in query builder (#50680) (#50688)

* Prometheus,Loki: Fix showing of duplicated values in dropdown

* Use different more readable solution

* Update

(cherry picked from commit 77bdbe1dea)

Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>
This commit is contained in:
Grot (@grafanabot)
2022-06-13 15:47:36 +02:00
committed by GitHub
co-authored by Ivana Huckova
parent 001f3709ae
commit da76c87bfe
@@ -1,3 +1,4 @@
import { uniqBy } from 'lodash';
import React, { useState } from 'react';
import { SelectableValue, toOption } from '@grafana/data';
@@ -38,7 +39,11 @@ export function LabelFilterItem({ item, defaultOp, onChange, onDelete, onGetLabe
};
const getOptions = (): SelectableValue[] => {
return [...getSelectOptionsFromString(item?.value).map(toOption), ...(state.labelValues ?? [])];
const labelValues = state.labelValues ? [...state.labelValues] : [];
const selectedOptions = getSelectOptionsFromString(item?.value).map(toOption);
// Remove possible duplicated values
return uniqBy([...selectedOptions, ...labelValues], 'value');
};
return (