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

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

* Use different more readable solution

* Update
This commit is contained in:
Ivana Huckova 2022-06-13 15:19:20 +02:00 committed by GitHub
parent 95d49711b2
commit 77bdbe1dea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 (