mirror of
https://github.com/grafana/grafana.git
synced 2025-02-10 15:45:43 -06:00
Prometheus: Fix disappearing multi values in metric label values (#48127)
This commit is contained in:
parent
b92fe0e0f5
commit
bd9cec8827
@ -17,8 +17,8 @@ export interface Props {
|
||||
|
||||
export function LabelFilterItem({ item, defaultOp, onChange, onDelete, onGetLabelNames, onGetLabelValues }: Props) {
|
||||
const [state, setState] = useState<{
|
||||
labelNames?: Array<SelectableValue<any>>;
|
||||
labelValues?: Array<SelectableValue<any>>;
|
||||
labelNames?: SelectableValue[];
|
||||
labelValues?: SelectableValue[];
|
||||
isLoadingLabelNames?: boolean;
|
||||
isLoadingLabelValues?: boolean;
|
||||
}>({});
|
||||
@ -27,22 +27,18 @@ export function LabelFilterItem({ item, defaultOp, onChange, onDelete, onGetLabe
|
||||
return item.op === operators[0].label;
|
||||
};
|
||||
|
||||
const getValue = (item: any) => {
|
||||
if (item && item.value) {
|
||||
if (item.value.indexOf('|') > 0) {
|
||||
return item.value.split('|').map((x: any) => ({ label: x, value: x }));
|
||||
const getSelectOptionsFromString = (item?: string): string[] => {
|
||||
if (item) {
|
||||
if (item.indexOf('|') > 0) {
|
||||
return item.split('|');
|
||||
}
|
||||
return toOption(item.value);
|
||||
return [item];
|
||||
}
|
||||
return null;
|
||||
return [];
|
||||
};
|
||||
|
||||
const getOptions = () => {
|
||||
if (!state.labelValues && item && item.value && item.value.indexOf('|') > 0) {
|
||||
return getValue(item);
|
||||
}
|
||||
|
||||
return state.labelValues;
|
||||
const getOptions = (): SelectableValue[] => {
|
||||
return [...getSelectOptionsFromString(item?.value).map(toOption), ...(state.labelValues ?? [])];
|
||||
};
|
||||
|
||||
return (
|
||||
@ -85,7 +81,11 @@ export function LabelFilterItem({ item, defaultOp, onChange, onDelete, onGetLabe
|
||||
<Select
|
||||
inputId="prometheus-dimensions-filter-item-value"
|
||||
width="auto"
|
||||
value={getValue(item)}
|
||||
value={
|
||||
isMultiSelect()
|
||||
? getSelectOptionsFromString(item?.value).map(toOption)
|
||||
: getSelectOptionsFromString(item?.value).map(toOption)[0]
|
||||
}
|
||||
allowCustomValue
|
||||
onOpenMenu={async () => {
|
||||
setState({ isLoadingLabelValues: true });
|
||||
|
Loading…
Reference in New Issue
Block a user