Prometheus: Fix disappearing multi values in metric label values (#48127)

This commit is contained in:
Andrej Ocenas 2022-04-29 10:22:49 +02:00 committed by GitHub
parent b92fe0e0f5
commit bd9cec8827
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 });