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