mirror of
https://github.com/grafana/grafana.git
synced 2025-02-10 23:55:47 -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) {
|
export function LabelFilterItem({ item, defaultOp, onChange, onDelete, onGetLabelNames, onGetLabelValues }: Props) {
|
||||||
const [state, setState] = useState<{
|
const [state, setState] = useState<{
|
||||||
labelNames?: Array<SelectableValue<any>>;
|
labelNames?: SelectableValue[];
|
||||||
labelValues?: Array<SelectableValue<any>>;
|
labelValues?: SelectableValue[];
|
||||||
isLoadingLabelNames?: boolean;
|
isLoadingLabelNames?: boolean;
|
||||||
isLoadingLabelValues?: boolean;
|
isLoadingLabelValues?: boolean;
|
||||||
}>({});
|
}>({});
|
||||||
@ -27,22 +27,18 @@ export function LabelFilterItem({ item, defaultOp, onChange, onDelete, onGetLabe
|
|||||||
return item.op === operators[0].label;
|
return item.op === operators[0].label;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getValue = (item: any) => {
|
const getSelectOptionsFromString = (item?: string): string[] => {
|
||||||
if (item && item.value) {
|
if (item) {
|
||||||
if (item.value.indexOf('|') > 0) {
|
if (item.indexOf('|') > 0) {
|
||||||
return item.value.split('|').map((x: any) => ({ label: x, value: x }));
|
return item.split('|');
|
||||||
}
|
}
|
||||||
return toOption(item.value);
|
return [item];
|
||||||
}
|
}
|
||||||
return null;
|
return [];
|
||||||
};
|
};
|
||||||
|
|
||||||
const getOptions = () => {
|
const getOptions = (): SelectableValue[] => {
|
||||||
if (!state.labelValues && item && item.value && item.value.indexOf('|') > 0) {
|
return [...getSelectOptionsFromString(item?.value).map(toOption), ...(state.labelValues ?? [])];
|
||||||
return getValue(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
return state.labelValues;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -85,7 +81,11 @@ export function LabelFilterItem({ item, defaultOp, onChange, onDelete, onGetLabe
|
|||||||
<Select
|
<Select
|
||||||
inputId="prometheus-dimensions-filter-item-value"
|
inputId="prometheus-dimensions-filter-item-value"
|
||||||
width="auto"
|
width="auto"
|
||||||
value={getValue(item)}
|
value={
|
||||||
|
isMultiSelect()
|
||||||
|
? getSelectOptionsFromString(item?.value).map(toOption)
|
||||||
|
: getSelectOptionsFromString(item?.value).map(toOption)[0]
|
||||||
|
}
|
||||||
allowCustomValue
|
allowCustomValue
|
||||||
onOpenMenu={async () => {
|
onOpenMenu={async () => {
|
||||||
setState({ isLoadingLabelValues: true });
|
setState({ isLoadingLabelValues: true });
|
||||||
|
Loading…
Reference in New Issue
Block a user